summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-25 02:16:05 (EDT)
committerEike Stepper2007-08-25 02:16:05 (EDT)
commitad2b06991ec82c9456d67a1a8d10f829ac44fa06 (patch)
tree2fcb5f5de115a694e44d02c7066da624322f64d8
parent0645d0a2af7e685b3b9cc9d069f219660fd0b10b (diff)
downloadcdo-ad2b06991ec82c9456d67a1a8d10f829ac44fa06.zip
cdo-ad2b06991ec82c9456d67a1a8d10f829ac44fa06.tar.gz
cdo-ad2b06991ec82c9456d67a1a8d10f829ac44fa06.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java68
2 files changed, 58 insertions, 14 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
index f46f662..f4e3f16 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
@@ -75,10 +75,10 @@ public abstract class Mapping implements IMapping
protected void initTable(IDBTable table, boolean full)
{
table.addField("cdo_id", DBType.BIGINT);
+ table.addField("cdo_version", DBType.INTEGER);
if (full)
{
table.addField("cdo_class", DBType.INTEGER);
- table.addField("cdo_version", DBType.INTEGER);
table.addField("cdo_created", DBType.BIGINT);
table.addField("cdo_revised", DBType.BIGINT);
table.addField("cdo_resource", DBType.BIGINT);
@@ -176,10 +176,10 @@ public abstract class Mapping implements IMapping
protected IDBField addField(CDOFeature cdoFeature, IDBTable table) throws DBException
{
+ DBType fieldType = getDBType(cdoFeature.getType());
for (int attempt = 0;; ++attempt)
{
String fieldName = mangleFieldName(cdoFeature.getName(), attempt);
- DBType fieldType = getDBType(cdoFeature.getType());
try
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
index 108bd3a..b838a57 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
@@ -1,6 +1,7 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
@@ -11,6 +12,7 @@ import org.eclipse.emf.cdo.server.db.IReferenceMapping;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.IDBTable;
+import java.util.List;
import java.util.Map;
/**
@@ -20,10 +22,15 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
{
private IDBTable table;
- public ReferenceMapping(ValueMapping valueMapping, CDOFeature feature)
+ private ToMany toMany;
+
+ private boolean withFeature;
+
+ public ReferenceMapping(ValueMapping valueMapping, CDOFeature feature, ToMany toMany)
{
super(valueMapping, feature);
- table = mapReference(valueMapping.getCDOClass(), feature, ToMany.PER_REFERENCE);
+ this.toMany = toMany;
+ mapReference(valueMapping.getCDOClass(), feature);
}
public IDBTable getTable()
@@ -33,41 +40,78 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
public void writeReference(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
+ int idx = 0;
+ long source = revision.getID().getValue();
+ CDOFeature feature = getFeature();
+ List list = revision.getList(feature);
+ for (Object value : list)
+ {
+ long target = ((CDOID)value).getValue();
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+ if (withFeature)
+ {
+ builder.append(FeatureServerInfo.getDBID(feature));
+ builder.append(", ");
+ }
+
+ builder.append(idx++);
+ builder.append(", ");
+ builder.append(source);
+ builder.append(", ");
+ builder.append(target);
+ builder.append(")");
+ getValueMapping().sqlUpdate(storeAccessor, builder.toString());
+ }
}
- protected IDBTable mapReference(CDOClass cdoClass, CDOFeature cdoFeature, ToMany mapping)
+ protected void mapReference(CDOClass cdoClass, CDOFeature cdoFeature)
{
- switch (mapping)
+ switch (toMany)
{
case PER_REFERENCE:
- return mapReferenceTable(cdoFeature, cdoClass.getName() + "_" + cdoFeature.getName() + "_refs", false);
+ withFeature = false;
+ table = mapReferenceTable(cdoFeature, cdoClass.getName() + "_" + cdoFeature.getName() + "_refs");
+ break;
+
case PER_CLASS:
- return mapReferenceTable(cdoClass, cdoClass.getName() + "_refs", true);
+ withFeature = true;
+ table = mapReferenceTable(cdoClass, cdoClass.getName() + "_refs");
+ break;
+
case PER_PACKAGE:
+ withFeature = true;
CDOPackage cdoPackage = cdoClass.getContainingPackage();
- return mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs", true);
+ table = mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs");
+ break;
+
case PER_REPOSITORY:
+ withFeature = true;
IRepository repository = getValueMapping().getMappingStrategy().getStore().getRepository();
- return mapReferenceTable(repository, repository.getName() + "_refs", true);
+ table = mapReferenceTable(repository, repository.getName() + "_refs");
+ break;
+
default:
- throw new IllegalArgumentException("Invalid mapping: " + mapping);
+ throw new IllegalArgumentException("Invalid mapping: " + toMany);
}
}
- protected IDBTable mapReferenceTable(Object key, String tableName, boolean withFeature)
+ protected IDBTable mapReferenceTable(Object key, String tableName)
{
Map<Object, IDBTable> referenceTables = getValueMapping().getMappingStrategy().getReferenceTables();
IDBTable table = referenceTables.get(key);
if (table == null)
{
- table = addReferenceTable(tableName, withFeature);
+ table = addReferenceTable(tableName);
referenceTables.put(key, table);
}
return table;
}
- protected IDBTable addReferenceTable(String tableName, boolean withFeature)
+ protected IDBTable addReferenceTable(String tableName)
{
IDBTable table = getValueMapping().addTable(tableName);
if (withFeature)