Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-05-20 06:01:48 -0400
committerEike Stepper2013-05-20 06:12:17 -0400
commit75a58509574d64c76cd03c78a8e9969f7e188f00 (patch)
tree86cfe439c1c1abe7494384fb08ef3ef5027b60f3
parent48d2b79743b43ab7f7c15e43d78e2291c88475bc (diff)
downloadcdo-75a58509574d64c76cd03c78a8e9969f7e188f00.tar.gz
cdo-75a58509574d64c76cd03c78a8e9969f7e188f00.tar.xz
cdo-75a58509574d64c76cd03c78a8e9969f7e188f00.zip
[408479] [DB] Provide the concept of a ColumnTypeModifier to influence
ITypeMappings https://bugs.eclipse.org/bugs/show_bug.cgi?id=408479
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/.settings/.api_filters14
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ColumnTypeModifier.java64
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingRegistry.java73
4 files changed, 148 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/.settings/.api_filters b/plugins/org.eclipse.emf.cdo.server.db/.settings/.api_filters
index 223edc88c1..16058e23d1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/.settings/.api_filters
+++ b/plugins/org.eclipse.emf.cdo.server.db/.settings/.api_filters
@@ -1,5 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.emf.cdo.server.db" version="2">
+ <resource path="src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java" type="org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy">
+ <filter id="403767336">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy"/>
+ <message_argument value="PROP_COLUMN_TYPE_MODIFIER"/>
+ </message_arguments>
+ </filter>
+ <filter id="403767336">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy"/>
+ <message_argument value="PROP_TYPE_MAPPING_MODIFIER"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java" type="org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor">
<filter id="574660632">
<message_arguments>
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ColumnTypeModifier.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ColumnTypeModifier.java
new file mode 100644
index 0000000000..f1a250892f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ColumnTypeModifier.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2004-2013 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.db.mapping;
+
+import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping.Provider;
+
+import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+/**
+ * Can modify the column type of a {@link ITypeMapping type mapping} that is created by the {@link ITypeMapping.Registry type mapping registry}.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ */
+public abstract class ColumnTypeModifier
+{
+ public static final ColumnTypeModifier NOOP = new ColumnTypeModifier()
+ {
+ @Override
+ public DBType modify(Provider provider, IMappingStrategy mappingStrategy, EStructuralFeature feature, DBType dbType)
+ {
+ return dbType;
+ }
+ };
+
+ public ColumnTypeModifier()
+ {
+ }
+
+ /**
+ * Can modify the column type of a {@link ITypeMapping type mapping} that is created by the {@link ITypeMapping.Registry type mapping registry}.
+ */
+ public abstract DBType modify(ITypeMapping.Provider provider, IMappingStrategy mappingStrategy,
+ EStructuralFeature feature, DBType dbType);
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class Factory extends org.eclipse.net4j.util.factory.Factory
+ {
+ /**
+ * The Net4j factory product group for column type modifiers.
+ */
+ public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.server.db.columnTypeModifiers";
+
+ public Factory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+
+ public abstract ColumnTypeModifier create(String description) throws ProductCreationException;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
index 151ac2172b..a2b946ea1a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
@@ -97,6 +97,13 @@ public interface IMappingStrategy
public static final String PROP_OBJECT_TYPE_CACHE_SIZE = "objectTypeCacheSize"; //$NON-NLS-1$
/**
+ * Name of a String property that specifies the name of a {@link ColumnTypeModifier column type modifier}.
+ *
+ * @since 4.2
+ */
+ public static final String PROP_COLUMN_TYPE_MODIFIER = "columnTypeModifier"; //$NON-NLS-1$
+
+ /**
* @return the store, this MappingStrategy instance belongs to.
*/
public IDBStore getStore();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingRegistry.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingRegistry.java
index 52d14f83b8..dc1c3bb354 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingRegistry.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMappingRegistry.java
@@ -14,6 +14,7 @@ package org.eclipse.emf.cdo.server.internal.db.mapping;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.etypes.EtypesPackage;
import org.eclipse.emf.cdo.server.db.IIDHandler;
+import org.eclipse.emf.cdo.server.db.mapping.ColumnTypeModifier;
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;
@@ -25,6 +26,7 @@ import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.container.ContainerEvent;
+import org.eclipse.net4j.util.container.FactoryNotFoundException;
import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.container.IContainerDelta.Kind;
import org.eclipse.net4j.util.container.IManagedContainer;
@@ -33,6 +35,7 @@ import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.factory.IFactory;
import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.factory.ProductCreationException;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.ecore.EClass;
@@ -110,6 +113,18 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
populator.connect();
}
+ public void registerColumnTypeModifier(String factoryType, final ColumnTypeModifier columnTypeModifier)
+ {
+ getContainer().registerFactory(new ColumnTypeModifier.Factory(factoryType)
+ {
+ @Override
+ public ColumnTypeModifier create(String description) throws ProductCreationException
+ {
+ return columnTypeModifier;
+ }
+ });
+ }
+
/**
* Register builtin type mapping factories
*/
@@ -241,8 +256,7 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
}
else
{
- IDBAdapter dbAdapter = mappingStrategy.getStore().getDBAdapter();
- DBType dbType = getDBType(feature, dbAdapter);
+ DBType dbType = getDBType(mappingStrategy, feature);
ITypeMapping.Descriptor descriptor = null;
@@ -280,6 +294,7 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
typeMapping.setMappingStrategy(mappingStrategy);
typeMapping.setFeature(feature);
+
return typeMapping;
}
@@ -310,23 +325,60 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
return EcorePackage.eINSTANCE.getEDataType();
}
- private DBType getDBType(EStructuralFeature feature, IDBAdapter dbAdapter)
+ private DBType getDBType(IMappingStrategy mappingStrategy, EStructuralFeature feature)
{
+ DBType dbType;
+
String typeKeyword = DBAnnotation.COLUMN_TYPE.getValue(feature);
if (typeKeyword != null)
{
- DBType dbType = DBType.getTypeByKeyword(typeKeyword);
+ dbType = DBType.getTypeByKeyword(typeKeyword);
if (dbType == null)
{
throw new IllegalArgumentException("Unsupported columnType (" + typeKeyword + ") annotation of feature "
+ feature.getName());
}
+ }
+ else
+ {
+ // No annotation present - lookup default DB type.
+ IDBAdapter dbAdapter = mappingStrategy.getStore().getDBAdapter();
+ dbType = getDefaultDBType(getEType(feature), dbAdapter);
+ }
- return dbType;
+ ColumnTypeModifier columnTypeModifier = getColumnTypeModifier(mappingStrategy);
+ if (columnTypeModifier != null)
+ {
+ dbType = columnTypeModifier.modify(this, mappingStrategy, feature, dbType);
+ }
+
+ return dbType;
+ }
+
+ private ColumnTypeModifier getColumnTypeModifier(IMappingStrategy mappingStrategy)
+ {
+ String factoryType = mappingStrategy.getProperties().get(IMappingStrategy.PROP_COLUMN_TYPE_MODIFIER);
+ if (factoryType == null)
+ {
+ factoryType = mappingStrategy.getStore().getDBAdapter().getName();
}
- // No annotation present - lookup default DB type.
- return getDefaultDBType(getEType(feature), dbAdapter);
+ ColumnTypeModifier columnTypeModifier = null;
+
+ try
+ {
+ columnTypeModifier = (ColumnTypeModifier)IPluginContainer.INSTANCE.getElement(
+ ColumnTypeModifier.Factory.PRODUCT_GROUP, factoryType, null);
+ }
+ catch (FactoryNotFoundException ex)
+ {
+ //$FALL-THROUGH$
+ }
+ catch (ProductCreationException ex)
+ {
+ //$FALL-THROUGH$
+ }
+ return columnTypeModifier;
}
private DBType getDefaultDBType(EClassifier type, IDBAdapter dbAdapter)
@@ -395,10 +447,10 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
private void populateTypeMappingRegistry()
{
- // get available factory types
+ // Get available factory types
Set<String> factoryTypes = container.getFactoryTypes(ITypeMapping.Factory.PRODUCT_GROUP);
- // parse the descriptor of each factory type
+ // Parse the descriptor of each factory type
for (String factoryType : factoryTypes)
{
registerFactoryType(factoryType);
@@ -430,7 +482,8 @@ public class TypeMappingRegistry implements ITypeMapping.Registry, ITypeMapping.
for (IContainerDelta<Map.Entry<IFactoryKey, IFactory>> delta : ev.getDeltas())
{
IFactoryKey key = delta.getElement().getKey();
- if (key.getProductGroup().equals(ITypeMapping.Factory.PRODUCT_GROUP))
+ String productGroup = key.getProductGroup();
+ if (productGroup.equals(ITypeMapping.Factory.PRODUCT_GROUP))
{
if (delta.getKind() == Kind.ADDED)
{

Back to the top