Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2016-12-14 03:06:34 -0500
committerEike Stepper2016-12-14 03:06:34 -0500
commite06ec8c3a7c6a8cfa334752f3435264d5dc6dd7c (patch)
tree7a87ada54a771b2207bbe48b8a5a8d71502305e8 /plugins/org.eclipse.emf.cdo.server.embedded
parent5986b206d25da8e5d040cc042cba11fa1581b272 (diff)
downloadcdo-e06ec8c3a7c6a8cfa334752f3435264d5dc6dd7c.tar.gz
cdo-e06ec8c3a7c6a8cfa334752f3435264d5dc6dd7c.tar.xz
cdo-e06ec8c3a7c6a8cfa334752f3435264d5dc6dd7c.zip
[509149] Provide an EmbeddedRepository
https://bugs.eclipse.org/bugs/show_bug.cgi?id=509149
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.embedded')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/.settings/.api_filters24
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/embedded/CDOEmbeddedRepositoryConfig.java87
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/AbstractClientManager.java94
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientBranchManager.java133
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientRevisionManager.java297
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java494
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerBranchLoader.java157
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerRevisionLoader.java123
-rw-r--r--plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerSession.java40
10 files changed, 960 insertions, 491 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/.settings/.api_filters b/plugins/org.eclipse.emf.cdo.server.embedded/.settings/.api_filters
index 1246807b0e..eb8bc080dc 100644
--- a/plugins/org.eclipse.emf.cdo.server.embedded/.settings/.api_filters
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/.settings/.api_filters
@@ -1,18 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.emf.cdo.server.embedded" version="2">
- <resource path="src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java" type="org.eclipse.emf.cdo.server.internal.embedded.EmbeddedRepository$ClientAwareRevisionLoader">
+ <resource path="src/org/eclipse/emf/cdo/server/internal/embedded/ClientBranchManager.java" type="org.eclipse.emf.cdo.server.internal.embedded.ClientBranchManager">
<filter id="574619656">
<message_arguments>
- <message_argument value="RevisionLoader"/>
- <message_argument value="ClientAwareRevisionLoader"/>
+ <message_argument value="InternalCDOBranchManager"/>
+ <message_argument value="ClientBranchManager"/>
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java" type="org.eclipse.emf.cdo.server.internal.embedded.EmbeddedRepository$DelegatingRevisionManager">
+ <resource path="src/org/eclipse/emf/cdo/server/internal/embedded/ClientRevisionManager.java" type="org.eclipse.emf.cdo.server.internal.embedded.ClientRevisionManager">
<filter id="574619656">
<message_arguments>
<message_argument value="InternalCDORevisionManager"/>
- <message_argument value="DelegatingRevisionManager"/>
+ <message_argument value="ClientRevisionManager"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/emf/cdo/server/internal/embedded/ServerRevisionLoader.java" type="org.eclipse.emf.cdo.server.internal.embedded.ServerRevisionLoader">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="RevisionLoader"/>
+ <message_argument value="ServerRevisionLoader"/>
+ </message_arguments>
+ </filter>
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="RevisionLoader2"/>
+ <message_argument value="ServerRevisionLoader"/>
</message_arguments>
</filter>
</resource>
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.embedded/META-INF/MANIFEST.MF
index 9a44dff2c3..d63f001f49 100644
--- a/plugins/org.eclipse.emf.cdo.server.embedded/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/META-INF/MANIFEST.MF
@@ -14,5 +14,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)";resoluti
org.eclipse.emf.cdo.server.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.net4j.jvm;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo.server.embedded;version="4.6.0",
- org.eclipse.emf.cdo.server.internal.embedded;version="4.6.0";x-internal:=true,
+ org.eclipse.emf.cdo.server.internal.embedded;version="4.6.0";x-friends:="org.eclipse.emf.cdo.tests",
org.eclipse.emf.cdo.server.internal.embedded.bundle;version="4.6.0";x-internal:=true
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/embedded/CDOEmbeddedRepositoryConfig.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/embedded/CDOEmbeddedRepositoryConfig.java
index 68cef3cfe4..208d2e2933 100644
--- a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/embedded/CDOEmbeddedRepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/embedded/CDOEmbeddedRepositoryConfig.java
@@ -1,17 +1,34 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
package org.eclipse.emf.cdo.server.embedded;
+import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
+import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
import org.eclipse.emf.cdo.net4j.CDONet4jSession;
import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
+import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.internal.embedded.EmbeddedRepository;
-import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.spi.server.InternalStore;
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.emf.ecore.EPackage;
@@ -27,6 +44,8 @@ import java.util.Map;
*/
public abstract class CDOEmbeddedRepositoryConfig extends Lifecycle
{
+ private static final String JVM_ACCEPTOR_PREFIX = "cdo_embedded_repo_";
+
private final String repositoryName;
private EmbeddedRepository repository;
@@ -41,7 +60,7 @@ public abstract class CDOEmbeddedRepositoryConfig extends Lifecycle
return repository;
}
- public final CDOSession openClientSession()
+ public final CDONet4jSession openClientSession()
{
return repository.openClientSession();
}
@@ -96,22 +115,55 @@ public abstract class CDOEmbeddedRepositoryConfig extends Lifecycle
/**
* Subclasses may override.
*/
- public void modifySessionConfiguration(IRepository repository, CDONet4jSessionConfiguration config)
+ public void modifySession(IRepository repository, CDONet4jSession session)
{
- // Do nothing.
+ session.options().setCommitTimeout(Integer.MAX_VALUE);
}
/**
* Subclasses may override.
*/
- public void modifySession(IRepository repository, CDONet4jSession session)
+ public CDONet4jSessionConfiguration createSessionConfiguration(IConnector connector, CDOBranchManager branchManager, CDORevisionManager revisionManager)
{
- // Do nothing.
+ CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration();
+ configuration.setConnector(connector);
+ configuration.setRepositoryName(repositoryName);
+ configuration.setSignalTimeout(Integer.MAX_VALUE);
+ configuration.setBranchManager(branchManager);
+ configuration.setRevisionManager(revisionManager);
+ return configuration;
+ }
+
+ /**
+ * Subclasses may override.
+ */
+ public IAcceptor createAcceptor(IManagedContainer container)
+ {
+ return JVMUtil.getAcceptor(container, JVM_ACCEPTOR_PREFIX + repositoryName);
+ }
+
+ /**
+ * Subclasses may override.
+ */
+ public IConnector createConnector(IManagedContainer container)
+ {
+ return JVMUtil.getConnector(container, JVM_ACCEPTOR_PREFIX + repositoryName);
}
- public abstract IStore createStore();
+ public abstract IStore createStore(IManagedContainer container);
- public abstract void initProperties(Map<String, String> properties);
+ public abstract void initProperties(IManagedContainer container, Map<String, String> properties);
+
+ protected void activateRepository(IRepository repository)
+ {
+ LifecycleUtil.activate(repository);
+ }
+
+ protected void deactivateRepository()
+ {
+ LifecycleUtil.deactivate(repository);
+ repository = null;
+ }
@Override
protected void doActivate() throws Exception
@@ -120,25 +172,34 @@ public abstract class CDOEmbeddedRepositoryConfig extends Lifecycle
IManagedContainer container = getContainer();
// Initialize store.
- IStore store = createStore();
+ IStore store = createStore(container);
// Initialize properties.
Map<String, String> properties = new HashMap<String, String>();
properties.put(IRepository.Props.OVERRIDE_UUID, "");
- initProperties(properties);
+ initProperties(container, properties);
repository = new EmbeddedRepository(this);
((InternalRepository)repository).setContainer(container);
((InternalRepository)repository).setName(repositoryName);
((InternalRepository)repository).setStore((InternalStore)store);
((InternalRepository)repository).setProperties(properties);
- LifecycleUtil.activate(repository);
+
+ activateRepository(repository);
+
+ repository.addListener(new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ CDOEmbeddedRepositoryConfig.this.deactivate();
+ }
+ });
}
@Override
protected void doDeactivate() throws Exception
{
- LifecycleUtil.deactivate(repository);
- repository = null;
+ deactivateRepository();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/AbstractClientManager.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/AbstractClientManager.java
new file mode 100644
index 0000000000..a5bf5a5648
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/AbstractClientManager.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.net4j.CDONet4jSession;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+import org.eclipse.emf.cdo.spi.server.InternalSession;
+import org.eclipse.emf.cdo.spi.server.InternalSessionManager;
+
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleException;
+import org.eclipse.net4j.util.lifecycle.LifecycleState;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractClientManager<T extends ILifecycle> implements ILifecycle
+{
+ protected final T delegate;
+
+ protected CDONet4jSession clientSession;
+
+ protected InternalSession serverSession;
+
+ private LifecycleState lifecycleState = LifecycleState.INACTIVE;
+
+ public AbstractClientManager(T delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public boolean hasListeners()
+ {
+ return delegate.hasListeners();
+ }
+
+ public IListener[] getListeners()
+ {
+ return delegate.getListeners();
+ }
+
+ public void addListener(IListener listener)
+ {
+ delegate.addListener(listener);
+ }
+
+ public void removeListener(IListener listener)
+ {
+ delegate.removeListener(listener);
+ }
+
+ public LifecycleState getLifecycleState()
+ {
+ return lifecycleState;
+ }
+
+ public boolean isActive()
+ {
+ return lifecycleState == LifecycleState.ACTIVE;
+ }
+
+ public void activate() throws LifecycleException
+ {
+ lifecycleState = LifecycleState.ACTIVE;
+ }
+
+ public Exception deactivate()
+ {
+ lifecycleState = LifecycleState.INACTIVE;
+ clientSession = null;
+ serverSession = null;
+ return null;
+ }
+
+ protected final void initServerSession(CDONet4jSession clientSession)
+ {
+ this.clientSession = clientSession;
+
+ InternalRepository repository = getRepository(delegate);
+ InternalSessionManager sessionManager = repository.getSessionManager();
+ serverSession = sessionManager.getSession(clientSession.getSessionID());
+ }
+
+ protected abstract InternalRepository getRepository(T delegate);
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientBranchManager.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientBranchManager.java
new file mode 100644
index 0000000000..d2df1a40ae
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientBranchManager.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchChangedEvent.ChangeKind;
+import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
+import org.eclipse.emf.cdo.common.util.CDOTimeProvider;
+import org.eclipse.emf.cdo.net4j.CDONet4jSession;
+import org.eclipse.emf.cdo.session.CDORepositoryInfo;
+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.BranchInfo;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+/**
+ * @author Eike Stepper
+ */
+public class ClientBranchManager extends AbstractClientManager<InternalCDOBranchManager> implements InternalCDOBranchManager
+{
+ public ClientBranchManager(InternalCDOBranchManager delegate)
+ {
+ super(delegate);
+ }
+
+ public void initMainBranch(boolean local, long timestamp)
+ {
+ // Do nothing.
+ }
+
+ public CDOCommonRepository getRepository()
+ {
+ if (clientSession == null)
+ {
+ return null;
+ }
+
+ return clientSession.getRepositoryInfo();
+ }
+
+ public void setRepository(CDOCommonRepository repository)
+ {
+ initServerSession((CDONet4jSession)((CDORepositoryInfo)repository).getSession());
+ }
+
+ public BranchLoader getBranchLoader()
+ {
+ return delegate.getBranchLoader();
+ }
+
+ public void setBranchLoader(BranchLoader branchLoader)
+ {
+ // Do nothing.
+ }
+
+ public CDOTimeProvider getTimeProvider()
+ {
+ return delegate.getTimeProvider();
+ }
+
+ public InternalCDOBranch getMainBranch()
+ {
+ return delegate.getMainBranch();
+ }
+
+ public InternalCDOBranch getBranch(int branchID)
+ {
+ return delegate.getBranch(branchID);
+ }
+
+ public InternalCDOBranch getBranch(int id, String name, InternalCDOBranch baseBranch, long baseTimeStamp)
+ {
+ return delegate.getBranch(id, name, baseBranch, baseTimeStamp);
+ }
+
+ public InternalCDOBranch getBranch(int id, BranchInfo branchInfo)
+ {
+ return delegate.getBranch(id, branchInfo);
+ }
+
+ public InternalCDOBranch getBranch(String path)
+ {
+ return delegate.getBranch(path);
+ }
+
+ public InternalCDOBranch createBranch(int id, String name, InternalCDOBranch baseBranch, long baseTimeStamp)
+ {
+ return delegate.createBranch(id, name, baseBranch, baseTimeStamp);
+ }
+
+ public void handleBranchChanged(InternalCDOBranch branch, ChangeKind changeKind)
+ {
+ delegate.handleBranchChanged(branch, changeKind);
+ }
+
+ public int getBranches(int startID, int endID, CDOBranchHandler handler)
+ {
+ return delegate.getBranches(startID, endID, handler);
+ }
+
+ @Deprecated
+ public void setTimeProvider(CDOTimeProvider timeProvider)
+ {
+ // Do nothing.
+ }
+
+ @Deprecated
+ public void renameBranch(CDOBranch branch, String newName)
+ {
+ // Do nothing.
+ }
+
+ @Deprecated
+ public void handleBranchCreated(InternalCDOBranch branch)
+ {
+ // Do nothing.
+ }
+
+ @Override
+ protected InternalRepository getRepository(InternalCDOBranchManager delegate)
+ {
+ return (InternalRepository)delegate.getRepository();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientRevisionManager.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientRevisionManager.java
new file mode 100644
index 0000000000..49899cf76a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ClientRevisionManager.java
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionCache;
+import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
+import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
+import org.eclipse.emf.cdo.net4j.CDONet4jSession;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionCache;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
+import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+import org.eclipse.emf.ecore.EClass;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ClientRevisionManager extends AbstractClientManager<InternalCDORevisionManager> implements InternalCDORevisionManager
+{
+ public ClientRevisionManager(InternalCDORevisionManager delegate)
+ {
+ super(delegate);
+ }
+
+ public RevisionLocker getRevisionLocker()
+ {
+ return delegate.getRevisionLocker();
+ }
+
+ public void setRevisionLocker(RevisionLocker revisionLocker)
+ {
+ if (revisionLocker instanceof CDONet4jSession)
+ {
+ initServerSession((CDONet4jSession)revisionLocker);
+ }
+ }
+
+ public RevisionLoader getRevisionLoader()
+ {
+ return delegate.getRevisionLoader();
+ }
+
+ public void setRevisionLoader(RevisionLoader revisionLoader)
+ {
+ // Do nothing.
+ }
+
+ public CDORevisionFactory getFactory()
+ {
+ return delegate.getFactory();
+ }
+
+ public void setFactory(CDORevisionFactory factory)
+ {
+ // Do nothing.
+ }
+
+ public InternalCDORevisionCache getCache()
+ {
+ return delegate.getCache();
+ }
+
+ public void setCache(CDORevisionCache cache)
+ {
+ // Do nothing.
+ }
+
+ public boolean isSupportingAudits()
+ {
+ return delegate.isSupportingAudits();
+ }
+
+ public void setSupportingAudits(boolean on)
+ {
+ // Do nothing.
+ }
+
+ public boolean isSupportingBranches()
+ {
+ return delegate.isSupportingBranches();
+ }
+
+ public void setSupportingBranches(boolean on)
+ {
+ // Do nothing.
+ }
+
+ public EClass getObjectType(CDOID id)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getObjectType(id);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public EClass getObjectType(CDOID id, CDOBranchManager branchManagerForLoadOnDemand)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getObjectType(id, branchManagerForLoadOnDemand);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public CDOBranchPointRange getObjectLifetime(CDOID id, CDOBranchPoint branchPoint)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getObjectLifetime(id, branchPoint);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public boolean containsRevision(CDOID id, CDOBranchPoint branchPoint)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.containsRevision(id, branchPoint);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public boolean containsRevisionByVersion(CDOID id, CDOBranchVersion branchVersion)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.containsRevisionByVersion(id, branchVersion);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand,
+ SyntheticCDORevision[] synthetics)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getRevision(id, branchPoint, referenceChunk, prefetchDepth, loadOnDemand, synthetics);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public List<CDORevision> getRevisions(List<CDOID> ids, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand,
+ SyntheticCDORevision[] synthetics)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, loadOnDemand, synthetics);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getRevision(id, branchPoint, referenceChunk, prefetchDepth, loadOnDemand);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public InternalCDORevision getRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk, boolean loadOnDemand)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getRevisionByVersion(id, branchVersion, referenceChunk, loadOnDemand);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public List<CDORevision> getRevisions(List<CDOID> ids, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ return delegate.getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, loadOnDemand);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, CDORevisionHandler handler)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public void addRevision(CDORevision revision)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ delegate.addRevision(revision);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public void reviseLatest(CDOID id, CDOBranch branch)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ delegate.reviseLatest(id, branch);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ public void reviseVersion(CDOID id, CDOBranchVersion branchVersion, long timeStamp)
+ {
+ try
+ {
+ ServerSession.set(serverSession);
+ delegate.reviseVersion(id, branchVersion, timeStamp);
+ }
+ finally
+ {
+ ServerSession.unset();
+ }
+ }
+
+ @Override
+ protected InternalRepository getRepository(InternalCDORevisionManager delegate)
+ {
+ ServerRevisionLoader revisionLoader = (ServerRevisionLoader)delegate.getRevisionLoader();
+ return (InternalRepository)revisionLoader.getDelegate();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java
index 8437f99345..9bf6c7d73d 100644
--- a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/EmbeddedRepository.java
@@ -1,32 +1,24 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
package org.eclipse.emf.cdo.server.internal.embedded;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionCache;
-import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.net4j.CDONet4jSession;
import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
-import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.server.embedded.CDOEmbeddedRepositoryConfig;
import org.eclipse.emf.cdo.server.net4j.CDONet4jServerUtil;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionCache;
+import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager.RevisionLoader;
-import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo;
-import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-import org.eclipse.emf.cdo.spi.server.InternalSessionManager;
import org.eclipse.emf.cdo.spi.server.InternalStore;
import org.eclipse.emf.cdo.spi.server.RepositoryFactory;
@@ -35,13 +27,9 @@ import org.eclipse.net4j.acceptor.IAcceptor;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.LifecycleException;
-import org.eclipse.net4j.util.lifecycle.LifecycleState;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import java.util.ArrayList;
@@ -52,8 +40,6 @@ import java.util.List;
*/
public class EmbeddedRepository extends Repository.Default
{
- private static final String JVM_ACCEPTOR_PREFIX = "cdo_embedded_repo_";
-
private CDOEmbeddedRepositoryConfig config;
private IAcceptor acceptor;
@@ -67,12 +53,13 @@ public class EmbeddedRepository extends Repository.Default
public CDONet4jSession openClientSession()
{
- CDORevisionManager revisionManager = new DelegatingRevisionManager(getRevisionManager());
- CDONet4jSessionConfiguration configuration = createSessionConfiguration(connector, revisionManager);
+ CDOBranchManager branchManager = new ClientBranchManager(getBranchManager());
+ CDORevisionManager revisionManager = new ClientRevisionManager(getRevisionManager());
+
+ CDONet4jSessionConfiguration configuration = config.createSessionConfiguration(connector, branchManager, revisionManager);
CDONet4jSession session = configuration.openNet4jSession();
- session.options().setCommitTimeout(Integer.MAX_VALUE);
- config.modifySessionConfiguration(this, configuration);
+ config.modifySession(this, session);
return session;
}
@@ -106,8 +93,11 @@ public class EmbeddedRepository extends Repository.Default
super.doBeforeActivate();
+ InternalCDOBranchManager branchManager = getBranchManager();
+ branchManager.setBranchLoader(new ServerBranchLoader(this));
+
InternalCDORevisionManager revisionManager = getRevisionManager();
- revisionManager.setRevisionLoader(new ClientAwareRevisionLoader(this));
+ revisionManager.setRevisionLoader(new ServerRevisionLoader(this));
}
@Override
@@ -118,8 +108,8 @@ public class EmbeddedRepository extends Repository.Default
IManagedContainer container = getContainer();
container.putElement(RepositoryFactory.PRODUCT_GROUP, RepositoryFactory.TYPE, getName(), this);
- acceptor = createAcceptor(container);
- connector = createConnector(container);
+ acceptor = config.createAcceptor(container);
+ connector = config.createConnector(container);
InternalStore store = getStore();
if (store.isFirstStart())
@@ -132,22 +122,6 @@ public class EmbeddedRepository extends Repository.Default
}
}
- protected void doAfterFirstStart()
- {
- // Subclasses may override.
- }
-
- protected void doAfterReStart()
- {
- // Subclasses may override.
- }
-
- @Override
- protected void doBeforeDeactivate() throws Exception
- {
- super.doBeforeDeactivate();
- }
-
@Override
protected void doDeactivate() throws Exception
{
@@ -159,428 +133,4 @@ public class EmbeddedRepository extends Repository.Default
super.doDeactivate();
}
-
- protected IAcceptor createAcceptor(IManagedContainer container)
- {
- return JVMUtil.getAcceptor(container, JVM_ACCEPTOR_PREFIX + getName());
- }
-
- protected IConnector createConnector(IManagedContainer container)
- {
- return JVMUtil.getConnector(container, JVM_ACCEPTOR_PREFIX + getName());
- }
-
- protected CDONet4jSessionConfiguration createSessionConfiguration(IConnector connector, CDORevisionManager revisionManager)
- {
- CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration();
- configuration.setConnector(connector);
- configuration.setRepositoryName(getName());
- configuration.setSignalTimeout(Integer.MAX_VALUE);
- configuration.setRevisionManager(revisionManager);
- config.modifySessionConfiguration(this, configuration);
- return configuration;
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class ClientAwareRevisionLoader implements RevisionLoader
- {
- private static final ThreadLocal<InternalSession> SERVER_SESSION = new ThreadLocal<InternalSession>();
-
- private final RevisionLoader delegate;
-
- private ClientAwareRevisionLoader(RevisionLoader delegate)
- {
- this.delegate = delegate;
- }
-
- public RevisionLoader getDelegate()
- {
- return delegate;
- }
-
- public List<RevisionInfo> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth)
- {
- InternalSession serverSession = SERVER_SESSION.get();
- if (serverSession != null)
- {
- try
- {
- StoreThreadLocal.setSession(serverSession);
- return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth);
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth);
- }
-
- public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk)
- {
- InternalSession serverSession = SERVER_SESSION.get();
- if (serverSession != null)
- {
- try
- {
- StoreThreadLocal.setSession(serverSession);
- return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk);
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk);
- }
-
- public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, CDORevisionHandler handler)
- {
- InternalSession serverSession = SERVER_SESSION.get();
- if (serverSession != null)
- {
- try
- {
- StoreThreadLocal.setSession(serverSession);
- delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
- else
- {
- delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class DelegatingRevisionManager implements InternalCDORevisionManager
- {
- private final InternalCDORevisionManager delegate;
-
- private LifecycleState lifecycleState = LifecycleState.INACTIVE;
-
- private CDONet4jSession clientSession;
-
- private InternalSession serverSession;
-
- public DelegatingRevisionManager(InternalCDORevisionManager delegate)
- {
- this.delegate = delegate;
- }
-
- public boolean hasListeners()
- {
- return delegate.hasListeners();
- }
-
- public IListener[] getListeners()
- {
- return delegate.getListeners();
- }
-
- public void addListener(IListener listener)
- {
- delegate.addListener(listener);
- }
-
- public void removeListener(IListener listener)
- {
- delegate.removeListener(listener);
- }
-
- public LifecycleState getLifecycleState()
- {
- return lifecycleState;
- }
-
- public boolean isActive()
- {
- return lifecycleState == LifecycleState.ACTIVE;
- }
-
- public void activate() throws LifecycleException
- {
- lifecycleState = LifecycleState.ACTIVE;
- }
-
- public Exception deactivate()
- {
- lifecycleState = LifecycleState.INACTIVE;
- serverSession = null;
- clientSession = null;
- return null;
- }
-
- public RevisionLocker getRevisionLocker()
- {
- return delegate.getRevisionLocker();
- }
-
- public void setRevisionLocker(RevisionLocker revisionLocker)
- {
- if (revisionLocker instanceof CDONet4jSession)
- {
- clientSession = (CDONet4jSession)revisionLocker;
-
- ClientAwareRevisionLoader revisionLoader = (ClientAwareRevisionLoader)delegate.getRevisionLoader();
- InternalRepository repository = (InternalRepository)revisionLoader.getDelegate();
- InternalSessionManager sessionManager = repository.getSessionManager();
- serverSession = sessionManager.getSession(clientSession.getSessionID());
- }
- }
-
- public RevisionLoader getRevisionLoader()
- {
- return delegate.getRevisionLoader();
- }
-
- public void setRevisionLoader(RevisionLoader revisionLoader)
- {
- // Do nothing.
- }
-
- public CDORevisionFactory getFactory()
- {
- return delegate.getFactory();
- }
-
- public void setFactory(CDORevisionFactory factory)
- {
- // Do nothing.
- }
-
- public InternalCDORevisionCache getCache()
- {
- return delegate.getCache();
- }
-
- public void setCache(CDORevisionCache cache)
- {
- // Do nothing.
- }
-
- public boolean isSupportingAudits()
- {
- return delegate.isSupportingAudits();
- }
-
- public void setSupportingAudits(boolean on)
- {
- // Do nothing.
- }
-
- public boolean isSupportingBranches()
- {
- return delegate.isSupportingBranches();
- }
-
- public void setSupportingBranches(boolean on)
- {
- // Do nothing.
- }
-
- public EClass getObjectType(CDOID id)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getObjectType(id);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public EClass getObjectType(CDOID id, CDOBranchManager branchManagerForLoadOnDemand)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getObjectType(id, branchManagerForLoadOnDemand);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public CDOBranchPointRange getObjectLifetime(CDOID id, CDOBranchPoint branchPoint)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getObjectLifetime(id, branchPoint);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public boolean containsRevision(CDOID id, CDOBranchPoint branchPoint)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.containsRevision(id, branchPoint);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public boolean containsRevisionByVersion(CDOID id, CDOBranchVersion branchVersion)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.containsRevisionByVersion(id, branchVersion);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand,
- SyntheticCDORevision[] synthetics)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getRevision(id, branchPoint, referenceChunk, prefetchDepth, loadOnDemand, synthetics);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public List<CDORevision> getRevisions(List<CDOID> ids, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand,
- SyntheticCDORevision[] synthetics)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, loadOnDemand, synthetics);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getRevision(id, branchPoint, referenceChunk, prefetchDepth, loadOnDemand);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public InternalCDORevision getRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk, boolean loadOnDemand)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getRevisionByVersion(id, branchVersion, referenceChunk, loadOnDemand);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public List<CDORevision> getRevisions(List<CDOID> ids, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth, boolean loadOnDemand)
- {
- try
- {
- setServerSession(serverSession);
- return delegate.getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, loadOnDemand);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, CDORevisionHandler handler)
- {
- try
- {
- setServerSession(serverSession);
- delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public void addRevision(CDORevision revision)
- {
- try
- {
- setServerSession(serverSession);
- delegate.addRevision(revision);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public void reviseLatest(CDOID id, CDOBranch branch)
- {
- try
- {
- setServerSession(serverSession);
- delegate.reviseLatest(id, branch);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- public void reviseVersion(CDOID id, CDOBranchVersion branchVersion, long timeStamp)
- {
- try
- {
- setServerSession(serverSession);
- delegate.reviseVersion(id, branchVersion, timeStamp);
- }
- finally
- {
- unsetServerSession();
- }
- }
-
- private static void setServerSession(InternalSession serverSession)
- {
- ClientAwareRevisionLoader.SERVER_SESSION.set(serverSession);
- }
-
- private static void unsetServerSession()
- {
- ClientAwareRevisionLoader.SERVER_SESSION.remove();
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerBranchLoader.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerBranchLoader.java
new file mode 100644
index 0000000000..d5a213ba97
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerBranchLoader.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.server.ISessionManager;
+import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader3;
+import org.eclipse.emf.cdo.spi.server.InternalSession;
+
+import org.eclipse.net4j.util.collection.Pair;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ServerBranchLoader implements BranchLoader3
+{
+ private final BranchLoader3 delegate;
+
+ private final ISessionManager sessionManager;
+
+ public ServerBranchLoader(BranchLoader3 delegate)
+ {
+ this.delegate = delegate;
+ sessionManager = ((IRepository)delegate).getSessionManager();
+ }
+
+ public BranchLoader3 getDelegate()
+ {
+ return delegate;
+ }
+
+ public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
+ {
+ if (!StoreThreadLocal.hasSession())
+ {
+ try
+ {
+ StoreThreadLocal.setSession(getServerSession());
+ return delegate.createBranch(branchID, branchInfo);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.createBranch(branchID, branchInfo);
+ }
+
+ public BranchInfo loadBranch(int branchID)
+ {
+ if (!StoreThreadLocal.hasSession())
+ {
+ try
+ {
+ StoreThreadLocal.setSession(getServerSession());
+ return delegate.loadBranch(branchID);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadBranch(branchID);
+ }
+
+ public SubBranchInfo[] loadSubBranches(int branchID)
+ {
+ if (!StoreThreadLocal.hasSession())
+ {
+ try
+ {
+ StoreThreadLocal.setSession(getServerSession());
+ return delegate.loadSubBranches(branchID);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadSubBranches(branchID);
+ }
+
+ public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler)
+ {
+ if (!StoreThreadLocal.hasSession())
+ {
+ try
+ {
+ StoreThreadLocal.setSession(getServerSession());
+ return delegate.loadBranches(startID, endID, branchHandler);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadBranches(startID, endID, branchHandler);
+ }
+
+ public void renameBranch(int branchID, String oldName, String newName)
+ {
+ if (!StoreThreadLocal.hasSession())
+ {
+ try
+ {
+ StoreThreadLocal.setSession(getServerSession());
+ delegate.renameBranch(branchID, oldName, newName);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+ else
+ {
+ delegate.renameBranch(branchID, oldName, newName);
+ }
+ }
+
+ @Deprecated
+ public void deleteBranch(int branchID)
+ {
+ }
+
+ @Deprecated
+ public void renameBranch(int branchID, String newName)
+ {
+ }
+
+ private InternalSession getServerSession()
+ {
+ InternalSession serverSession = ServerSession.get();
+ if (serverSession == null)
+ {
+ // In contrast to revision loading the branch loading can happen through
+ // parent branches and not explicitly through the delegating client branch manager.
+ // In these cases the server session is not set, so use any open session.
+ serverSession = (InternalSession)sessionManager.getSessions()[0];
+ }
+
+ return serverSession;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerRevisionLoader.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerRevisionLoader.java
new file mode 100644
index 0000000000..55040d393e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerRevisionLoader.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
+import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager.RevisionLoader2;
+import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo;
+import org.eclipse.emf.cdo.spi.server.InternalSession;
+
+import org.eclipse.emf.ecore.EClass;
+
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ServerRevisionLoader implements RevisionLoader2
+{
+ private final RevisionLoader2 delegate;
+
+ public ServerRevisionLoader(RevisionLoader2 delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public RevisionLoader2 getDelegate()
+ {
+ return delegate;
+ }
+
+ public List<RevisionInfo> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint, int referenceChunk, int prefetchDepth)
+ {
+ InternalSession serverSession = ServerSession.get();
+ if (serverSession != null)
+ {
+ try
+ {
+ StoreThreadLocal.setSession(serverSession);
+ return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth);
+ }
+
+ public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk)
+ {
+ InternalSession serverSession = ServerSession.get();
+ if (serverSession != null)
+ {
+ try
+ {
+ StoreThreadLocal.setSession(serverSession);
+ return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk);
+ }
+
+ public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, CDORevisionHandler handler)
+ {
+ InternalSession serverSession = ServerSession.get();
+ if (serverSession != null)
+ {
+ try
+ {
+ StoreThreadLocal.setSession(serverSession);
+ delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+ else
+ {
+ delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
+ }
+ }
+
+ public CDOBranchPointRange loadObjectLifetime(CDOID id, CDOBranchPoint branchPoint)
+ {
+ InternalSession serverSession = ServerSession.get();
+ if (serverSession != null)
+ {
+ try
+ {
+ StoreThreadLocal.setSession(serverSession);
+ return delegate.loadObjectLifetime(id, branchPoint);
+ }
+ finally
+ {
+ StoreThreadLocal.release();
+ }
+ }
+
+ return delegate.loadObjectLifetime(id, branchPoint);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerSession.java b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerSession.java
new file mode 100644
index 0000000000..d1ad10838b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.embedded/src/org/eclipse/emf/cdo/server/internal/embedded/ServerSession.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.embedded;
+
+import org.eclipse.emf.cdo.spi.server.InternalSession;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ServerSession
+{
+ private static final ThreadLocal<InternalSession> THREAD_LOCAL = new ThreadLocal<InternalSession>();
+
+ private ServerSession()
+ {
+ }
+
+ public static InternalSession get()
+ {
+ return THREAD_LOCAL.get();
+ }
+
+ static void set(InternalSession serverSession)
+ {
+ THREAD_LOCAL.set(serverSession);
+ }
+
+ static void unset()
+ {
+ THREAD_LOCAL.remove();
+ }
+}

Back to the top