summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2010-01-16 10:09:29 (EST)
committerStefan Winkler2010-01-16 10:09:29 (EST)
commit8c401d05827c15668d82b1d574f24bdf114e8ee4 (patch)
tree52ec4b80d0586d91c07923a4b5d71279938258b9
parentcf5edf5c4fb853cbe5c5910c9452327a49a211bd (diff)
downloadcdo-8c401d05827c15668d82b1d574f24bdf114e8ee4.zip
cdo-8c401d05827c15668d82b1d574f24bdf114e8ee4.tar.gz
cdo-8c401d05827c15668d82b1d574f24bdf114e8ee4.tar.bz2
[270716] Provide support for branching
https://bugs.eclipse.org/bugs/show_bug.cgi?id=270716
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMappingAuditSupport.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java51
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java8
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 054246b..d036a0a 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 893b8f5..76c4efe 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 <code>true</code> it is guaranteed that
- * <code>revision.getCreated() <= timeStamp && (getRevised() == 0 || getRevised() >= timeStamp))</code>
- *
- * @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 <code>true</code>, if the revision has been found and read correctly. <code>false</code> if the revision
- * could not be found. In this case, the content of <code>revision</code> 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 9ed631a..eadf834 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 da020a5..a2f2114 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 115c5ac..10c16a2 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 3344e7f..6bea68f 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 91ddc9b..5a366f4 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 66f04c6..d1eb8d6 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()));