summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-24 06:05:21 (EDT)
committerEike Stepper2007-08-24 06:05:21 (EDT)
commitcb7f6f20d7d4891d5e467d313bc57d6912819032 (patch)
treea28a8dd28fc4d380564a25928deb9b637d71385f
parent0b09585b20a8dbca4eb6f69f216390438a61e6b4 (diff)
downloadcdo-cb7f6f20d7d4891d5e467d313bc57d6912819032.zip
cdo-cb7f6f20d7d4891d5e467d313bc57d6912819032.tar.gz
cdo-cb7f6f20d7d4891d5e467d313bc57d6912819032.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapping.java (renamed from plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapper.java)18
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java84
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java48
7 files changed, 202 insertions, 78 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
index a782bd3..61feaaf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
@@ -24,5 +24,5 @@ public interface IReferenceMapping
public IDBTable getTable();
- public void writeReference(IMapping mapping, IDBStoreAccessor storeAccessor, CDORevisionImpl revision);
+ public void writeReference(IDBStoreAccessor storeAccessor, CDORevisionImpl revision);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
new file mode 100644
index 0000000..a1f46d6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
@@ -0,0 +1,38 @@
+package org.eclipse.emf.cdo.server.internal.db;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
+
+import org.eclipse.net4j.db.IDBField;
+
+/**
+ * @author Eike Stepper
+ */
+public class AttributeMapping extends FeatureMapping implements IAttributeMapping
+{
+ private IDBField field;
+
+ public AttributeMapping(ValueMapping valueMapping, CDOFeature feature)
+ {
+ super(valueMapping, feature);
+ field = valueMapping.addField(feature, valueMapping.getTable());
+ }
+
+ public IDBField getField()
+ {
+ return field;
+ }
+
+ public void appendValue(StringBuilder builder, CDORevisionImpl revision)
+ {
+ Object value = getRevisionValue(revision);
+ field.appendValue(builder, value);
+ }
+
+ protected Object getRevisionValue(CDORevisionImpl revision)
+ {
+ CDOFeature feature = getFeature();
+ return revision.getValue(feature);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapper.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapping.java
index 66599d0..14dd776 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapper.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureMapping.java
@@ -15,25 +15,25 @@ import org.eclipse.emf.cdo.protocol.model.CDOFeature;
/**
* @author Eike Stepper
*/
-public class FeatureMapper
+public class FeatureMapping
{
- private CDOFeature feature;
+ private ValueMapping valueMapping;
- private int index;
+ private CDOFeature feature;
- public FeatureMapper(CDOFeature feature, int index)
+ public FeatureMapping(ValueMapping valueMapping, CDOFeature feature)
{
+ this.valueMapping = valueMapping;
this.feature = feature;
- this.index = index;
}
- public CDOFeature getFeature()
+ public ValueMapping getValueMapping()
{
- return feature;
+ return valueMapping;
}
- public int getIndex()
+ public CDOFeature getFeature()
{
- return index;
+ return feature;
}
}
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 4aa3fa4..c6e80c6 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
@@ -122,20 +122,6 @@ public abstract class Mapping implements IMapping
return mappingStrategy.getStore().getDBAdapter().mangleFieldName(name, attempt);
}
- protected IDBTable addReferenceTable(String tableName, boolean withFeature)
- {
- IDBTable table = addTable(tableName);
- if (withFeature)
- {
- table.addField("cdo_feature", DBType.INTEGER);
- }
-
- table.addField("cdo_idx", DBType.INTEGER);
- table.addField("cdo_source", DBType.BIGINT);
- table.addField("cdo_target", DBType.BIGINT);
- return table;
- }
-
protected IDBTable addTable(String name)
{
for (int attempt = 0;; ++attempt)
@@ -226,47 +212,4 @@ public abstract class Mapping implements IMapping
throw new ImplementationError("Unrecognized CDOType: " + type);
}
-
- // protected IDBField mapReference(CDOClass cdoClass, CDOFeature cdoFeature,
- // ToMany mapping)
- // {
- // switch (mapping)
- // {
- // case PER_REFERENCE:
- // return mapReferenceTable(cdoFeature, cdoClass.getName() + "_" +
- // cdoFeature.getName() + "_refs", false);
- // case PER_CLASS:
- // return mapReferenceTable(cdoClass, cdoClass.getName() + "_refs", true);
- // case PER_PACKAGE:
- // CDOPackage cdoPackage = cdoClass.getContainingPackage();
- // return mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs", true);
- // case PER_REPOSITORY:
- // IRepository repository = mappingStrategy.getStore().getRepository();
- // return mapReferenceTable(repository, repository.getName() + "_refs", true);
- // case LIKE_ATTRIBUTES:
- // return mapReferenceSerialized(cdoClass, cdoFeature);
- // default:
- // throw new IllegalArgumentException("Invalid mapping: " + mapping);
- // }
- // }
- //
- // protected IDBField mapReferenceSerialized(CDOClass cdoClass, CDOFeature
- // cdoFeature)
- // {
- // // TODO Implement method HorizontalMappingStrategy.mapReferenceSerialized()
- // throw new UnsupportedOperationException("Not yet implemented");
- // }
- //
- // protected IDBField mapReferenceTable(Object key, String tableName, boolean
- // withFeature)
- // {
- // IDBTable table = referenceTables.get(key);
- // if (table == null)
- // {
- // table = addReferenceTable(tableName, withFeature);
- // referenceTables.put(key, table);
- // }
- //
- // return table.getField(0);
- // }
}
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
new file mode 100644
index 0000000..108bd3a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
@@ -0,0 +1,84 @@
+package org.eclipse.emf.cdo.server.internal.db;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+
+import org.eclipse.net4j.db.DBType;
+import org.eclipse.net4j.db.IDBTable;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class ReferenceMapping extends FeatureMapping implements IReferenceMapping
+{
+ private IDBTable table;
+
+ public ReferenceMapping(ValueMapping valueMapping, CDOFeature feature)
+ {
+ super(valueMapping, feature);
+ table = mapReference(valueMapping.getCDOClass(), feature, ToMany.PER_REFERENCE);
+ }
+
+ public IDBTable getTable()
+ {
+ return table;
+ }
+
+ public void writeReference(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ }
+
+ protected IDBTable mapReference(CDOClass cdoClass, CDOFeature cdoFeature, ToMany mapping)
+ {
+ switch (mapping)
+ {
+ case PER_REFERENCE:
+ return mapReferenceTable(cdoFeature, cdoClass.getName() + "_" + cdoFeature.getName() + "_refs", false);
+ case PER_CLASS:
+ return mapReferenceTable(cdoClass, cdoClass.getName() + "_refs", true);
+ case PER_PACKAGE:
+ CDOPackage cdoPackage = cdoClass.getContainingPackage();
+ return mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs", true);
+ case PER_REPOSITORY:
+ IRepository repository = getValueMapping().getMappingStrategy().getStore().getRepository();
+ return mapReferenceTable(repository, repository.getName() + "_refs", true);
+ default:
+ throw new IllegalArgumentException("Invalid mapping: " + mapping);
+ }
+ }
+
+ protected IDBTable mapReferenceTable(Object key, String tableName, boolean withFeature)
+ {
+ Map<Object, IDBTable> referenceTables = getValueMapping().getMappingStrategy().getReferenceTables();
+ IDBTable table = referenceTables.get(key);
+ if (table == null)
+ {
+ table = addReferenceTable(tableName, withFeature);
+ referenceTables.put(key, table);
+ }
+
+ return table;
+ }
+
+ protected IDBTable addReferenceTable(String tableName, boolean withFeature)
+ {
+ IDBTable table = getValueMapping().addTable(tableName);
+ if (withFeature)
+ {
+ table.addField("cdo_feature", DBType.INTEGER);
+ }
+
+ table.addField("cdo_idx", DBType.INTEGER);
+ table.addField("cdo_source", DBType.BIGINT);
+ table.addField("cdo_target", DBType.BIGINT);
+ return table;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java
new file mode 100644
index 0000000..63fb951
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.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.CDOFeature;
+
+/**
+ * @author Eike Stepper
+ */
+public class ToOneReferenceMapping extends AttributeMapping
+{
+ public ToOneReferenceMapping(ValueMapping valueMapping, CDOFeature feature)
+ {
+ super(valueMapping, feature);
+ }
+
+ @Override
+ protected Long getRevisionValue(CDORevisionImpl revision)
+ {
+ CDOID id = (CDOID)super.getRevisionValue(revision);
+ return id.getValue();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java
index f3e65b7..31f443b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -36,16 +37,6 @@ public abstract class ValueMapping extends Mapping
referenceMappings = createReferenceMappings(features);
}
- public List<IAttributeMapping> createAttributeMappings(CDOFeature[] features)
- {
- return null;
- }
-
- public List<IReferenceMapping> createReferenceMappings(CDOFeature[] features)
- {
- return null;
- }
-
public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
if (attributeMappings != null)
@@ -82,8 +73,43 @@ public abstract class ValueMapping extends Mapping
{
for (IReferenceMapping referenceMapping : referenceMappings)
{
- referenceMapping.writeReference(this, storeAccessor, revision);
+ referenceMapping.writeReference(storeAccessor, revision);
+ }
+ }
+
+ protected List<IAttributeMapping> createAttributeMappings(CDOFeature[] features)
+ {
+ List<IAttributeMapping> attributeMappings = new ArrayList();
+ for (CDOFeature feature : features)
+ {
+ if (feature.isReference())
+ {
+ if (!feature.isMany())
+ {
+ attributeMappings.add(new ToOneReferenceMapping(this, feature));
+ }
+ }
+ else
+ {
+ attributeMappings.add(new AttributeMapping(this, feature));
+ }
}
+
+ return attributeMappings.isEmpty() ? null : attributeMappings;
+ }
+
+ protected List<IReferenceMapping> createReferenceMappings(CDOFeature[] features)
+ {
+ List<IReferenceMapping> referenceMappings = new ArrayList();
+ for (CDOFeature feature : features)
+ {
+ if (feature.isReference() && feature.isMany())
+ {
+ referenceMappings.add(new ReferenceMapping(this, feature));
+ }
+ }
+
+ return referenceMappings.isEmpty() ? null : referenceMappings;
}
protected abstract boolean hasFullRevisionInfo();