diff options
author | Eike Stepper | 2010-03-13 15:08:19 +0000 |
---|---|---|
committer | Eike Stepper | 2010-03-13 15:08:19 +0000 |
commit | 1e07fed44a31294864a19196af3d998abd249c91 (patch) | |
tree | 86678c335ed4ebed998e0508cf5efe31f5831569 /plugins | |
parent | 86ce4f732d578de20b23dad2b737b513e31dc3e5 (diff) | |
download | cdo-1e07fed44a31294864a19196af3d998abd249c91.tar.gz cdo-1e07fed44a31294864a19196af3d998abd249c91.tar.xz cdo-1e07fed44a31294864a19196af3d998abd249c91.zip |
[256936] Support for Offline Mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256936
Diffstat (limited to 'plugins')
7 files changed, 139 insertions, 14 deletions
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 8d088a91c7..0a0544d864 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 @@ -44,6 +44,9 @@ public class CDODBSchema extends DBSchema public static final IDBField REPOSITORY_STOPPED = // REPOSITORY.addField("stopped", DBType.BIGINT); //$NON-NLS-1$ + public static final IDBField REPOSITORY_NEXT_LOCAL_CDOID = // + REPOSITORY.addField("next_local_cdoid", DBType.BIGINT); //$NON-NLS-1$ + public static final IDBField REPOSITORY_LAST_CDOID = // REPOSITORY.addField("last_cdoid", DBType.BIGINT); //$NON-NLS-1$ 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 286adda377..d1971b3396 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 @@ -403,13 +403,14 @@ public class DBStore extends LongIDStore implements IDBStore firstTime = true; DBUtil.insertRow(connection, dbAdapter, CDODBSchema.REPOSITORY, creationTime, 1, creationTime, 0, CRASHED_OID, - CRASHED_OID, CRASHED_BRANCHID, CDORevision.UNSPECIFIED_DATE); + CRASHED_OID, CRASHED_OID, CRASHED_BRANCHID, CDORevision.UNSPECIFIED_DATE); OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.8"), creationTime)); //$NON-NLS-1$ } protected void reStart(Connection connection) { creationTime = DBUtil.selectMaximumLong(connection, CDODBSchema.REPOSITORY_CREATED); + long nextLocalObjectID = DBUtil.selectMaximumLong(connection, CDODBSchema.REPOSITORY_NEXT_LOCAL_CDOID); long lastObjectID = DBUtil.selectMaximumLong(connection, CDODBSchema.REPOSITORY_LAST_CDOID); long lastMetaID = DBUtil.selectMaximumLong(connection, CDODBSchema.REPOSITORY_LAST_METAID); int lastBranchID = DBUtil.selectMaximumInt(connection, CDODBSchema.REPOSITORY_LAST_BRANCHID); @@ -419,15 +420,17 @@ public class DBStore extends LongIDStore implements IDBStore { OM.LOG.info(Messages.getString("DBStore.9")); //$NON-NLS-1$ long[] result = mappingStrategy.repairAfterCrash(dbAdapter, connection); - lastObjectID = result[0]; - lastCommitTime = result[1]; + nextLocalObjectID = result[0]; + lastObjectID = result[1]; + lastCommitTime = result[2]; lastMetaID = DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGE_INFOS_META_UB); lastBranchID = DBUtil.selectMaximumInt(connection, CDODBSchema.BRANCHES_ID); OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.10"), lastObjectID, lastMetaID)); //$NON-NLS-1$ } - setLastMetaID(lastMetaID); + setNextLocalObjectID(nextLocalObjectID); setLastObjectID(lastObjectID); + setLastMetaID(lastMetaID); setLastBranchID(lastBranchID); setLastCommitTime(lastCommitTime); @@ -482,6 +485,10 @@ public class DBStore extends LongIDStore implements IDBStore builder.append("="); //$NON-NLS-1$ builder.append(getRepository().getTimeStamp()); builder.append(", "); //$NON-NLS-1$ + builder.append(CDODBSchema.REPOSITORY_NEXT_LOCAL_CDOID); + builder.append("="); //$NON-NLS-1$ + builder.append(getNextLocalObjectID()); + builder.append(", "); //$NON-NLS-1$ builder.append(CDODBSchema.REPOSITORY_LAST_CDOID); builder.append("="); //$NON-NLS-1$ builder.append(getLastObjectID()); diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java index 23713d38f6..97cd8b5c2c 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java @@ -73,10 +73,11 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS public long[] repairAfterCrash(IDBAdapter dbAdapter, Connection connection) { + long minLocalID = getMinLocalID(connection); long maxID = objectTypeCache.getMaxID(connection); long maxTime = getMaxTime(connection); - long[] result = { maxID, maxTime }; + long[] result = { minLocalID, maxID, maxTime }; return result; } @@ -188,6 +189,26 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS } } + private long getMinLocalID(Connection connection) + { + long min = Long.MAX_VALUE; + if (getStore().getRepository().isSupportingBranches()) + { + for (IClassMapping classMapping : getClassMappings().values()) + { + IDBTable table = classMapping.getDBTables().get(0); + IDBField field = table.getField(CDODBSchema.ATTRIBUTES_ID); + long id = DBUtil.selectMinimumLong(connection, field, "0>" + CDODBSchema.ATTRIBUTES_BRANCH); //$NON-NLS-1$ + if (id < min) + { + min = id; + } + } + } + + return min; + } + private long getMaxTime(Connection connection) { long max = CDORevision.UNSPECIFIED_DATE; diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStore.java index 74ea3e959d..fb4947133b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStore.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStore.java @@ -34,6 +34,9 @@ public abstract class LongIDStore extends Store @ExcludeFromDump private transient AtomicLong lastObjectID = new AtomicLong(); + @ExcludeFromDump + private transient AtomicLong nextLocalObjectID = new AtomicLong(Long.MAX_VALUE); + public LongIDStore(String type, Set<ChangeFormat> supportedChangeFormats, Set<RevisionTemporality> supportedRevisionTemporalities, Set<RevisionParallelism> supportedRevisionParallelisms) { @@ -50,8 +53,32 @@ public abstract class LongIDStore extends Store this.lastObjectID.set(lastObjectID); } - public CDOID getNextCDOID() + /** + * @since 3.0 + */ + public long getNextLocalObjectID() + { + return nextLocalObjectID.get(); + } + + /** + * @since 3.0 + */ + public void setNextLocalObjectID(long nextLocalObjectID) + { + this.nextLocalObjectID.set(nextLocalObjectID); + } + + /** + * @since 3.0 + */ + public CDOID getNextCDOID(boolean local) { + if (local) + { + return CDOIDUtil.createLong(nextLocalObjectID.getAndDecrement()); + } + return CDOIDUtil.createLong(lastObjectID.incrementAndGet()); } } diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStoreAccessor.java index edd7ccd5fe..6156f84f06 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/LongIDStoreAccessor.java @@ -51,7 +51,7 @@ public abstract class LongIDStoreAccessor extends StoreAccessor if (id instanceof CDOIDTemp) { CDOIDTemp oldID = (CDOIDTemp)id; - CDOID newID = longIDStore.getNextCDOID(); + CDOID newID = longIDStore.getNextCDOID(revision.getBranch().isLocal()); if (CDOIDUtil.isNull(newID) || newID.isTemporary()) { throw new IllegalStateException("newID=" + newID); //$NON-NLS-1$ diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java index 787d9df70f..b5687b856d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java @@ -317,9 +317,11 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa long now = session.getLastUpdateTime(); CDOBranchPoint target = getBranch().getPoint(now); + + CDOBranch sourceBranch = source.getBranch(); if (source.getTimeStamp() == CDOBranchPoint.UNSPECIFIED_DATE) { - source = source.getBranch().getPoint(now); + source = sourceBranch.getPoint(now); } if (CDOBranchUtil.isContainedBy(source, target)) @@ -349,6 +351,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa return null; } + if (sourceBranch.isLocal()) + { + } + return applyChangeSetData(ancestorInfo, targetInfo, result); } } diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java index fe73d4dcaa..9f33989f61 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java @@ -285,9 +285,48 @@ public final class DBUtil } } - public static int selectMaximumInt(Connection connection, IDBField field) throws DBException + /** + * @since 3.0 + */ + public static int selectMinimumInt(Connection connection, IDBField field, String... where) throws DBException + { + Number number = getFunctionResult(connection, field, "MIN", where); //$NON-NLS-1$ + if (number instanceof Integer) + { + return (Integer)number; + } + else if (number == null) + { + return 0; + } + + throw new DBException("Not an integer number: " + number); //$NON-NLS-1$ + } + + /** + * @since 3.0 + */ + public static long selectMinimumLong(Connection connection, IDBField field, String... where) throws DBException + { + Number number = getFunctionResult(connection, field, "MIN", where); //$NON-NLS-1$ + if (number instanceof Long) + { + return (Long)number; + } + else if (number == null) + { + return 0L; + } + + throw new DBException("Not a long number: " + number); //$NON-NLS-1$ + } + + /** + * @since 3.0 + */ + public static int selectMaximumInt(Connection connection, IDBField field, String... where) throws DBException { - Number number = getMaximumNumber(connection, field); + Number number = getFunctionResult(connection, field, "MAX", where); //$NON-NLS-1$ if (number instanceof Integer) { return (Integer)number; @@ -300,9 +339,12 @@ public final class DBUtil throw new DBException("Not an integer number: " + number); //$NON-NLS-1$ } - public static long selectMaximumLong(Connection connection, IDBField field) throws DBException + /** + * @since 3.0 + */ + public static long selectMaximumLong(Connection connection, IDBField field, String... where) throws DBException { - Number number = getMaximumNumber(connection, field); + Number number = getFunctionResult(connection, field, "MAX", where); //$NON-NLS-1$ if (number instanceof Long) { return (Long)number; @@ -315,14 +357,33 @@ public final class DBUtil throw new DBException("Not a long number: " + number); //$NON-NLS-1$ } - private static Number getMaximumNumber(Connection connection, IDBField field) throws DBException + private static Number getFunctionResult(Connection connection, IDBField field, String function, String... where) + throws DBException { StringBuilder builder = new StringBuilder(); - builder.append("SELECT MAX("); //$NON-NLS-1$ + builder.append("SELECT "); //$NON-NLS-1$ + builder.append(function); + builder.append("("); //$NON-NLS-1$ builder.append(field); builder.append(") FROM "); //$NON-NLS-1$ builder.append(field.getTable()); + for (int i = 0; i < where.length; i++) + { + if (i == 0) + { + builder.append(" WHERE "); //$NON-NLS-1$ + } + else + { + builder.append(" AND "); //$NON-NLS-1$ + } + + builder.append("("); //$NON-NLS-1$ + builder.append(where[i]); + builder.append(")"); //$NON-NLS-1$ + } + String sql = builder.toString(); trace(sql); Statement statement = null; |