summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-17 15:55:58 (EDT)
committerEike Stepper2007-08-17 15:55:58 (EDT)
commit9a5843414dda3f911ffd1c5432f79482e3120ffb (patch)
tree5c6d38e9f6f49e3187642af431958dafdaf2e385
parentf58e43265420cf5f8ce2686c87034c3021a916ef (diff)
downloadcdo-9a5843414dda3f911ffd1c5432f79482e3120ffb.zip
cdo-9a5843414dda3f911ffd1c5432f79482e3120ffb.tar.gz
cdo-9a5843414dda3f911ffd1c5432f79482e3120ffb.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java134
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/config/cdo.server.xml16
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java10
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java7
6 files changed, 179 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
index 1f03f0a..75f7a85 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
@@ -17,11 +18,14 @@ import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBField;
import org.eclipse.net4j.db.IDBTable;
import java.sql.Connection;
+import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
/**
* @author Eike Stepper
@@ -65,7 +69,16 @@ public class HorizontalMappingStrategy extends MappingStrategy
public void writeRevision(Connection connection, CDORevisionImpl revision)
{
- revision.getCDOClass();
+ CDOClassImpl cdoClass = revision.getCDOClass();
+ ClassMapping classMapping = getClassMapping(cdoClass);
+ Map<IDBTable, FeatureMapping[]> tables = classMapping.getTables();
+ for (Entry<IDBTable, FeatureMapping[]> entry : tables.entrySet())
+ {
+ IDBTable table = entry.getKey();
+ FeatureMapping[] featureMappings = entry.getValue();
+
+ DBUtil.insertRow(connection, table);
+ }
}
public CDORevision readRevision(Connection connection, CDOID id)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index 9667b7f..818340e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -26,12 +26,18 @@ import org.eclipse.net4j.db.IDBTable;
import org.eclipse.net4j.internal.db.DBSchema;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.ObjectUtil;
+import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.Map.Entry;
/**
* @author Eike Stepper
@@ -46,6 +52,8 @@ public abstract class MappingStrategy implements IMappingStrategy
private IDBSchema schema;
+ private Map<CDOClass, ClassMapping> classMappings = new HashMap();
+
public MappingStrategy()
{
}
@@ -169,6 +177,28 @@ public abstract class MappingStrategy implements IMappingStrategy
*/
protected abstract IDBField map(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables);
+ protected ClassMapping getClassMapping(CDOClass cdoClass)
+ {
+ ClassMapping classMapping = classMappings.get(cdoClass);
+ if (classMapping == null)
+ {
+ classMapping = new ClassMapping(cdoClass);
+ classMappings.put(cdoClass, classMapping);
+ for (CDOFeature feature : cdoClass.getAllFeatures())
+ {
+ DBFeatureInfo featureInfo = (DBFeatureInfo)feature.getServerInfo();
+ IDBField field = featureInfo.getField(cdoClass);
+ if (field != null)
+ {
+ classMapping.addFeatureMapping(feature, field);
+ }
+ }
+ }
+
+ classMapping.sortFeatureMappings();
+ return classMapping;
+ }
+
protected String mangleTableName(String name, int attempt)
{
return store.getDBAdapter().mangleTableName(name, attempt);
@@ -274,4 +304,108 @@ public abstract class MappingStrategy implements IMappingStrategy
throw new ImplementationError("Unrecognized CDOType: " + type);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class ClassMapping
+ {
+ private CDOClass cdoClass;
+
+ private Map<IDBTable, FeatureMapping[]> tables;
+
+ public ClassMapping(CDOClass cdoClass)
+ {
+ this.cdoClass = cdoClass;
+ }
+
+ public CDOClass getCdoClass()
+ {
+ return cdoClass;
+ }
+
+ public Map<IDBTable, FeatureMapping[]> getTables()
+ {
+ return tables;
+ }
+
+ public void addFeatureMapping(CDOFeature feature, IDBField field)
+ {
+ if (tables == null)
+ {
+ tables = new HashMap();
+ }
+
+ IDBTable table = field.getTable();
+ FeatureMapping featureMapping = new FeatureMapping(feature, field);
+ FeatureMapping[] featureMappings = tables.get(table);
+ if (featureMappings == null)
+ {
+ FeatureMapping[] newFeatureMappings = { featureMapping };
+ tables.put(table, newFeatureMappings);
+ }
+ else
+ {
+ FeatureMapping[] newFeatureMappings = ObjectUtil.appendtoArray(featureMappings, featureMapping);
+ tables.put(table, newFeatureMappings);
+ }
+ }
+
+ public void sortFeatureMappings()
+ {
+ for (Entry<IDBTable, FeatureMapping[]> entry : tables.entrySet())
+ {
+ FeatureMapping[] featureMappings = entry.getValue();
+ Arrays.sort(featureMappings);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class FeatureMapping implements Comparable
+ {
+ private CDOFeature feature;
+
+ private IDBField field;
+
+ public FeatureMapping(CDOFeature feature, IDBField field)
+ {
+ this.feature = feature;
+ this.field = field;
+ }
+
+ public CDOFeature getFeature()
+ {
+ return feature;
+ }
+
+ public IDBField getField()
+ {
+ return field;
+ }
+
+ public IDBTable getTable()
+ {
+ return field.getTable();
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("FeatureMapping[{0}, {1}]", feature, field);
+ }
+
+ public int compareTo(Object o)
+ {
+ if (o instanceof FeatureMapping)
+ {
+ FeatureMapping that = (FeatureMapping)o;
+ return new Integer(field.getPosition()).compareTo(that.getField().getPosition());
+ }
+
+ throw new IllegalArgumentException("Not a FeatureMapping: " + o);
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.ui/config/cdo.server.xml b/plugins/org.eclipse.emf.cdo.ui/config/cdo.server.xml
index f6e9644..f1a5969 100644
--- a/plugins/org.eclipse.emf.cdo.ui/config/cdo.server.xml
+++ b/plugins/org.eclipse.emf.cdo.ui/config/cdo.server.xml
@@ -3,10 +3,24 @@
<repository name="repo1">
<store type="db">
+ <!-- mode: OFF | EXPRESS | NORMAL | GUARANTEED -->
+ <invalidationStrategy mode="EXPRESS"/>
+
+ <!-- type: horizontal | vertical | <any user-contributed type> -->
<mappingStrategy type="horizontal">
- <property name="referenceMapping" value="ONE_TABLE_PER_REFERENCE"/>
+ <!-- ONE_TABLE_PER_REFERENCE | ONE_TABLE_PER_CLASS | ONE_TABLE_PER_PACKAGE | ONE_TABLE_PER_REPOSITORY | LIKE_ATTRIBUTES -->
+ <property name="toManyReferences" value="ONE_TABLE_PER_REFERENCE"/>
+
+ <!-- LIKE_ATTRIBUTES | LIKE_TO_MANY_REFERENCES -->
+ <property name="toOneReferences" value="LIKE_ATTRIBUTES"/>
+
+ <!-- MODEL | STRATEGY -->
+ <property name="mappingPrecedence" value="MODEL"/>
</mappingStrategy>
+
+ <!-- name: <any user-contributed DBAdapter name> -->
<dbAdapter name="derby"/>
+
<dataSource
driverClass="org.apache.derby.jdbc.EmbeddedDataSource"
databaseName="C:/temp/cdodb1"
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
index 0875d85..d6a7438 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util;
+import java.lang.reflect.Array;
+
/**
* @author Eike Stepper
*/
@@ -38,4 +40,12 @@ public final class ObjectUtil
return o.hashCode();
}
+
+ public static <T> T[] appendtoArray(T[] array, T... elements)
+ {
+ T[] result = (T[])Array.newInstance(array.getClass().getComponentType(), array.length + elements.length);
+ System.arraycopy(array, 0, result, 0, array.length);
+ System.arraycopy(elements, 0, result, array.length, elements.length);
+ return result;
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
index 2de9e9b..f454cf9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/Pair.java
@@ -19,6 +19,10 @@ public class Pair<T1, T2>
private T2 element2;
+ public Pair()
+ {
+ }
+
public Pair(T1 element1, T2 element2)
{
this.element1 = element1;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
index 32db901..c90f1e9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
@@ -238,13 +238,10 @@ public final class ZIPUtil
final int baseLength = sourceFolder.getAbsolutePath().length();
List<File> list = IOUtil.listBreadthFirst(sourceFolder);
- Collections.sort(list, new Comparator()
+ Collections.sort(list, new Comparator<File>()
{
- public int compare(Object o1, Object o2)
+ public int compare(File f1, File f2)
{
- File f1 = (File)o1;
- File f2 = (File)o2;
-
String path1 = getPath(f1, baseLength);
String path2 = getPath(f2, baseLength);
if (path1.length() == 0) return ORDER_KEEP;