summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-20 04:03:51 (EDT)
committerEike Stepper2007-08-20 04:03:51 (EDT)
commit4803976e13512affb0ef81d18198444c66458f66 (patch)
tree28d98ad48e38cfacec87260759633e35a0fa929c
parentbe5d9a1ef236432aff0ffcd96b52f1e4d0b2f9f6 (diff)
downloadcdo-4803976e13512affb0ef81d18198444c66458f66.zip
cdo-4803976e13512affb0ef81d18198444c66458f66.tar.gz
cdo-4803976e13512affb0ef81d18198444c66458f66.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java145
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java5
3 files changed, 148 insertions, 17 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 b90f2bc..335499f 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
@@ -17,9 +17,13 @@ import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.server.db.ToManyReferenceMapping;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBField;
import org.eclipse.net4j.db.IDBTable;
@@ -27,6 +31,7 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import java.sql.Connection;
import java.sql.Date;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
@@ -38,6 +43,8 @@ public class HorizontalMappingStrategy extends MappingStrategy
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HorizontalMappingStrategy.class);
+ private Map<Object, IDBTable> referenceTables = new HashMap();
+
public HorizontalMappingStrategy()
{
}
@@ -48,31 +55,149 @@ public class HorizontalMappingStrategy extends MappingStrategy
}
@Override
- protected IDBTable map(CDOClass cdoClass, Set<IDBTable> affectedTables)
+ protected IDBTable mapClass(CDOClass cdoClass, Set<IDBTable> affectedTables)
{
- if (cdoClass.isAbstract())
- {
- return null;
- }
-
- IDBTable table = addTable(cdoClass);
- initTable(table, true);
- return table;
+ return null;
}
@Override
- protected IDBField map(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables)
+ protected IDBField mapFeature(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables)
{
if (cdoClass.isAbstract())
{
return null;
}
+ if (cdoFeature.isReference())
+ {
+ if (cdoFeature.isMany())
+ {
+ return mapReferenceMany(cdoClass, cdoFeature, getToManyReferenceMapping());
+ }
+ else
+ {
+ switch (getToOneReferenceMapping())
+ {
+ case LIKE_ATTRIBUTES:
+ return mapAttribute(cdoClass, cdoFeature);
+ case LIKE_TO_MANY_REFERENCES:
+ return mapReferenceMany(cdoClass, cdoFeature, getToManyReferenceMapping());
+ default:
+ throw new IllegalArgumentException("Invalid mapping: " + getToOneReferenceMapping());
+ }
+ }
+ }
+ else
+ {
+ if (cdoFeature.isMany())
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ return mapAttribute(cdoClass, cdoFeature);
+ }
+ }
+
+ protected IDBField mapAttribute(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
DBClassInfo classInfo = (DBClassInfo)cdoClass.getServerInfo();
IDBTable table = classInfo.getTable();
+ if (table == null)
+ {
+ table = addTable(cdoClass);
+ initTable(table, true);
+ }
+
return addField(cdoFeature, table);
}
+ protected IDBField mapReferenceMany(CDOClass cdoClass, CDOFeature cdoFeature, ToManyReferenceMapping mapping)
+ {
+ switch (mapping)
+ {
+ case ONE_TABLE_PER_REFERENCE:
+ return mapReference(cdoClass, cdoFeature);
+ case ONE_TABLE_PER_CLASS:
+ return mapReferencePerClass(cdoClass);
+ case ONE_TABLE_PER_PACKAGE:
+ return mapReferencePerPackage(cdoClass.getContainingPackage());
+ case ONE_TABLE_PER_REPOSITORY:
+ return mapReferencePerRepository(getStore().getRepository());
+ case LIKE_ATTRIBUTES:
+ return mapReferenceSerialized(cdoClass, cdoFeature);
+ default:
+ throw new IllegalArgumentException("Invalid mapping: " + mapping);
+ }
+ }
+
+ protected IDBField mapReference(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ IDBTable table = referenceTables.get(cdoFeature);
+ if (table == null)
+ {
+ table = addReferenceTable(cdoClass.getName() + "_" + cdoFeature.getName() + "_refs", false);
+ referenceTables.put(cdoFeature, table);
+ }
+
+ return table.getField(0);
+ }
+
+ protected IDBField mapReferencePerClass(CDOClass cdoClass)
+ {
+ IDBTable table = referenceTables.get(cdoClass);
+ if (table == null)
+ {
+ table = addReferenceTable(cdoClass.getName() + "_refs", true);
+ referenceTables.put(cdoClass, table);
+ }
+
+ return table.getField(0);
+ }
+
+ protected IDBField mapReferencePerPackage(CDOPackage cdoPackage)
+ {
+ IDBTable table = referenceTables.get(cdoPackage);
+ if (table == null)
+ {
+ table = addReferenceTable(cdoPackage.getName() + "_refs", true);
+ referenceTables.put(cdoPackage, table);
+ }
+
+ return table.getField(0);
+ }
+
+ protected IDBField mapReferencePerRepository(IRepository repository)
+ {
+ IDBTable table = referenceTables.get(repository);
+ if (table == null)
+ {
+ table = addReferenceTable(repository.getName() + "_refs", true);
+ referenceTables.put(repository, table);
+ }
+
+ return table.getField(0);
+ }
+
+ protected IDBField mapReferenceSerialized(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ // TODO Implement method HorizontalMappingStrategy.mapReferenceSerialized()
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ protected IDBTable addReferenceTable(String tableName, boolean withFeature)
+ {
+ IDBTable table = addTable(tableName);
+ if (withFeature)
+ {
+ table.addField("cdo_feature", DBType.INTEGER);
+ }
+
+ table.addField("cdo_source", DBType.BIGINT);
+ table.addField("cdo_target", DBType.BIGINT);
+ table.addField("cdo_idx", DBType.INTEGER);
+ return table;
+ }
+
public void writeRevision(Connection connection, CDORevisionImpl revision)
{
if (TRACER.isEnabled())
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 713258d..6252fd4 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
@@ -191,7 +191,7 @@ public abstract class MappingStrategy implements IMappingStrategy
for (CDOClass cdoClass : cdoPackage.getClasses())
{
cdoClasses.add(cdoClass);
- IDBTable table = map(cdoClass, affectedTables);
+ IDBTable table = mapClass(cdoClass, affectedTables);
if (table != null)
{
((DBClassInfo)cdoClass.getServerInfo()).setTable(table);
@@ -214,7 +214,7 @@ public abstract class MappingStrategy implements IMappingStrategy
for (CDOFeature cdoFeature : cdoClass.getAllFeatures())
{
- IDBField field = map(cdoClass, cdoFeature, affectedTables);
+ IDBField field = mapFeature(cdoClass, cdoFeature, affectedTables);
if (field != null)
{
((DBFeatureInfo)cdoFeature.getServerInfo()).addField(cdoClass, field);
@@ -236,7 +236,7 @@ public abstract class MappingStrategy implements IMappingStrategy
* tables. There is no need to add the returned table to this set of
* affected tables. The caller takes care of that.
*/
- protected abstract IDBTable map(CDOClass cdoClass, Set<IDBTable> affectedTables);
+ protected abstract IDBTable mapClass(CDOClass cdoClass, Set<IDBTable> affectedTables);
/**
* @param affectedTables
@@ -244,7 +244,7 @@ public abstract class MappingStrategy implements IMappingStrategy
* tables. There is no need to add the table of the returned field to
* this set of affected tables. The caller takes care of that.
*/
- protected abstract IDBField map(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables);
+ protected abstract IDBField mapFeature(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables);
protected ClassMapping getClassMapping(CDOClass cdoClass)
{
@@ -304,11 +304,16 @@ public abstract class MappingStrategy implements IMappingStrategy
protected IDBTable addTable(CDOClass cdoClass)
{
+ return addTable(cdoClass.getName());
+ }
+
+ protected IDBTable addTable(String name)
+ {
for (int attempt = 0;; ++attempt)
{
try
{
- String tableName = mangleTableName(cdoClass.getName(), attempt);
+ String tableName = mangleTableName(name, attempt);
return getSchema().addTable(tableName);
}
catch (DBException ignore)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
index d6d7b05..e4da219 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
@@ -31,6 +31,7 @@ public class VerticalMappingStrategy extends MappingStrategy
{
public VerticalMappingStrategy()
{
+ throw new UnsupportedOperationException();
}
public String getType()
@@ -48,7 +49,7 @@ public class VerticalMappingStrategy extends MappingStrategy
}
@Override
- protected IDBTable map(CDOClass cdoClass, Set<IDBTable> affectedTables)
+ protected IDBTable mapClass(CDOClass cdoClass, Set<IDBTable> affectedTables)
{
if (cdoClass.isRoot())
{
@@ -61,7 +62,7 @@ public class VerticalMappingStrategy extends MappingStrategy
}
@Override
- protected IDBField map(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables)
+ protected IDBField mapFeature(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables)
{
if (cdoFeature.getContainingClass() != cdoClass)
{