Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-04-13 16:36:56 +0000
committerEike Stepper2010-04-13 16:36:56 +0000
commitbd188f02d5be908b95fcdfd005456556bd018828 (patch)
tree6e3651d10b078d06b584d948dabeeb64bde13587 /plugins
parentd75971af40d92181892288cb48d24427a8fc89ff (diff)
downloadcdo-bd188f02d5be908b95fcdfd005456556bd018828.tar.gz
cdo-bd188f02d5be908b95fcdfd005456556bd018828.tar.xz
cdo-bd188f02d5be908b95fcdfd005456556bd018828.zip
[256936] Support for Offline Mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256936
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchManagerImpl.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CreateBranchRequest.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java15
-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.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingRepository.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/clone/CloneRepository.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionProtocol.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java34
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java4
19 files changed, 161 insertions, 51 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
index 28c7fe17ee..1cab6e759b 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchImpl.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
+import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader.BranchInfo;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader.SubBranchInfo;
@@ -133,12 +134,12 @@ public class CDOBranchImpl extends Container<CDOBranch> implements InternalCDOBr
public InternalCDOBranch createBranch(String name, long timeStamp)
{
- return getBranchManager().createBranch(name, this, timeStamp);
+ return getBranchManager().createBranch(BranchLoader.NEW_BRANCH, name, this, timeStamp);
}
public InternalCDOBranch createBranch(String name)
{
- return getBranchManager().createBranch(name, this, CDOBranchPoint.UNSPECIFIED_DATE);
+ return createBranch(name, CDOBranchPoint.UNSPECIFIED_DATE);
}
public CDOBranch[] getElements()
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchManagerImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchManagerImpl.java
index 4326c488ac..36b937b83a 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/branch/CDOBranchManagerImpl.java
@@ -164,21 +164,33 @@ public class CDOBranchManagerImpl extends Lifecycle implements InternalCDOBranch
return branchLoader.loadBranches(startID, endID, handler);
}
- public InternalCDOBranch createBranch(String name, InternalCDOBranch baseBranch, long baseTimeStamp)
+ // public InternalCDOBranch createBranch(String name, InternalCDOBranch baseBranch, long baseTimeStamp)
+ // {
+ // return createBranch(name, baseBranch, baseTimeStamp, false);
+ // }
+ //
+ // public InternalCDOBranch createBranch(String name, InternalCDOBranch baseBranch, long baseTimeStamp, boolean local)
+ // {
+ // checkActive();
+ //
+ // if (baseTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE)
+ // {
+ // baseTimeStamp = timeProvider.getTimeStamp();
+ // }
+ //
+ // int branchID = branchLoader.createBranch(new BranchInfo(name, baseBranch.getID(), baseTimeStamp), local);
+ // return createBranch(branchID, name, baseBranch, baseTimeStamp);
+ // }
+
+ public InternalCDOBranch createBranch(int branchID, String name, InternalCDOBranch baseBranch, long baseTimeStamp)
{
checkActive();
-
if (baseTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE)
{
baseTimeStamp = timeProvider.getTimeStamp();
}
- int branchID = branchLoader.createBranch(new BranchInfo(name, baseBranch.getID(), baseTimeStamp));
- return createBranch(branchID, name, baseBranch, baseTimeStamp);
- }
-
- public InternalCDOBranch createBranch(int branchID, String name, InternalCDOBranch baseBranch, long baseTimeStamp)
- {
+ branchID = branchLoader.createBranch(branchID, new BranchInfo(name, baseBranch.getID(), baseTimeStamp));
CDOBranchPoint base = baseBranch.getPoint(baseTimeStamp);
InternalCDOBranch branch = new CDOBranchImpl(branchID, name, base);
synchronized (branches)
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
index 024bb81b62..7d3f206595 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
@@ -47,9 +47,7 @@ public interface InternalCDOBranchManager extends CDOBranchManager, ILifecycle
public InternalCDOBranch getBranch(String path);
- public InternalCDOBranch createBranch(String name, InternalCDOBranch baseBranch, long baseTimeStamp);
-
- public InternalCDOBranch createBranch(int branchID, String name, InternalCDOBranch baseBranch, long baseTimeStamp);
+ public InternalCDOBranch createBranch(int id, String name, InternalCDOBranch baseBranch, long baseTimeStamp);
public void handleBranchCreated(InternalCDOBranch branch);
@@ -59,7 +57,23 @@ public interface InternalCDOBranchManager extends CDOBranchManager, ILifecycle
*/
public interface BranchLoader
{
- public int createBranch(BranchInfo branchInfo);
+ /**
+ * Passed as the branchID in {@link #createBranch(int, BranchInfo)} causes a new non-local branch to be created.
+ */
+ public static final int NEW_BRANCH = Integer.MAX_VALUE;
+
+ /**
+ * Passed as the branchID in {@link #createBranch(int, BranchInfo)} causes a new local branch to be created.
+ */
+ public static final int NEW_LOCAL_BRANCH = Integer.MIN_VALUE;
+
+ /**
+ * Creates a new branch with the given id and branch info. If the id is equal to {@link #NEW_BRANCH} the implementor
+ * of this method will determine a new positive unique branch id.If the id is equal to {@link #NEW_LOCAL_BRANCH} the
+ * implementor of this method will determine a new negative unique branch id, so that the new branch becomes a local
+ * branch. In either case the used branch id is returned to the caller.
+ */
+ public int createBranch(int branchID, BranchInfo branchInfo);
public BranchInfo loadBranch(int branchID);
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
index fc82235476..8257a7bbed 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
@@ -111,9 +111,9 @@ public class CDOClientProtocol extends SignalProtocol<CDOSession> implements CDO
return send(new LoadPackagesRequest(this, (InternalCDOPackageUnit)packageUnit));
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
- return send(new CreateBranchRequest(this, branchInfo));
+ return send(new CreateBranchRequest(this, branchID, branchInfo));
}
public BranchInfo loadBranch(int branchID)
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CreateBranchRequest.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CreateBranchRequest.java
index 1fdf4fe23d..5d4f72372a 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CreateBranchRequest.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CreateBranchRequest.java
@@ -22,17 +22,21 @@ import java.io.IOException;
*/
public class CreateBranchRequest extends CDOClientRequest<Integer>
{
+ private int branchID;
+
private BranchInfo branchInfo;
- public CreateBranchRequest(CDOClientProtocol protocol, BranchInfo branchInfo)
+ public CreateBranchRequest(CDOClientProtocol protocol, int branchID, BranchInfo branchInfo)
{
super(protocol, CDOProtocolConstants.SIGNAL_CREATE_BRANCH);
+ this.branchID = branchID;
this.branchInfo = branchInfo;
}
@Override
protected void requesting(CDODataOutput out) throws IOException
{
+ out.writeInt(branchID);
branchInfo.write(out);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
index c795273ad8..a411bd3d5e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
@@ -135,7 +135,10 @@ public class CDODBBrowser extends Worker
}
catch (Exception ex)
{
- ex.printStackTrace();
+ if (isActive())
+ {
+ ex.printStackTrace();
+ }
}
finally
{
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 afe909fae6..48036885cd 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
@@ -57,8 +57,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -79,6 +79,8 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro
private static final String PROP_LAST_BRANCHID = "org.eclipse.emf.cdo.server.db.lastBranchID"; //$NON-NLS-1$
+ private static final String PROP_LAST_LOCAL_BRANCHID = "org.eclipse.emf.cdo.server.db.lastLocalBranchID"; //$NON-NLS-1$
+
private static final String PROP_LAST_COMMITTIME = "org.eclipse.emf.cdo.server.db.lastCommitTime"; //$NON-NLS-1$
private static final String PROP_GRACEFULLY_SHUT_DOWN = "org.eclipse.emf.cdo.server.db.gracefullyShutDown"; //$NON-NLS-1$
@@ -477,6 +479,7 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro
map.put(PROP_LAST_CDOID, Long.toString(getLastObjectID()));
map.put(PROP_LAST_METAID, Long.toString(getLastMetaID()));
map.put(PROP_LAST_BRANCHID, Integer.toString(getLastBranchID()));
+ map.put(PROP_LAST_LOCAL_BRANCHID, Integer.toString(getLastLocalBranchID()));
map.put(PROP_LAST_COMMITTIME, Long.toString(getLastCommitTime()));
setPropertyValues(map);
@@ -513,6 +516,7 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro
names.add(PROP_LAST_CDOID);
names.add(PROP_LAST_METAID);
names.add(PROP_LAST_BRANCHID);
+ names.add(PROP_LAST_LOCAL_BRANCHID);
names.add(PROP_LAST_COMMITTIME);
map = getPropertyValues(names);
@@ -520,6 +524,7 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro
setLastObjectID(Long.valueOf(map.get(PROP_LAST_CDOID)));
setLastMetaID(Long.valueOf(map.get(PROP_LAST_METAID)));
setLastBranchID(Integer.valueOf(map.get(PROP_LAST_BRANCHID)));
+ setLastLocalBranchID(Integer.valueOf(map.get(PROP_LAST_LOCAL_BRANCHID)));
setLastCommitTime(Long.valueOf(map.get(PROP_LAST_COMMITTIME)));
}
else
@@ -530,7 +535,13 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro
setNextLocalObjectID(result[0]);
setLastObjectID(result[1]);
setLastMetaID(DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGE_INFOS_META_UB));
- setLastBranchID(DBUtil.selectMaximumInt(connection, CDODBSchema.BRANCHES_ID));
+
+ int branchID = DBUtil.selectMaximumInt(connection, CDODBSchema.BRANCHES_ID);
+ setLastBranchID(branchID > 0 ? branchID : 0);
+
+ int localBranchID = DBUtil.selectMinimumInt(connection, CDODBSchema.BRANCHES_ID);
+ setLastLocalBranchID(localBranchID < 0 ? localBranchID : 0);
+
setLastCommitTime(result[2]);
OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.10"), getLastObjectID(), getLastMetaID())); //$NON-NLS-1$
}
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 23f530b9fd..0a6889fe43 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
@@ -545,23 +545,31 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
checkBranchingSupport();
- int id = getStore().getNextBranchID();
+ if (branchID == NEW_BRANCH)
+ {
+ branchID = getStore().getNextBranchID();
+ }
+ else if (branchID == NEW_LOCAL_BRANCH)
+ {
+ branchID = getStore().getNextLocalBranchID();
+ }
+
PreparedStatement pstmt = null;
try
{
pstmt = statementCache.getPreparedStatement(CDODBSchema.SQL_CREATE_BRANCH, ReuseProbability.LOW);
- pstmt.setInt(1, id);
+ pstmt.setInt(1, branchID);
pstmt.setString(2, branchInfo.getName());
pstmt.setInt(3, branchInfo.getBaseBranchID());
pstmt.setLong(4, branchInfo.getBaseTimeStamp());
CDODBUtil.sqlUpdate(pstmt, true);
getConnection().commit();
- return id;
+ return branchID;
}
catch (SQLException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
index 3d802be8fd..62c85c13de 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
@@ -352,9 +352,9 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
return revision;
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
- // TODO: implement HibernateStoreAccessor.createBranch(branchInfo)
+ // TODO: implement HibernateStoreAccessor.createBranch(branchID, branchInfo)
throw new UnsupportedOperationException();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java
index 09d27b78eb..cfcdcb052e 100644
--- a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CreateBranchIndication.java
@@ -25,6 +25,8 @@ import java.io.IOException;
*/
public class CreateBranchIndication extends CDOReadIndication
{
+ private int branchID;
+
private BranchInfo branchInfo;
public CreateBranchIndication(CDOServerProtocol protocol)
@@ -35,6 +37,7 @@ public class CreateBranchIndication extends CDOReadIndication
@Override
protected void indicating(CDODataInput in) throws IOException
{
+ branchID = in.readInt();
branchInfo = new BranchInfo(in);
}
@@ -43,7 +46,7 @@ public class CreateBranchIndication extends CDOReadIndication
{
InternalCDOBranchManager branchManager = getRepository().getBranchManager();
InternalCDOBranch baseBranch = branchManager.getBranch(branchInfo.getBaseBranchID());
- InternalCDOBranch branch = branchManager.createBranch(branchInfo.getName(), baseBranch, branchInfo
+ InternalCDOBranch branch = branchManager.createBranch(branchID, branchInfo.getName(), baseBranch, branchInfo
.getBaseTimeStamp());
out.writeInt(branch.getID());
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingRepository.java
index 518c30a269..0bb8a1873c 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingRepository.java
@@ -196,9 +196,9 @@ public abstract class DelegatingRepository implements InternalRepository
getDelegate().setBranchManager(branchManager);
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
- return getDelegate().createBranch(branchInfo);
+ return getDelegate().createBranch(branchID, branchInfo);
}
public BranchInfo loadBranch(int branchID)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index 9d8f7a917b..3a5ed2dc95 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -281,12 +281,12 @@ public class Repository extends Container<Object> implements InternalRepository
return accessor.loadPackageUnit((InternalCDOPackageUnit)packageUnit);
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
synchronized (createBranchLock)
{
IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- return accessor.createBranch(branchInfo);
+ return accessor.createBranch(branchID, branchInfo);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/clone/CloneRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/clone/CloneRepository.java
index 372894adaf..f100807afc 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/clone/CloneRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/clone/CloneRepository.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.internal.server.TransactionCommitContext;
+import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.spi.common.CDOReplicationContext;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
@@ -70,8 +71,6 @@ public class CloneRepository extends Repository.Default implements CDOReplicatio
private static final String PROP_LAST_REPLICATED_COMMIT_TIME = "org.eclipse.emf.cdo.server.clone.lastReplicatedCommitTime"; //$NON-NLS-1$
- private static final String PROP_LAST_TEMP_BRANCH_ID = "org.eclipse.emf.cdo.server.clone.lastTempBranchID"; //$NON-NLS-1$
-
private static final String PROP_GRACEFULLY_SHUT_DOWN = "org.eclipse.emf.cdo.server.clone.gracefullyShutDown"; //$NON-NLS-1$
private CloneSynchronizer synchronizer;
@@ -241,12 +240,10 @@ public class CloneRepository extends Repository.Default implements CDOReplicatio
Set<String> names = new HashSet<String>();
names.add(PROP_LAST_REPLICATED_BRANCH_ID);
names.add(PROP_LAST_REPLICATED_COMMIT_TIME);
- names.add(PROP_LAST_TEMP_BRANCH_ID);
map = store.getPropertyValues(names);
lastReplicatedBranchID = Integer.valueOf(map.get(PROP_LAST_REPLICATED_BRANCH_ID));
lastReplicatedCommitTime = Long.valueOf(map.get(PROP_LAST_REPLICATED_COMMIT_TIME));
- lastTempBranchID.set(Integer.valueOf(map.get(PROP_LAST_TEMP_BRANCH_ID)));
}
else
{
@@ -268,8 +265,6 @@ public class CloneRepository extends Repository.Default implements CDOReplicatio
Map<String, String> map = new HashMap<String, String>();
map.put(PROP_LAST_REPLICATED_BRANCH_ID, Integer.toString(lastReplicatedBranchID));
map.put(PROP_LAST_REPLICATED_COMMIT_TIME, Long.toString(lastReplicatedCommitTime));
- map.put(PROP_LAST_TEMP_BRANCH_ID, Integer.toString(lastTempBranchID.get()));
- map.put(PROP_LAST_TEMP_BRANCH_ID, Integer.toString(lastTempBranchID.get()));
map.put(PROP_GRACEFULLY_SHUT_DOWN, Boolean.TRUE.toString());
InternalStore store = getStore();
@@ -286,9 +281,17 @@ public class CloneRepository extends Repository.Default implements CDOReplicatio
protected CDOBranch createOfflineBranch(CDOBranch baseBranch, long baseTimeStamp)
{
- int branchID = lastTempBranchID.decrementAndGet();
- InternalCDOBranchManager branchManager = getBranchManager();
- return branchManager.createBranch(branchID, "Offline" + branchID, (InternalCDOBranch)baseBranch, baseTimeStamp); //$NON-NLS-1$
+ try
+ {
+ StoreThreadLocal.setSession(replicatorSession);
+ InternalCDOBranchManager branchManager = getBranchManager();
+ return branchManager.createBranch(NEW_LOCAL_BRANCH,
+ "Offline-" + baseTimeStamp, (InternalCDOBranch)baseBranch, baseTimeStamp); //$NON-NLS-1$
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionProtocol.java
index cde8282629..c3199edf5d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionProtocol.java
@@ -103,7 +103,7 @@ public class EmbeddedClientSessionProtocol extends Lifecycle implements CDOSessi
throw new UnsupportedOperationException();
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
throw new UnsupportedOperationException();
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
index 3de46fbb3e..db879ad745 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
@@ -71,6 +71,10 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
private Map<Integer, BranchInfo> branchInfos = new HashMap<Integer, BranchInfo>();
+ private int lastBranchID;
+
+ private int lastLocalBranchID;
+
private Map<Object, List<InternalCDORevision>> revisions = new HashMap<Object, List<InternalCDORevision>>();
private List<CommitInfo> commitInfos = new ArrayList<CommitInfo>();
@@ -129,11 +133,19 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
}
}
- public synchronized int createBranch(BranchInfo branchInfo)
+ public synchronized int createBranch(int branchID, BranchInfo branchInfo)
{
- int id = branchInfos.size() + 1;
- branchInfos.put(id, branchInfo);
- return id;
+ if (branchID == NEW_BRANCH)
+ {
+ branchID = ++lastBranchID;
+ }
+ else if (branchID == NEW_LOCAL_BRANCH)
+ {
+ branchID = --lastLocalBranchID;
+ }
+
+ branchInfos.put(branchID, branchInfo);
+ return branchID;
}
public synchronized BranchInfo loadBranch(int branchID)
@@ -589,6 +601,13 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
protected void doDeactivate() throws Exception
{
revisions.clear();
+ branchInfos.clear();
+ commitInfos.clear();
+ objectTypes.clear();
+ properties.clear();
+ resourceNameFeature = null;
+ lastBranchID = 0;
+ lastLocalBranchID = 0;
super.doDeactivate();
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
index c6f7f7afb8..02446a47ae 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
@@ -157,9 +157,9 @@ public class MEMStoreAccessor extends LongIDStoreAccessor
throw new UnsupportedOperationException();
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
- return getStore().createBranch(branchInfo);
+ return getStore().createBranch(branchID, branchInfo);
}
public BranchInfo loadBranch(int branchID)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
index 76444e9566..ad7e9cf939 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
@@ -34,6 +34,8 @@ public interface InternalStore extends IStore, ILifecycle
public int getNextBranchID();
+ public int getNextLocalBranchID();
+
public long getLastCommitTime();
public void setLastCommitTime(long lastCommitTime);
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
index 1d8dc05fe2..4b2fe09122 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
@@ -14,9 +14,9 @@ import org.eclipse.emf.cdo.common.CDOCommonView;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
import org.eclipse.emf.cdo.common.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.server.IRepository;
@@ -27,8 +27,8 @@ import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -79,6 +79,12 @@ public abstract class Store extends Lifecycle implements InternalStore
@ExcludeFromDump
private transient int lastBranchID;
+ /**
+ * Is protected against concurrent thread access through {@link Repository#createBranchLock}.
+ */
+ @ExcludeFromDump
+ private transient int lastLocalBranchID;
+
@ExcludeFromDump
private transient long lastMetaID;
@@ -223,6 +229,30 @@ public abstract class Store extends Lifecycle implements InternalStore
return ++lastBranchID;
}
+ /**
+ * @since 3.0
+ */
+ public int getLastLocalBranchID()
+ {
+ return lastLocalBranchID;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void setLastLocalBranchID(int lastLocalBranchID)
+ {
+ this.lastLocalBranchID = lastLocalBranchID;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public int getNextLocalBranchID()
+ {
+ return --lastLocalBranchID;
+ }
+
public long getLastMetaID()
{
synchronized (lastMetaIDLock)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java
index 4a75ce0aeb..08de5d5631 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java
@@ -1563,14 +1563,14 @@ public abstract class CDOSessionImpl extends Container<CDOView> implements Inter
}
}
- public int createBranch(BranchInfo branchInfo)
+ public int createBranch(int branchID, BranchInfo branchInfo)
{
int attempt = 0;
for (;;)
{
try
{
- return delegate.createBranch(branchInfo);
+ return delegate.createBranch(branchID, branchInfo);
}
catch (Exception ex)
{

Back to the top