summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-24 13:21:00 (EDT)
committerEike Stepper2007-08-24 13:21:00 (EDT)
commita7e9054f7b5cf7b0670e65b6fa894cadb2308cb1 (patch)
tree24d14d4f335754f3eea2df5fbc5c382e88297c25
parent4edac8339da2462e68d9b3142b961e555c67121c (diff)
downloadcdo-a7e9054f7b5cf7b0670e65b6fa894cadb2308cb1.zip
cdo-a7e9054f7b5cf7b0670e65b6fa894cadb2308cb1.tar.gz
cdo-a7e9054f7b5cf7b0670e65b6fa894cadb2308cb1.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMapping.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java74
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java18
8 files changed, 137 insertions, 48 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMapping.java
index a3f5398..68d1a32 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMapping.java
@@ -29,4 +29,6 @@ public interface IMapping
public Set<IDBTable> getAffectedTables();
public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision);
+
+ public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index 8d283b5..12fecc2 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -24,6 +24,8 @@ import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.protocol.model.CDOPackageInfo;
import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IPackageManager;
+import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
@@ -369,14 +371,25 @@ public class DBStoreAccessor implements IDBStoreAccessor
CDOClassImpl cdoClass = revision.getCDOClass();
IMapping mapping = ClassServerInfo.getMapping(cdoClass);
-
mapping.writeRevision(this, revision);
}
public CDORevision readRevision(CDOID id)
{
- // TODO Implement method DBStoreAccessor.readRevision()
- throw new UnsupportedOperationException("Not yet implemented");
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Selecting revision: {0}", id);
+ }
+
+ IRepository repository = store.getRepository();
+ IPackageManager packageManager = repository.getPackageManager();
+ CDOClassRef type = repository.getObjectType(this, id);
+ CDOClassImpl cdoClass = (CDOClassImpl)type.resolve(packageManager);
+ CDORevisionImpl revision = new CDORevisionImpl(cdoClass, id);
+
+ IMapping mapping = ClassServerInfo.getMapping(cdoClass);
+ mapping.readRevision(this, revision);
+ return revision;
}
public CDORevision readRevision(CDOID id, long timeStamp)
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 194b4e8..f46f662 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
@@ -72,7 +72,37 @@ public abstract class Mapping implements IMapping
return affectedTables;
}
- protected void appendRevisionInfo(StringBuilder builder, CDORevisionImpl revision, boolean full)
+ protected void initTable(IDBTable table, boolean full)
+ {
+ table.addField("cdo_id", DBType.BIGINT);
+ 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);
+ table.addField("cdo_container", DBType.BIGINT);
+ table.addField("cdo_feature", DBType.INTEGER);
+ }
+ }
+
+ @Deprecated
+ protected void appendRevisionFields(StringBuilder builder, CDORevisionImpl revision, boolean full)
+ {
+ IDBField[] fields = table.getFields();
+ builder.append(fields[0].getName());
+ if (full)
+ {
+ for (int i = 1; i < 8; i++)
+ {
+ builder.append(", ");
+ builder.append(fields[i].getName());
+ }
+ }
+ }
+
+ protected void appendRevisionInfos(StringBuilder builder, CDORevisionImpl revision, boolean full)
{
builder.append(revision.getID().getValue());
if (full)
@@ -94,7 +124,7 @@ public abstract class Mapping implements IMapping
}
}
- protected void executeSQL(IDBStoreAccessor storeAccessor, String sql) throws DBException
+ protected int sqlUpdate(IDBStoreAccessor storeAccessor, String sql) throws DBException
{
if (TRACER.isEnabled())
{
@@ -104,11 +134,7 @@ public abstract class Mapping implements IMapping
try
{
Statement statement = storeAccessor.getStatement();
- int count = statement.executeUpdate(sql);
- if (count != 1)
- {
- throw new DBException("Wrong update count: " + count);
- }
+ return statement.executeUpdate(sql);
}
catch (SQLException ex)
{
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 351b0a5..751a2ca 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
@@ -15,7 +15,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMapping;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
-import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.IDBTable;
import java.util.HashMap;
@@ -128,20 +127,5 @@ public abstract class MappingStrategy implements IMappingStrategy
return getType();
}
- protected void initTable(IDBTable table, boolean full)
- {
- table.addField("cdo_id", DBType.BIGINT);
- 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);
- table.addField("cdo_container", DBType.BIGINT);
- table.addField("cdo_feature", DBType.INTEGER);
- }
- }
-
protected abstract IMapping createMapping(CDOClass cdoClass);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoMapping.java
index 234f549..d167631 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoMapping.java
@@ -50,4 +50,8 @@ public class NoMapping implements IMapping
public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
}
+
+ public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java
index 5f76529..198dd30 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java
@@ -22,7 +22,7 @@ public class RootMapping extends Mapping
public RootMapping(VerticalMappingStrategy mappingStrategy)
{
super(mappingStrategy, getRootClass(mappingStrategy));
- mappingStrategy.initTable(getTable(), true);
+ initTable(getTable(), true);
}
@Override
@@ -37,9 +37,15 @@ public class RootMapping extends Mapping
builder.append("INSERT INTO ");
builder.append(getTable());
builder.append(" VALUES (");
- appendRevisionInfo(builder, revision, true);
+ appendRevisionInfos(builder, revision, true);
builder.append(")");
- executeSQL(storeAccessor, builder.toString());
+ sqlUpdate(storeAccessor, builder.toString());
+ }
+
+ public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ // TODO Implement method RootMapping.readRevision()
+ throw new UnsupportedOperationException("Not yet implemented");
}
private static CDOObjectClass getRootClass(VerticalMappingStrategy mappingStrategy)
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 658465d..f305a70 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
@@ -16,6 +16,10 @@ import org.eclipse.emf.cdo.protocol.model.CDOFeature;
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 org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+
+import org.eclipse.net4j.db.IDBField;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import java.util.ArrayList;
import java.util.List;
@@ -25,6 +29,8 @@ import java.util.List;
*/
public abstract class ValueMapping extends Mapping
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ValueMapping.class);
+
private List<IAttributeMapping> attributeMappings;
private List<IReferenceMapping> referenceMappings;
@@ -32,7 +38,7 @@ public abstract class ValueMapping extends Mapping
public ValueMapping(MappingStrategy mappingStrategy, CDOClass cdoClass, CDOFeature[] features)
{
super(mappingStrategy, cdoClass);
- mappingStrategy.initTable(getTable(), hasFullRevisionInfo());
+ initTable(getTable(), hasFullRevisionInfo());
attributeMappings = createAttributeMappings(features);
referenceMappings = createReferenceMappings(features);
}
@@ -50,13 +56,26 @@ public abstract class ValueMapping extends Mapping
}
}
+ public void readRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ if (attributeMappings != null)
+ {
+ readAttributes(storeAccessor, revision);
+ }
+
+ if (referenceMappings != null)
+ {
+ readReferences(storeAccessor, revision);
+ }
+ }
+
protected void writeAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
StringBuilder builder = new StringBuilder();
builder.append("INSERT INTO ");
builder.append(getTable());
builder.append(" VALUES (");
- appendRevisionInfo(builder, revision, hasFullRevisionInfo());
+ appendRevisionInfos(builder, revision, hasFullRevisionInfo());
for (IAttributeMapping attributeMapping : attributeMappings)
{
@@ -65,7 +84,7 @@ public abstract class ValueMapping extends Mapping
}
builder.append(")");
- executeSQL(storeAccessor, builder.toString());
+ sqlUpdate(storeAccessor, builder.toString());
}
protected void writeReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
@@ -76,6 +95,55 @@ public abstract class ValueMapping extends Mapping
}
}
+ protected void readAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ IDBField[] fields = getTable().getFields();
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ for (int i = 1; i < 8; i++)
+ {
+ if (i > 1)
+ {
+ builder.append(", ");
+ }
+
+ builder.append(fields[i].getName());
+ }
+
+ 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");
+
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ attributeMapping.appendValue(builder, revision);
+ }
+
+ builder.append(")");
+ String sql = builder.toString();
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ }
+
+ protected void readReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ for (IReferenceMapping referenceMapping : referenceMappings)
+ {
+ referenceMapping.writeReference(storeAccessor, revision);
+ }
+ }
+
protected List<IAttributeMapping> createAttributeMappings(CDOFeature[] features)
{
List<IAttributeMapping> attributeMappings = new ArrayList();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
index fc0c97f..eeebbcb 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
@@ -18,10 +18,8 @@ import org.eclipse.emf.cdo.internal.server.protocol.CDOServerProtocol;
import org.eclipse.emf.cdo.internal.server.protocol.InvalidationRequest;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.SessionCreationException;
import org.eclipse.emf.cdo.server.IView.Type;
@@ -177,7 +175,8 @@ public class Session extends Container<IView> implements ISession, CDOIDProvider
}
knownObjects.add(id);
- CDOClassRef type = getObjectType(id);
+ Repository repository = sessionManager.getRepository();
+ CDOClassRef type = repository.getObjectType(StoreUtil.getReader(), id);
return CDOIDImpl.create(id.getValue(), type);
}
@@ -194,17 +193,4 @@ public class Session extends Container<IView> implements ISession, CDOIDProvider
sessionManager.sessionClosed(this);
super.doDeactivate();
}
-
- protected CDOClassRef getObjectType(CDOID id)
- {
- RevisionManager revisionManager = sessionManager.getRepository().getRevisionManager();
- CDOClass cdoClass = revisionManager.getObjectType(id);
- if (cdoClass != null)
- {
- return cdoClass.createClassRef();
- }
-
- IStoreReader storeReader = StoreUtil.getReader();
- return storeReader.readObjectType(id);
- }
}