summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-12 10:47:11 (EDT)
committerEike Stepper2007-09-12 10:47:11 (EDT)
commit3df10783a4f7664004c7e6ef2adc62516bea3a0f (patch)
tree26dc1721dd2fdfaefe7b020b4377777843439726
parentfcb747687621f07373cafa9db6fc77f47a8fed77 (diff)
downloadcdo-3df10783a4f7664004c7e6ef2adc62516bea3a0f.zip
cdo-3df10783a4f7664004c7e6ef2adc62516bea3a0f.tar.gz
cdo-3df10783a4f7664004c7e6ef2adc62516bea3a0f.tar.bz2
[202833] Horizontal Mapping Strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java269
3 files changed, 194 insertions, 90 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
index dd6f600..9b71169 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
@@ -15,6 +15,8 @@ import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.net4j.db.IDBField;
+import java.sql.ResultSet;
+
/**
* @author Eike Stepper
*/
@@ -27,4 +29,6 @@ public interface IAttributeMapping
public IDBField getField();
public void appendValue(StringBuilder builder, CDORevisionImpl revision);
+
+ public void extractValue(ResultSet resultSet, int column, 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
index dad11dd..74a5e85 100644
--- 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
@@ -7,10 +7,12 @@ import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBField;
+import java.sql.ResultSet;
+
/**
* @author Eike Stepper
*/
-public class AttributeMapping extends FeatureMapping implements IAttributeMapping
+public abstract class AttributeMapping extends FeatureMapping implements IAttributeMapping
{
private IDBField field;
@@ -37,4 +39,11 @@ public class AttributeMapping extends FeatureMapping implements IAttributeMappin
CDOFeature feature = getFeature();
return revision.getValue(feature);
}
+
+ public void extractValue(ResultSet resultSet, int column, CDORevisionImpl revision)
+ {
+ revision.setValue(getFeature(), getResultSetValue(resultSet, column));
+ }
+
+ protected abstract Object getResultSetValue(ResultSet resultSet, int column);
} \ No newline at end of file
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 79c3898..5b06991 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
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
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;
@@ -19,9 +20,12 @@ import org.eclipse.emf.cdo.server.db.IReferenceMapping;
import org.eclipse.emf.cdo.server.db.IValueMapping;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.net4j.db.IDBField;
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@@ -32,18 +36,69 @@ public abstract class ValueMapping extends Mapping implements IValueMapping
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ValueMapping.class);
- private static final long NO_TIMESTAMP = 0L;
-
private List<IAttributeMapping> attributeMappings;
private List<IReferenceMapping> referenceMappings;
+ private String selectPrefix;
+
+ private String selectPrefixWithVersion;
+
public ValueMapping(MappingStrategy mappingStrategy, CDOClass cdoClass, CDOFeature[] features)
{
super(mappingStrategy, cdoClass);
initTable(getTable(), hasFullRevisionInfo());
attributeMappings = createAttributeMappings(features);
referenceMappings = createReferenceMappings(features);
+
+ selectPrefix = createSelectPrefix(false);
+ selectPrefixWithVersion = createSelectPrefix(true);
+ }
+
+ protected String createSelectPrefix(boolean readVersion)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+
+ if (hasFullRevisionInfo())
+ {
+ if (readVersion)
+ {
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(", ");
+ }
+
+ builder.append(CDODBSchema.ATTRIBUTES_CREATED);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_RESOURCE);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_CONTAINER);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_FEATURE);
+ }
+ else
+ {
+ if (attributeMappings == null)
+ {
+ // Only references
+ return null;
+ }
+ }
+
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ builder.append(attributeMapping.getField().getName());
+ }
+
+ builder.append(" FROM ");
+ builder.append(getTable());
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append("=");
+ return builder.toString();
}
public List<IAttributeMapping> getAttributeMappings()
@@ -69,45 +124,71 @@ public abstract class ValueMapping extends Mapping implements IValueMapping
return null;
}
- public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ protected List<IAttributeMapping> createAttributeMappings(CDOFeature[] features)
{
- if (attributeMappings != null)
+ List<IAttributeMapping> attributeMappings = new ArrayList<IAttributeMapping>();
+ for (CDOFeature feature : features)
{
- writeAttributes(storeAccessor, revision);
+ if (feature.isReference())
+ {
+ if (!feature.isMany())
+ {
+ attributeMappings.add(createToOneReferenceMapping(feature));
+ }
+ }
+ else
+ {
+ attributeMappings.add(createAttributeMapping(feature));
+ }
}
- if (referenceMappings != null)
+ return attributeMappings.isEmpty() ? null : attributeMappings;
+ }
+
+ protected List<IReferenceMapping> createReferenceMappings(CDOFeature[] features)
+ {
+ List<IReferenceMapping> referenceMappings = new ArrayList<IReferenceMapping>();
+ for (CDOFeature feature : features)
{
- writeReferences(storeAccessor, revision);
+ if (feature.isReference() && feature.isMany())
+ {
+ referenceMappings.add(createReferenceMapping(feature));
+ }
}
+
+ return referenceMappings.isEmpty() ? null : referenceMappings;
}
- public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int referenceChunk)
+ protected AttributeMapping createAttributeMapping(CDOFeature feature)
{
- readRevisionByTime(storeAccessor, revision, NO_TIMESTAMP, referenceChunk);
+ return new AttributeMapping(this, feature);
}
- public void readRevisionByTime(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, long timeStamp,
- int referenceChunk)
+ protected ToOneReferenceMapping createToOneReferenceMapping(CDOFeature feature)
+ {
+ return new ToOneReferenceMapping(this, feature);
+ }
+
+ protected ReferenceMapping createReferenceMapping(CDOFeature feature)
+ {
+ return new ReferenceMapping(this, feature, ToMany.PER_REFERENCE);
+ }
+
+ protected abstract boolean hasFullRevisionInfo();
+
+ public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
if (attributeMappings != null)
{
- readAttributes(storeAccessor, revision, timeStamp);
+ writeAttributes(storeAccessor, revision);
}
if (referenceMappings != null)
{
- readReferences(storeAccessor, revision, referenceChunk);
+ writeReferences(storeAccessor, revision);
}
}
- public void readRevisionByVersion(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int version,
- int referenceChunk)
- {
- // TODO Implement method ValueMapping.readRevisionByVersion()
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
protected void writeAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
StringBuilder builder = new StringBuilder();
@@ -134,99 +215,109 @@ public abstract class ValueMapping extends Mapping implements IValueMapping
}
}
- protected void readAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, long timeStamp)
+ public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int referenceChunk)
{
- IDBField[] fields = getTable().getFields();
- StringBuilder builder = new StringBuilder();
- builder.append("SELECT ");
- for (int i = 1; i < 8; i++)
- {
- if (i > 1)
- {
- builder.append(", ");
- }
+ String where = CDODBSchema.ATTRIBUTES_REVISED + "=0";
+ readRevision(storeAccessor, revision, where, true, referenceChunk);
+ }
- builder.append(fields[i].getName());
- }
+ public void readRevisionByTime(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, long timeStamp,
+ int referenceChunk)
+ {
+ StringBuilder where = new StringBuilder();
+ where.append("(");
+ where.append(CDODBSchema.ATTRIBUTES_REVISED);
+ where.append("=0 OR ");
+ where.append(CDODBSchema.ATTRIBUTES_REVISED);
+ where.append(">=");
+ where.append(timeStamp);
+ where.append(") AND ");
+ where.append(timeStamp);
+ where.append(">=");
+ where.append(CDODBSchema.ATTRIBUTES_CREATED);
+ readRevision(storeAccessor, revision, where.toString(), true, referenceChunk);
+ }
- builder.append(" FROM ");
- builder.append(getTable());
- builder.append(" WHERE ");
- builder.append(fields[0].getName());
- builder.append("=");
- builder.append(revision.getID().getValue());
- builder.append(" AND ");
- builder.append(fields[0].getName());
- builder.append("=0");
+ public void readRevisionByVersion(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int version,
+ int referenceChunk)
+ {
+ String where = CDODBSchema.ATTRIBUTES_VERSION + "=" + version;
+ readRevision(storeAccessor, revision, where, false, referenceChunk);
+ }
- for (IAttributeMapping attributeMapping : attributeMappings)
+ protected void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, String where,
+ boolean readVersion, int referenceChunk)
+ {
+ if (attributeMappings != null)
{
- builder.append(", ");
- attributeMapping.appendValue(builder, revision);
+ readAttributes(storeAccessor, revision, where, readVersion);
}
- builder.append(")");
- String sql = builder.toString();
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ if (referenceMappings != null)
+ {
+ readReferences(storeAccessor, revision, referenceChunk);
+ }
}
- protected void readReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int referenceChunk)
+ protected void readAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, String where,
+ boolean readVersion)
{
- for (IReferenceMapping referenceMapping : referenceMappings)
+ long id = revision.getID().getValue();
+ StringBuilder builder = new StringBuilder(readVersion ? selectPrefixWithVersion : selectPrefix);
+ builder.append(id);
+ if (where != null)
{
- referenceMapping.readReference(storeAccessor, revision, referenceChunk);
+ builder.append(" AND ");
+ builder.append(where);
}
- }
- protected List<IAttributeMapping> createAttributeMappings(CDOFeature[] features)
- {
- List<IAttributeMapping> attributeMappings = new ArrayList<IAttributeMapping>();
- for (CDOFeature feature : features)
+ String sql = builder.toString();
+ if (TRACER.isEnabled()) TRACER.trace(sql);
+ ResultSet resultSet = null;
+
+ try
{
- if (feature.isReference())
+ resultSet = storeAccessor.getStatement().executeQuery(sql);
+ if (!resultSet.next())
{
- if (!feature.isMany())
+ throw new IllegalStateException("Revision not found: " + id);
+ }
+
+ int i = 0;
+ if (hasFullRevisionInfo())
+ {
+ if (readVersion)
{
- attributeMappings.add(createToOneReferenceMapping(feature));
+ revision.setVersion(resultSet.getInt(i++));
}
+
+ revision.setCreated(resultSet.getLong(i++));
+ revision.setRevised(resultSet.getLong(i++));
+ revision.setResourceID(CDOIDImpl.create(resultSet.getLong(i++)));
+ revision.setContainerID(CDOIDImpl.create(resultSet.getLong(i++)));
+ revision.setContainingFeature(resultSet.getInt(i++));
}
- else
+
+ for (IAttributeMapping attributeMapping : attributeMappings)
{
- attributeMappings.add(createAttributeMapping(feature));
+ attributeMapping.extractValue(resultSet, i++, revision);
}
}
-
- return attributeMappings.isEmpty() ? null : attributeMappings;
- }
-
- protected List<IReferenceMapping> createReferenceMappings(CDOFeature[] features)
- {
- List<IReferenceMapping> referenceMappings = new ArrayList<IReferenceMapping>();
- for (CDOFeature feature : features)
+ catch (SQLException ex)
{
- if (feature.isReference() && feature.isMany())
- {
- referenceMappings.add(createReferenceMapping(feature));
- }
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
}
-
- return referenceMappings.isEmpty() ? null : referenceMappings;
- }
-
- protected AttributeMapping createAttributeMapping(CDOFeature feature)
- {
- return new AttributeMapping(this, feature);
- }
-
- protected ToOneReferenceMapping createToOneReferenceMapping(CDOFeature feature)
- {
- return new ToOneReferenceMapping(this, feature);
}
- protected ReferenceMapping createReferenceMapping(CDOFeature feature)
+ protected void readReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision, int referenceChunk)
{
- return new ReferenceMapping(this, feature, ToMany.PER_REFERENCE);
+ for (IReferenceMapping referenceMapping : referenceMappings)
+ {
+ referenceMapping.readReference(storeAccessor, revision, referenceChunk);
+ }
}
-
- protected abstract boolean hasFullRevisionInfo();
}