From 8c401d05827c15668d82b1d574f24bdf114e8ee4 Mon Sep 17 00:00:00 2001
From: Stefan Winkler
Date: Sat, 16 Jan 2010 15:09:29 +0000
Subject: [270716] Provide support for branching
https://bugs.eclipse.org/bugs/show_bug.cgi?id=270716
---
.../emf/cdo/server/db/mapping/IClassMapping.java | 4 +-
.../db/mapping/IClassMappingAuditSupport.java | 20 --------
.../emf/cdo/server/internal/db/CDODBSchema.java | 8 +--
.../emf/cdo/server/internal/db/DBStore.java | 6 ---
.../cdo/server/internal/db/DBStoreAccessor.java | 16 +++---
.../horizontal/HorizontalAuditClassMapping.java | 51 ++++++-------------
.../HorizontalBranchingClassMapping.java | 58 +++++++---------------
.../horizontal/HorizontalNonAuditClassMapping.java | 8 ++-
8 files changed, 55 insertions(+), 116 deletions(-)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
index 054246be8d..d036a0abdf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
@@ -54,7 +54,9 @@ public interface IClassMapping
public IListMapping getListMapping(EStructuralFeature feature);
/**
- * Read the current version of a revision.
+ * Read a revision. The branch and timestamp to be read are derived from the branchPoint which is set to the Revision.
+ * Note that non-audit stores only support {@link CDOBranchPoint#UNSPECIFIED_DATE} and non-branching stores only
+ * support the main branch.
*
* @param dbStoreAccessor
* the accessor to use.
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMappingAuditSupport.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMappingAuditSupport.java
index 893b8f5d1f..76c4efeeed 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMappingAuditSupport.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMappingAuditSupport.java
@@ -47,24 +47,4 @@ public interface IClassMappingAuditSupport
* @since 3.0
*/
public boolean readRevisionByVersion(IDBStoreAccessor storeAccessor, InternalCDORevision revision, int listChunk);
-
- /**
- * Read a specific past version of a revision. If this method returns true
it is guaranteed that
- * revision.getCreated() <= timeStamp && (getRevised() == 0 || getRevised() >= timeStamp))
- *
- * @param storeAccessor
- * the accessor to use.
- * @param revision
- * the revision object into which the data should be read. The revision has to be have its ID set to the
- * requested object's ID. The version is ignored, as the version parameter is used to determine the version
- * to be read.
- * @param timeStamp
- * the timeStamp which should be used to determine the revision's version.
- * @param listChunk
- * the chunk size to read attribute lists.
- * @return true
, if the revision has been found and read correctly. false
if the revision
- * could not be found. In this case, the content of revision
is undefined.
- * @since 3.0
- */
- public boolean readRevision(IDBStoreAccessor storeAccessor, InternalCDORevision revision, int listChunk);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
index 9ed631a67c..eadf834faf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
@@ -104,7 +104,7 @@ public class CDODBSchema extends DBSchema
/**
* DBTable cdo_branches
*/
- public static final IDBTable BRANCHES = INSTANCE.addTable("cdo_ecdo_branchesxternal_refs"); //$NON-NLS-1$
+ public static final IDBTable BRANCHES = INSTANCE.addTable("cdo_branches"); //$NON-NLS-1$
public static final IDBField BRANCHES_ID = //
BRANCHES.addField("id", DBType.INTEGER); //$NON-NLS-1$
@@ -116,19 +116,19 @@ public class CDODBSchema extends DBSchema
BRANCHES.addField("base_id", DBType.INTEGER); //$NON-NLS-1$
public static final IDBField BRANCHES_BASE_TIMESTAMP = //
- BRANCHES.addField("name_time", DBType.BIGINT); //$NON-NLS-1$
+ BRANCHES.addField("base_time", DBType.BIGINT); //$NON-NLS-1$
public static final IDBIndex INDEX_BRANCHES_ID = //
BRANCHES.addIndex(IDBIndex.Type.PRIMARY_KEY, BRANCHES_ID);
public static final String SQL_CREATE_BRANCH = "INSERT INTO " + BRANCHES + " (" + BRANCHES_ID + ", " + BRANCHES_NAME
- + ", " + BRANCHES_BASE_BRANCH_ID + ", " + BRANCHES_BASE_TIMESTAMP + ") VALUES (?, ?, ?, ?)";
+ + ", " + BRANCHES_BASE_BRANCH_ID + ", " + BRANCHES_BASE_TIMESTAMP + ") VALUES (?, ?, ?, ?)";
public static final String SQL_LOAD_BRANCH = "SELECT " + BRANCHES_NAME + ", " + BRANCHES_BASE_BRANCH_ID + ", "
+ BRANCHES_BASE_TIMESTAMP + " FROM " + BRANCHES + " WHERE " + BRANCHES_ID + "=?";
public static final String SQL_LOAD_SUB_BRANCHES = "SELECT " + BRANCHES_ID + ", " + BRANCHES_NAME + ", "
- + BRANCHES_BASE_TIMESTAMP + ", " + " FROM " + BRANCHES + " WHERE " + BRANCHES_BASE_BRANCH_ID + "=?";
+ + BRANCHES_BASE_TIMESTAMP + " FROM " + BRANCHES + " WHERE " + BRANCHES_BASE_BRANCH_ID + "=?";
/**
* DBTable cdo_external_refs
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index da020a545e..a2f2114573 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -420,10 +420,4 @@ public class DBStore extends LongIDStore implements IDBStore
{
return System.currentTimeMillis();
}
-
- @Override
- public int getNextBranchID()
- {
- return 0;
- }
}
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 115c5acb87..10c16a20ac 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
@@ -175,22 +175,18 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
public InternalCDORevision readRevision(CDOID id, CDOBranchPoint branchPoint, int listChunk,
CDORevisionCacheAdder cache)
{
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- if (!mappingStrategy.hasAuditSupport())
- {
- throw new UnsupportedOperationException("Mapping strategy does not support audits."); //$NON-NLS-1$
- }
-
if (TRACER.isEnabled())
{
TRACER.format("Selecting revision {0} from {1}", id, branchPoint); //$NON-NLS-1$
}
+ IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
+
EClass eClass = getObjectType(id);
InternalCDORevision revision = getStore().createRevision(eClass, id);
revision.setBranchPoint(branchPoint);
- IClassMappingAuditSupport mapping = (IClassMappingAuditSupport)mappingStrategy.getClassMapping(eClass);
+ IClassMapping mapping = mappingStrategy.getClassMapping(eClass);
if (mapping.readRevision(this, revision, listChunk))
{
return revision;
@@ -426,6 +422,12 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
if (TRACER.isEnabled())
{
+ CDODBUtil.sqlDump(getConnection(), "SELECT * FROM CDOResource");
+
+ CDODBUtil.sqlDump(getConnection(), "SELECT * FROM CDOResource_contents_list ORDER BY "
+ + CDODBSchema.LIST_REVISION_ID + "," + CDODBSchema.LIST_REVISION_BRANCH + ","
+ + CDODBSchema.LIST_REVISION_VERSION + "," + CDODBSchema.LIST_IDX);
+
TRACER.format("--- DB COMMIT ---"); //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
index 3344e7f897..6bea68f0db 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
@@ -209,18 +209,24 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
sqlSelectAllObjectIds = builder.toString();
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, CDOBranchPoint branchPoint,
- int listChunk)
+ public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
- long timeStamp = branchPoint.getTimeStamp();
PreparedStatement pstmt = null;
-
try
{
- pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
- pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
- pstmt.setLong(2, timeStamp);
- pstmt.setLong(3, timeStamp);
+ long timeStamp = revision.getTimeStamp();
+ if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
+ pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
+ pstmt.setLong(2, timeStamp);
+ pstmt.setLong(3, timeStamp);
+ }
+ else
+ {
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
+ pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
+ }
// Read singleval-attribute table always (even without modeled attributes!)
boolean success = readValuesFromStatement(pstmt, revision, accessor);
@@ -364,35 +370,6 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
return accessor.getStatementCache().getPreparedStatement(sqlSelectAllObjectIds, ReuseProbability.HIGH);
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
- {
- PreparedStatement pstmt = null;
- try
- {
- pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
- pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
-
- // Read singleval-attribute table always (even without modeled attributes!)
- boolean success = readValuesFromStatement(pstmt, revision, accessor);
-
- // Read multival tables only if revision exists
- if (success)
- {
- readLists(accessor, revision, listChunk);
- }
-
- return success;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- accessor.getStatementCache().releasePreparedStatement(pstmt);
- }
- }
-
@Override
protected final void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
index 91ddc9bc32..5a366f41fd 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
@@ -232,21 +232,29 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
sqlSelectAllObjectIds = builder.toString();
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, CDOBranchPoint branchPoint,
- int listChunk)
+ public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
- long timeStamp = branchPoint.getTimeStamp();
- int branchId = branchPoint.getBranch().getID();
-
PreparedStatement pstmt = null;
+ long timeStamp = revision.getTimeStamp();
+ int branchId = revision.getBranch().getID();
+
try
{
- pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
- pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
- pstmt.setLong(2, branchId);
- pstmt.setLong(3, timeStamp);
- pstmt.setLong(4, timeStamp);
+ if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
+ pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
+ pstmt.setLong(2, branchId);
+ pstmt.setLong(3, timeStamp);
+ pstmt.setLong(4, timeStamp);
+ }
+ else
+ {
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
+ pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
+ pstmt.setLong(2, branchId);
+ }
// Read singleval-attribute table always (even without modeled attributes!)
boolean success = readValuesFromStatement(pstmt, revision, accessor);
@@ -396,36 +404,6 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
return accessor.getStatementCache().getPreparedStatement(sqlSelectAllObjectIds, ReuseProbability.HIGH);
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
- {
- PreparedStatement pstmt = null;
- try
- {
- pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
- pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
- pstmt.setInt(2, revision.getBranch().getID());
-
- // Read singleval-attribute table always (even without modeled attributes!)
- boolean success = readValuesFromStatement(pstmt, revision, accessor);
-
- // Read multival tables only if revision exists
- if (success)
- {
- readLists(accessor, revision, listChunk);
- }
-
- return success;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- accessor.getStatementCache().releasePreparedStatement(pstmt);
- }
- }
-
@Override
protected final void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
index 66f04c660b..d1eb8d667b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
@@ -364,11 +364,17 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
+
+ long timeStamp = revision.getTimeStamp();
+ if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ throw new UnsupportedOperationException("Mapping strategy does not support audits."); //$NON-NLS-1$
+ }
+
PreparedStatement pstmt = null;
try
{
- // TODO add caching
pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
--
cgit v1.2.3