summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-07-14 09:21:10 (EDT)
committerStefan Winkler2009-07-14 09:21:10 (EDT)
commit062fba4f5136988e029900dbebc8f0d7a1784066 (patch)
tree9d969eb1e279a58cb9b85bfd0c4fb21a63d07e63
parent72f24679f7083bd8be80f65496a8992b5e739ff0 (diff)
downloadcdo-062fba4f5136988e029900dbebc8f0d7a1784066.zip
cdo-062fba4f5136988e029900dbebc8f0d7a1784066.tar.gz
cdo-062fba4f5136988e029900dbebc8f0d7a1784066.tar.bz2
[282976] [DB] Influence Mappings through EAnnotations
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282976
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java60
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java59
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java67
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java89
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingFactory.java301
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java188
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java10
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java30
10 files changed, 643 insertions, 184 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
index 247b091..be5322b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
@@ -4,19 +4,19 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - bug 271444: [DB] Multiple refactorings
+ * Kai Schlamp - bug 282976: [DB] Influence Mappings through EAnnotations
+ * Stefan Winkler - bug 282976: [DB] Influence Mappings through EAnnotations
*/
package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EPackage;
@@ -63,10 +63,10 @@ public interface IMetaDataManager
/**
* Reads information about package units present in the database.
* @param connection the DB connection to read from.
- * @return a collection of package unit information records which can be
+ * @return a collection of package unit information records which can be
* passed to {@link IMetaDataManager#loadPackageUnit(Connection, InternalCDOPackageUnit))
* in order to read the EPackage.
- *
+ *
* @since 2.0
*/
public Collection<InternalCDOPackageUnit> readPackageUnits(Connection connection);
@@ -83,14 +83,4 @@ public interface IMetaDataManager
* @since 2.0
*/
public void writePackageUnits(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);
-
- /**
- * Get the DB type associated with the given {@link EClassifier}.
- *
- * @param eType
- * the type to look up.
- * @return the {@link DBType} of the given {@link EClassifier}.
- * @since 2.0
- */
- public DBType getDBType(EClassifier eType);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java
new file mode 100644
index 0000000..d33942a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kai Schlamp - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.server.internal.db;
+
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * @author Kai Schlamp
+ */
+public enum DBAnnotation
+{
+ TABLE_NAME("tableName"), //
+ COLUMN_NAME("columnName"), //
+ COLUMN_TYPE("columnType"), //
+ COLUMN_LENGTH("columnLength");
+
+ public final static String SOURCE_URI = "http://www.eclipse.org/CDO/DBStore";
+
+ private String keyword;
+
+ private DBAnnotation(String keyword)
+ {
+ this.keyword = keyword;
+ }
+
+ public String getKeyword()
+ {
+ return keyword == null ? super.toString() : keyword;
+ }
+
+ /**
+ * @return A non-empty string or <code>null</code>.
+ */
+ public String getValue(EModelElement element)
+ {
+ String value = EcoreUtil.getAnnotation(element, SOURCE_URI, keyword);
+ if (value != null && value.length() == 0)
+ {
+ return null;
+ }
+
+ return value;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getKeyword();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
index de62e0c..dee1d5c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
@@ -4,10 +4,12 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - bug 271444: [DB] Multiple refactorings
+ * Kai Schlamp - bug 282976: [DB] Influence Mappings through EAnnotations
+ * Stefan Winkler - bug 282976: [DB] Influence Mappings through EAnnotations
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -27,7 +29,6 @@ import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.net4j.db.DBException;
-import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBRowHandler;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
@@ -35,12 +36,8 @@ import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
import java.sql.Connection;
@@ -60,37 +57,10 @@ public class MetaDataManager extends Lifecycle implements IMetaDataManager
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, MetaDataManager.class);
- private static Map<EClassifier, DBType> typeMap = new HashMap<EClassifier, DBType>();
-
private static final boolean ZIP_PACKAGE_BYTES = true;
private IDBStore store;
- static
- {
- typeMap.put(EcorePackage.eINSTANCE.getEDate(), DBType.TIMESTAMP);
- typeMap.put(EcorePackage.eINSTANCE.getEString(), DBType.VARCHAR);
- typeMap.put(EcorePackage.eINSTANCE.getEByteArray(), DBType.BLOB);
-
- typeMap.put(EcorePackage.eINSTANCE.getEBoolean(), DBType.BOOLEAN);
- typeMap.put(EcorePackage.eINSTANCE.getEByte(), DBType.SMALLINT);
- typeMap.put(EcorePackage.eINSTANCE.getEChar(), DBType.CHAR);
- typeMap.put(EcorePackage.eINSTANCE.getEDouble(), DBType.DOUBLE);
- typeMap.put(EcorePackage.eINSTANCE.getEFloat(), DBType.FLOAT);
- typeMap.put(EcorePackage.eINSTANCE.getEInt(), DBType.INTEGER);
- typeMap.put(EcorePackage.eINSTANCE.getELong(), DBType.BIGINT);
- typeMap.put(EcorePackage.eINSTANCE.getEShort(), DBType.SMALLINT);
-
- typeMap.put(EcorePackage.eINSTANCE.getEBooleanObject(), DBType.BOOLEAN);
- typeMap.put(EcorePackage.eINSTANCE.getEByteObject(), DBType.SMALLINT);
- typeMap.put(EcorePackage.eINSTANCE.getECharacterObject(), DBType.CHAR);
- typeMap.put(EcorePackage.eINSTANCE.getEDoubleObject(), DBType.DOUBLE);
- typeMap.put(EcorePackage.eINSTANCE.getEFloatObject(), DBType.FLOAT);
- typeMap.put(EcorePackage.eINSTANCE.getEIntegerObject(), DBType.INTEGER);
- typeMap.put(EcorePackage.eINSTANCE.getELongObject(), DBType.BIGINT);
- typeMap.put(EcorePackage.eINSTANCE.getEShortObject(), DBType.SMALLINT);
- }
-
public MetaDataManager(IDBStore store)
{
this.store = store;
@@ -193,27 +163,6 @@ public class MetaDataManager extends Lifecycle implements IMetaDataManager
}
}
- public DBType getDBType(EClassifier type)
- {
- if (type instanceof EClass)
- {
- return DBType.BIGINT;
- }
-
- if (type instanceof EEnum)
- {
- return DBType.INTEGER;
- }
-
- DBType dbType = typeMap.get(type);
- if (dbType != null)
- {
- return dbType;
- }
-
- return DBType.VARCHAR;
- }
-
protected IDBStore getStore()
{
return store;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index 689590d..460bfff 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -9,13 +9,13 @@
* Eike Stepper - initial API and implementation
* Stefan Winkler - major refactoring
* Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - 282976: [DB] Influence Mappings through EAnnotations
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
-import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
import org.eclipse.emf.cdo.server.db.IDBStore;
@@ -385,70 +385,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
public ITypeMapping createValueMapping(EStructuralFeature feature)
{
- CDOType type = CDOModelUtil.getType(feature);
-
- if (type == CDOType.BOOLEAN || type == CDOType.BOOLEAN_OBJECT)
- {
- return new TypeMapping.TMBoolean(this, feature);
- }
- else if (type == CDOType.BYTE || type == CDOType.BYTE_OBJECT)
- {
- return new TypeMapping.TMByte(this, feature);
- }
- else if (type == CDOType.CHAR || type == CDOType.CHARACTER_OBJECT)
- {
- return new TypeMapping.TMCharacter(this, feature);
- }
- else if (type == CDOType.DATE)
- {
- return new TypeMapping.TMDate(this, feature);
- }
- else if (type == CDOType.DOUBLE || type == CDOType.DOUBLE_OBJECT)
- {
- return new TypeMapping.TMDouble(this, feature);
- }
- else if (type == CDOType.FLOAT || type == CDOType.FLOAT_OBJECT)
- {
- return new TypeMapping.TMFloat(this, feature);
- }
- else if (type == CDOType.INT || type == CDOType.INTEGER_OBJECT)
- {
- return new TypeMapping.TMInteger(this, feature);
- }
- else if (type == CDOType.LONG || type == CDOType.LONG_OBJECT)
- {
- return new TypeMapping.TMLong(this, feature);
- }
- else if (type == CDOType.OBJECT)
- {
- return new TypeMapping.TMObject(this, feature);
- }
- else if (type == CDOType.SHORT || type == CDOType.SHORT_OBJECT)
- {
- return new TypeMapping.TMShort(this, feature);
- }
- else if (type == CDOType.ENUM)
- {
- return new TypeMapping.TMEnum(this, feature);
- }
- else if (type == CDOType.STRING || type == CDOType.CUSTOM)
- {
- return new TypeMapping.TMString(this, feature);
- }
- else if (type == CDOType.BIG_INTEGER)
- {
- return new TypeMapping.TMBigInteger(this, feature);
- }
- else if (type == CDOType.BIG_DECIMAL)
- {
- return new TypeMapping.TMBigDecimal(this, feature);
- }
- else if (type == CDOType.BYTE_ARRAY)
- {
- return new TypeMapping.TMBytes(this, feature);
- }
-
- throw new ImplementationError("Unrecognized CDOType: " + type); //$NON-NLS-1$
+ return TypeMappingFactory.createTypeMapping(this, feature);
}
public final IListMapping createListMapping(EClass containingClass, EStructuralFeature feature)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
index a1c7c0d..9d72898 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
@@ -7,8 +7,10 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
- * Stefan Winkler - 275303: [DB] DBStore does not handle BIG_INTEGER and BIG_DECIMAL
+ * Stefan Winkler - bug 271444: [DB] Multiple refactorings
+ * Stefan Winkler - bug 275303: [DB] DBStore does not handle BIG_INTEGER and BIG_DECIMAL
+ * Kai Schlamp - bug 282976: [DB] Influence Mappings through EAnnotations
+ * Stefan Winkler - bug 282976: [DB] Influence Mappings through EAnnotations
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
@@ -17,7 +19,9 @@ import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
+import org.eclipse.emf.cdo.server.internal.db.DBAnnotation;
import org.eclipse.emf.cdo.server.internal.db.MetaDataManager;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBType;
@@ -48,6 +52,8 @@ public abstract class TypeMapping implements ITypeMapping
private IDBField field;
+ private DBType dbType;
+
/**
* Create a new type mapping
*
@@ -56,10 +62,11 @@ public abstract class TypeMapping implements ITypeMapping
* @param feature
* the feature to be mapped.
*/
- public TypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature)
+ protected TypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
{
this.mappingStrategy = mappingStrategy;
this.feature = feature;
+ dbType = type;
}
public final void setValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision revision)
@@ -143,13 +150,27 @@ public abstract class TypeMapping implements ITypeMapping
protected DBType getDBType()
{
- return mappingStrategy.getStore().getMetaDataManager().getDBType(feature.getEType());
+ return dbType;
}
protected int getDBLength(DBType type)
{
+ String value = DBAnnotation.COLUMN_LENGTH.getValue(feature);
+ if (value != null)
+ {
+ try
+ {
+ return Integer.parseInt(value);
+ }
+ catch (NumberFormatException e)
+ {
+ OM.LOG.error("Illegal columnLength annotation of feature " + feature.getName());
+ }
+ }
+
// TODO: implement DBAdapter.getDBLength
// mappingStrategy.getStore().getDBAdapter().getDBLength(type);
+ // which should then return the correct default field length for the db type
return type == DBType.VARCHAR ? 32672 : IDBField.DEFAULT;
}
@@ -160,9 +181,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMEnum extends TypeMapping
{
- public TMEnum(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMEnum(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -187,9 +208,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMString extends TypeMapping
{
- public TMString(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMString(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -204,9 +225,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMShort extends TypeMapping
{
- public TMShort(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMShort(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -222,9 +243,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMObject extends TypeMapping
{
- public TMObject(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMObject(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -251,9 +272,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMLong extends TypeMapping
{
- public TMLong(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMLong(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -268,9 +289,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMInteger extends TypeMapping
{
- public TMInteger(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMInteger(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -285,9 +306,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMFloat extends TypeMapping
{
- public TMFloat(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMFloat(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -302,9 +323,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMDouble extends TypeMapping
{
- public TMDouble(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMDouble(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -319,9 +340,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMDate extends TypeMapping
{
- public TMDate(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMDate(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -342,9 +363,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMCharacter extends TypeMapping
{
- public TMCharacter(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMCharacter(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -371,9 +392,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMByte extends TypeMapping
{
- public TMByte(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMByte(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -388,9 +409,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMBytes extends TypeMapping
{
- public TMBytes(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMBytes(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -405,9 +426,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMBoolean extends TypeMapping
{
- public TMBoolean(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMBoolean(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -422,9 +443,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMBigInteger extends TypeMapping
{
- public TMBigInteger(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMBigInteger(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
@@ -452,9 +473,9 @@ public abstract class TypeMapping implements ITypeMapping
*/
public static class TMBigDecimal extends TypeMapping
{
- public TMBigDecimal(IMappingStrategy strategy, EStructuralFeature feature)
+ public TMBigDecimal(IMappingStrategy strategy, EStructuralFeature feature, DBType type)
{
- super(strategy, feature);
+ super(strategy, feature, type);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingFactory.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingFactory.java
new file mode 100644
index 0000000..7aa6360
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingFactory.java
@@ -0,0 +1,301 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Winkler - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.server.internal.db.mapping;
+
+import org.eclipse.emf.cdo.common.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.model.CDOType;
+import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
+import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
+import org.eclipse.emf.cdo.server.internal.db.DBAnnotation;
+
+import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.util.collection.Pair;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Stefan Winkler
+ */
+public enum TypeMappingFactory
+{
+ BOOLEAN_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMBoolean(mappingStrategy, feature, type);
+ }
+ },
+
+ BYTE_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMByte(mappingStrategy, feature, type);
+ }
+ },
+
+ CHARACTER_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMCharacter(mappingStrategy, feature, type);
+ }
+ },
+
+ DATE_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMDate(mappingStrategy, feature, type);
+ }
+ },
+
+ DOUBLE_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMDouble(mappingStrategy, feature, type);
+ }
+ },
+
+ FLOAT_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMFloat(mappingStrategy, feature, type);
+ }
+ },
+
+ INT_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMInteger(mappingStrategy, feature, type);
+ }
+ },
+
+ LONG_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMLong(mappingStrategy, feature, type);
+ }
+ },
+
+ OBJECT_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMObject(mappingStrategy, feature, type);
+ }
+ },
+
+ SHORT_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMShort(mappingStrategy, feature, type);
+ }
+ },
+
+ ENUM_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMEnum(mappingStrategy, feature, type);
+ }
+ },
+
+ STRING_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMString(mappingStrategy, feature, type);
+ }
+ },
+
+ BIG_INT_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMBigInteger(mappingStrategy, feature, type);
+ }
+ },
+
+ BIG_DECIMAL_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMBigDecimal(mappingStrategy, feature, type);
+ }
+ },
+
+ BYTES_MAPPING
+ {
+ @Override
+ public ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType type)
+ {
+ return new TypeMapping.TMBytes(mappingStrategy, feature, type);
+ }
+ };
+
+ private static Map<EClassifier, DBType> defaultTypeMap = new HashMap<EClassifier, DBType>();
+
+ private static Map<Pair<CDOType, DBType>, TypeMappingFactory> mappingTable = new HashMap<Pair<CDOType, DBType>, TypeMappingFactory>();
+
+ static
+ {
+ /* --- initialize default types --- */
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEDate(), DBType.TIMESTAMP);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEString(), DBType.VARCHAR);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEByteArray(), DBType.BLOB);
+
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEBoolean(), DBType.BOOLEAN);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEByte(), DBType.SMALLINT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEChar(), DBType.CHAR);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEDouble(), DBType.DOUBLE);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEFloat(), DBType.FLOAT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEInt(), DBType.INTEGER);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getELong(), DBType.BIGINT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEShort(), DBType.SMALLINT);
+
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEBooleanObject(), DBType.BOOLEAN);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEByteObject(), DBType.SMALLINT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getECharacterObject(), DBType.CHAR);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEDoubleObject(), DBType.DOUBLE);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEFloatObject(), DBType.FLOAT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEIntegerObject(), DBType.INTEGER);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getELongObject(), DBType.BIGINT);
+ defaultTypeMap.put(EcorePackage.eINSTANCE.getEShortObject(), DBType.SMALLINT);
+
+ /* --- register type mappings --- */
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BIG_INTEGER, DBType.VARCHAR), BIG_INT_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BIG_DECIMAL, DBType.VARCHAR), BIG_DECIMAL_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BOOLEAN, DBType.BOOLEAN), BOOLEAN_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BOOLEAN_OBJECT, DBType.BOOLEAN), BOOLEAN_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BYTE, DBType.SMALLINT), BYTE_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BYTE_OBJECT, DBType.SMALLINT), BYTE_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.BYTE_ARRAY, DBType.BLOB), BYTES_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.CHAR, DBType.CHAR), CHARACTER_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.CHARACTER_OBJECT, DBType.CHAR), CHARACTER_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.DATE, DBType.TIMESTAMP), DATE_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.DOUBLE, DBType.DOUBLE), DOUBLE_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.DOUBLE_OBJECT, DBType.DOUBLE), DOUBLE_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.ENUM, DBType.INTEGER), ENUM_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.FLOAT, DBType.FLOAT), FLOAT_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.FLOAT_OBJECT, DBType.FLOAT), FLOAT_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.INT, DBType.INTEGER), INT_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.INTEGER_OBJECT, DBType.INTEGER), INT_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.LONG, DBType.BIGINT), LONG_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.LONG_OBJECT, DBType.BIGINT), LONG_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.OBJECT, DBType.BIGINT), OBJECT_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.SHORT, DBType.SMALLINT), SHORT_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.SHORT_OBJECT, DBType.SMALLINT), SHORT_MAPPING);
+
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.STRING, DBType.VARCHAR), STRING_MAPPING);
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.STRING, DBType.CLOB), STRING_MAPPING);
+
+ // preliminary
+ mappingTable.put(new Pair<CDOType, DBType>(CDOType.FEATURE_MAP_ENTRY, DBType.VARCHAR), STRING_MAPPING);
+ }
+
+ protected abstract ITypeMapping doCreateTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature,
+ DBType type);
+
+ public static ITypeMapping createTypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature)
+ {
+ CDOType cdoType = CDOModelUtil.getType(feature);
+ DBType dbType = getDBType(feature);
+
+ TypeMappingFactory concreteFactory = mappingTable.get(new Pair<CDOType, DBType>(cdoType, dbType));
+ if (concreteFactory == null)
+ {
+ throw new IllegalArgumentException("No suitable mapping found from EMF type " + cdoType.getName()
+ + " to DB type " + dbType.getClass().getSimpleName());
+ }
+
+ return concreteFactory.doCreateTypeMapping(mappingStrategy, feature, dbType);
+ }
+
+ private static DBType getDBType(EStructuralFeature feature)
+ {
+ String typeKeyword = DBAnnotation.COLUMN_TYPE.getValue(feature);
+ if (typeKeyword != null)
+ {
+ DBType dbType = DBType.getTypeByKeyword(typeKeyword);
+ if (dbType == null)
+ {
+ throw new IllegalArgumentException("Unsupported columnType (" + typeKeyword + ") annotation of feature "
+ + feature.getName());
+ }
+
+ return dbType;
+ }
+
+ // no annotation present - lookup default DB type.
+ return getDefaultDBType(feature.getEType());
+ }
+
+ private static DBType getDefaultDBType(EClassifier type)
+ {
+ if (type instanceof EClass)
+ {
+ return DBType.BIGINT;
+ }
+
+ if (type instanceof EEnum)
+ {
+ return DBType.INTEGER;
+ }
+
+ DBType dbType = defaultTypeMap.get(type);
+ if (dbType != null)
+ {
+ return dbType;
+ }
+
+ return DBType.VARCHAR;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java
new file mode 100644
index 0000000..250e40c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java
@@ -0,0 +1,188 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kai Schlamp - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.tests.db;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.db.verifier.DBStoreVerifier;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+
+import junit.framework.Assert;
+
+/**
+ * Test different DB annotations.
+ *
+ * @author Kai Schlamp
+ */
+public class DBAnnotationsTest extends AbstractCDOTest
+{
+ public void testLengthAnnotationPositive() throws Exception
+ {
+ msg("Opening session");
+ EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ addLengthAnnotation(model1, "8");
+ CDOSession session = openSession(model1);
+
+ disableConsole();
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Commit a product that has a name with an allowed string length.");
+ EClass eClass = (EClass)model1.getEClassifier("Product1");
+ EObject product = model1.getEFactoryInstance().create(eClass);
+ product.eSet(eClass.getEStructuralFeature("name"), "01234567");
+
+ resource.getContents().add(product);
+ transaction.commit();
+ }
+
+ public void testLengthAnnotationNegative() throws Exception
+ {
+ msg("Opening session");
+ EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ addLengthAnnotation(model1, "8");
+ CDOSession session = openSession(model1);
+
+ disableConsole();
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Commit a product that has a name with an invalid string length.");
+ EClass eClass = (EClass)model1.getEClassifier("Product1");
+ EObject product = model1.getEFactoryInstance().create(eClass);
+ product.eSet(eClass.getEStructuralFeature("name"), "012345678");
+
+ resource.getContents().add(product);
+
+ try
+ {
+ transaction.commit();
+ fail("Committing too long data did not result in an exception");
+ }
+ catch (Exception success)
+ {
+ }
+ }
+
+ public void testLengthAnnotationByMetaData()
+ {
+ msg("Opening session");
+ EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ addLengthAnnotation(model1, "8");
+ CDOSession session = openSession(model1);
+
+ disableConsole();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Commit a product.");
+ EClass eClass = (EClass)model1.getEClassifier("Product1");
+ EObject product = model1.getEFactoryInstance().create(eClass);
+ resource.getContents().add(product);
+
+ transaction.commit();
+
+ msg("Check if column size was correctly set.");
+ new DBStoreVerifier(getRepository())
+ {
+ @Override
+ protected void doVerify() throws Exception
+ {
+ DatabaseMetaData metaData = getStatement().getConnection().getMetaData();
+ ResultSet rset = metaData.getColumns(null, null, "PRODUCT1", "NAME");
+ rset.next();
+ Assert.assertEquals("8", rset.getString(7));
+ }
+ }.verify();
+ }
+
+ public void testTypeAnnotationByMetaData()
+ {
+ msg("Opening session");
+ EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ addTypeAnnotation(model1, "CLOB");
+ CDOSession session = openSession(model1);
+
+ disableConsole();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Commit a category.");
+ EClass eClass = (EClass)model1.getEClassifier("Category");
+ EObject category = model1.getEFactoryInstance().create(eClass);
+
+ resource.getContents().add(category);
+ transaction.commit();
+
+ msg("Check if column type was correctly set.");
+ new DBStoreVerifier(getRepository())
+ {
+ @Override
+ protected void doVerify() throws Exception
+ {
+ DatabaseMetaData metaData = getStatement().getConnection().getMetaData();
+ ResultSet rset = metaData.getColumns(null, null, "CATEGORY", "NAME");
+ rset.next();
+ Assert.assertEquals("CLOB", rset.getString(6));
+ }
+ }.verify();
+ }
+
+ private void addLengthAnnotation(EPackage model1, String value)
+ {
+ EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ annotation.setSource("http://www.eclipse.org/CDO/DBStore");
+ annotation.getDetails().put("columnLength", value);
+
+ EClass product1 = (EClass)model1.getEClassifier("Product1");
+ EStructuralFeature element = product1.getEStructuralFeature(Model1Package.PRODUCT1__NAME);
+ element.getEAnnotations().add(annotation);
+ }
+
+ private void addTypeAnnotation(EPackage model1, String value)
+ {
+ EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ annotation.setSource("http://www.eclipse.org/CDO/DBStore");
+ annotation.getDetails().put("columnType", value);
+
+ EClass category = (EClass)model1.getEClassifier("Category");
+ EStructuralFeature element = category.getEStructuralFeature(Model1Package.CATEGORY__NAME);
+ element.getEAnnotations().add(annotation);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBConfigs.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBConfigs.java
index a00b400..9b1fc20 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBConfigs.java
@@ -26,5 +26,6 @@ public abstract class DBConfigs extends AllTestsAllConfigs
super.initTestClasses(testClasses);
testClasses.add(DBStoreTest.class);
testClasses.add(SQLQueryTest.class);
+ testClasses.add(DBAnnotationsTest.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
index f0d0525..0e64583 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBStoreTest.java
@@ -112,23 +112,23 @@ public class DBStoreTest extends AbstractCDOTest
CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.getOrCreateResource("/test");
-
+
Company e = Model1Factory.eINSTANCE.createCompany();
e.setName(s);
// this escapes only the string!
// resulting string only contains one backslash
-
+
resource.getContents().add(e);
transaction.commit();
-
+
transaction.close();
session.close();
clearCache(getRepository().getRevisionManager());
-
+
session = openModel1Session();
CDOView view = session.openView();
resource = view.getResource("/test");
-
+
assertEquals(1, resource.getContents().size());
e = (Company)resource.getContents().get(0);
assertEquals(s, e.getName());
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
index 9d37e16..37a0b1f 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Kai Schlamp - bug 282976: [DB] Influence Mappings through EAnnotations
*/
package org.eclipse.net4j.db;
@@ -31,6 +32,8 @@ public enum DBType
CHAR(1), //
VARCHAR(12), //
LONGVARCHAR(-1, "LONG VARCHAR"), // //$NON-NLS-1$
+ CLOB(2005), //
+
DATE(91)
{
@Override
@@ -102,15 +105,6 @@ public enum DBType
{
throw new UnsupportedOperationException();
}
- }, //
-
- CLOB(2005)
- {
- @Override
- public void appendValue(StringBuilder builder, Object value)
- {
- throw new UnsupportedOperationException();
- }
}; //
private int code;
@@ -164,4 +158,22 @@ public enum DBType
}
}
}
+
+ /**
+ * @since 3.0
+ */
+ public static DBType getTypeByKeyword(String keyword)
+ {
+ DBType[] values = DBType.values();
+ for (int i = 0; i < values.length; i++)
+ {
+ DBType dbType = values[i];
+ if (dbType.getKeyword().equalsIgnoreCase(keyword))
+ {
+ return dbType;
+ }
+ }
+
+ return null;
+ }
}