diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server/src/org')
82 files changed, 11209 insertions, 11209 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/CommitManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/CommitManager.java index 576ac89226..55748218e6 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/CommitManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/CommitManager.java @@ -1,191 +1,191 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalCommitManager;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CommitManager extends Lifecycle implements InternalCommitManager
-{
- private InternalRepository repository;
-
- @ExcludeFromDump
- private transient ExecutorService executors;
-
- private boolean shutdownExecutorService;
-
- @ExcludeFromDump
- private transient Map<InternalTransaction, TransactionCommitContextEntry> contextEntries = new ConcurrentHashMap<InternalTransaction, TransactionCommitContextEntry>();
-
- public CommitManager()
- {
- }
-
- public InternalRepository getRepository()
- {
- return repository;
- }
-
- public void setRepository(InternalRepository repository)
- {
- this.repository = repository;
- }
-
- public synchronized ExecutorService getExecutors()
- {
- if (executors == null)
- {
- shutdownExecutorService = true;
- executors = Executors.newFixedThreadPool(10);
- }
-
- return executors;
- }
-
- public synchronized void setExecutors(ExecutorService executors)
- {
- if (shutdownExecutorService)
- {
- this.executors.shutdown();
- shutdownExecutorService = false;
- }
-
- this.executors = executors;
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- super.doDeactivate();
- setExecutors(null);
- }
-
- /**
- * Create a future to execute commitContext in a different thread.
- */
- public void preCommit(InternalCommitContext commitContext, OMMonitor monitor)
- {
- TransactionCommitContextEntry contextEntry = new TransactionCommitContextEntry(monitor);
- contextEntry.setContext(commitContext);
-
- Future<Object> future = getExecutors().submit(contextEntry.createCallable());
- contextEntry.setFuture(future);
-
- contextEntries.put(commitContext.getTransaction(), contextEntry);
- }
-
- /**
- * Called after a commitContext is done successfully or not.
- */
- public void remove(InternalCommitContext commitContext)
- {
- contextEntries.remove(commitContext.getTransaction());
- }
-
- public void rollback(InternalCommitContext commitContext)
- {
- TransactionCommitContextEntry contextEntry = contextEntries.get(commitContext.getTransaction());
- if (contextEntry != null)
- {
- contextEntry.getFuture().cancel(true);
- commitContext.rollback("Remote rollback"); //$NON-NLS-1$
- commitContext.postCommit(false);
- }
- }
-
- /**
- * Waiting for a commit to be done.
- */
- public void waitForTermination(InternalTransaction transaction) throws InterruptedException, ExecutionException
- {
- TransactionCommitContextEntry contextEntry = contextEntries.get(transaction);
- contextEntry.getFuture().get();
- }
-
- public InternalCommitContext get(InternalTransaction transaction)
- {
- TransactionCommitContextEntry contextEntry = contextEntries.get(transaction);
- if (contextEntry != null)
- {
- return contextEntry.getContext();
- }
-
- return null;
- }
-
- /**
- * @author Simon McDuff
- */
- private static final class TransactionCommitContextEntry
- {
- private InternalCommitContext context;
-
- private Future<Object> future;
-
- private OMMonitor monitor;
-
- public TransactionCommitContextEntry(OMMonitor monitor)
- {
- this.monitor = monitor;
- }
-
- public Callable<Object> createCallable()
- {
- return new Callable<Object>()
- {
- public Object call() throws Exception
- {
- context.write(monitor);
- return null;
- }
- };
- }
-
- public InternalCommitContext getContext()
- {
- return context;
- }
-
- public void setContext(InternalCommitContext context)
- {
- this.context = context;
- }
-
- public Future<Object> getFuture()
- {
- return future;
- }
-
- public void setFuture(Future<Object> future)
- {
- this.future = future;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; +import org.eclipse.emf.cdo.spi.server.InternalCommitManager; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CommitManager extends Lifecycle implements InternalCommitManager +{ + private InternalRepository repository; + + @ExcludeFromDump + private transient ExecutorService executors; + + private boolean shutdownExecutorService; + + @ExcludeFromDump + private transient Map<InternalTransaction, TransactionCommitContextEntry> contextEntries = new ConcurrentHashMap<InternalTransaction, TransactionCommitContextEntry>(); + + public CommitManager() + { + } + + public InternalRepository getRepository() + { + return repository; + } + + public void setRepository(InternalRepository repository) + { + this.repository = repository; + } + + public synchronized ExecutorService getExecutors() + { + if (executors == null) + { + shutdownExecutorService = true; + executors = Executors.newFixedThreadPool(10); + } + + return executors; + } + + public synchronized void setExecutors(ExecutorService executors) + { + if (shutdownExecutorService) + { + this.executors.shutdown(); + shutdownExecutorService = false; + } + + this.executors = executors; + } + + @Override + protected void doDeactivate() throws Exception + { + super.doDeactivate(); + setExecutors(null); + } + + /** + * Create a future to execute commitContext in a different thread. + */ + public void preCommit(InternalCommitContext commitContext, OMMonitor monitor) + { + TransactionCommitContextEntry contextEntry = new TransactionCommitContextEntry(monitor); + contextEntry.setContext(commitContext); + + Future<Object> future = getExecutors().submit(contextEntry.createCallable()); + contextEntry.setFuture(future); + + contextEntries.put(commitContext.getTransaction(), contextEntry); + } + + /** + * Called after a commitContext is done successfully or not. + */ + public void remove(InternalCommitContext commitContext) + { + contextEntries.remove(commitContext.getTransaction()); + } + + public void rollback(InternalCommitContext commitContext) + { + TransactionCommitContextEntry contextEntry = contextEntries.get(commitContext.getTransaction()); + if (contextEntry != null) + { + contextEntry.getFuture().cancel(true); + commitContext.rollback("Remote rollback"); //$NON-NLS-1$ + commitContext.postCommit(false); + } + } + + /** + * Waiting for a commit to be done. + */ + public void waitForTermination(InternalTransaction transaction) throws InterruptedException, ExecutionException + { + TransactionCommitContextEntry contextEntry = contextEntries.get(transaction); + contextEntry.getFuture().get(); + } + + public InternalCommitContext get(InternalTransaction transaction) + { + TransactionCommitContextEntry contextEntry = contextEntries.get(transaction); + if (contextEntry != null) + { + return contextEntry.getContext(); + } + + return null; + } + + /** + * @author Simon McDuff + */ + private static final class TransactionCommitContextEntry + { + private InternalCommitContext context; + + private Future<Object> future; + + private OMMonitor monitor; + + public TransactionCommitContextEntry(OMMonitor monitor) + { + this.monitor = monitor; + } + + public Callable<Object> createCallable() + { + return new Callable<Object>() + { + public Object call() throws Exception + { + context.write(monitor); + return null; + } + }; + } + + public InternalCommitContext getContext() + { + return context; + } + + public void setContext(InternalCommitContext context) + { + this.context = context; + } + + public Future<Object> getFuture() + { + return future; + } + + public void setFuture(Future<Object> future) + { + this.future = future; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingCommitContext.java index c9979a97c6..9a653a6851 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingCommitContext.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/DelegatingCommitContext.java @@ -1,109 +1,109 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
-import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-
-import org.eclipse.emf.ecore.EClass;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public abstract class DelegatingCommitContext implements IStoreAccessor.CommitContext
-{
- protected abstract CommitContext getDelegate();
-
- public ITransaction getTransaction()
- {
- return getDelegate().getTransaction();
- }
-
- public CDOBranchPoint getBranchPoint()
- {
- return getDelegate().getBranchPoint();
- }
-
- public String getUserID()
- {
- return getDelegate().getUserID();
- }
-
- public String getCommitComment()
- {
- return getDelegate().getCommitComment();
- }
-
- public boolean isAutoReleaseLocksEnabled()
- {
- return getDelegate().isAutoReleaseLocksEnabled();
- }
-
- public InternalCDOPackageRegistry getPackageRegistry()
- {
- return getDelegate().getPackageRegistry();
- }
-
- public InternalCDOPackageUnit[] getNewPackageUnits()
- {
- return getDelegate().getNewPackageUnits();
- }
-
- public InternalCDORevision[] getNewObjects()
- {
- return getDelegate().getNewObjects();
- }
-
- public InternalCDORevision[] getDirtyObjects()
- {
- return getDelegate().getDirtyObjects();
- }
-
- public InternalCDORevisionDelta[] getDirtyObjectDeltas()
- {
- return getDelegate().getDirtyObjectDeltas();
- }
-
- public CDOID[] getDetachedObjects()
- {
- return getDelegate().getDetachedObjects();
- }
-
- public Map<CDOID, EClass> getDetachedObjectTypes()
- {
- return getDelegate().getDetachedObjectTypes();
- }
-
- public CDORevision getRevision(CDOID id)
- {
- return getDelegate().getRevision(id);
- }
-
- public Map<CDOID, CDOID> getIDMappings()
- {
- return getDelegate().getIDMappings();
- }
-
- public String getRollbackMessage()
- {
- return getDelegate().getRollbackMessage();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext; +import org.eclipse.emf.cdo.server.ITransaction; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; + +import org.eclipse.emf.ecore.EClass; + +import java.util.Map; + +/** + * @author Eike Stepper + */ +public abstract class DelegatingCommitContext implements IStoreAccessor.CommitContext +{ + protected abstract CommitContext getDelegate(); + + public ITransaction getTransaction() + { + return getDelegate().getTransaction(); + } + + public CDOBranchPoint getBranchPoint() + { + return getDelegate().getBranchPoint(); + } + + public String getUserID() + { + return getDelegate().getUserID(); + } + + public String getCommitComment() + { + return getDelegate().getCommitComment(); + } + + public boolean isAutoReleaseLocksEnabled() + { + return getDelegate().isAutoReleaseLocksEnabled(); + } + + public InternalCDOPackageRegistry getPackageRegistry() + { + return getDelegate().getPackageRegistry(); + } + + public InternalCDOPackageUnit[] getNewPackageUnits() + { + return getDelegate().getNewPackageUnits(); + } + + public InternalCDORevision[] getNewObjects() + { + return getDelegate().getNewObjects(); + } + + public InternalCDORevision[] getDirtyObjects() + { + return getDelegate().getDirtyObjects(); + } + + public InternalCDORevisionDelta[] getDirtyObjectDeltas() + { + return getDelegate().getDirtyObjectDeltas(); + } + + public CDOID[] getDetachedObjects() + { + return getDelegate().getDetachedObjects(); + } + + public Map<CDOID, EClass> getDetachedObjectTypes() + { + return getDelegate().getDetachedObjectTypes(); + } + + public CDORevision getRevision(CDOID id) + { + return getDelegate().getRevision(id); + } + + public Map<CDOID, CDOID> getIDMappings() + { + return getDelegate().getIDMappings(); + } + + public String getRollbackMessage() + { + return getDelegate().getRollbackMessage(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LockingManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LockingManager.java index 6e186f3362..58952bed94 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LockingManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/LockingManager.java @@ -1,829 +1,829 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- * Caspar De Groot - write options
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.CDOObject;
-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.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.CDOServerUtil;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.ISessionManager;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking;
-import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking2;
-import org.eclipse.emf.cdo.server.IView;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
-import org.eclipse.emf.cdo.spi.server.InternalLockManager;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalStore;
-import org.eclipse.emf.cdo.spi.server.InternalView;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.CheckUtil;
-import org.eclipse.net4j.util.ImplementationError;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.ConcurrentArray;
-import org.eclipse.net4j.util.concurrent.RWOLockManager;
-import org.eclipse.net4j.util.container.ContainerEventAdapter;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.options.IOptionsContainer;
-
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * @author Simon McDuff
- * @since 3.0
- */
-public class LockingManager extends RWOLockManager<Object, IView> implements InternalLockManager
-{
- private InternalRepository repository;
-
- private Map<String, InternalView> openViews = new HashMap<String, InternalView>();
-
- private Map<String, DurableView> durableViews = new HashMap<String, DurableView>();
-
- private ConcurrentArray<DurableViewHandler> durableViewHandlers = new ConcurrentArray<DurableViewHandler>()
- {
- @Override
- protected DurableViewHandler[] newArray(int length)
- {
- return new DurableViewHandler[length];
- }
- };
-
- @ExcludeFromDump
- private transient IListener sessionListener = new ContainerEventAdapter<IView>()
- {
- @Override
- protected void onRemoved(IContainer<IView> container, IView view)
- {
- String durableLockingID = view.getDurableLockingID();
- if (durableLockingID == null)
- {
- unlock(view);
- }
- else
- {
- DurableView durableView = new DurableView(durableLockingID);
- changeContext(view, durableView);
- unregisterOpenView(durableLockingID);
- durableViews.put(durableLockingID, durableView);
- }
- }
- };
-
- @ExcludeFromDump
- private transient IListener sessionManagerListener = new ContainerEventAdapter<ISession>()
- {
- @Override
- protected void onAdded(IContainer<ISession> container, ISession session)
- {
- session.addListener(sessionListener);
- }
-
- @Override
- protected void onRemoved(IContainer<ISession> container, ISession session)
- {
- session.removeListener(sessionListener);
- }
- };
-
- public LockingManager()
- {
- }
-
- public InternalRepository getRepository()
- {
- return repository;
- }
-
- public void setRepository(InternalRepository repository)
- {
- this.repository = repository;
- }
-
- public synchronized Object getLockEntryObject(Object key)
- {
- LockState<Object, IView> lockState = getObjectToLocksMap().get(key);
- return lockState == null ? null : lockState.getLockedObject();
- }
-
- public Object getLockKey(CDOID id, CDOBranch branch)
- {
- if (repository.isSupportingBranches())
- {
- return CDOIDUtil.createIDAndBranch(id, branch);
- }
-
- return id;
- }
-
- public synchronized Map<CDOID, LockGrade> getLocks(final IView view)
- {
- final Map<CDOID, LockGrade> result = new HashMap<CDOID, LockGrade>();
-
- for (LockState<Object, IView> lockState : getObjectToLocksMap().values())
- {
- LockGrade grade = LockGrade.NONE;
- if (lockState.hasLock(LockType.READ, view, false))
- {
- grade = grade.getUpdated(LockType.READ, true);
- }
-
- if (lockState.hasLock(LockType.WRITE, view, false))
- {
- grade = grade.getUpdated(LockType.WRITE, true);
- }
-
- if (lockState.hasLock(LockType.OPTION, view, false))
- {
- grade = grade.getUpdated(LockType.OPTION, true);
- }
-
- if (grade != LockGrade.NONE)
- {
- CDOID id = getLockKeyID(lockState.getLockedObject());
- result.put(id, grade);
- }
- }
-
- return result;
- }
-
- @Deprecated
- public void lock(boolean explicit, LockType type, IView view, Collection<? extends Object> objectsToLock, long timeout)
- throws InterruptedException
- {
- lock2(explicit, type, view, objectsToLock, false, timeout);
- }
-
- public List<LockState<Object, IView>> lock2(boolean explicit, LockType type, IView view,
- Collection<? extends Object> objectsToLock, boolean recursive, long timeout) throws InterruptedException
- {
- String durableLockingID = null;
- DurableLocking accessor = null;
-
- if (explicit)
- {
- durableLockingID = view.getDurableLockingID();
- if (durableLockingID != null)
- {
- accessor = getDurableLocking();
- }
- }
-
- long startTime = timeout == WAIT ? 0L : currentTimeMillis();
-
- List<LockState<Object, IView>> newLockStates;
- synchronized (this)
- {
- if (recursive)
- {
- objectsToLock = createContentSet(objectsToLock, view);
- }
-
- // Adjust timeout for delay we may have incurred on entering this synchronized block
- if (timeout != WAIT)
- {
- timeout -= currentTimeMillis() - startTime;
- }
-
- newLockStates = super.lock2(type, view, objectsToLock, timeout);
- }
-
- if (accessor != null)
- {
- accessor.lock(durableLockingID, type, objectsToLock);
- }
-
- return newLockStates;
- }
-
- private Set<? extends Object> createContentSet(Collection<? extends Object> objectsToLock, IView view)
- {
- CDOBranch branch = view.getBranch();
- CDOView cdoView = CDOServerUtil.openView(view.getSession(), branch.getHead(), true);
-
- Set<Object> contents = new HashSet<Object>();
- for (Object o : objectsToLock)
- {
- contents.add(o);
-
- boolean isIDandBranch = o instanceof CDOIDAndBranch;
- CDOID id;
- if (isIDandBranch)
- {
- id = ((CDOIDAndBranch)o).getID();
- }
- else
- {
- id = (CDOID)o;
- }
-
- CDOObject obj = cdoView.getObject(id);
- TreeIterator<EObject> iter = obj.eAllContents();
- while (iter.hasNext())
- {
- EObject eObj = iter.next();
- CDOObject cdoObj = CDOUtil.getCDOObject(eObj);
- CDOID childID = cdoObj.cdoID();
- Object child;
- if (isIDandBranch)
- {
- child = CDOIDUtil.createIDAndBranch(childID, branch);
- }
- else
- {
- child = childID;
- }
- contents.add(child);
- }
- }
-
- return contents;
- }
-
- @Deprecated
- public synchronized void unlock(boolean explicit, LockType type, IView view,
- Collection<? extends Object> objectsToUnlock)
- {
- unlock2(explicit, type, view, objectsToUnlock, false);
- }
-
- public synchronized List<LockState<Object, IView>> unlock2(boolean explicit, LockType type, IView view,
- Collection<? extends Object> objects, boolean recursive)
- {
- List<LockState<Object, IView>> newLockStates;
- synchronized (this)
- {
- if (recursive)
- {
- objects = createContentSet(objects, view);
- }
-
- newLockStates = super.unlock2(type, view, objects);
- }
-
- if (explicit)
- {
- String durableLockingID = view.getDurableLockingID();
- if (durableLockingID != null)
- {
- DurableLocking accessor = getDurableLocking();
- accessor.unlock(durableLockingID, type, objects);
- }
- }
-
- return newLockStates;
- }
-
- @Deprecated
- public synchronized void unlock(boolean explicit, IView view)
- {
- unlock2(explicit, view);
- }
-
- public synchronized List<LockState<Object, IView>> unlock2(boolean explicit, IView view)
- {
- if (explicit)
- {
- String durableLockingID = view.getDurableLockingID();
- if (durableLockingID != null)
- {
- DurableLocking accessor = getDurableLocking();
- accessor.unlock(durableLockingID);
- }
- }
-
- return super.unlock2(view);
- }
-
- public LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly,
- Map<CDOID, LockGrade> locks)
- {
- return createLockArea(userID, branchPoint, readOnly, locks, null);
- }
-
- private LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly,
- Map<CDOID, LockGrade> locks, String lockAreaID)
- {
- if (lockAreaID == null)
- {
- DurableLocking accessor = getDurableLocking();
- return accessor.createLockArea(userID, branchPoint, readOnly, locks);
- }
-
- DurableLocking2 accessor = getDurableLocking2();
- return accessor.createLockArea(lockAreaID, userID, branchPoint, readOnly, locks);
- }
-
- public LockArea createLockArea(InternalView view)
- {
- return createLockArea(view, null);
- }
-
- public LockArea createLockArea(InternalView view, String lockAreaID)
- {
- String userID = view.getSession().getUserID();
- CDOBranchPoint branchPoint = CDOBranchUtil.copyBranchPoint(view);
- boolean readOnly = view.isReadOnly();
- Map<CDOID, LockGrade> locks = getLocks(view);
-
- LockArea area = createLockArea(userID, branchPoint, readOnly, locks, lockAreaID);
- synchronized (openViews)
- {
- openViews.put(area.getDurableLockingID(), view);
- }
-
- return area;
- }
-
- public LockArea getLockArea(String durableLockingID) throws LockAreaNotFoundException
- {
- DurableLocking accessor = getDurableLocking();
- return accessor.getLockArea(durableLockingID);
- }
-
- public void getLockAreas(String userIDPrefix, LockArea.Handler handler)
- {
- if (userIDPrefix == null)
- {
- userIDPrefix = "";
- }
-
- DurableLocking accessor = getDurableLocking();
- accessor.getLockAreas(userIDPrefix, handler);
- }
-
- public void deleteLockArea(String durableLockingID)
- {
- DurableLocking accessor = getDurableLocking();
- accessor.deleteLockArea(durableLockingID);
- unregisterOpenView(durableLockingID);
- }
-
- public IView openView(ISession session, int viewID, boolean readOnly, final String durableLockingID)
- {
- synchronized (openViews)
- {
- InternalView view = openViews.get(durableLockingID);
- if (view != null)
- {
- throw new IllegalStateException("Durable view is already open: " + view);
- }
-
- LockArea area = getLockArea(durableLockingID);
- if (area.isReadOnly() != readOnly)
- {
- throw new IllegalStateException("Durable read-only state does not match the request");
- }
-
- for (DurableViewHandler handler : durableViewHandlers.get())
- {
- try
- {
- handler.openingView(session, viewID, readOnly, area);
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- if (readOnly)
- {
- view = (InternalView)session.openView(viewID, area);
- }
- else
- {
- view = (InternalView)session.openTransaction(viewID, area);
- }
-
- DurableView durableView = durableViews.get(durableLockingID);
- changeContext(durableView, view);
- view.setDurableLockingID(durableLockingID);
- view.addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- synchronized (openViews)
- {
- openViews.remove(durableLockingID);
- }
- }
- });
-
- openViews.put(durableLockingID, view);
- return view;
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- loadLocks();
- getRepository().getSessionManager().addListener(sessionManagerListener);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- ISessionManager sessionManager = getRepository().getSessionManager();
- sessionManager.removeListener(sessionManagerListener);
- for (ISession session : sessionManager.getSessions())
- {
- session.removeListener(sessionListener);
- }
-
- super.doDeactivate();
- }
-
- private DurableLocking getDurableLocking()
- {
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- if (accessor instanceof DurableLocking)
- {
- return (DurableLocking)accessor;
- }
-
- throw new IllegalStateException("Store does not implement " + DurableLocking.class.getSimpleName());
- }
-
- private DurableLocking2 getDurableLocking2()
- {
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- if (accessor instanceof DurableLocking2)
- {
- return (DurableLocking2)accessor;
- }
-
- throw new IllegalStateException("Store does not implement " + DurableLocking2.class.getSimpleName());
- }
-
- public void reloadLocks()
- {
- DurableLockLoader handler = new DurableLockLoader();
- getLockAreas(null, handler);
- }
-
- private void loadLocks()
- {
- InternalStore store = repository.getStore();
- IStoreAccessor reader = null;
-
- try
- {
- reader = store.getReader(null);
- if (reader instanceof DurableLocking)
- {
- StoreThreadLocal.setAccessor(reader);
- reloadLocks();
- }
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- private void unregisterOpenView(String durableLockingID)
- {
- synchronized (openViews)
- {
- InternalView view = openViews.remove(durableLockingID);
- if (view != null)
- {
- view.setDurableLockingID(null);
- }
- }
- }
-
- public CDOID getLockKeyID(Object key)
- {
- if (key instanceof CDOID)
- {
- return (CDOID)key;
- }
-
- if (key instanceof CDOIDAndBranch)
- {
- return ((CDOIDAndBranch)key).getID();
- }
-
- throw new ImplementationError("Unexpected lock object: " + key);
- }
-
- public void addDurableViewHandler(DurableViewHandler handler)
- {
- durableViewHandlers.add(handler);
- }
-
- public void removeDurableViewHandler(DurableViewHandler handler)
- {
- durableViewHandlers.remove(handler);
- }
-
- public DurableViewHandler[] getDurableViewHandlers()
- {
- return durableViewHandlers.get();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class DurableView implements IView, CDOCommonView.Options
- {
- private String durableLockingID;
-
- public DurableView(String durableLockingID)
- {
- this.durableLockingID = durableLockingID;
- }
-
- public String getDurableLockingID()
- {
- return durableLockingID;
- }
-
- public boolean isDurableView()
- {
- return true;
- }
-
- public int getSessionID()
- {
- throw new UnsupportedOperationException();
- }
-
- public int getViewID()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isReadOnly()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOBranch getBranch()
- {
- throw new UnsupportedOperationException();
- }
-
- public long getTimeStamp()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDORevision getRevision(CDOID id)
- {
- throw new UnsupportedOperationException();
- }
-
- public void close()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isClosed()
- {
- throw new UnsupportedOperationException();
- }
-
- public IRepository getRepository()
- {
- throw new UnsupportedOperationException();
- }
-
- public ISession getSession()
- {
- return null;
- }
-
- @Override
- public int hashCode()
- {
- return durableLockingID.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof DurableView)
- {
- DurableView that = (DurableView)obj;
- return durableLockingID.equals(that.getDurableLockingID());
- }
-
- return false;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("DurableView[{0}]", durableLockingID);
- }
-
- public IOptionsContainer getContainer()
- {
- return null;
- }
-
- public void addListener(IListener listener)
- {
- }
-
- public void removeListener(IListener listener)
- {
- }
-
- public boolean hasListeners()
- {
- return false;
- }
-
- public IListener[] getListeners()
- {
- return null;
- }
-
- public Options options()
- {
- return this;
- }
-
- public boolean isLockNotificationEnabled()
- {
- return false;
- }
-
- public void setLockNotificationEnabled(boolean enabled)
- {
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class DurableLockLoader implements LockArea.Handler
- {
- public DurableLockLoader()
- {
- }
-
- private IView getView(String lockAreaID)
- {
- IView view = openViews.get(lockAreaID);
- if (view == null)
- {
- view = durableViews.get(lockAreaID);
- }
-
- return view;
- }
-
- public boolean handleLockArea(LockArea area)
- {
- String durableLockingID = area.getDurableLockingID();
- IView view = getView(durableLockingID);
- if (view != null)
- {
- unlock2(view);
- }
-
- if (view == null)
- {
- view = new DurableView(durableLockingID);
- durableViews.put(durableLockingID, (DurableView)view);
- }
-
- Collection<Object> readLocks = new ArrayList<Object>();
- Collection<Object> writeLocks = new ArrayList<Object>();
- Collection<Object> writeOptions = new ArrayList<Object>();
- for (Entry<CDOID, LockGrade> entry : area.getLocks().entrySet())
- {
- Object key = getLockKey(entry.getKey(), area.getBranch());
- LockGrade grade = entry.getValue();
- if (grade.isRead())
- {
- readLocks.add(key);
- }
-
- if (grade.isWrite())
- {
- writeLocks.add(key);
- }
-
- if (grade.isOption())
- {
- writeOptions.add(key);
- }
- }
-
- try
- {
- lock(LockType.READ, view, readLocks, 1000L);
- lock(LockType.WRITE, view, writeLocks, 1000L);
- lock(LockType.OPTION, view, writeOptions, 1000L);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- return true;
- }
- }
-
- public LockGrade getLockGrade(Object key)
- {
- LockState<Object, IView> lockState = getObjectToLocksMap().get(key);
- LockGrade grade = LockGrade.NONE;
- if (lockState != null)
- {
- for (LockType type : LockType.values())
- {
- if (lockState.hasLock(type))
- {
- grade = grade.getUpdated(type, true);
- }
- }
- }
-
- return grade;
- }
-
- private LockArea getLockAreaNoEx(String durableLockingID)
- {
- try
- {
- return getLockArea(durableLockingID);
- }
- catch (LockAreaNotFoundException e)
- {
- return null;
- }
- }
-
- public void updateLockArea(LockArea lockArea)
- {
- String durableLockingID = lockArea.getDurableLockingID();
- DurableLocking2 accessor = getDurableLocking2();
-
- if (lockArea.isMissing())
- {
- LockArea localLockArea = getLockAreaNoEx(durableLockingID);
- if (localLockArea != null && localLockArea.getLocks().size() > 0)
- {
- accessor.deleteLockArea(durableLockingID);
- DurableView deletedView = durableViews.remove(durableLockingID);
- CheckUtil.checkNull(deletedView, "deletedView");
- }
- }
- else
- {
- accessor.updateLockArea(lockArea);
- new DurableLockLoader().handleLockArea(lockArea);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + * Caspar De Groot - write options + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.CDOObject; +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.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.CDOServerUtil; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.ISessionManager; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking; +import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking2; +import org.eclipse.emf.cdo.server.IView; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil; +import org.eclipse.emf.cdo.spi.server.InternalLockManager; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalStore; +import org.eclipse.emf.cdo.spi.server.InternalView; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.CheckUtil; +import org.eclipse.net4j.util.ImplementationError; +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.collection.ConcurrentArray; +import org.eclipse.net4j.util.concurrent.RWOLockManager; +import org.eclipse.net4j.util.container.ContainerEventAdapter; +import org.eclipse.net4j.util.container.IContainer; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.net4j.util.options.IOptionsContainer; + +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * @author Simon McDuff + * @since 3.0 + */ +public class LockingManager extends RWOLockManager<Object, IView> implements InternalLockManager +{ + private InternalRepository repository; + + private Map<String, InternalView> openViews = new HashMap<String, InternalView>(); + + private Map<String, DurableView> durableViews = new HashMap<String, DurableView>(); + + private ConcurrentArray<DurableViewHandler> durableViewHandlers = new ConcurrentArray<DurableViewHandler>() + { + @Override + protected DurableViewHandler[] newArray(int length) + { + return new DurableViewHandler[length]; + } + }; + + @ExcludeFromDump + private transient IListener sessionListener = new ContainerEventAdapter<IView>() + { + @Override + protected void onRemoved(IContainer<IView> container, IView view) + { + String durableLockingID = view.getDurableLockingID(); + if (durableLockingID == null) + { + unlock(view); + } + else + { + DurableView durableView = new DurableView(durableLockingID); + changeContext(view, durableView); + unregisterOpenView(durableLockingID); + durableViews.put(durableLockingID, durableView); + } + } + }; + + @ExcludeFromDump + private transient IListener sessionManagerListener = new ContainerEventAdapter<ISession>() + { + @Override + protected void onAdded(IContainer<ISession> container, ISession session) + { + session.addListener(sessionListener); + } + + @Override + protected void onRemoved(IContainer<ISession> container, ISession session) + { + session.removeListener(sessionListener); + } + }; + + public LockingManager() + { + } + + public InternalRepository getRepository() + { + return repository; + } + + public void setRepository(InternalRepository repository) + { + this.repository = repository; + } + + public synchronized Object getLockEntryObject(Object key) + { + LockState<Object, IView> lockState = getObjectToLocksMap().get(key); + return lockState == null ? null : lockState.getLockedObject(); + } + + public Object getLockKey(CDOID id, CDOBranch branch) + { + if (repository.isSupportingBranches()) + { + return CDOIDUtil.createIDAndBranch(id, branch); + } + + return id; + } + + public synchronized Map<CDOID, LockGrade> getLocks(final IView view) + { + final Map<CDOID, LockGrade> result = new HashMap<CDOID, LockGrade>(); + + for (LockState<Object, IView> lockState : getObjectToLocksMap().values()) + { + LockGrade grade = LockGrade.NONE; + if (lockState.hasLock(LockType.READ, view, false)) + { + grade = grade.getUpdated(LockType.READ, true); + } + + if (lockState.hasLock(LockType.WRITE, view, false)) + { + grade = grade.getUpdated(LockType.WRITE, true); + } + + if (lockState.hasLock(LockType.OPTION, view, false)) + { + grade = grade.getUpdated(LockType.OPTION, true); + } + + if (grade != LockGrade.NONE) + { + CDOID id = getLockKeyID(lockState.getLockedObject()); + result.put(id, grade); + } + } + + return result; + } + + @Deprecated + public void lock(boolean explicit, LockType type, IView view, Collection<? extends Object> objectsToLock, long timeout) + throws InterruptedException + { + lock2(explicit, type, view, objectsToLock, false, timeout); + } + + public List<LockState<Object, IView>> lock2(boolean explicit, LockType type, IView view, + Collection<? extends Object> objectsToLock, boolean recursive, long timeout) throws InterruptedException + { + String durableLockingID = null; + DurableLocking accessor = null; + + if (explicit) + { + durableLockingID = view.getDurableLockingID(); + if (durableLockingID != null) + { + accessor = getDurableLocking(); + } + } + + long startTime = timeout == WAIT ? 0L : currentTimeMillis(); + + List<LockState<Object, IView>> newLockStates; + synchronized (this) + { + if (recursive) + { + objectsToLock = createContentSet(objectsToLock, view); + } + + // Adjust timeout for delay we may have incurred on entering this synchronized block + if (timeout != WAIT) + { + timeout -= currentTimeMillis() - startTime; + } + + newLockStates = super.lock2(type, view, objectsToLock, timeout); + } + + if (accessor != null) + { + accessor.lock(durableLockingID, type, objectsToLock); + } + + return newLockStates; + } + + private Set<? extends Object> createContentSet(Collection<? extends Object> objectsToLock, IView view) + { + CDOBranch branch = view.getBranch(); + CDOView cdoView = CDOServerUtil.openView(view.getSession(), branch.getHead(), true); + + Set<Object> contents = new HashSet<Object>(); + for (Object o : objectsToLock) + { + contents.add(o); + + boolean isIDandBranch = o instanceof CDOIDAndBranch; + CDOID id; + if (isIDandBranch) + { + id = ((CDOIDAndBranch)o).getID(); + } + else + { + id = (CDOID)o; + } + + CDOObject obj = cdoView.getObject(id); + TreeIterator<EObject> iter = obj.eAllContents(); + while (iter.hasNext()) + { + EObject eObj = iter.next(); + CDOObject cdoObj = CDOUtil.getCDOObject(eObj); + CDOID childID = cdoObj.cdoID(); + Object child; + if (isIDandBranch) + { + child = CDOIDUtil.createIDAndBranch(childID, branch); + } + else + { + child = childID; + } + contents.add(child); + } + } + + return contents; + } + + @Deprecated + public synchronized void unlock(boolean explicit, LockType type, IView view, + Collection<? extends Object> objectsToUnlock) + { + unlock2(explicit, type, view, objectsToUnlock, false); + } + + public synchronized List<LockState<Object, IView>> unlock2(boolean explicit, LockType type, IView view, + Collection<? extends Object> objects, boolean recursive) + { + List<LockState<Object, IView>> newLockStates; + synchronized (this) + { + if (recursive) + { + objects = createContentSet(objects, view); + } + + newLockStates = super.unlock2(type, view, objects); + } + + if (explicit) + { + String durableLockingID = view.getDurableLockingID(); + if (durableLockingID != null) + { + DurableLocking accessor = getDurableLocking(); + accessor.unlock(durableLockingID, type, objects); + } + } + + return newLockStates; + } + + @Deprecated + public synchronized void unlock(boolean explicit, IView view) + { + unlock2(explicit, view); + } + + public synchronized List<LockState<Object, IView>> unlock2(boolean explicit, IView view) + { + if (explicit) + { + String durableLockingID = view.getDurableLockingID(); + if (durableLockingID != null) + { + DurableLocking accessor = getDurableLocking(); + accessor.unlock(durableLockingID); + } + } + + return super.unlock2(view); + } + + public LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly, + Map<CDOID, LockGrade> locks) + { + return createLockArea(userID, branchPoint, readOnly, locks, null); + } + + private LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly, + Map<CDOID, LockGrade> locks, String lockAreaID) + { + if (lockAreaID == null) + { + DurableLocking accessor = getDurableLocking(); + return accessor.createLockArea(userID, branchPoint, readOnly, locks); + } + + DurableLocking2 accessor = getDurableLocking2(); + return accessor.createLockArea(lockAreaID, userID, branchPoint, readOnly, locks); + } + + public LockArea createLockArea(InternalView view) + { + return createLockArea(view, null); + } + + public LockArea createLockArea(InternalView view, String lockAreaID) + { + String userID = view.getSession().getUserID(); + CDOBranchPoint branchPoint = CDOBranchUtil.copyBranchPoint(view); + boolean readOnly = view.isReadOnly(); + Map<CDOID, LockGrade> locks = getLocks(view); + + LockArea area = createLockArea(userID, branchPoint, readOnly, locks, lockAreaID); + synchronized (openViews) + { + openViews.put(area.getDurableLockingID(), view); + } + + return area; + } + + public LockArea getLockArea(String durableLockingID) throws LockAreaNotFoundException + { + DurableLocking accessor = getDurableLocking(); + return accessor.getLockArea(durableLockingID); + } + + public void getLockAreas(String userIDPrefix, LockArea.Handler handler) + { + if (userIDPrefix == null) + { + userIDPrefix = ""; + } + + DurableLocking accessor = getDurableLocking(); + accessor.getLockAreas(userIDPrefix, handler); + } + + public void deleteLockArea(String durableLockingID) + { + DurableLocking accessor = getDurableLocking(); + accessor.deleteLockArea(durableLockingID); + unregisterOpenView(durableLockingID); + } + + public IView openView(ISession session, int viewID, boolean readOnly, final String durableLockingID) + { + synchronized (openViews) + { + InternalView view = openViews.get(durableLockingID); + if (view != null) + { + throw new IllegalStateException("Durable view is already open: " + view); + } + + LockArea area = getLockArea(durableLockingID); + if (area.isReadOnly() != readOnly) + { + throw new IllegalStateException("Durable read-only state does not match the request"); + } + + for (DurableViewHandler handler : durableViewHandlers.get()) + { + try + { + handler.openingView(session, viewID, readOnly, area); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + } + + if (readOnly) + { + view = (InternalView)session.openView(viewID, area); + } + else + { + view = (InternalView)session.openTransaction(viewID, area); + } + + DurableView durableView = durableViews.get(durableLockingID); + changeContext(durableView, view); + view.setDurableLockingID(durableLockingID); + view.addListener(new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + synchronized (openViews) + { + openViews.remove(durableLockingID); + } + } + }); + + openViews.put(durableLockingID, view); + return view; + } + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + loadLocks(); + getRepository().getSessionManager().addListener(sessionManagerListener); + } + + @Override + protected void doDeactivate() throws Exception + { + ISessionManager sessionManager = getRepository().getSessionManager(); + sessionManager.removeListener(sessionManagerListener); + for (ISession session : sessionManager.getSessions()) + { + session.removeListener(sessionListener); + } + + super.doDeactivate(); + } + + private DurableLocking getDurableLocking() + { + IStoreAccessor accessor = StoreThreadLocal.getAccessor(); + if (accessor instanceof DurableLocking) + { + return (DurableLocking)accessor; + } + + throw new IllegalStateException("Store does not implement " + DurableLocking.class.getSimpleName()); + } + + private DurableLocking2 getDurableLocking2() + { + IStoreAccessor accessor = StoreThreadLocal.getAccessor(); + if (accessor instanceof DurableLocking2) + { + return (DurableLocking2)accessor; + } + + throw new IllegalStateException("Store does not implement " + DurableLocking2.class.getSimpleName()); + } + + public void reloadLocks() + { + DurableLockLoader handler = new DurableLockLoader(); + getLockAreas(null, handler); + } + + private void loadLocks() + { + InternalStore store = repository.getStore(); + IStoreAccessor reader = null; + + try + { + reader = store.getReader(null); + if (reader instanceof DurableLocking) + { + StoreThreadLocal.setAccessor(reader); + reloadLocks(); + } + } + finally + { + StoreThreadLocal.release(); + } + } + + private void unregisterOpenView(String durableLockingID) + { + synchronized (openViews) + { + InternalView view = openViews.remove(durableLockingID); + if (view != null) + { + view.setDurableLockingID(null); + } + } + } + + public CDOID getLockKeyID(Object key) + { + if (key instanceof CDOID) + { + return (CDOID)key; + } + + if (key instanceof CDOIDAndBranch) + { + return ((CDOIDAndBranch)key).getID(); + } + + throw new ImplementationError("Unexpected lock object: " + key); + } + + public void addDurableViewHandler(DurableViewHandler handler) + { + durableViewHandlers.add(handler); + } + + public void removeDurableViewHandler(DurableViewHandler handler) + { + durableViewHandlers.remove(handler); + } + + public DurableViewHandler[] getDurableViewHandlers() + { + return durableViewHandlers.get(); + } + + /** + * @author Eike Stepper + */ + private final class DurableView implements IView, CDOCommonView.Options + { + private String durableLockingID; + + public DurableView(String durableLockingID) + { + this.durableLockingID = durableLockingID; + } + + public String getDurableLockingID() + { + return durableLockingID; + } + + public boolean isDurableView() + { + return true; + } + + public int getSessionID() + { + throw new UnsupportedOperationException(); + } + + public int getViewID() + { + throw new UnsupportedOperationException(); + } + + public boolean isReadOnly() + { + throw new UnsupportedOperationException(); + } + + public CDOBranch getBranch() + { + throw new UnsupportedOperationException(); + } + + public long getTimeStamp() + { + throw new UnsupportedOperationException(); + } + + public CDORevision getRevision(CDOID id) + { + throw new UnsupportedOperationException(); + } + + public void close() + { + throw new UnsupportedOperationException(); + } + + public boolean isClosed() + { + throw new UnsupportedOperationException(); + } + + public IRepository getRepository() + { + throw new UnsupportedOperationException(); + } + + public ISession getSession() + { + return null; + } + + @Override + public int hashCode() + { + return durableLockingID.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + + if (obj instanceof DurableView) + { + DurableView that = (DurableView)obj; + return durableLockingID.equals(that.getDurableLockingID()); + } + + return false; + } + + @Override + public String toString() + { + return MessageFormat.format("DurableView[{0}]", durableLockingID); + } + + public IOptionsContainer getContainer() + { + return null; + } + + public void addListener(IListener listener) + { + } + + public void removeListener(IListener listener) + { + } + + public boolean hasListeners() + { + return false; + } + + public IListener[] getListeners() + { + return null; + } + + public Options options() + { + return this; + } + + public boolean isLockNotificationEnabled() + { + return false; + } + + public void setLockNotificationEnabled(boolean enabled) + { + } + } + + /** + * @author Eike Stepper + */ + private final class DurableLockLoader implements LockArea.Handler + { + public DurableLockLoader() + { + } + + private IView getView(String lockAreaID) + { + IView view = openViews.get(lockAreaID); + if (view == null) + { + view = durableViews.get(lockAreaID); + } + + return view; + } + + public boolean handleLockArea(LockArea area) + { + String durableLockingID = area.getDurableLockingID(); + IView view = getView(durableLockingID); + if (view != null) + { + unlock2(view); + } + + if (view == null) + { + view = new DurableView(durableLockingID); + durableViews.put(durableLockingID, (DurableView)view); + } + + Collection<Object> readLocks = new ArrayList<Object>(); + Collection<Object> writeLocks = new ArrayList<Object>(); + Collection<Object> writeOptions = new ArrayList<Object>(); + for (Entry<CDOID, LockGrade> entry : area.getLocks().entrySet()) + { + Object key = getLockKey(entry.getKey(), area.getBranch()); + LockGrade grade = entry.getValue(); + if (grade.isRead()) + { + readLocks.add(key); + } + + if (grade.isWrite()) + { + writeLocks.add(key); + } + + if (grade.isOption()) + { + writeOptions.add(key); + } + } + + try + { + lock(LockType.READ, view, readLocks, 1000L); + lock(LockType.WRITE, view, writeLocks, 1000L); + lock(LockType.OPTION, view, writeOptions, 1000L); + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + + return true; + } + } + + public LockGrade getLockGrade(Object key) + { + LockState<Object, IView> lockState = getObjectToLocksMap().get(key); + LockGrade grade = LockGrade.NONE; + if (lockState != null) + { + for (LockType type : LockType.values()) + { + if (lockState.hasLock(type)) + { + grade = grade.getUpdated(type, true); + } + } + } + + return grade; + } + + private LockArea getLockAreaNoEx(String durableLockingID) + { + try + { + return getLockArea(durableLockingID); + } + catch (LockAreaNotFoundException e) + { + return null; + } + } + + public void updateLockArea(LockArea lockArea) + { + String durableLockingID = lockArea.getDurableLockingID(); + DurableLocking2 accessor = getDurableLocking2(); + + if (lockArea.isMissing()) + { + LockArea localLockArea = getLockAreaNoEx(durableLockingID); + if (localLockArea != null && localLockArea.getLocks().size() > 0) + { + accessor.deleteLockArea(durableLockingID); + DurableView deletedView = durableViews.remove(durableLockingID); + CheckUtil.checkNull(deletedView, "deletedView"); + } + } + else + { + accessor.updateLockArea(lockArea); + new DurableLockLoader().handleLockArea(lockArea); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java index ccd2eddf72..ae5d3cb519 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.spi.common.AbstractQueryResult;
-import org.eclipse.emf.cdo.spi.server.InternalQueryResult;
-import org.eclipse.emf.cdo.spi.server.InternalView;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class QueryResult extends AbstractQueryResult<Object> implements InternalQueryResult
-{
- public QueryResult(InternalView view, CDOQueryInfo queryInfo, int queryID)
- {
- super(view, queryInfo, queryID);
- }
-
- @Override
- public InternalView getView()
- {
- return (InternalView)super.getView();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.spi.common.AbstractQueryResult; +import org.eclipse.emf.cdo.spi.server.InternalQueryResult; +import org.eclipse.emf.cdo.spi.server.InternalView; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class QueryResult extends AbstractQueryResult<Object> implements InternalQueryResult +{ + public QueryResult(InternalView view, CDOQueryInfo queryInfo, int queryID) + { + super(view, queryInfo, queryID); + } + + @Override + public InternalView getView() + { + return (InternalView)super.getView(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java index 08c574d5a2..830279b00b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java @@ -1,146 +1,146 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server;
-
-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.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.server.IQueryContext;
-import org.eclipse.emf.cdo.server.IQueryHandler;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
-
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class ResourcesQueryHandler implements IQueryHandler
-{
- public ResourcesQueryHandler()
- {
- }
-
- public void executeQuery(CDOQueryInfo info, IQueryContext context)
- {
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- QueryContext resourcesContext = new QueryContext(info, context);
- accessor.queryResources(resourcesContext);
-
- CDOBranchPoint branchPoint = context;
- CDOBranch branch = branchPoint.getBranch();
- while (!branch.isMainBranch() && resourcesContext.getResourceIDs().size() < info.getMaxResults())
- {
- branchPoint = branch.getBase();
- branch = branchPoint.getBranch();
-
- resourcesContext.setBranchPoint(branchPoint);
- accessor.queryResources(resourcesContext);
- }
- }
-
- /**
- * @author Eike Stepper
- * @since 3.0
- */
- private static final class QueryContext implements IStoreAccessor.QueryResourcesContext
- {
- private CDOQueryInfo info;
-
- private IQueryContext context;
-
- private CDOBranchPoint branchPoint;
-
- private Set<CDOID> resourceIDs = new HashSet<CDOID>();
-
- public QueryContext(CDOQueryInfo info, IQueryContext context)
- {
- this.info = info;
- this.context = context;
- branchPoint = context;
- }
-
- public void setBranchPoint(CDOBranchPoint branchPoint)
- {
- this.branchPoint = branchPoint;
- }
-
- public Set<CDOID> getResourceIDs()
- {
- return resourceIDs;
- }
-
- public CDOBranch getBranch()
- {
- return branchPoint.getBranch();
- }
-
- public long getTimeStamp()
- {
- return branchPoint.getTimeStamp();
- }
-
- public CDOID getFolderID()
- {
- return (CDOID)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_FOLDER_ID);
- }
-
- public String getName()
- {
- return info.getQueryString();
- }
-
- public boolean exactMatch()
- {
- return (Boolean)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_EXACT_MATCH);
- }
-
- public int getMaxResults()
- {
- return info.getMaxResults();
- }
-
- public boolean addResource(CDOID resourceID)
- {
- if (resourceIDs.add(resourceID))
- {
- return context.addResult(resourceID);
- }
-
- return true;
- }
- }
-
- /**
- * @author Eike Stepper
- * @since 2.0
- */
- public static class Factory extends QueryHandlerFactory
- {
- public Factory()
- {
- super(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES);
- }
-
- @Override
- public ResourcesQueryHandler create(String description) throws ProductCreationException
- {
- return new ResourcesQueryHandler();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server; + +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.protocol.CDOProtocolConstants; +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.server.IQueryContext; +import org.eclipse.emf.cdo.server.IQueryHandler; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory; + +import org.eclipse.net4j.util.factory.ProductCreationException; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class ResourcesQueryHandler implements IQueryHandler +{ + public ResourcesQueryHandler() + { + } + + public void executeQuery(CDOQueryInfo info, IQueryContext context) + { + IStoreAccessor accessor = StoreThreadLocal.getAccessor(); + QueryContext resourcesContext = new QueryContext(info, context); + accessor.queryResources(resourcesContext); + + CDOBranchPoint branchPoint = context; + CDOBranch branch = branchPoint.getBranch(); + while (!branch.isMainBranch() && resourcesContext.getResourceIDs().size() < info.getMaxResults()) + { + branchPoint = branch.getBase(); + branch = branchPoint.getBranch(); + + resourcesContext.setBranchPoint(branchPoint); + accessor.queryResources(resourcesContext); + } + } + + /** + * @author Eike Stepper + * @since 3.0 + */ + private static final class QueryContext implements IStoreAccessor.QueryResourcesContext + { + private CDOQueryInfo info; + + private IQueryContext context; + + private CDOBranchPoint branchPoint; + + private Set<CDOID> resourceIDs = new HashSet<CDOID>(); + + public QueryContext(CDOQueryInfo info, IQueryContext context) + { + this.info = info; + this.context = context; + branchPoint = context; + } + + public void setBranchPoint(CDOBranchPoint branchPoint) + { + this.branchPoint = branchPoint; + } + + public Set<CDOID> getResourceIDs() + { + return resourceIDs; + } + + public CDOBranch getBranch() + { + return branchPoint.getBranch(); + } + + public long getTimeStamp() + { + return branchPoint.getTimeStamp(); + } + + public CDOID getFolderID() + { + return (CDOID)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_FOLDER_ID); + } + + public String getName() + { + return info.getQueryString(); + } + + public boolean exactMatch() + { + return (Boolean)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_EXACT_MATCH); + } + + public int getMaxResults() + { + return info.getMaxResults(); + } + + public boolean addResource(CDOID resourceID) + { + if (resourceIDs.add(resourceID)) + { + return context.addResult(resourceID); + } + + return true; + } + } + + /** + * @author Eike Stepper + * @since 2.0 + */ + public static class Factory extends QueryHandlerFactory + { + public Factory() + { + super(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES); + } + + @Override + public ResourcesQueryHandler create(String description) throws ProductCreationException + { + return new ResourcesQueryHandler(); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java index 28c398b9a6..39985f7df7 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java @@ -1,955 +1,955 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
-import org.eclipse.emf.cdo.common.id.CDOIDGenerator;
-import org.eclipse.emf.cdo.common.lob.CDOLobStore;
-import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.common.revision.CDORevisionProvider;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-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.commit.CDORevisionAvailabilityInfo;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
-import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-import org.eclipse.emf.cdo.view.CDOInvalidationPolicy;
-import org.eclipse.emf.cdo.view.CDORevisionPrefetchingPolicy;
-import org.eclipse.emf.cdo.view.CDOStaleReferencePolicy;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.internal.cdo.session.SessionUtil;
-import org.eclipse.emf.internal.cdo.view.AbstractCDOView;
-
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-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.ref.ReferenceType;
-import org.eclipse.net4j.util.ref.ReferenceValueMap;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol.RefreshSessionResult;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager;
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class ServerCDOView extends AbstractCDOView implements org.eclipse.emf.cdo.view.CDOView.Options
-{
- private static final CDOAdapterPolicy[] ADAPTER_POLICIES = new CDOAdapterPolicy[0];
-
- private static final CDORevisionPrefetchingPolicy REVISION_PREFETCHING = CDOUtil
- .createRevisionPrefetchingPolicy(NO_REVISION_PREFETCHING);
-
- private InternalCDOSession session;
-
- private CDORevisionProvider revisionProvider;
-
- public ServerCDOView(InternalSession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled,
- CDORevisionProvider revisionProvider)
- {
- super(branchPoint, legacyModeEnabled);
- this.session = new ServerCDOSession(session);
- this.revisionProvider = revisionProvider;
-
- setViewSet(SessionUtil.prepareResourceSet(new ResourceSetImpl()));
- setObjects(new ReferenceValueMap.Weak<CDOID, InternalCDOObject>());
- activate();
- }
-
- public int getViewID()
- {
- return 1;
- }
-
- public InternalCDOSession getSession()
- {
- return session;
- }
-
- public long getLastUpdateTime()
- {
- return getTimeStamp();
- }
-
- public void setLastUpdateTime(long lastUpdateTime)
- {
- throw new UnsupportedOperationException();
- }
-
- public Options options()
- {
- return this;
- }
-
- public synchronized InternalCDORevision getRevision(CDOID id, boolean loadOnDemand)
- {
- return (InternalCDORevision)revisionProvider.getRevision(id);
- }
-
- @Override
- protected synchronized void excludeNewObject(CDOID id)
- {
- // Do nothing
- }
-
- public boolean isInvalidationRunnerActive()
- {
- return false;
- }
-
- public boolean setBranchPoint(CDOBranchPoint branchPoint)
- {
- throw new UnsupportedOperationException();
- }
-
- public void lockObjects(Collection<? extends CDOObject> objects, LockType lockType, long timeout)
- throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- public void lockObjects(Collection<? extends CDOObject> objects, LockType lockType, long timeout, boolean recursive)
- throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- public void unlockObjects(Collection<? extends CDOObject> objects, LockType lockType)
- {
- throw new UnsupportedOperationException();
- }
-
- public void unlockObjects(Collection<? extends CDOObject> objects, LockType lockType, boolean recursive)
- {
- throw new UnsupportedOperationException();
- }
-
- public void unlockObjects()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean waitForUpdate(long updateTime, long timeoutMillis)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setViewID(int viewId)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setSession(InternalCDOSession session)
- {
- throw new UnsupportedOperationException();
- }
-
- public int getSessionID()
- {
- return session.getSessionID();
- }
-
- public boolean isDurableView()
- {
- return false;
- }
-
- public String getDurableLockingID()
- {
- return null;
- }
-
- @Deprecated
- public String enableDurableLocking(boolean enable)
- {
- throw new UnsupportedOperationException();
- }
-
- public String enableDurableLocking()
- {
- throw new UnsupportedOperationException();
- }
-
- public void disableDurableLocking(boolean releaseLocks)
- {
- throw new UnsupportedOperationException();
- }
-
- @SuppressWarnings("deprecation")
- public CDOFeatureAnalyzer getFeatureAnalyzer()
- {
- return CDOFeatureAnalyzer.NOOP;
- }
-
- @SuppressWarnings("deprecation")
- public void setFeatureAnalyzer(CDOFeatureAnalyzer featureAnalyzer)
- {
- throw new UnsupportedOperationException();
- }
-
- public InternalCDOTransaction toTransaction()
- {
- throw new UnsupportedOperationException();
- }
-
- public void invalidate(CDOBranch branch, long lastUpdateTime, List<CDORevisionKey> allChangedObjects,
- List<CDOIDAndVersion> allDetachedObjects, Map<CDOID, InternalCDORevision> oldRevisions, boolean async)
- {
- throw new UnsupportedOperationException();
- }
-
- public void handleLockNotification(InternalCDOView sender, CDOLockChangeInfo lockChangeInfo)
- {
- // Do nothing
- }
-
- public void prefetchRevisions(CDOID id, int depth)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isObjectLocked(CDOObject object, LockType lockType, boolean byOthers)
- {
- return false;
- }
-
- public void handleAddAdapter(InternalCDOObject eObject, Adapter adapter)
- {
- // Do nothing
- }
-
- public void handleRemoveAdapter(InternalCDOObject eObject, Adapter adapter)
- {
- // Do nothing
- }
-
- public void subscribe(EObject eObject, Adapter adapter)
- {
- throw new UnsupportedOperationException();
- }
-
- public void unsubscribe(EObject eObject, Adapter adapter)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean hasSubscription(CDOID id)
- {
- return false;
- }
-
- public CDOView getContainer()
- {
- return this;
- }
-
- public ReferenceType getCacheReferenceType()
- {
- return ReferenceType.WEAK;
- }
-
- public boolean setCacheReferenceType(ReferenceType referenceType)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOInvalidationPolicy getInvalidationPolicy()
- {
- return CDOInvalidationPolicy.DEFAULT;
- }
-
- public void setInvalidationPolicy(CDOInvalidationPolicy policy)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isDetachmentNotificationEnabled()
- {
- return false;
- }
-
- public void setDetachmentNotificationEnabled(boolean enabled)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isInvalidationNotificationEnabled()
- {
- return false;
- }
-
- public void setInvalidationNotificationEnabled(boolean enabled)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isLoadNotificationEnabled()
- {
- return false;
- }
-
- public void setLoadNotificationEnabled(boolean enabled)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isLockNotificationEnabled()
- {
- return false;
- }
-
- public void setLockNotificationEnabled(boolean enabled)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOAdapterPolicy[] getChangeSubscriptionPolicies()
- {
- return ADAPTER_POLICIES;
- }
-
- public void addChangeSubscriptionPolicy(CDOAdapterPolicy policy)
- {
- throw new UnsupportedOperationException();
- }
-
- public void removeChangeSubscriptionPolicy(CDOAdapterPolicy policy)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOAdapterPolicy getStrongReferencePolicy()
- {
- return CDOAdapterPolicy.ALL;
- }
-
- public void setStrongReferencePolicy(CDOAdapterPolicy policy)
- {
- throw new UnsupportedOperationException();
- }
-
- @Deprecated
- public CDOStaleReferencePolicy getStaleReferenceBehaviour()
- {
- return getStaleReferencePolicy();
- }
-
- @Deprecated
- public void setStaleReferenceBehaviour(CDOStaleReferencePolicy policy)
- {
- setStaleReferencePolicy(policy);
- }
-
- public CDOStaleReferencePolicy getStaleReferencePolicy()
- {
- return CDOStaleReferencePolicy.EXCEPTION;
- }
-
- public void setStaleReferencePolicy(CDOStaleReferencePolicy policy)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy()
- {
- return REVISION_PREFETCHING;
- }
-
- public void setRevisionPrefetchingPolicy(CDORevisionPrefetchingPolicy prefetchingPolicy)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOLockState[] getLockStates(Collection<CDOID> ids)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class ServerCDOSession implements InternalCDOSession, CDORepositoryInfo
- {
- private InternalSession internalSession;
-
- private InternalRepository repository;
-
- public ServerCDOSession(InternalSession internalSession)
- {
- this.internalSession = internalSession;
- repository = internalSession.getManager().getRepository();
- }
-
- public CDOView[] getElements()
- {
- return new ServerCDOView[] { ServerCDOView.this };
- }
-
- public InternalCDOTransaction getTransaction(int viewID)
- {
- return null;
- }
-
- public InternalCDOTransaction[] getTransactions()
- {
- return new InternalCDOTransaction[0];
- }
-
- public CDOView[] getViews()
- {
- return getElements();
- }
-
- public CDOView getView(int viewID)
- {
- return viewID == getViewID() ? ServerCDOView.this : null;
- }
-
- public CDOSessionProtocol getSessionProtocol()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOLobStore getLobStore()
- {
- throw new UnsupportedOperationException();
- }
-
- public InternalCDORevisionManager getRevisionManager()
- {
- return repository.getRevisionManager();
- }
-
- public InternalCDOPackageRegistry getPackageRegistry()
- {
- if (revisionProvider instanceof IStoreAccessor.CommitContext)
- {
- IStoreAccessor.CommitContext context = (IStoreAccessor.CommitContext)revisionProvider;
- return context.getPackageRegistry();
- }
-
- return repository.getPackageRegistry(false);
- }
-
- public InternalCDOCommitInfoManager getCommitInfoManager()
- {
- return repository.getCommitInfoManager();
- }
-
- public InternalCDOBranchManager getBranchManager()
- {
- return repository.getBranchManager();
- }
-
- public void setMainBranchLocal(boolean mainBranchLocal)
- {
- // Do nothing
- }
-
- public boolean hasListeners()
- {
- return false;
- }
-
- public IListener[] getListeners()
- {
- return null;
- }
-
- public void addListener(IListener listener)
- {
- // Do nothing
- }
-
- public void removeListener(IListener listener)
- {
- // Do nothing
- }
-
- public void activate() throws LifecycleException
- {
- throw new UnsupportedOperationException();
- }
-
- public Exception deactivate()
- {
- return ServerCDOView.this.deactivate();
- }
-
- public LifecycleState getLifecycleState()
- {
- return LifecycleState.ACTIVE;
- }
-
- public boolean isActive()
- {
- return ServerCDOView.this.isActive();
- }
-
- public boolean isClosed()
- {
- return !isActive();
- }
-
- public void close()
- {
- deactivate();
- }
-
- public CDORepositoryInfo getRepositoryInfo()
- {
- return this;
- }
-
- public String getName()
- {
- return repository.getName();
- }
-
- public String getUUID()
- {
- return repository.getUUID();
- }
-
- public Type getType()
- {
- return repository.getType();
- }
-
- public State getState()
- {
- return repository.getState();
- }
-
- public long getCreationTime()
- {
- return repository.getCreationTime();
- }
-
- public long getTimeStamp()
- {
- return repository.getTimeStamp();
- }
-
- public long getTimeStamp(boolean forceRefresh)
- {
- return getTimeStamp();
- }
-
- public String getStoreType()
- {
- return repository.getStoreType();
- }
-
- public Set<ObjectType> getObjectIDTypes()
- {
- return repository.getObjectIDTypes();
- }
-
- public CDOID getRootResourceID()
- {
- return repository.getRootResourceID();
- }
-
- public boolean isSupportingAudits()
- {
- return repository.isSupportingAudits();
- }
-
- public boolean isSupportingBranches()
- {
- return repository.isSupportingBranches();
- }
-
- public boolean isSupportingEcore()
- {
- return repository.isSupportingEcore();
- }
-
- public boolean isEnsuringReferentialIntegrity()
- {
- return repository.isEnsuringReferentialIntegrity();
- }
-
- public IDGenerationLocation getIDGenerationLocation()
- {
- return repository.getIDGenerationLocation();
- }
-
- public void handleRepositoryTypeChanged(Type oldType, Type newType)
- {
- }
-
- public void handleRepositoryStateChanged(State oldState, State newState)
- {
- }
-
- public EPackage[] loadPackages(CDOPackageUnit packageUnit)
- {
- return null;
- }
-
- public void releaseAtomicRequestLock(Object key)
- {
- // Do nothing
- }
-
- public void acquireAtomicRequestLock(Object key)
- {
- // Do nothing
- }
-
- public Object processPackage(Object value)
- {
- return value;
- }
-
- public boolean isEmpty()
- {
- return false;
- }
-
- public boolean waitForUpdate(long updateTime, long timeoutMillis)
- {
- throw new UnsupportedOperationException();
- }
-
- public void waitForUpdate(long updateTime)
- {
- throw new UnsupportedOperationException();
- }
-
- public long getLastUpdateTime()
- {
- return getBranchPoint().getTimeStamp();
- }
-
- public String getUserID()
- {
- return null;
- }
-
- public int getSessionID()
- {
- return internalSession.getSessionID();
- }
-
- public long refresh()
- {
- throw new UnsupportedOperationException();
- }
-
- public Options options()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(String durableLockingID)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(String durableLockingID, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(long timeStamp)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(CDOBranch branch)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(CDOBranch branch, long timeStamp)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(CDOBranch branch, long timeStamp, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(CDOBranchPoint target, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(CDOBranchPoint target)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(CDOBranchPoint target, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOView openView(CDOBranchPoint target)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(String durableLockingID)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(String durableLockingID, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(CDOBranch branch)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOTransaction openTransaction(CDOBranch branch, ResourceSet resourceSet)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOFetchRuleManager getFetchRuleManager()
- {
- return null;
- }
-
- public ExceptionHandler getExceptionHandler()
- {
- return null;
- }
-
- public CDOIDGenerator getIDGenerator()
- {
- return null;
- }
-
- public void viewDetached(InternalCDOView view)
- {
- // Do nothing
- }
-
- public void setUserID(String userID)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setSessionProtocol(CDOSessionProtocol sessionProtocol)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setSessionID(int sessionID)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setRepositoryInfo(CDORepositoryInfo repositoryInfo)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setRemoteSessionManager(InternalCDORemoteSessionManager remoteSessionManager)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setLastUpdateTime(long lastUpdateTime)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setFetchRuleManager(CDOFetchRuleManager fetchRuleManager)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setExceptionHandler(ExceptionHandler exceptionHandler)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setIDGenerator(CDOIDGenerator idGenerator)
- {
- throw new UnsupportedOperationException();
- }
-
- public Object resolveElementProxy(CDORevision revision, EStructuralFeature feature, int accessIndex, int serverIndex)
- {
- throw new UnsupportedOperationException();
- }
-
- public void resolveAllElementProxies(CDORevision revision)
- {
- throw new UnsupportedOperationException();
- }
-
- public void processRefreshSessionResult(RefreshSessionResult result, CDOBranch branch,
- List<InternalCDOView> branchViews, Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions)
- {
- throw new UnsupportedOperationException();
- }
-
- public void invalidate(CDOCommitInfo commitInfo, InternalCDOTransaction sender)
- {
- throw new UnsupportedOperationException();
- }
-
- public void handleCommitNotification(CDOCommitInfo commitInfo)
- {
- throw new UnsupportedOperationException();
- }
-
- public void handleLockNotification(CDOLockChangeInfo lockChangeInfo, InternalCDOView sender)
- {
- throw new UnsupportedOperationException();
- }
-
- public void handleBranchNotification(InternalCDOBranch branch)
- {
- throw new UnsupportedOperationException();
- }
-
- public InternalCDORemoteSessionManager getRemoteSessionManager()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOAuthenticator getAuthenticator()
- {
- throw new UnsupportedOperationException();
- }
-
- public void setAuthenticator(CDOAuthenticator authenticator)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setRevisionManager(InternalCDORevisionManager revisionManager)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setBranchManager(InternalCDOBranchManager branchManager)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setCommitInfoManager(InternalCDOCommitInfoManager commitInfoManager)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setPackageRegistry(InternalCDOPackageRegistry packageRegistry)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isSticky()
- {
- return false;
- }
-
- public CDOBranchPoint getCommittedSinceLastRefresh(CDOID id)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setCommittedSinceLastRefresh(CDOID id, CDOBranchPoint branchPoint)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clearCommittedSinceLastRefresh()
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOChangeSetData compareRevisions(CDOBranchPoint source, CDOBranchPoint target)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDORevisionAvailabilityInfo createRevisionAvailabilityInfo(CDOBranchPoint branchPoint)
- {
- throw new UnsupportedOperationException();
- }
-
- public void cacheRevisions(CDORevisionAvailabilityInfo info)
- {
- throw new UnsupportedOperationException();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.commit.CDOChangeSetData; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOID.ObjectType; +import org.eclipse.emf.cdo.common.id.CDOIDGenerator; +import org.eclipse.emf.cdo.common.lob.CDOLobStore; +import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.common.revision.CDORevisionProvider; +import org.eclipse.emf.cdo.server.IStoreAccessor; +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.commit.CDORevisionAvailabilityInfo; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalSession; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOAdapterPolicy; +import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; +import org.eclipse.emf.cdo.view.CDOInvalidationPolicy; +import org.eclipse.emf.cdo.view.CDORevisionPrefetchingPolicy; +import org.eclipse.emf.cdo.view.CDOStaleReferencePolicy; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.internal.cdo.session.SessionUtil; +import org.eclipse.emf.internal.cdo.view.AbstractCDOView; + +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; +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.ref.ReferenceType; +import org.eclipse.net4j.util.ref.ReferenceValueMap; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol.RefreshSessionResult; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager; +import org.eclipse.emf.spi.cdo.InternalCDOSession; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOView; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class ServerCDOView extends AbstractCDOView implements org.eclipse.emf.cdo.view.CDOView.Options +{ + private static final CDOAdapterPolicy[] ADAPTER_POLICIES = new CDOAdapterPolicy[0]; + + private static final CDORevisionPrefetchingPolicy REVISION_PREFETCHING = CDOUtil + .createRevisionPrefetchingPolicy(NO_REVISION_PREFETCHING); + + private InternalCDOSession session; + + private CDORevisionProvider revisionProvider; + + public ServerCDOView(InternalSession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled, + CDORevisionProvider revisionProvider) + { + super(branchPoint, legacyModeEnabled); + this.session = new ServerCDOSession(session); + this.revisionProvider = revisionProvider; + + setViewSet(SessionUtil.prepareResourceSet(new ResourceSetImpl())); + setObjects(new ReferenceValueMap.Weak<CDOID, InternalCDOObject>()); + activate(); + } + + public int getViewID() + { + return 1; + } + + public InternalCDOSession getSession() + { + return session; + } + + public long getLastUpdateTime() + { + return getTimeStamp(); + } + + public void setLastUpdateTime(long lastUpdateTime) + { + throw new UnsupportedOperationException(); + } + + public Options options() + { + return this; + } + + public synchronized InternalCDORevision getRevision(CDOID id, boolean loadOnDemand) + { + return (InternalCDORevision)revisionProvider.getRevision(id); + } + + @Override + protected synchronized void excludeNewObject(CDOID id) + { + // Do nothing + } + + public boolean isInvalidationRunnerActive() + { + return false; + } + + public boolean setBranchPoint(CDOBranchPoint branchPoint) + { + throw new UnsupportedOperationException(); + } + + public void lockObjects(Collection<? extends CDOObject> objects, LockType lockType, long timeout) + throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + public void lockObjects(Collection<? extends CDOObject> objects, LockType lockType, long timeout, boolean recursive) + throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + public void unlockObjects(Collection<? extends CDOObject> objects, LockType lockType) + { + throw new UnsupportedOperationException(); + } + + public void unlockObjects(Collection<? extends CDOObject> objects, LockType lockType, boolean recursive) + { + throw new UnsupportedOperationException(); + } + + public void unlockObjects() + { + throw new UnsupportedOperationException(); + } + + public boolean waitForUpdate(long updateTime, long timeoutMillis) + { + throw new UnsupportedOperationException(); + } + + public void setViewID(int viewId) + { + throw new UnsupportedOperationException(); + } + + public void setSession(InternalCDOSession session) + { + throw new UnsupportedOperationException(); + } + + public int getSessionID() + { + return session.getSessionID(); + } + + public boolean isDurableView() + { + return false; + } + + public String getDurableLockingID() + { + return null; + } + + @Deprecated + public String enableDurableLocking(boolean enable) + { + throw new UnsupportedOperationException(); + } + + public String enableDurableLocking() + { + throw new UnsupportedOperationException(); + } + + public void disableDurableLocking(boolean releaseLocks) + { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("deprecation") + public CDOFeatureAnalyzer getFeatureAnalyzer() + { + return CDOFeatureAnalyzer.NOOP; + } + + @SuppressWarnings("deprecation") + public void setFeatureAnalyzer(CDOFeatureAnalyzer featureAnalyzer) + { + throw new UnsupportedOperationException(); + } + + public InternalCDOTransaction toTransaction() + { + throw new UnsupportedOperationException(); + } + + public void invalidate(CDOBranch branch, long lastUpdateTime, List<CDORevisionKey> allChangedObjects, + List<CDOIDAndVersion> allDetachedObjects, Map<CDOID, InternalCDORevision> oldRevisions, boolean async) + { + throw new UnsupportedOperationException(); + } + + public void handleLockNotification(InternalCDOView sender, CDOLockChangeInfo lockChangeInfo) + { + // Do nothing + } + + public void prefetchRevisions(CDOID id, int depth) + { + throw new UnsupportedOperationException(); + } + + public boolean isObjectLocked(CDOObject object, LockType lockType, boolean byOthers) + { + return false; + } + + public void handleAddAdapter(InternalCDOObject eObject, Adapter adapter) + { + // Do nothing + } + + public void handleRemoveAdapter(InternalCDOObject eObject, Adapter adapter) + { + // Do nothing + } + + public void subscribe(EObject eObject, Adapter adapter) + { + throw new UnsupportedOperationException(); + } + + public void unsubscribe(EObject eObject, Adapter adapter) + { + throw new UnsupportedOperationException(); + } + + public boolean hasSubscription(CDOID id) + { + return false; + } + + public CDOView getContainer() + { + return this; + } + + public ReferenceType getCacheReferenceType() + { + return ReferenceType.WEAK; + } + + public boolean setCacheReferenceType(ReferenceType referenceType) + { + throw new UnsupportedOperationException(); + } + + public CDOInvalidationPolicy getInvalidationPolicy() + { + return CDOInvalidationPolicy.DEFAULT; + } + + public void setInvalidationPolicy(CDOInvalidationPolicy policy) + { + throw new UnsupportedOperationException(); + } + + public boolean isDetachmentNotificationEnabled() + { + return false; + } + + public void setDetachmentNotificationEnabled(boolean enabled) + { + throw new UnsupportedOperationException(); + } + + public boolean isInvalidationNotificationEnabled() + { + return false; + } + + public void setInvalidationNotificationEnabled(boolean enabled) + { + throw new UnsupportedOperationException(); + } + + public boolean isLoadNotificationEnabled() + { + return false; + } + + public void setLoadNotificationEnabled(boolean enabled) + { + throw new UnsupportedOperationException(); + } + + public boolean isLockNotificationEnabled() + { + return false; + } + + public void setLockNotificationEnabled(boolean enabled) + { + throw new UnsupportedOperationException(); + } + + public CDOAdapterPolicy[] getChangeSubscriptionPolicies() + { + return ADAPTER_POLICIES; + } + + public void addChangeSubscriptionPolicy(CDOAdapterPolicy policy) + { + throw new UnsupportedOperationException(); + } + + public void removeChangeSubscriptionPolicy(CDOAdapterPolicy policy) + { + throw new UnsupportedOperationException(); + } + + public CDOAdapterPolicy getStrongReferencePolicy() + { + return CDOAdapterPolicy.ALL; + } + + public void setStrongReferencePolicy(CDOAdapterPolicy policy) + { + throw new UnsupportedOperationException(); + } + + @Deprecated + public CDOStaleReferencePolicy getStaleReferenceBehaviour() + { + return getStaleReferencePolicy(); + } + + @Deprecated + public void setStaleReferenceBehaviour(CDOStaleReferencePolicy policy) + { + setStaleReferencePolicy(policy); + } + + public CDOStaleReferencePolicy getStaleReferencePolicy() + { + return CDOStaleReferencePolicy.EXCEPTION; + } + + public void setStaleReferencePolicy(CDOStaleReferencePolicy policy) + { + throw new UnsupportedOperationException(); + } + + public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy() + { + return REVISION_PREFETCHING; + } + + public void setRevisionPrefetchingPolicy(CDORevisionPrefetchingPolicy prefetchingPolicy) + { + throw new UnsupportedOperationException(); + } + + public CDOLockState[] getLockStates(Collection<CDOID> ids) + { + throw new UnsupportedOperationException(); + } + + /** + * @author Eike Stepper + */ + private final class ServerCDOSession implements InternalCDOSession, CDORepositoryInfo + { + private InternalSession internalSession; + + private InternalRepository repository; + + public ServerCDOSession(InternalSession internalSession) + { + this.internalSession = internalSession; + repository = internalSession.getManager().getRepository(); + } + + public CDOView[] getElements() + { + return new ServerCDOView[] { ServerCDOView.this }; + } + + public InternalCDOTransaction getTransaction(int viewID) + { + return null; + } + + public InternalCDOTransaction[] getTransactions() + { + return new InternalCDOTransaction[0]; + } + + public CDOView[] getViews() + { + return getElements(); + } + + public CDOView getView(int viewID) + { + return viewID == getViewID() ? ServerCDOView.this : null; + } + + public CDOSessionProtocol getSessionProtocol() + { + throw new UnsupportedOperationException(); + } + + public CDOLobStore getLobStore() + { + throw new UnsupportedOperationException(); + } + + public InternalCDORevisionManager getRevisionManager() + { + return repository.getRevisionManager(); + } + + public InternalCDOPackageRegistry getPackageRegistry() + { + if (revisionProvider instanceof IStoreAccessor.CommitContext) + { + IStoreAccessor.CommitContext context = (IStoreAccessor.CommitContext)revisionProvider; + return context.getPackageRegistry(); + } + + return repository.getPackageRegistry(false); + } + + public InternalCDOCommitInfoManager getCommitInfoManager() + { + return repository.getCommitInfoManager(); + } + + public InternalCDOBranchManager getBranchManager() + { + return repository.getBranchManager(); + } + + public void setMainBranchLocal(boolean mainBranchLocal) + { + // Do nothing + } + + public boolean hasListeners() + { + return false; + } + + public IListener[] getListeners() + { + return null; + } + + public void addListener(IListener listener) + { + // Do nothing + } + + public void removeListener(IListener listener) + { + // Do nothing + } + + public void activate() throws LifecycleException + { + throw new UnsupportedOperationException(); + } + + public Exception deactivate() + { + return ServerCDOView.this.deactivate(); + } + + public LifecycleState getLifecycleState() + { + return LifecycleState.ACTIVE; + } + + public boolean isActive() + { + return ServerCDOView.this.isActive(); + } + + public boolean isClosed() + { + return !isActive(); + } + + public void close() + { + deactivate(); + } + + public CDORepositoryInfo getRepositoryInfo() + { + return this; + } + + public String getName() + { + return repository.getName(); + } + + public String getUUID() + { + return repository.getUUID(); + } + + public Type getType() + { + return repository.getType(); + } + + public State getState() + { + return repository.getState(); + } + + public long getCreationTime() + { + return repository.getCreationTime(); + } + + public long getTimeStamp() + { + return repository.getTimeStamp(); + } + + public long getTimeStamp(boolean forceRefresh) + { + return getTimeStamp(); + } + + public String getStoreType() + { + return repository.getStoreType(); + } + + public Set<ObjectType> getObjectIDTypes() + { + return repository.getObjectIDTypes(); + } + + public CDOID getRootResourceID() + { + return repository.getRootResourceID(); + } + + public boolean isSupportingAudits() + { + return repository.isSupportingAudits(); + } + + public boolean isSupportingBranches() + { + return repository.isSupportingBranches(); + } + + public boolean isSupportingEcore() + { + return repository.isSupportingEcore(); + } + + public boolean isEnsuringReferentialIntegrity() + { + return repository.isEnsuringReferentialIntegrity(); + } + + public IDGenerationLocation getIDGenerationLocation() + { + return repository.getIDGenerationLocation(); + } + + public void handleRepositoryTypeChanged(Type oldType, Type newType) + { + } + + public void handleRepositoryStateChanged(State oldState, State newState) + { + } + + public EPackage[] loadPackages(CDOPackageUnit packageUnit) + { + return null; + } + + public void releaseAtomicRequestLock(Object key) + { + // Do nothing + } + + public void acquireAtomicRequestLock(Object key) + { + // Do nothing + } + + public Object processPackage(Object value) + { + return value; + } + + public boolean isEmpty() + { + return false; + } + + public boolean waitForUpdate(long updateTime, long timeoutMillis) + { + throw new UnsupportedOperationException(); + } + + public void waitForUpdate(long updateTime) + { + throw new UnsupportedOperationException(); + } + + public long getLastUpdateTime() + { + return getBranchPoint().getTimeStamp(); + } + + public String getUserID() + { + return null; + } + + public int getSessionID() + { + return internalSession.getSessionID(); + } + + public long refresh() + { + throw new UnsupportedOperationException(); + } + + public Options options() + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(String durableLockingID) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(String durableLockingID, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView() + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(long timeStamp) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(CDOBranch branch) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(CDOBranch branch, long timeStamp) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(CDOBranch branch, long timeStamp, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(CDOBranchPoint target, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(CDOBranchPoint target) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(CDOBranchPoint target, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOView openView(CDOBranchPoint target) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(String durableLockingID) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(String durableLockingID, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction() + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(CDOBranch branch) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOTransaction openTransaction(CDOBranch branch, ResourceSet resourceSet) + { + throw new UnsupportedOperationException(); + } + + public CDOFetchRuleManager getFetchRuleManager() + { + return null; + } + + public ExceptionHandler getExceptionHandler() + { + return null; + } + + public CDOIDGenerator getIDGenerator() + { + return null; + } + + public void viewDetached(InternalCDOView view) + { + // Do nothing + } + + public void setUserID(String userID) + { + throw new UnsupportedOperationException(); + } + + public void setSessionProtocol(CDOSessionProtocol sessionProtocol) + { + throw new UnsupportedOperationException(); + } + + public void setSessionID(int sessionID) + { + throw new UnsupportedOperationException(); + } + + public void setRepositoryInfo(CDORepositoryInfo repositoryInfo) + { + throw new UnsupportedOperationException(); + } + + public void setRemoteSessionManager(InternalCDORemoteSessionManager remoteSessionManager) + { + throw new UnsupportedOperationException(); + } + + public void setLastUpdateTime(long lastUpdateTime) + { + throw new UnsupportedOperationException(); + } + + public void setFetchRuleManager(CDOFetchRuleManager fetchRuleManager) + { + throw new UnsupportedOperationException(); + } + + public void setExceptionHandler(ExceptionHandler exceptionHandler) + { + throw new UnsupportedOperationException(); + } + + public void setIDGenerator(CDOIDGenerator idGenerator) + { + throw new UnsupportedOperationException(); + } + + public Object resolveElementProxy(CDORevision revision, EStructuralFeature feature, int accessIndex, int serverIndex) + { + throw new UnsupportedOperationException(); + } + + public void resolveAllElementProxies(CDORevision revision) + { + throw new UnsupportedOperationException(); + } + + public void processRefreshSessionResult(RefreshSessionResult result, CDOBranch branch, + List<InternalCDOView> branchViews, Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions) + { + throw new UnsupportedOperationException(); + } + + public void invalidate(CDOCommitInfo commitInfo, InternalCDOTransaction sender) + { + throw new UnsupportedOperationException(); + } + + public void handleCommitNotification(CDOCommitInfo commitInfo) + { + throw new UnsupportedOperationException(); + } + + public void handleLockNotification(CDOLockChangeInfo lockChangeInfo, InternalCDOView sender) + { + throw new UnsupportedOperationException(); + } + + public void handleBranchNotification(InternalCDOBranch branch) + { + throw new UnsupportedOperationException(); + } + + public InternalCDORemoteSessionManager getRemoteSessionManager() + { + throw new UnsupportedOperationException(); + } + + public CDOAuthenticator getAuthenticator() + { + throw new UnsupportedOperationException(); + } + + public void setAuthenticator(CDOAuthenticator authenticator) + { + throw new UnsupportedOperationException(); + } + + public void setRevisionManager(InternalCDORevisionManager revisionManager) + { + throw new UnsupportedOperationException(); + } + + public void setBranchManager(InternalCDOBranchManager branchManager) + { + throw new UnsupportedOperationException(); + } + + public void setCommitInfoManager(InternalCDOCommitInfoManager commitInfoManager) + { + throw new UnsupportedOperationException(); + } + + public void setPackageRegistry(InternalCDOPackageRegistry packageRegistry) + { + throw new UnsupportedOperationException(); + } + + public boolean isSticky() + { + return false; + } + + public CDOBranchPoint getCommittedSinceLastRefresh(CDOID id) + { + throw new UnsupportedOperationException(); + } + + public void setCommittedSinceLastRefresh(CDOID id, CDOBranchPoint branchPoint) + { + throw new UnsupportedOperationException(); + } + + public void clearCommittedSinceLastRefresh() + { + throw new UnsupportedOperationException(); + } + + public CDOChangeSetData compareRevisions(CDOBranchPoint source, CDOBranchPoint target) + { + throw new UnsupportedOperationException(); + } + + public CDORevisionAvailabilityInfo createRevisionAvailabilityInfo(CDOBranchPoint branchPoint) + { + throw new UnsupportedOperationException(); + } + + public void cacheRevisions(CDORevisionAvailabilityInfo info) + { + throw new UnsupportedOperationException(); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TimeStampAuthority.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TimeStampAuthority.java index e9d85408f6..3db8a538c9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TimeStampAuthority.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TimeStampAuthority.java @@ -1,230 +1,230 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Caspar De Groot - initial API and implementation
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Bugzilla 297940, 290032
- *
- * @author Caspar De Groot
- */
-class TimeStampAuthority
-{
- private InternalRepository repository;
-
- /**
- * Holds the timestamp that was issued in response to the last call to {@link #createTimestamp()}
- */
- @ExcludeFromDump
- private transient long lastIssuedTimeStamp = CDOBranchPoint.UNSPECIFIED_DATE;
-
- /**
- * Holds the timestamp that was last reported finished by a call to {@link #endCommit(long)}
- */
- private long lastFinishedTimeStamp;
-
- private LastCommitTimeStampLock lastCommitTimeStampLock = new LastCommitTimeStampLock();
-
- private boolean strictOrdering; // TODO (CD) Should be a repo property
-
- /**
- * A lock to block on if strict commit ordering is enabled
- */
- private StrictOrderingLock strictOrderingLock = new StrictOrderingLock();
-
- /**
- * An ordered list of timestamps that have been issued but have not (yet) been reported finished. (It is ordered
- * because the timestamps are added sequentially.)
- */
- private List<Long> runningTransactions = new LinkedList<Long>();
-
- /**
- * A set of timestamps that have been reported finished but have not yet been
- */
- private SortedSet<Long> finishedTransactions = new TreeSet<Long>();
-
- TimeStampAuthority(InternalRepository repository)
- {
- this.repository = repository;
- }
-
- synchronized long[] startCommit(OMMonitor monitor)
- {
- return startCommit(CDOBranchPoint.UNSPECIFIED_DATE, monitor);
- }
-
- synchronized long[] startCommit(long timeStampOverride, OMMonitor monitor)
- {
- monitor.begin();
-
- if (strictOrdering)
- {
- strictOrderingLock.lock();
- }
-
- try
- {
- long now = repository.getTimeStamp();
- if (lastIssuedTimeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- while (lastIssuedTimeStamp == now)
- {
- ConcurrencyUtil.sleep(1);
- now = repository.getTimeStamp();
- monitor.checkCanceled();
- }
- }
-
- if (timeStampOverride != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- now = timeStampOverride;
- }
-
- lastIssuedTimeStamp = now;
-
- runningTransactions.add(lastIssuedTimeStamp);
- return new long[] { lastIssuedTimeStamp, getLastFinishedTimeStamp() };
- }
- finally
- {
- monitor.done();
- }
- }
-
- synchronized void endCommit(long timeStamp)
- {
- if (!runningTransactions.remove(timeStamp))
- {
- throw new IllegalArgumentException("Cannot end transaction with unknown timestamp " + timeStamp);
- }
-
- finishedTransactions.add(timeStamp);
-
- // We can remove a timestamp from finishedTransactions if it is smaller (i.e. older) than any
- // of the runningTransactions. Since both sets are sorted, we only need to compare the heads.
- long oldestRunning = runningTransactions.isEmpty() ? Long.MAX_VALUE : runningTransactions.get(0);
- long oldestFinished;
- synchronized (lastCommitTimeStampLock)
- {
- long oldValue = lastFinishedTimeStamp;
- while (!finishedTransactions.isEmpty() && (oldestFinished = finishedTransactions.first()) < oldestRunning)
- {
- finishedTransactions.remove(oldestFinished);
- lastFinishedTimeStamp = oldestFinished;
- }
-
- // If we actually changed the lastFinishedTimeStamp, we need to notify waiting threads
- if (lastFinishedTimeStamp != oldValue)
- {
- lastCommitTimeStampLock.notifyAll();
- }
- }
-
- if (strictOrdering)
- {
- strictOrderingLock.unlock();
- }
- }
-
- synchronized void failCommit(long timeStamp)
- {
- if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE) // Exclude problems before TransactionCommitContext.setTimeStamp()
- {
- if (!runningTransactions.remove(timeStamp))
- {
- throw new IllegalArgumentException("Cannot fail transaction with unknown timestamp " + timeStamp);
- }
- }
-
- if (strictOrdering)
- {
- strictOrderingLock.unlock();
- }
- }
-
- synchronized long getLastFinishedTimeStamp()
- {
- if (lastFinishedTimeStamp != 0)
- {
- return lastFinishedTimeStamp;
- }
-
- // If we get here, no commit has finished since the server was started
- if (lastIssuedTimeStamp == 0) // No commit has started either
- {
- // We can safely return the current system time minus one milli.
- return repository.getTimeStamp() - 1;
- }
-
- // If we get here, one or more commits are running
- // We can safely return the start time of the longest-running, minus one milli.
- return runningTransactions.get(0) - 1;
- }
-
- long waitForCommit(long timeout)
- {
- synchronized (lastCommitTimeStampLock)
- {
- try
- {
- lastCommitTimeStampLock.wait(timeout);
- }
- catch (Exception ignore)
- {
- }
-
- return lastFinishedTimeStamp;
- }
- }
-
- void setLastFinishedTimeStamp(long lastCommitTimeStamp)
- {
- synchronized (lastCommitTimeStampLock)
- {
- if (lastFinishedTimeStamp < lastCommitTimeStamp)
- {
- lastFinishedTimeStamp = lastCommitTimeStamp;
- lastCommitTimeStampLock.notifyAll();
- }
- }
- }
-
- /**
- * A separate class for better monitor debugging.
- *
- * @author Eike Stepper
- */
- private static final class LastCommitTimeStampLock
- {
- }
-
- /**
- * A separate class for better monitor debugging.
- *
- * @author Eike Stepper
- */
- private static final class StrictOrderingLock extends ReentrantLock
- {
- private static final long serialVersionUID = 1L;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Caspar De Groot - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.spi.server.InternalRepository; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.concurrent.ConcurrencyUtil; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.util.LinkedList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Bugzilla 297940, 290032 + * + * @author Caspar De Groot + */ +class TimeStampAuthority +{ + private InternalRepository repository; + + /** + * Holds the timestamp that was issued in response to the last call to {@link #createTimestamp()} + */ + @ExcludeFromDump + private transient long lastIssuedTimeStamp = CDOBranchPoint.UNSPECIFIED_DATE; + + /** + * Holds the timestamp that was last reported finished by a call to {@link #endCommit(long)} + */ + private long lastFinishedTimeStamp; + + private LastCommitTimeStampLock lastCommitTimeStampLock = new LastCommitTimeStampLock(); + + private boolean strictOrdering; // TODO (CD) Should be a repo property + + /** + * A lock to block on if strict commit ordering is enabled + */ + private StrictOrderingLock strictOrderingLock = new StrictOrderingLock(); + + /** + * An ordered list of timestamps that have been issued but have not (yet) been reported finished. (It is ordered + * because the timestamps are added sequentially.) + */ + private List<Long> runningTransactions = new LinkedList<Long>(); + + /** + * A set of timestamps that have been reported finished but have not yet been + */ + private SortedSet<Long> finishedTransactions = new TreeSet<Long>(); + + TimeStampAuthority(InternalRepository repository) + { + this.repository = repository; + } + + synchronized long[] startCommit(OMMonitor monitor) + { + return startCommit(CDOBranchPoint.UNSPECIFIED_DATE, monitor); + } + + synchronized long[] startCommit(long timeStampOverride, OMMonitor monitor) + { + monitor.begin(); + + if (strictOrdering) + { + strictOrderingLock.lock(); + } + + try + { + long now = repository.getTimeStamp(); + if (lastIssuedTimeStamp != CDOBranchPoint.UNSPECIFIED_DATE) + { + while (lastIssuedTimeStamp == now) + { + ConcurrencyUtil.sleep(1); + now = repository.getTimeStamp(); + monitor.checkCanceled(); + } + } + + if (timeStampOverride != CDOBranchPoint.UNSPECIFIED_DATE) + { + now = timeStampOverride; + } + + lastIssuedTimeStamp = now; + + runningTransactions.add(lastIssuedTimeStamp); + return new long[] { lastIssuedTimeStamp, getLastFinishedTimeStamp() }; + } + finally + { + monitor.done(); + } + } + + synchronized void endCommit(long timeStamp) + { + if (!runningTransactions.remove(timeStamp)) + { + throw new IllegalArgumentException("Cannot end transaction with unknown timestamp " + timeStamp); + } + + finishedTransactions.add(timeStamp); + + // We can remove a timestamp from finishedTransactions if it is smaller (i.e. older) than any + // of the runningTransactions. Since both sets are sorted, we only need to compare the heads. + long oldestRunning = runningTransactions.isEmpty() ? Long.MAX_VALUE : runningTransactions.get(0); + long oldestFinished; + synchronized (lastCommitTimeStampLock) + { + long oldValue = lastFinishedTimeStamp; + while (!finishedTransactions.isEmpty() && (oldestFinished = finishedTransactions.first()) < oldestRunning) + { + finishedTransactions.remove(oldestFinished); + lastFinishedTimeStamp = oldestFinished; + } + + // If we actually changed the lastFinishedTimeStamp, we need to notify waiting threads + if (lastFinishedTimeStamp != oldValue) + { + lastCommitTimeStampLock.notifyAll(); + } + } + + if (strictOrdering) + { + strictOrderingLock.unlock(); + } + } + + synchronized void failCommit(long timeStamp) + { + if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE) // Exclude problems before TransactionCommitContext.setTimeStamp() + { + if (!runningTransactions.remove(timeStamp)) + { + throw new IllegalArgumentException("Cannot fail transaction with unknown timestamp " + timeStamp); + } + } + + if (strictOrdering) + { + strictOrderingLock.unlock(); + } + } + + synchronized long getLastFinishedTimeStamp() + { + if (lastFinishedTimeStamp != 0) + { + return lastFinishedTimeStamp; + } + + // If we get here, no commit has finished since the server was started + if (lastIssuedTimeStamp == 0) // No commit has started either + { + // We can safely return the current system time minus one milli. + return repository.getTimeStamp() - 1; + } + + // If we get here, one or more commits are running + // We can safely return the start time of the longest-running, minus one milli. + return runningTransactions.get(0) - 1; + } + + long waitForCommit(long timeout) + { + synchronized (lastCommitTimeStampLock) + { + try + { + lastCommitTimeStampLock.wait(timeout); + } + catch (Exception ignore) + { + } + + return lastFinishedTimeStamp; + } + } + + void setLastFinishedTimeStamp(long lastCommitTimeStamp) + { + synchronized (lastCommitTimeStampLock) + { + if (lastFinishedTimeStamp < lastCommitTimeStamp) + { + lastFinishedTimeStamp = lastCommitTimeStamp; + lastCommitTimeStampLock.notifyAll(); + } + } + } + + /** + * A separate class for better monitor debugging. + * + * @author Eike Stepper + */ + private static final class LastCommitTimeStampLock + { + } + + /** + * A separate class for better monitor debugging. + * + * @author Eike Stepper + */ + private static final class StrictOrderingLock extends ReentrantLock + { + private static final long serialVersionUID = 1L; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java index c14daf7430..f449e3d50c 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java @@ -1,88 +1,88 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 233490
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class Transaction extends View implements InternalTransaction
-{
- public Transaction(InternalSession session, int viewID, CDOBranchPoint branchPoint)
- {
- super(session, viewID, branchPoint);
- }
-
- @Override
- public boolean isReadOnly()
- {
- return false;
- }
-
- @Override
- protected String getClassName()
- {
- return "Transaction"; //$NON-NLS-1$
- }
-
- /**
- * @since 2.0
- */
- public InternalCommitContext createCommitContext()
- {
- checkOpen();
- return getRepository().createCommitContext(this);
- }
-
- /**
- * For tests only.
- *
- * @since 2.0
- */
- public InternalCommitContext testCreateCommitContext(final long timeStamp)
- {
- checkOpen();
- return new TransactionCommitContext(this)
- {
- @Override
- protected long[] createTimeStamp(OMMonitor monitor)
- {
- return new long[] { timeStamp, CDOBranchPoint.UNSPECIFIED_DATE };
- }
- };
- }
-
- @Override
- protected void validateTimeStamp(long timeStamp) throws IllegalArgumentException
- {
- if (timeStamp != UNSPECIFIED_DATE)
- {
- throw new IllegalArgumentException("Changing the target time is not supported by transactions");
- }
- }
-
- private void checkOpen()
- {
- if (isClosed())
- {
- throw new IllegalStateException("View closed"); //$NON-NLS-1$
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 233490 + * Simon McDuff - bug 213402 + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; +import org.eclipse.emf.cdo.spi.server.InternalSession; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class Transaction extends View implements InternalTransaction +{ + public Transaction(InternalSession session, int viewID, CDOBranchPoint branchPoint) + { + super(session, viewID, branchPoint); + } + + @Override + public boolean isReadOnly() + { + return false; + } + + @Override + protected String getClassName() + { + return "Transaction"; //$NON-NLS-1$ + } + + /** + * @since 2.0 + */ + public InternalCommitContext createCommitContext() + { + checkOpen(); + return getRepository().createCommitContext(this); + } + + /** + * For tests only. + * + * @since 2.0 + */ + public InternalCommitContext testCreateCommitContext(final long timeStamp) + { + checkOpen(); + return new TransactionCommitContext(this) + { + @Override + protected long[] createTimeStamp(OMMonitor monitor) + { + return new long[] { timeStamp, CDOBranchPoint.UNSPECIFIED_DATE }; + } + }; + } + + @Override + protected void validateTimeStamp(long timeStamp) throws IllegalArgumentException + { + if (timeStamp != UNSPECIFIED_DATE) + { + throw new IllegalArgumentException("Changing the target time is not supported by transactions"); + } + } + + private void checkOpen() + { + if (isClosed()) + { + throw new IllegalStateException("View closed"); //$NON-NLS-1$ + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XATransactionCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XATransactionCommitContext.java index fc06f9c333..a339960c24 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XATransactionCommitContext.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XATransactionCommitContext.java @@ -1,185 +1,185 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.concurrent.ConcurrentValue;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class XATransactionCommitContext extends TransactionCommitContext
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION, XATransactionCommitContext.class);
-
- private ConcurrentValue<CommitState> state = new ConcurrentValue<CommitState>(CommitState.STARTING);
-
- public XATransactionCommitContext(InternalTransaction transaction)
- {
- super(transaction);
- }
-
- public ConcurrentValue<CommitState> getState()
- {
- return state;
- }
-
- @Override
- public void preWrite()
- {
- super.preWrite();
- StoreThreadLocal.setAccessor(null);
- }
-
- @Override
- public void commit(OMMonitor monitor)
- {
- StoreThreadLocal.setAccessor(getAccessor());
- try
- {
- super.commit(monitor);
- }
- finally
- {
- StoreThreadLocal.setAccessor(null);
- }
- }
-
- @Override
- public void write(OMMonitor monitor)
- {
- StoreThreadLocal.setAccessor(getAccessor());
- try
- {
- super.write(monitor);
- }
- finally
- {
- StoreThreadLocal.setAccessor(null);
- }
- }
-
- @Override
- public void postCommit(boolean success)
- {
- StoreThreadLocal.setAccessor(getAccessor());
- InternalRepository repository = getTransaction().getRepository();
- repository.getCommitManager().remove(this);
- super.postCommit(success);
- }
-
- @Override
- public synchronized void rollback(String message)
- {
- super.rollback(message);
-
- // Change the state to unblock call.
- state.set(CommitState.ROLLED_BACK);
- }
-
- /**
- * Wait until another thread fills ID mapping for external objects.
- */
- @Override
- public void applyIDMappings(OMMonitor monitor)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Notify phase2 to fill ID mapping."); //$NON-NLS-1$
- }
-
- state.set(CommitState.APPLY_ID_MAPPING);
- if (TRACER.isEnabled())
- {
- TRACER.format("Waiting for phase2 to be completed before continueing."); //$NON-NLS-1$
- }
-
- try
- {
- state.acquire(PHASEAPPLYMAPPING_DONE);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Received signal to continue."); //$NON-NLS-1$
- }
-
- super.applyIDMappings(monitor);
- }
-
- /**
- * Object to test if the process is at ApplyIDMapping
- */
- final public static Object PHASEAPPLYMAPPING = new Object()
- {
- @Override
- public int hashCode()
- {
- return CommitState.APPLY_ID_MAPPING.hashCode();
- }
-
- @Override
- public boolean equals(Object object)
- {
- if (object == CommitState.ROLLED_BACK)
- {
- throw new RuntimeException("RolledBack"); //$NON-NLS-1$
- }
-
- return CommitState.APPLY_ID_MAPPING == object;
- }
- };
-
- /**
- * Object to test if the process did applyIDMapping
- */
- final public static Object PHASEAPPLYMAPPING_DONE = new Object()
- {
- @Override
- public int hashCode()
- {
- return CommitState.APPLY_ID_MAPPING_DONE.hashCode();
- }
-
- @Override
- public boolean equals(Object object)
- {
- if (object == CommitState.ROLLED_BACK)
- {
- throw new RuntimeException("RolledBack"); //$NON-NLS-1$
- }
-
- return CommitState.APPLY_ID_MAPPING_DONE == object;
- }
- };
-
- /**
- * @author Simon McDuff
- * @since 2.0
- */
- public enum CommitState
- {
- STARTING, APPLY_ID_MAPPING, APPLY_ID_MAPPING_DONE, ROLLED_BACK
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server; + +import org.eclipse.emf.cdo.internal.server.bundle.OM; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.concurrent.ConcurrentValue; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class XATransactionCommitContext extends TransactionCommitContext +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION, XATransactionCommitContext.class); + + private ConcurrentValue<CommitState> state = new ConcurrentValue<CommitState>(CommitState.STARTING); + + public XATransactionCommitContext(InternalTransaction transaction) + { + super(transaction); + } + + public ConcurrentValue<CommitState> getState() + { + return state; + } + + @Override + public void preWrite() + { + super.preWrite(); + StoreThreadLocal.setAccessor(null); + } + + @Override + public void commit(OMMonitor monitor) + { + StoreThreadLocal.setAccessor(getAccessor()); + try + { + super.commit(monitor); + } + finally + { + StoreThreadLocal.setAccessor(null); + } + } + + @Override + public void write(OMMonitor monitor) + { + StoreThreadLocal.setAccessor(getAccessor()); + try + { + super.write(monitor); + } + finally + { + StoreThreadLocal.setAccessor(null); + } + } + + @Override + public void postCommit(boolean success) + { + StoreThreadLocal.setAccessor(getAccessor()); + InternalRepository repository = getTransaction().getRepository(); + repository.getCommitManager().remove(this); + super.postCommit(success); + } + + @Override + public synchronized void rollback(String message) + { + super.rollback(message); + + // Change the state to unblock call. + state.set(CommitState.ROLLED_BACK); + } + + /** + * Wait until another thread fills ID mapping for external objects. + */ + @Override + public void applyIDMappings(OMMonitor monitor) + { + if (TRACER.isEnabled()) + { + TRACER.format("Notify phase2 to fill ID mapping."); //$NON-NLS-1$ + } + + state.set(CommitState.APPLY_ID_MAPPING); + if (TRACER.isEnabled()) + { + TRACER.format("Waiting for phase2 to be completed before continueing."); //$NON-NLS-1$ + } + + try + { + state.acquire(PHASEAPPLYMAPPING_DONE); + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + + if (TRACER.isEnabled()) + { + TRACER.format("Received signal to continue."); //$NON-NLS-1$ + } + + super.applyIDMappings(monitor); + } + + /** + * Object to test if the process is at ApplyIDMapping + */ + final public static Object PHASEAPPLYMAPPING = new Object() + { + @Override + public int hashCode() + { + return CommitState.APPLY_ID_MAPPING.hashCode(); + } + + @Override + public boolean equals(Object object) + { + if (object == CommitState.ROLLED_BACK) + { + throw new RuntimeException("RolledBack"); //$NON-NLS-1$ + } + + return CommitState.APPLY_ID_MAPPING == object; + } + }; + + /** + * Object to test if the process did applyIDMapping + */ + final public static Object PHASEAPPLYMAPPING_DONE = new Object() + { + @Override + public int hashCode() + { + return CommitState.APPLY_ID_MAPPING_DONE.hashCode(); + } + + @Override + public boolean equals(Object object) + { + if (object == CommitState.ROLLED_BACK) + { + throw new RuntimeException("RolledBack"); //$NON-NLS-1$ + } + + return CommitState.APPLY_ID_MAPPING_DONE == object; + } + }; + + /** + * @author Simon McDuff + * @since 2.0 + */ + public enum CommitState + { + STARTING, APPLY_ID_MAPPING, APPLY_ID_MAPPING_DONE, ROLLED_BACK + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java index 798f666ddc..53d8fc339c 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java @@ -1,357 +1,357 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Stefan Winkler - Bug 331619 - Support cross-referencing (XRef) for abstract classes and class hierarchies
- */
-package org.eclipse.emf.cdo.internal.server;
-
-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.CDOIDReference;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit.State;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.server.IQueryContext;
-import org.eclipse.emf.cdo.server.IQueryHandler;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IView;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
-
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-/**
- * @author Eike Stepper
- */
-public class XRefsQueryHandler implements IQueryHandler
-{
- public XRefsQueryHandler()
- {
- }
-
- public void executeQuery(CDOQueryInfo info, IQueryContext context)
- {
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- QueryContext xrefsContext = new QueryContext(info, context);
- accessor.queryXRefs(xrefsContext);
-
- CDOBranchPoint branchPoint = context;
- CDOBranch branch = branchPoint.getBranch();
- while (!branch.isMainBranch() && context.getResultCount() < info.getMaxResults())
- {
- branchPoint = branch.getBase();
- branch = branchPoint.getBranch();
-
- xrefsContext.setBranchPoint(branchPoint);
- accessor.queryXRefs(xrefsContext);
- }
- }
-
- public static void collectSourceCandidates(IView view, Collection<EClass> concreteTypes,
- Map<EClass, List<EReference>> sourceCandidates)
- {
- InternalRepository repository = (InternalRepository)view.getRepository();
- CDOPackageRegistry packageRegistry = repository.getPackageRegistry(false);
-
- for (CDOPackageInfo packageInfo : packageRegistry.getPackageInfos())
- {
- // System.out.println();
- // System.out.println();
- // System.out.println(packageInfo);
- collectSourceCandidates(packageInfo, concreteTypes, sourceCandidates);
- // for (Entry<EClass, List<EReference>> entry : sourceCandidates.entrySet())
- // {
- // System.out.println(" ---> " + entry.getKey().getName());
- // for (EReference eReference : entry.getValue())
- // {
- // System.out.println(" ---> " + eReference.getName());
- // }
- // }
- //
- // System.out.println();
- // System.out.println();
- }
- }
-
- public static void collectSourceCandidates(CDOPackageInfo packageInfo, Collection<EClass> concreteTypes,
- Map<EClass, List<EReference>> sourceCandidates)
- {
- State state = packageInfo.getPackageUnit().getState();
- if (state == CDOPackageUnit.State.LOADED || state == CDOPackageUnit.State.PROXY)
- {
- EPackage ePackage = packageInfo.getEPackage();
- for (EClassifier eClassifier : ePackage.getEClassifiers())
- {
- if (eClassifier instanceof EClass)
- {
- collectSourceCandidates((EClass)eClassifier, concreteTypes, sourceCandidates);
- }
- }
- }
- }
-
- public static void collectSourceCandidates(EClass eClass, Collection<EClass> concreteTypes,
- Map<EClass, List<EReference>> sourceCandidates)
- {
- if (!eClass.isAbstract() && !eClass.isInterface())
- {
- for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures())
- {
- if (eStructuralFeature instanceof EReference && EMFUtil.isPersistent(eStructuralFeature))
- {
- collectSourceCandidates(eClass, (EReference)eStructuralFeature, concreteTypes, sourceCandidates);
- }
- }
- }
- }
-
- public static void collectSourceCandidates(EReference eReference, Collection<EClass> concreteTypes,
- Map<EClass, List<EReference>> sourceCandidates, CDOPackageRegistry packageRegistry)
- {
- EClass rootClass = eReference.getEContainingClass();
- collectSourceCandidates(rootClass, eReference, concreteTypes, sourceCandidates);
-
- Collection<EClass> descendentClasses = packageRegistry.getSubTypes().get(rootClass);
- if (descendentClasses != null)
- {
- for (EClass candidateClass : descendentClasses)
- {
- collectSourceCandidates(candidateClass, eReference, concreteTypes, sourceCandidates);
- }
- }
- }
-
- public static void collectSourceCandidates(EClass eClass, EReference eReference, Collection<EClass> concreteTypes,
- Map<EClass, List<EReference>> sourceCandidates)
- {
- if (!eClass.isAbstract() && !eClass.isInterface())
- {
- if (!eReference.isContainer() && !eReference.isContainment())
- {
- if (canReference(eReference.getEReferenceType(), concreteTypes))
- {
- List<EReference> list = sourceCandidates.get(eClass);
- if (list == null)
- {
- list = new ArrayList<EReference>();
- sourceCandidates.put(eClass, list);
- }
-
- list.add(eReference);
- }
- }
- }
- }
-
- private static boolean canReference(EClass declaredType, Collection<EClass> concreteTypes)
- {
- for (EClass concreteType : concreteTypes)
- {
- if (declaredType.isSuperTypeOf(concreteType))
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @author Eike Stepper
- * @since 3.0
- */
- private static final class QueryContext implements IStoreAccessor.QueryXRefsContext
- {
- private CDOQueryInfo info;
-
- private IQueryContext context;
-
- private CDOBranchPoint branchPoint;
-
- private Map<CDOID, EClass> targetObjects;
-
- private Map<EClass, List<EReference>> sourceCandidates;
-
- private EReference[] sourceReferences;
-
- public QueryContext(CDOQueryInfo info, IQueryContext context)
- {
- this.info = info;
- this.context = context;
- branchPoint = context;
- }
-
- public void setBranchPoint(CDOBranchPoint branchPoint)
- {
- this.branchPoint = branchPoint;
- }
-
- public CDOBranch getBranch()
- {
- return branchPoint.getBranch();
- }
-
- public long getTimeStamp()
- {
- return branchPoint.getTimeStamp();
- }
-
- public Map<CDOID, EClass> getTargetObjects()
- {
- if (targetObjects == null)
- {
- IRepository repository = context.getView().getRepository();
- IStore store = repository.getStore();
- CDOPackageRegistry packageRegistry = repository.getPackageRegistry();
-
- targetObjects = new HashMap<CDOID, EClass>();
- StringTokenizer tokenizer = new StringTokenizer(info.getQueryString(), "|");
- while (tokenizer.hasMoreTokens())
- {
- String val = tokenizer.nextToken();
- CDOID id = store.createObjectID(val);
-
- CDOClassifierRef classifierRef;
- if (id instanceof CDOClassifierRef.Provider)
- {
- classifierRef = ((CDOClassifierRef.Provider)id).getClassifierRef();
- }
- else
- {
- val = tokenizer.nextToken();
- classifierRef = new CDOClassifierRef(val);
- }
-
- EClass eClass = (EClass)classifierRef.resolve(packageRegistry);
- targetObjects.put(id, eClass);
- }
- }
-
- return targetObjects;
- }
-
- public EReference[] getSourceReferences()
- {
- if (sourceReferences == null)
- {
- sourceReferences = parseSourceReferences();
- }
-
- return sourceReferences;
- }
-
- private EReference[] parseSourceReferences()
- {
- List<EReference> result = new ArrayList<EReference>();
- CDOPackageRegistry packageRegistry = context.getView().getRepository().getPackageRegistry();
-
- String params = (String)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_XREFS_SOURCE_REFERENCES);
- if (params == null)
- {
- return new EReference[0];
- }
-
- StringTokenizer tokenizer = new StringTokenizer(params, "|");
- while (tokenizer.hasMoreTokens())
- {
- String className = tokenizer.nextToken();
- CDOClassifierRef classifierRef = new CDOClassifierRef(className);
- EClass eClass = (EClass)classifierRef.resolve(packageRegistry);
-
- String featureName = tokenizer.nextToken();
- EReference sourceReference = (EReference)eClass.getEStructuralFeature(featureName);
- result.add(sourceReference);
- }
-
- return result.toArray(new EReference[result.size()]);
- }
-
- public Map<EClass, List<EReference>> getSourceCandidates()
- {
- if (sourceCandidates == null)
- {
- sourceCandidates = new HashMap<EClass, List<EReference>>();
- Collection<EClass> concreteTypes = getTargetObjects().values();
- EReference[] sourceReferences = getSourceReferences();
-
- if (sourceReferences.length != 0)
- {
- InternalRepository repository = (InternalRepository)context.getView().getRepository();
- InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false);
- for (EReference eReference : sourceReferences)
- {
- collectSourceCandidates(eReference, concreteTypes, sourceCandidates, packageRegistry);
- }
- }
- else
- {
- collectSourceCandidates(context.getView(), concreteTypes, sourceCandidates);
- }
- }
-
- return sourceCandidates;
- }
-
- public int getMaxResults()
- {
- return info.getMaxResults();
- }
-
- public boolean addXRef(CDOID targetID, CDOID sourceID, EReference sourceReference, int sourceIndex)
- {
- if (CDOIDUtil.isNull(targetID))
- {
- return true;
- }
-
- return context.addResult(new CDOIDReference(targetID, sourceID, sourceReference, sourceIndex));
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends QueryHandlerFactory
- {
- public Factory()
- {
- super(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES);
- }
-
- @Override
- public XRefsQueryHandler create(String description) throws ProductCreationException
- {
- return new XRefsQueryHandler();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Stefan Winkler - Bug 331619 - Support cross-referencing (XRef) for abstract classes and class hierarchies + */ +package org.eclipse.emf.cdo.internal.server; + +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.CDOIDReference; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.model.CDOClassifierRef; +import org.eclipse.emf.cdo.common.model.CDOPackageInfo; +import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit.State; +import org.eclipse.emf.cdo.common.model.EMFUtil; +import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.server.IQueryContext; +import org.eclipse.emf.cdo.server.IQueryHandler; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IView; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory; + +import org.eclipse.net4j.util.factory.ProductCreationException; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * @author Eike Stepper + */ +public class XRefsQueryHandler implements IQueryHandler +{ + public XRefsQueryHandler() + { + } + + public void executeQuery(CDOQueryInfo info, IQueryContext context) + { + IStoreAccessor accessor = StoreThreadLocal.getAccessor(); + QueryContext xrefsContext = new QueryContext(info, context); + accessor.queryXRefs(xrefsContext); + + CDOBranchPoint branchPoint = context; + CDOBranch branch = branchPoint.getBranch(); + while (!branch.isMainBranch() && context.getResultCount() < info.getMaxResults()) + { + branchPoint = branch.getBase(); + branch = branchPoint.getBranch(); + + xrefsContext.setBranchPoint(branchPoint); + accessor.queryXRefs(xrefsContext); + } + } + + public static void collectSourceCandidates(IView view, Collection<EClass> concreteTypes, + Map<EClass, List<EReference>> sourceCandidates) + { + InternalRepository repository = (InternalRepository)view.getRepository(); + CDOPackageRegistry packageRegistry = repository.getPackageRegistry(false); + + for (CDOPackageInfo packageInfo : packageRegistry.getPackageInfos()) + { + // System.out.println(); + // System.out.println(); + // System.out.println(packageInfo); + collectSourceCandidates(packageInfo, concreteTypes, sourceCandidates); + // for (Entry<EClass, List<EReference>> entry : sourceCandidates.entrySet()) + // { + // System.out.println(" ---> " + entry.getKey().getName()); + // for (EReference eReference : entry.getValue()) + // { + // System.out.println(" ---> " + eReference.getName()); + // } + // } + // + // System.out.println(); + // System.out.println(); + } + } + + public static void collectSourceCandidates(CDOPackageInfo packageInfo, Collection<EClass> concreteTypes, + Map<EClass, List<EReference>> sourceCandidates) + { + State state = packageInfo.getPackageUnit().getState(); + if (state == CDOPackageUnit.State.LOADED || state == CDOPackageUnit.State.PROXY) + { + EPackage ePackage = packageInfo.getEPackage(); + for (EClassifier eClassifier : ePackage.getEClassifiers()) + { + if (eClassifier instanceof EClass) + { + collectSourceCandidates((EClass)eClassifier, concreteTypes, sourceCandidates); + } + } + } + } + + public static void collectSourceCandidates(EClass eClass, Collection<EClass> concreteTypes, + Map<EClass, List<EReference>> sourceCandidates) + { + if (!eClass.isAbstract() && !eClass.isInterface()) + { + for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) + { + if (eStructuralFeature instanceof EReference && EMFUtil.isPersistent(eStructuralFeature)) + { + collectSourceCandidates(eClass, (EReference)eStructuralFeature, concreteTypes, sourceCandidates); + } + } + } + } + + public static void collectSourceCandidates(EReference eReference, Collection<EClass> concreteTypes, + Map<EClass, List<EReference>> sourceCandidates, CDOPackageRegistry packageRegistry) + { + EClass rootClass = eReference.getEContainingClass(); + collectSourceCandidates(rootClass, eReference, concreteTypes, sourceCandidates); + + Collection<EClass> descendentClasses = packageRegistry.getSubTypes().get(rootClass); + if (descendentClasses != null) + { + for (EClass candidateClass : descendentClasses) + { + collectSourceCandidates(candidateClass, eReference, concreteTypes, sourceCandidates); + } + } + } + + public static void collectSourceCandidates(EClass eClass, EReference eReference, Collection<EClass> concreteTypes, + Map<EClass, List<EReference>> sourceCandidates) + { + if (!eClass.isAbstract() && !eClass.isInterface()) + { + if (!eReference.isContainer() && !eReference.isContainment()) + { + if (canReference(eReference.getEReferenceType(), concreteTypes)) + { + List<EReference> list = sourceCandidates.get(eClass); + if (list == null) + { + list = new ArrayList<EReference>(); + sourceCandidates.put(eClass, list); + } + + list.add(eReference); + } + } + } + } + + private static boolean canReference(EClass declaredType, Collection<EClass> concreteTypes) + { + for (EClass concreteType : concreteTypes) + { + if (declaredType.isSuperTypeOf(concreteType)) + { + return true; + } + } + + return false; + } + + /** + * @author Eike Stepper + * @since 3.0 + */ + private static final class QueryContext implements IStoreAccessor.QueryXRefsContext + { + private CDOQueryInfo info; + + private IQueryContext context; + + private CDOBranchPoint branchPoint; + + private Map<CDOID, EClass> targetObjects; + + private Map<EClass, List<EReference>> sourceCandidates; + + private EReference[] sourceReferences; + + public QueryContext(CDOQueryInfo info, IQueryContext context) + { + this.info = info; + this.context = context; + branchPoint = context; + } + + public void setBranchPoint(CDOBranchPoint branchPoint) + { + this.branchPoint = branchPoint; + } + + public CDOBranch getBranch() + { + return branchPoint.getBranch(); + } + + public long getTimeStamp() + { + return branchPoint.getTimeStamp(); + } + + public Map<CDOID, EClass> getTargetObjects() + { + if (targetObjects == null) + { + IRepository repository = context.getView().getRepository(); + IStore store = repository.getStore(); + CDOPackageRegistry packageRegistry = repository.getPackageRegistry(); + + targetObjects = new HashMap<CDOID, EClass>(); + StringTokenizer tokenizer = new StringTokenizer(info.getQueryString(), "|"); + while (tokenizer.hasMoreTokens()) + { + String val = tokenizer.nextToken(); + CDOID id = store.createObjectID(val); + + CDOClassifierRef classifierRef; + if (id instanceof CDOClassifierRef.Provider) + { + classifierRef = ((CDOClassifierRef.Provider)id).getClassifierRef(); + } + else + { + val = tokenizer.nextToken(); + classifierRef = new CDOClassifierRef(val); + } + + EClass eClass = (EClass)classifierRef.resolve(packageRegistry); + targetObjects.put(id, eClass); + } + } + + return targetObjects; + } + + public EReference[] getSourceReferences() + { + if (sourceReferences == null) + { + sourceReferences = parseSourceReferences(); + } + + return sourceReferences; + } + + private EReference[] parseSourceReferences() + { + List<EReference> result = new ArrayList<EReference>(); + CDOPackageRegistry packageRegistry = context.getView().getRepository().getPackageRegistry(); + + String params = (String)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_XREFS_SOURCE_REFERENCES); + if (params == null) + { + return new EReference[0]; + } + + StringTokenizer tokenizer = new StringTokenizer(params, "|"); + while (tokenizer.hasMoreTokens()) + { + String className = tokenizer.nextToken(); + CDOClassifierRef classifierRef = new CDOClassifierRef(className); + EClass eClass = (EClass)classifierRef.resolve(packageRegistry); + + String featureName = tokenizer.nextToken(); + EReference sourceReference = (EReference)eClass.getEStructuralFeature(featureName); + result.add(sourceReference); + } + + return result.toArray(new EReference[result.size()]); + } + + public Map<EClass, List<EReference>> getSourceCandidates() + { + if (sourceCandidates == null) + { + sourceCandidates = new HashMap<EClass, List<EReference>>(); + Collection<EClass> concreteTypes = getTargetObjects().values(); + EReference[] sourceReferences = getSourceReferences(); + + if (sourceReferences.length != 0) + { + InternalRepository repository = (InternalRepository)context.getView().getRepository(); + InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false); + for (EReference eReference : sourceReferences) + { + collectSourceCandidates(eReference, concreteTypes, sourceCandidates, packageRegistry); + } + } + else + { + collectSourceCandidates(context.getView(), concreteTypes, sourceCandidates); + } + } + + return sourceCandidates; + } + + public int getMaxResults() + { + return info.getMaxResults(); + } + + public boolean addXRef(CDOID targetID, CDOID sourceID, EReference sourceReference, int sourceIndex) + { + if (CDOIDUtil.isNull(targetID)) + { + return true; + } + + return context.addResult(new CDOIDReference(targetID, sourceID, sourceReference, sourceIndex)); + } + } + + /** + * @author Eike Stepper + */ + public static class Factory extends QueryHandlerFactory + { + public Factory() + { + super(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES); + } + + @Override + public XRefsQueryHandler create(String description) throws ProductCreationException + { + return new XRefsQueryHandler(); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java index 58ca1baff2..7527dfe454 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/CDOServerApplication.java @@ -1,137 +1,137 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.bundle;
-
-import org.eclipse.emf.cdo.internal.server.messages.Messages;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.spi.server.IAppExtension;
-import org.eclipse.emf.cdo.spi.server.RepositoryConfigurator;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiApplication;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class CDOServerApplication extends OSGiApplication
-{
- public static final String ID = OM.BUNDLE_ID + ".app"; //$NON-NLS-1$
-
- public static final String PROP_BROWSER_PORT = "org.eclipse.emf.cdo.server.browser.port"; //$NON-NLS-1$
-
- private IRepository[] repositories;
-
- private List<IAppExtension> extensions = new ArrayList<IAppExtension>();
-
- public CDOServerApplication()
- {
- super(ID);
- }
-
- @Override
- protected void doStart() throws Exception
- {
- super.doStart();
- IManagedContainer container = getContainer();
-
- OM.LOG.info(Messages.getString("CDOServerApplication.1")); //$NON-NLS-1$
- File configFile = OMPlatform.INSTANCE.getConfigFile("cdo-server.xml"); //$NON-NLS-1$
- if (configFile != null && configFile.exists())
- {
- RepositoryConfigurator repositoryConfigurator = new RepositoryConfigurator(container);
- repositories = repositoryConfigurator.configure(configFile);
- if (repositories == null || repositories.length == 0)
- {
- OM.LOG.warn(Messages.getString("CDOServerApplication.3") + " " + configFile.getAbsolutePath()); //$NON-NLS-1$
- }
-
- String port = OMPlatform.INSTANCE.getProperty(PROP_BROWSER_PORT);
- if (port != null)
- {
- container.getElement("org.eclipse.emf.cdo.server.browsers", "default", port); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- startExtensions(configFile);
- }
- else
- {
- OM.LOG.warn(Messages.getString("CDOServerApplication.5") + " " + configFile.getAbsolutePath()); //$NON-NLS-1$
- }
-
- OM.LOG.info(Messages.getString("CDOServerApplication.6")); //$NON-NLS-1$
- }
-
- @Override
- protected void doStop() throws Exception
- {
- OM.LOG.info(Messages.getString("CDOServerApplication.7")); //$NON-NLS-1$
- for (IAppExtension extension : extensions)
- {
- try
- {
- extension.stop();
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
-
- if (repositories != null)
- {
- for (IRepository repository : repositories)
- {
- LifecycleUtil.deactivate(repository);
- }
- }
-
- OM.LOG.info(Messages.getString("CDOServerApplication.8")); //$NON-NLS-1$
- super.doStop();
- }
-
- private void startExtensions(File configFile)
- {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, IAppExtension.EXT_POINT);
- for (final IConfigurationElement element : elements)
- {
- if ("appExtension".equals(element.getName())) //$NON-NLS-1$
- {
- try
- {
- IAppExtension extension = (IAppExtension)element.createExecutableExtension("class"); //$NON-NLS-1$
- extension.start(configFile);
- extensions.add(extension);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
- }
- }
-
- public static IManagedContainer getContainer()
- {
- return IPluginContainer.INSTANCE;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.bundle; + +import org.eclipse.emf.cdo.internal.server.messages.Messages; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.spi.server.IAppExtension; +import org.eclipse.emf.cdo.spi.server.RepositoryConfigurator; + +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiApplication; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + */ +public class CDOServerApplication extends OSGiApplication +{ + public static final String ID = OM.BUNDLE_ID + ".app"; //$NON-NLS-1$ + + public static final String PROP_BROWSER_PORT = "org.eclipse.emf.cdo.server.browser.port"; //$NON-NLS-1$ + + private IRepository[] repositories; + + private List<IAppExtension> extensions = new ArrayList<IAppExtension>(); + + public CDOServerApplication() + { + super(ID); + } + + @Override + protected void doStart() throws Exception + { + super.doStart(); + IManagedContainer container = getContainer(); + + OM.LOG.info(Messages.getString("CDOServerApplication.1")); //$NON-NLS-1$ + File configFile = OMPlatform.INSTANCE.getConfigFile("cdo-server.xml"); //$NON-NLS-1$ + if (configFile != null && configFile.exists()) + { + RepositoryConfigurator repositoryConfigurator = new RepositoryConfigurator(container); + repositories = repositoryConfigurator.configure(configFile); + if (repositories == null || repositories.length == 0) + { + OM.LOG.warn(Messages.getString("CDOServerApplication.3") + " " + configFile.getAbsolutePath()); //$NON-NLS-1$ + } + + String port = OMPlatform.INSTANCE.getProperty(PROP_BROWSER_PORT); + if (port != null) + { + container.getElement("org.eclipse.emf.cdo.server.browsers", "default", port); //$NON-NLS-1$ //$NON-NLS-2$ + } + + startExtensions(configFile); + } + else + { + OM.LOG.warn(Messages.getString("CDOServerApplication.5") + " " + configFile.getAbsolutePath()); //$NON-NLS-1$ + } + + OM.LOG.info(Messages.getString("CDOServerApplication.6")); //$NON-NLS-1$ + } + + @Override + protected void doStop() throws Exception + { + OM.LOG.info(Messages.getString("CDOServerApplication.7")); //$NON-NLS-1$ + for (IAppExtension extension : extensions) + { + try + { + extension.stop(); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + + if (repositories != null) + { + for (IRepository repository : repositories) + { + LifecycleUtil.deactivate(repository); + } + } + + OM.LOG.info(Messages.getString("CDOServerApplication.8")); //$NON-NLS-1$ + super.doStop(); + } + + private void startExtensions(File configFile) + { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, IAppExtension.EXT_POINT); + for (final IConfigurationElement element : elements) + { + if ("appExtension".equals(element.getName())) //$NON-NLS-1$ + { + try + { + IAppExtension extension = (IAppExtension)element.createExecutableExtension("class"); //$NON-NLS-1$ + extension.start(configFile); + extensions.add(extension); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + } + } + + public static IManagedContainer getContainer() + { + return IPluginContainer.INSTANCE; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java index c0d24a1b39..442b01aec0 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/bundle/OM.java @@ -1,66 +1,66 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.bundle;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_REPOSITORY = DEBUG.tracer("repository"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_SESSION = DEBUG.tracer("session"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_TRANSACTION = DEBUG.tracer("transaction"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_REVISION = DEBUG.tracer("revision"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_RESOURCE = DEBUG.tracer("resource"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_STORE = DEBUG.tracer("store"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_TYPES = DEBUG.tracer("types"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
-
- @Override
- protected void doStart() throws Exception
- {
- new CDOCommandProvider(bundleContext);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.bundle; + +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_REPOSITORY = DEBUG.tracer("repository"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_SESSION = DEBUG.tracer("session"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_TRANSACTION = DEBUG.tracer("transaction"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_REVISION = DEBUG.tracer("revision"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_RESOURCE = DEBUG.tracer("resource"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_STORE = DEBUG.tracer("store"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_TYPES = DEBUG.tracer("types"); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + /** + * @author Eike Stepper + */ + public static final class Activator extends OSGiActivator + { + public Activator() + { + super(BUNDLE); + } + + @Override + protected void doStart() throws Exception + { + new CDOCommandProvider(bundleContext); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSession.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSession.java index 4dd107da81..87a9254d77 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSession.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSession.java @@ -1,100 +1,100 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Andre Dietisheim - bug 256649
- */
-package org.eclipse.emf.cdo.internal.server.embedded;
-
-import org.eclipse.emf.cdo.common.lob.CDOLobStore;
-import org.eclipse.emf.cdo.common.revision.CDORevisionCache;
-import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
-import org.eclipse.emf.cdo.internal.server.embedded.EmbeddedClientSessionConfiguration.RepositoryInfo;
-import org.eclipse.emf.cdo.server.embedded.CDOSession;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-import org.eclipse.emf.internal.cdo.session.CDOSessionImpl;
-
-/**
- * @author Eike Stepper
- * @deprecated Not yet supported.
- */
-@Deprecated
-public class EmbeddedClientSession extends CDOSessionImpl implements CDOSession
-{
- private InternalRepository repository;
-
- public EmbeddedClientSession()
- {
- }
-
- public InternalRepository getRepository()
- {
- return repository;
- }
-
- @Override
- public InternalCDOPackageRegistry getPackageRegistry()
- {
- return getRepository().getPackageRegistry();
- }
-
- @Override
- public InternalCDOBranchManager getBranchManager()
- {
- return getRepository().getBranchManager();
- }
-
- @Override
- public InternalCDOCommitInfoManager getCommitInfoManager()
- {
- return getRepository().getCommitInfoManager();
- }
-
- @Override
- public CDOLobStore getLobStore()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
-
- EmbeddedClientSessionProtocol protocol = new EmbeddedClientSessionProtocol(this);
- setSessionProtocol(protocol);
- protocol.activate();
- protocol.openSession(options().isPassiveUpdateEnabled());
-
- setLastUpdateTime(repository.getLastCommitTimeStamp());
- setRepositoryInfo(new RepositoryInfo(this));
-
- InternalCDORevisionManager revisionManager = (InternalCDORevisionManager)CDORevisionUtil.createRevisionManager();
- setRevisionManager(revisionManager);
- revisionManager.setSupportingAudits(getRepositoryInfo().isSupportingAudits());
- revisionManager.setSupportingBranches(getRepositoryInfo().isSupportingBranches());
- revisionManager.setCache(CDORevisionCache.NOOP);
- revisionManager.setRevisionLoader(getSessionProtocol());
- revisionManager.setRevisionLocker(this);
- revisionManager.activate();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- super.doDeactivate();
-
- getRevisionManager().deactivate();
- setRevisionManager(null);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Andre Dietisheim - bug 256649 + */ +package org.eclipse.emf.cdo.internal.server.embedded; + +import org.eclipse.emf.cdo.common.lob.CDOLobStore; +import org.eclipse.emf.cdo.common.revision.CDORevisionCache; +import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; +import org.eclipse.emf.cdo.internal.server.embedded.EmbeddedClientSessionConfiguration.RepositoryInfo; +import org.eclipse.emf.cdo.server.embedded.CDOSession; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; +import org.eclipse.emf.cdo.spi.server.InternalRepository; + +import org.eclipse.emf.internal.cdo.session.CDOSessionImpl; + +/** + * @author Eike Stepper + * @deprecated Not yet supported. + */ +@Deprecated +public class EmbeddedClientSession extends CDOSessionImpl implements CDOSession +{ + private InternalRepository repository; + + public EmbeddedClientSession() + { + } + + public InternalRepository getRepository() + { + return repository; + } + + @Override + public InternalCDOPackageRegistry getPackageRegistry() + { + return getRepository().getPackageRegistry(); + } + + @Override + public InternalCDOBranchManager getBranchManager() + { + return getRepository().getBranchManager(); + } + + @Override + public InternalCDOCommitInfoManager getCommitInfoManager() + { + return getRepository().getCommitInfoManager(); + } + + @Override + public CDOLobStore getLobStore() + { + throw new UnsupportedOperationException(); + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + + EmbeddedClientSessionProtocol protocol = new EmbeddedClientSessionProtocol(this); + setSessionProtocol(protocol); + protocol.activate(); + protocol.openSession(options().isPassiveUpdateEnabled()); + + setLastUpdateTime(repository.getLastCommitTimeStamp()); + setRepositoryInfo(new RepositoryInfo(this)); + + InternalCDORevisionManager revisionManager = (InternalCDORevisionManager)CDORevisionUtil.createRevisionManager(); + setRevisionManager(revisionManager); + revisionManager.setSupportingAudits(getRepositoryInfo().isSupportingAudits()); + revisionManager.setSupportingBranches(getRepositoryInfo().isSupportingBranches()); + revisionManager.setCache(CDORevisionCache.NOOP); + revisionManager.setRevisionLoader(getSessionProtocol()); + revisionManager.setRevisionLocker(this); + revisionManager.activate(); + } + + @Override + protected void doDeactivate() throws Exception + { + super.doDeactivate(); + + getRevisionManager().deactivate(); + setRevisionManager(null); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionConfiguration.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionConfiguration.java index f0165ebda2..a2b6bc354a 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionConfiguration.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedClientSessionConfiguration.java @@ -1,155 +1,155 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.embedded;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-import org.eclipse.emf.internal.cdo.session.CDOSessionConfigurationImpl;
-
-import org.eclipse.net4j.util.CheckUtil;
-
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @deprecated Not yet supported.
- */
-@Deprecated
-public class EmbeddedClientSessionConfiguration extends CDOSessionConfigurationImpl implements CDOSessionConfiguration
-{
- private InternalRepository repository;
-
- public EmbeddedClientSessionConfiguration()
- {
- throw new UnsupportedOperationException("Embedded sessions are not yet supported");
- }
-
- public InternalRepository getRepository()
- {
- return repository;
- }
-
- public void setRepository(IRepository repository)
- {
- checkNotOpen();
- this.repository = (InternalRepository)repository;
- }
-
- @Override
- public org.eclipse.emf.cdo.server.embedded.CDOSession openSession()
- {
- return (org.eclipse.emf.cdo.server.embedded.CDOSession)super.openSession();
- }
-
- public InternalCDOSession createSession()
- {
- if (isActivateOnOpen())
- {
- CheckUtil.checkState(repository, "Specify a repository"); //$NON-NLS-1$
- }
-
- return new EmbeddedClientSession();
- }
-
- /**
- * @author Eike Stepper
- */
- protected static class RepositoryInfo implements org.eclipse.emf.cdo.session.CDORepositoryInfo
- {
- private EmbeddedClientSession session;
-
- public RepositoryInfo(EmbeddedClientSession session)
- {
- this.session = session;
- }
-
- public String getName()
- {
- return session.getRepository().getName();
- }
-
- public String getUUID()
- {
- return session.getRepository().getUUID();
- }
-
- public Type getType()
- {
- return session.getRepository().getType();
- }
-
- public State getState()
- {
- return session.getRepository().getState();
- }
-
- public long getCreationTime()
- {
- return session.getRepository().getCreationTime();
- }
-
- public long getTimeStamp()
- {
- return getTimeStamp(false);
- }
-
- public long getTimeStamp(boolean forceRefresh)
- {
- return System.currentTimeMillis();
- }
-
- public CDOID getRootResourceID()
- {
- return session.getRepository().getRootResourceID();
- }
-
- public boolean isSupportingAudits()
- {
- return session.getRepository().isSupportingAudits();
- }
-
- public boolean isSupportingBranches()
- {
- return session.getRepository().isSupportingBranches();
- }
-
- public boolean isSupportingEcore()
- {
- return session.getRepository().isSupportingEcore();
- }
-
- public boolean isEnsuringReferentialIntegrity()
- {
- return session.getRepository().isEnsuringReferentialIntegrity();
- }
-
- public IDGenerationLocation getIDGenerationLocation()
- {
- return session.getRepository().getIDGenerationLocation();
- }
-
- public String getStoreType()
- {
- return session.getRepository().getStoreType();
- }
-
- public Set<ObjectType> getObjectIDTypes()
- {
- return session.getRepository().getObjectIDTypes();
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.embedded; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOID.ObjectType; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration; +import org.eclipse.emf.cdo.spi.server.InternalRepository; + +import org.eclipse.emf.internal.cdo.session.CDOSessionConfigurationImpl; + +import org.eclipse.net4j.util.CheckUtil; + +import org.eclipse.emf.spi.cdo.InternalCDOSession; + +import java.util.Set; + +/** + * @author Eike Stepper + * @deprecated Not yet supported. + */ +@Deprecated +public class EmbeddedClientSessionConfiguration extends CDOSessionConfigurationImpl implements CDOSessionConfiguration +{ + private InternalRepository repository; + + public EmbeddedClientSessionConfiguration() + { + throw new UnsupportedOperationException("Embedded sessions are not yet supported"); + } + + public InternalRepository getRepository() + { + return repository; + } + + public void setRepository(IRepository repository) + { + checkNotOpen(); + this.repository = (InternalRepository)repository; + } + + @Override + public org.eclipse.emf.cdo.server.embedded.CDOSession openSession() + { + return (org.eclipse.emf.cdo.server.embedded.CDOSession)super.openSession(); + } + + public InternalCDOSession createSession() + { + if (isActivateOnOpen()) + { + CheckUtil.checkState(repository, "Specify a repository"); //$NON-NLS-1$ + } + + return new EmbeddedClientSession(); + } + + /** + * @author Eike Stepper + */ + protected static class RepositoryInfo implements org.eclipse.emf.cdo.session.CDORepositoryInfo + { + private EmbeddedClientSession session; + + public RepositoryInfo(EmbeddedClientSession session) + { + this.session = session; + } + + public String getName() + { + return session.getRepository().getName(); + } + + public String getUUID() + { + return session.getRepository().getUUID(); + } + + public Type getType() + { + return session.getRepository().getType(); + } + + public State getState() + { + return session.getRepository().getState(); + } + + public long getCreationTime() + { + return session.getRepository().getCreationTime(); + } + + public long getTimeStamp() + { + return getTimeStamp(false); + } + + public long getTimeStamp(boolean forceRefresh) + { + return System.currentTimeMillis(); + } + + public CDOID getRootResourceID() + { + return session.getRepository().getRootResourceID(); + } + + public boolean isSupportingAudits() + { + return session.getRepository().isSupportingAudits(); + } + + public boolean isSupportingBranches() + { + return session.getRepository().isSupportingBranches(); + } + + public boolean isSupportingEcore() + { + return session.getRepository().isSupportingEcore(); + } + + public boolean isEnsuringReferentialIntegrity() + { + return session.getRepository().isEnsuringReferentialIntegrity(); + } + + public IDGenerationLocation getIDGenerationLocation() + { + return session.getRepository().getIDGenerationLocation(); + } + + public String getStoreType() + { + return session.getRepository().getStoreType(); + } + + public Set<ObjectType> getObjectIDTypes() + { + return session.getRepository().getObjectIDTypes(); + } + } +} 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 e1e741d78a..364beb0efe 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 @@ -1,606 +1,606 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.embedded;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
-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.commit.CDOChangeSetData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDProvider;
-import org.eclipse.emf.cdo.common.lob.CDOLob;
-import org.eclipse.emf.cdo.common.lob.CDOLobInfo;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.common.util.CDOQueryQueue;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSession;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult;
-import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationContext;
-import org.eclipse.emf.cdo.spi.common.commit.CDORevisionAvailabilityInfo;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalQueryManager;
-import org.eclipse.emf.cdo.spi.server.InternalQueryResult;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-import org.eclipse.emf.cdo.spi.server.InternalView;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.spi.cdo.AbstractQueryIterator;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @deprecated Not yet supported.
- */
-@Deprecated
-public class EmbeddedClientSessionProtocol extends Lifecycle implements CDOSessionProtocol
-{
- private EmbeddedClientSession session;
-
- // A separate session protocol instance is required because the getSession() methods are ambiguous!
- private EmbeddedServerSessionProtocol serverSessionProtocol;
-
- private InternalRepository repository;
-
- public EmbeddedClientSessionProtocol(EmbeddedClientSession session)
- {
- this.session = session;
- }
-
- public EmbeddedClientSession getSession()
- {
- return session;
- }
-
- public EmbeddedServerSessionProtocol getServerSessionProtocol()
- {
- return serverSessionProtocol;
- }
-
- public InternalSession openSession(boolean passiveUpdateEnabled)
- {
- repository = session.getRepository();
- activate();
- return serverSessionProtocol.openSession(repository, passiveUpdateEnabled);
- }
-
- public EPackage[] loadPackages(CDOPackageUnit packageUnit)
- {
- throw new UnsupportedOperationException();
- }
-
- public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
- {
- throw new UnsupportedOperationException();
- }
-
- public BranchInfo loadBranch(int branchID)
- {
- throw new UnsupportedOperationException();
- }
-
- public SubBranchInfo[] loadSubBranches(int branchID)
- {
- throw new UnsupportedOperationException();
- }
-
- public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler)
- {
- throw new UnsupportedOperationException();
- }
-
- public RepositoryTimeResult getRepositoryTime()
- {
- RepositoryTimeResult result = new RepositoryTimeResult();
- long timeStamp = System.currentTimeMillis();
- result.setRequested(timeStamp);
- result.setIndicated(timeStamp);
- result.setResponded(timeStamp);
- result.setConfirmed(timeStamp);
- return result;
- }
-
- public CDOLockState[] getLockStates(int viewID, Collection<CDOID> ids)
- {
- throw new UnsupportedOperationException();
- }
-
- public void enableLockNotifications(int viewID, boolean enable)
- {
- throw new UnsupportedOperationException();
- }
-
- public void disablePassiveUpdate()
- {
- // serverSessionProtocol.getSession().setPassiveUpdateEnabled(passiveUpdateEnabled);
- // TODO: implement EmbeddedClientSessionProtocol.setPassiveUpdate(idAndVersions, initialChunkSize,
- // passiveUpdateEnabled)
- throw new UnsupportedOperationException();
- }
-
- public void setPassiveUpdateMode(PassiveUpdateMode mode)
- {
- // TODO: implement EmbeddedClientSessionProtocol.setPassiveUpdateMode(mode)
- throw new UnsupportedOperationException();
- }
-
- public void setLockNotificationMode(LockNotificationMode mode)
- {
- throw new UnsupportedOperationException();
- }
-
- public Object loadChunk(InternalCDORevision revision, EStructuralFeature feature, int accessIndex, int fetchIndex,
- int fromIndex, int toIndex)
- {
- throw new UnsupportedOperationException();
- }
-
- public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOCommitData loadCommitData(long timeStamp)
- {
- throw new UnsupportedOperationException();
- }
-
- public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk)
- {
- try
- {
- InternalSession session = serverSessionProtocol.getSession();
- StoreThreadLocal.setSession(session);
- return repository.getRevisionManager().getRevisionByVersion(id, branchVersion, referenceChunk, true);
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- public List<InternalCDORevision> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint,
- int referenceChunk, int prefetchDepth)
- {
- try
- {
- InternalSession session = serverSessionProtocol.getSession();
- StoreThreadLocal.setSession(session);
-
- List<CDOID> ids = new ArrayList<CDOID>(infos.size());
- for (RevisionInfo info : infos)
- {
- ids.add(info.getID());
- }
-
- // @SuppressWarnings("unchecked")
- // List<InternalCDORevision> revisions = (List<InternalCDORevision>)(List<?>)repository.getRevisionManager()
- // .getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, true);
-
- // TODO: implement EmbeddedClientSessionProtocol.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth)
- throw new UnsupportedOperationException();
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- public RefreshSessionResult refresh(long lastUpdateTime,
- Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions, int initialChunkSize,
- boolean enablePassiveUpdates)
- {
- throw new UnsupportedOperationException();
- }
-
- public void openView(int viewID, boolean readOnly, CDOBranchPoint branchPoint)
- {
- InternalSession session = serverSessionProtocol.getSession();
- if (readOnly)
- {
- session.openView(viewID, branchPoint);
- }
- else
- {
- session.openTransaction(viewID, branchPoint);
- }
- }
-
- public CDOBranchPoint openView(int viewID, boolean readOnly, String durableLockingID)
- {
- throw new UnsupportedOperationException();
- }
-
- public void switchTarget(int viewID, CDOBranchPoint branchPoint, List<InternalCDOObject> invalidObjects,
- List<CDORevisionKey> allChangedObjects, List<CDOIDAndVersion> allDetachedObjects, OMMonitor monitor)
- {
- // TODO: implement EmbeddedClientSessionProtocol.changeView(viewID, branchPoint, invalidObjects, allChangedObjects,
- // allDetachedObjects, monitor)
- throw new UnsupportedOperationException();
-
- // try
- // {
- // monitor.begin();
- // Async async = monitor.forkAsync();
- //
- // try
- // {
- // InternalView view = serverSessionProtocol.getSession().getView(viewID);
- // if (view != null)
- // {
- // List<CDOID> ids = new ArrayList<CDOID>(invalidObjects.size());
- // for (InternalCDOObject object : invalidObjects)
- // {
- // ids.add(object.cdoID());
- // }
- //
- // view.changeTarget(branchPoint, ids, allChangedObjects, allDetachedObjects);
- // }
- // }
- // finally
- // {
- // async.stop();
- // }
- // }
- // finally
- // {
- // monitor.done();
- // }
- }
-
- public void closeView(int viewID)
- {
- InternalView view = serverSessionProtocol.getSession().getView(viewID);
- if (view != null)
- {
- view.close();
- }
- }
-
- public void changeSubscription(int viewID, List<CDOID> ids, boolean subscribeMode, boolean clear)
- {
- throw new UnsupportedOperationException();
- }
-
- public void query(CDOView view, AbstractQueryIterator<?> query)
- {
- InternalView serverView = serverSessionProtocol.getSession().getView(view.getViewID());
- InternalQueryManager queryManager = repository.getQueryManager();
- InternalQueryResult result = queryManager.execute(serverView, query.getQueryInfo());
-
- query.setQueryID(result.getQueryID());
- CDOQueryQueue<Object> resultQueue = query.getQueue();
-
- try
- {
- while (result.hasNext())
- {
- Object object = result.next();
- resultQueue.add(object);
- }
- }
- catch (RuntimeException ex)
- {
- resultQueue.setException(ex);
- }
- catch (Throwable throwable)
- {
- resultQueue.setException(new RuntimeException(throwable.getMessage(), throwable));
- }
- finally
- {
- resultQueue.close();
- }
- }
-
- public boolean cancelQuery(int queryID)
- {
- repository.getQueryManager().cancel(queryID);
- return true;
- }
-
- public boolean isObjectLocked(CDOView view, CDOObject object, LockType lockType, boolean byOthers)
- {
- throw new UnsupportedOperationException();
- }
-
- @Deprecated
- public LockObjectsResult lockObjects(List<InternalCDORevision> viewedRevisions, int viewID, CDOBranch viewedBranch,
- LockType lockType, long timeout) throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @since 4.1
- */
- public LockObjectsResult lockObjects2(List<CDORevisionKey> keys, int viewID, CDOBranch viewedBranch, LockType type,
- boolean recursive, long timeout) throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- @Deprecated
- public void unlockObjects(CDOView view, Collection<CDOID> ids, LockType type)
- {
- throw new UnsupportedOperationException();
- }
-
- public UnlockObjectsResult unlockObjects2(CDOView view, Collection<CDOID> ids, LockType type, boolean recursive)
- {
- throw new UnsupportedOperationException();
- }
-
- public LockObjectsResult delegateLockObjects(String lockAreaID, List<CDORevisionKey> keys, CDOBranch viewedBranch,
- LockType type, boolean recursive, long timeout) throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- public UnlockObjectsResult delegateUnlockObjects(String lockAreaID, Collection<CDOID> ids, LockType type,
- boolean recursive)
- {
- throw new UnsupportedOperationException();
- }
-
- public String changeLockArea(CDOView view, boolean create)
- {
- throw new UnsupportedOperationException();
- }
-
- public List<byte[]> queryLobs(Set<byte[]> ids)
- {
- // TODO: implement EmbeddedClientSessionProtocol.queryLobs(ids)
- throw new UnsupportedOperationException();
- }
-
- public void loadLob(CDOLobInfo info, Object outputStreamOrWriter)
- {
- // TODO: implement EmbeddedClientSessionProtocol.loadLob(info, out)
- throw new UnsupportedOperationException();
- }
-
- public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime,
- CDORevisionHandler handler)
- {
- // TODO: implement EmbeddedClientSessionProtocol.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime,
- // handler)
- throw new UnsupportedOperationException();
- }
-
- @Deprecated
- public CommitTransactionResult commitTransaction(int transactionID, String comment, boolean releaseLocks,
- CDOIDProvider idProvider, CDOCommitData commitData, Collection<CDOLob<?>> lobs, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitTransaction(InternalCDOCommitContext context, OMMonitor monitor)
- {
- monitor.begin(2);
- boolean success = false;
- InternalCommitContext serverCommitContext = null;
- CommitTransactionResult result = null;
-
- try
- {
- InternalCDOTransaction transaction = context.getTransaction();
- CDOCommitData commitData = context.getCommitData();
-
- int transactionID = transaction.getViewID();
- InternalTransaction serverTransaction = (InternalTransaction)serverSessionProtocol.getSession().getView(
- transactionID);
- serverCommitContext = serverTransaction.createCommitContext();
- serverCommitContext.preWrite();
- serverCommitContext.setAutoReleaseLocksEnabled(transaction.options().isAutoReleaseLocksEnabled());
-
- List<CDOPackageUnit> npu = commitData.getNewPackageUnits();
- serverCommitContext.setNewPackageUnits(npu.toArray(new InternalCDOPackageUnit[npu.size()]));
-
- List<CDOIDAndVersion> no = commitData.getNewObjects();
- InternalCDORevision[] array = new InternalCDORevision[no.size()];
- int index = 0;
- for (CDOIDAndVersion object : no)
- {
- InternalCDORevision revision = (InternalCDORevision)object;
- // revision.convertEObjects(clientTransaction);
- array[index++] = revision;
- }
-
- serverCommitContext.setNewObjects(array);
-
- List<CDORevisionKey> rd = commitData.getChangedObjects();
- serverCommitContext.setDirtyObjectDeltas(rd.toArray(new InternalCDORevisionDelta[rd.size()]));
-
- List<CDOIDAndVersion> detachedObjects = commitData.getDetachedObjects();
- serverCommitContext.setDetachedObjects(detachedObjects.toArray(new CDOID[detachedObjects.size()]));
-
- serverCommitContext.write(monitor.fork());
- success = serverCommitContext.getRollbackMessage() == null;
- if (success)
- {
- serverCommitContext.commit(monitor.fork());
- }
- else
- {
- monitor.worked();
- }
-
- // result = new CommitTransactionResult(commitData, serverCommitContext.getBranchPoint().getTimeStamp());
- // for (Entry<CDOID, CDOID> entry : serverCommitContext.getIDMappings().entrySet())
- // {
- // result.addIDMapping(entry.getKey(), entry.getValue());
- // }
- }
- finally
- {
- if (serverCommitContext != null)
- {
- serverCommitContext.postCommit(success);
- }
-
- monitor.done();
- }
-
- return result;
- }
-
- @Deprecated
- public CommitTransactionResult commitDelegation(CDOBranch branch, String userID, String comment,
- CDOCommitData commitData, Map<CDOID, EClass> detachedObjectTypes, Collection<CDOLob<?>> lobs, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitDelegation(InternalCDOCommitContext context, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitXATransactionCancel(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitXATransactionPhase1(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitXATransactionPhase2(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitXATransactionPhase3(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public List<CDORemoteSession> getRemoteSessions(InternalCDORemoteSessionManager manager, boolean subscribe)
- {
- throw new UnsupportedOperationException();
- }
-
- public Set<Integer> sendRemoteMessage(CDORemoteSessionMessage message, List<CDORemoteSession> recipients)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean unsubscribeRemoteSessions()
- {
- throw new UnsupportedOperationException();
- }
-
- public void replicateRepository(CDOReplicationContext context, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public void replicateRepositoryRaw(CDORawReplicationContext context, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOChangeSetData[] loadChangeSets(CDOBranchPointRange... ranges)
- {
- throw new UnsupportedOperationException();
- }
-
- public Set<CDOID> loadMergeData(CDORevisionAvailabilityInfo targetInfo, CDORevisionAvailabilityInfo sourceInfo,
- CDORevisionAvailabilityInfo targetBaseInfo, CDORevisionAvailabilityInfo sourceBaseInfo)
- {
- throw new UnsupportedOperationException();
- }
-
- public CDOAuthenticationResult handleAuthenticationChallenge(byte[] randomToken) throws Exception
- {
- CDOAuthenticator authenticator = getSession().getAuthenticator();
- if (authenticator == null)
- {
- throw new IllegalStateException("No authenticator configured"); //$NON-NLS-1$
- }
-
- CDOAuthenticationResult result = authenticator.authenticate(randomToken);
- if (result == null)
- {
- throw new SecurityException("Not authenticated"); //$NON-NLS-1$
- }
-
- String userID = result.getUserID();
- if (userID == null)
- {
- throw new SecurityException("No user ID"); //$NON-NLS-1$
- }
-
- byte[] cryptedToken = result.getCryptedToken();
- if (cryptedToken == null)
- {
- throw new SecurityException("No crypted token"); //$NON-NLS-1$
- }
-
- return result;
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- serverSessionProtocol = new EmbeddedServerSessionProtocol(this);
- serverSessionProtocol.activate();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- serverSessionProtocol.deactivate();
- serverSessionProtocol = null;
- super.doDeactivate();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.embedded; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchHandler; +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.commit.CDOChangeSetData; +import org.eclipse.emf.cdo.common.commit.CDOCommitData; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDProvider; +import org.eclipse.emf.cdo.common.lob.CDOLob; +import org.eclipse.emf.cdo.common.lob.CDOLobInfo; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.common.util.CDOQueryQueue; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.session.remote.CDORemoteSession; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; +import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult; +import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext; +import org.eclipse.emf.cdo.spi.common.CDOReplicationContext; +import org.eclipse.emf.cdo.spi.common.commit.CDORevisionAvailabilityInfo; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; +import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo; +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; +import org.eclipse.emf.cdo.spi.server.InternalQueryManager; +import org.eclipse.emf.cdo.spi.server.InternalQueryResult; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalSession; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; +import org.eclipse.emf.cdo.spi.server.InternalView; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.collection.Pair; +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.spi.cdo.AbstractQueryIterator; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Eike Stepper + * @deprecated Not yet supported. + */ +@Deprecated +public class EmbeddedClientSessionProtocol extends Lifecycle implements CDOSessionProtocol +{ + private EmbeddedClientSession session; + + // A separate session protocol instance is required because the getSession() methods are ambiguous! + private EmbeddedServerSessionProtocol serverSessionProtocol; + + private InternalRepository repository; + + public EmbeddedClientSessionProtocol(EmbeddedClientSession session) + { + this.session = session; + } + + public EmbeddedClientSession getSession() + { + return session; + } + + public EmbeddedServerSessionProtocol getServerSessionProtocol() + { + return serverSessionProtocol; + } + + public InternalSession openSession(boolean passiveUpdateEnabled) + { + repository = session.getRepository(); + activate(); + return serverSessionProtocol.openSession(repository, passiveUpdateEnabled); + } + + public EPackage[] loadPackages(CDOPackageUnit packageUnit) + { + throw new UnsupportedOperationException(); + } + + public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo) + { + throw new UnsupportedOperationException(); + } + + public BranchInfo loadBranch(int branchID) + { + throw new UnsupportedOperationException(); + } + + public SubBranchInfo[] loadSubBranches(int branchID) + { + throw new UnsupportedOperationException(); + } + + public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler) + { + throw new UnsupportedOperationException(); + } + + public RepositoryTimeResult getRepositoryTime() + { + RepositoryTimeResult result = new RepositoryTimeResult(); + long timeStamp = System.currentTimeMillis(); + result.setRequested(timeStamp); + result.setIndicated(timeStamp); + result.setResponded(timeStamp); + result.setConfirmed(timeStamp); + return result; + } + + public CDOLockState[] getLockStates(int viewID, Collection<CDOID> ids) + { + throw new UnsupportedOperationException(); + } + + public void enableLockNotifications(int viewID, boolean enable) + { + throw new UnsupportedOperationException(); + } + + public void disablePassiveUpdate() + { + // serverSessionProtocol.getSession().setPassiveUpdateEnabled(passiveUpdateEnabled); + // TODO: implement EmbeddedClientSessionProtocol.setPassiveUpdate(idAndVersions, initialChunkSize, + // passiveUpdateEnabled) + throw new UnsupportedOperationException(); + } + + public void setPassiveUpdateMode(PassiveUpdateMode mode) + { + // TODO: implement EmbeddedClientSessionProtocol.setPassiveUpdateMode(mode) + throw new UnsupportedOperationException(); + } + + public void setLockNotificationMode(LockNotificationMode mode) + { + throw new UnsupportedOperationException(); + } + + public Object loadChunk(InternalCDORevision revision, EStructuralFeature feature, int accessIndex, int fetchIndex, + int fromIndex, int toIndex) + { + throw new UnsupportedOperationException(); + } + + public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler) + { + throw new UnsupportedOperationException(); + } + + public CDOCommitData loadCommitData(long timeStamp) + { + throw new UnsupportedOperationException(); + } + + public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk) + { + try + { + InternalSession session = serverSessionProtocol.getSession(); + StoreThreadLocal.setSession(session); + return repository.getRevisionManager().getRevisionByVersion(id, branchVersion, referenceChunk, true); + } + finally + { + StoreThreadLocal.release(); + } + } + + public List<InternalCDORevision> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint, + int referenceChunk, int prefetchDepth) + { + try + { + InternalSession session = serverSessionProtocol.getSession(); + StoreThreadLocal.setSession(session); + + List<CDOID> ids = new ArrayList<CDOID>(infos.size()); + for (RevisionInfo info : infos) + { + ids.add(info.getID()); + } + + // @SuppressWarnings("unchecked") + // List<InternalCDORevision> revisions = (List<InternalCDORevision>)(List<?>)repository.getRevisionManager() + // .getRevisions(ids, branchPoint, referenceChunk, prefetchDepth, true); + + // TODO: implement EmbeddedClientSessionProtocol.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth) + throw new UnsupportedOperationException(); + } + finally + { + StoreThreadLocal.release(); + } + } + + public RefreshSessionResult refresh(long lastUpdateTime, + Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions, int initialChunkSize, + boolean enablePassiveUpdates) + { + throw new UnsupportedOperationException(); + } + + public void openView(int viewID, boolean readOnly, CDOBranchPoint branchPoint) + { + InternalSession session = serverSessionProtocol.getSession(); + if (readOnly) + { + session.openView(viewID, branchPoint); + } + else + { + session.openTransaction(viewID, branchPoint); + } + } + + public CDOBranchPoint openView(int viewID, boolean readOnly, String durableLockingID) + { + throw new UnsupportedOperationException(); + } + + public void switchTarget(int viewID, CDOBranchPoint branchPoint, List<InternalCDOObject> invalidObjects, + List<CDORevisionKey> allChangedObjects, List<CDOIDAndVersion> allDetachedObjects, OMMonitor monitor) + { + // TODO: implement EmbeddedClientSessionProtocol.changeView(viewID, branchPoint, invalidObjects, allChangedObjects, + // allDetachedObjects, monitor) + throw new UnsupportedOperationException(); + + // try + // { + // monitor.begin(); + // Async async = monitor.forkAsync(); + // + // try + // { + // InternalView view = serverSessionProtocol.getSession().getView(viewID); + // if (view != null) + // { + // List<CDOID> ids = new ArrayList<CDOID>(invalidObjects.size()); + // for (InternalCDOObject object : invalidObjects) + // { + // ids.add(object.cdoID()); + // } + // + // view.changeTarget(branchPoint, ids, allChangedObjects, allDetachedObjects); + // } + // } + // finally + // { + // async.stop(); + // } + // } + // finally + // { + // monitor.done(); + // } + } + + public void closeView(int viewID) + { + InternalView view = serverSessionProtocol.getSession().getView(viewID); + if (view != null) + { + view.close(); + } + } + + public void changeSubscription(int viewID, List<CDOID> ids, boolean subscribeMode, boolean clear) + { + throw new UnsupportedOperationException(); + } + + public void query(CDOView view, AbstractQueryIterator<?> query) + { + InternalView serverView = serverSessionProtocol.getSession().getView(view.getViewID()); + InternalQueryManager queryManager = repository.getQueryManager(); + InternalQueryResult result = queryManager.execute(serverView, query.getQueryInfo()); + + query.setQueryID(result.getQueryID()); + CDOQueryQueue<Object> resultQueue = query.getQueue(); + + try + { + while (result.hasNext()) + { + Object object = result.next(); + resultQueue.add(object); + } + } + catch (RuntimeException ex) + { + resultQueue.setException(ex); + } + catch (Throwable throwable) + { + resultQueue.setException(new RuntimeException(throwable.getMessage(), throwable)); + } + finally + { + resultQueue.close(); + } + } + + public boolean cancelQuery(int queryID) + { + repository.getQueryManager().cancel(queryID); + return true; + } + + public boolean isObjectLocked(CDOView view, CDOObject object, LockType lockType, boolean byOthers) + { + throw new UnsupportedOperationException(); + } + + @Deprecated + public LockObjectsResult lockObjects(List<InternalCDORevision> viewedRevisions, int viewID, CDOBranch viewedBranch, + LockType lockType, long timeout) throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.1 + */ + public LockObjectsResult lockObjects2(List<CDORevisionKey> keys, int viewID, CDOBranch viewedBranch, LockType type, + boolean recursive, long timeout) throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + @Deprecated + public void unlockObjects(CDOView view, Collection<CDOID> ids, LockType type) + { + throw new UnsupportedOperationException(); + } + + public UnlockObjectsResult unlockObjects2(CDOView view, Collection<CDOID> ids, LockType type, boolean recursive) + { + throw new UnsupportedOperationException(); + } + + public LockObjectsResult delegateLockObjects(String lockAreaID, List<CDORevisionKey> keys, CDOBranch viewedBranch, + LockType type, boolean recursive, long timeout) throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + public UnlockObjectsResult delegateUnlockObjects(String lockAreaID, Collection<CDOID> ids, LockType type, + boolean recursive) + { + throw new UnsupportedOperationException(); + } + + public String changeLockArea(CDOView view, boolean create) + { + throw new UnsupportedOperationException(); + } + + public List<byte[]> queryLobs(Set<byte[]> ids) + { + // TODO: implement EmbeddedClientSessionProtocol.queryLobs(ids) + throw new UnsupportedOperationException(); + } + + public void loadLob(CDOLobInfo info, Object outputStreamOrWriter) + { + // TODO: implement EmbeddedClientSessionProtocol.loadLob(info, out) + throw new UnsupportedOperationException(); + } + + public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, + CDORevisionHandler handler) + { + // TODO: implement EmbeddedClientSessionProtocol.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, + // handler) + throw new UnsupportedOperationException(); + } + + @Deprecated + public CommitTransactionResult commitTransaction(int transactionID, String comment, boolean releaseLocks, + CDOIDProvider idProvider, CDOCommitData commitData, Collection<CDOLob<?>> lobs, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitTransaction(InternalCDOCommitContext context, OMMonitor monitor) + { + monitor.begin(2); + boolean success = false; + InternalCommitContext serverCommitContext = null; + CommitTransactionResult result = null; + + try + { + InternalCDOTransaction transaction = context.getTransaction(); + CDOCommitData commitData = context.getCommitData(); + + int transactionID = transaction.getViewID(); + InternalTransaction serverTransaction = (InternalTransaction)serverSessionProtocol.getSession().getView( + transactionID); + serverCommitContext = serverTransaction.createCommitContext(); + serverCommitContext.preWrite(); + serverCommitContext.setAutoReleaseLocksEnabled(transaction.options().isAutoReleaseLocksEnabled()); + + List<CDOPackageUnit> npu = commitData.getNewPackageUnits(); + serverCommitContext.setNewPackageUnits(npu.toArray(new InternalCDOPackageUnit[npu.size()])); + + List<CDOIDAndVersion> no = commitData.getNewObjects(); + InternalCDORevision[] array = new InternalCDORevision[no.size()]; + int index = 0; + for (CDOIDAndVersion object : no) + { + InternalCDORevision revision = (InternalCDORevision)object; + // revision.convertEObjects(clientTransaction); + array[index++] = revision; + } + + serverCommitContext.setNewObjects(array); + + List<CDORevisionKey> rd = commitData.getChangedObjects(); + serverCommitContext.setDirtyObjectDeltas(rd.toArray(new InternalCDORevisionDelta[rd.size()])); + + List<CDOIDAndVersion> detachedObjects = commitData.getDetachedObjects(); + serverCommitContext.setDetachedObjects(detachedObjects.toArray(new CDOID[detachedObjects.size()])); + + serverCommitContext.write(monitor.fork()); + success = serverCommitContext.getRollbackMessage() == null; + if (success) + { + serverCommitContext.commit(monitor.fork()); + } + else + { + monitor.worked(); + } + + // result = new CommitTransactionResult(commitData, serverCommitContext.getBranchPoint().getTimeStamp()); + // for (Entry<CDOID, CDOID> entry : serverCommitContext.getIDMappings().entrySet()) + // { + // result.addIDMapping(entry.getKey(), entry.getValue()); + // } + } + finally + { + if (serverCommitContext != null) + { + serverCommitContext.postCommit(success); + } + + monitor.done(); + } + + return result; + } + + @Deprecated + public CommitTransactionResult commitDelegation(CDOBranch branch, String userID, String comment, + CDOCommitData commitData, Map<CDOID, EClass> detachedObjectTypes, Collection<CDOLob<?>> lobs, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitDelegation(InternalCDOCommitContext context, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitXATransactionCancel(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitXATransactionPhase1(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitXATransactionPhase2(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitXATransactionPhase3(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public List<CDORemoteSession> getRemoteSessions(InternalCDORemoteSessionManager manager, boolean subscribe) + { + throw new UnsupportedOperationException(); + } + + public Set<Integer> sendRemoteMessage(CDORemoteSessionMessage message, List<CDORemoteSession> recipients) + { + throw new UnsupportedOperationException(); + } + + public boolean unsubscribeRemoteSessions() + { + throw new UnsupportedOperationException(); + } + + public void replicateRepository(CDOReplicationContext context, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public void replicateRepositoryRaw(CDORawReplicationContext context, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CDOChangeSetData[] loadChangeSets(CDOBranchPointRange... ranges) + { + throw new UnsupportedOperationException(); + } + + public Set<CDOID> loadMergeData(CDORevisionAvailabilityInfo targetInfo, CDORevisionAvailabilityInfo sourceInfo, + CDORevisionAvailabilityInfo targetBaseInfo, CDORevisionAvailabilityInfo sourceBaseInfo) + { + throw new UnsupportedOperationException(); + } + + public CDOAuthenticationResult handleAuthenticationChallenge(byte[] randomToken) throws Exception + { + CDOAuthenticator authenticator = getSession().getAuthenticator(); + if (authenticator == null) + { + throw new IllegalStateException("No authenticator configured"); //$NON-NLS-1$ + } + + CDOAuthenticationResult result = authenticator.authenticate(randomToken); + if (result == null) + { + throw new SecurityException("Not authenticated"); //$NON-NLS-1$ + } + + String userID = result.getUserID(); + if (userID == null) + { + throw new SecurityException("No user ID"); //$NON-NLS-1$ + } + + byte[] cryptedToken = result.getCryptedToken(); + if (cryptedToken == null) + { + throw new SecurityException("No crypted token"); //$NON-NLS-1$ + } + + return result; + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + serverSessionProtocol = new EmbeddedServerSessionProtocol(this); + serverSessionProtocol.activate(); + } + + @Override + protected void doDeactivate() throws Exception + { + serverSessionProtocol.deactivate(); + serverSessionProtocol = null; + super.doDeactivate(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedServerSessionProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedServerSessionProtocol.java index b47d7d8eae..cbc49a8f2a 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedServerSessionProtocol.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/embedded/EmbeddedServerSessionProtocol.java @@ -1,111 +1,111 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.embedded;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
-import org.eclipse.emf.cdo.spi.server.ISessionProtocol;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-/**
- * @author Eike Stepper
- * @deprecated Not yet supported.
- */
-@Deprecated
-public class EmbeddedServerSessionProtocol extends Lifecycle implements ISessionProtocol
-{
- // A separate session protocol instance is required because the getSession() methods are ambiguous!
- private EmbeddedClientSessionProtocol clientSessionProtocol;
-
- private InternalSession session;
-
- public EmbeddedServerSessionProtocol(EmbeddedClientSessionProtocol clientSessionProtocol)
- {
- this.clientSessionProtocol = clientSessionProtocol;
- }
-
- public EmbeddedClientSessionProtocol getClientSessionProtocol()
- {
- return clientSessionProtocol;
- }
-
- public InternalSession openSession(InternalRepository repository, boolean passiveUpdateEnabled)
- {
- session = repository.getSessionManager().openSession(this);
- session.setPassiveUpdateEnabled(passiveUpdateEnabled);
- return session;
- }
-
- public InternalSession getSession()
- {
- return session;
- }
-
- public CDOAuthenticationResult sendAuthenticationChallenge(byte[] randomToken) throws Exception
- {
- return clientSessionProtocol.handleAuthenticationChallenge(randomToken);
- }
-
- public void sendRepositoryTypeNotification(CDOCommonRepository.Type oldType, CDOCommonRepository.Type newType)
- {
- EmbeddedClientSession clientSession = clientSessionProtocol.getSession();
- clientSession.handleRepositoryTypeChanged(oldType, newType);
- }
-
- @Deprecated
- public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState)
- {
- sendRepositoryStateNotification(oldState, newState, null);
- }
-
- public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState,
- CDOID rootResourceID)
- {
- EmbeddedClientSession clientSession = clientSessionProtocol.getSession();
- clientSession.handleRepositoryStateChanged(oldState, newState);
- }
-
- public void sendBranchNotification(InternalCDOBranch branch)
- {
- EmbeddedClientSession clientSession = clientSessionProtocol.getSession();
- clientSession.handleBranchNotification(branch);
- }
-
- public void sendCommitNotification(CDOCommitInfo commitInfo)
- {
- EmbeddedClientSession clientSession = clientSessionProtocol.getSession();
- clientSession.handleCommitNotification(commitInfo);
- }
-
- public void sendLockNotification(CDOLockChangeInfo lockChangeInfo)
- {
- EmbeddedClientSession clientSession = clientSessionProtocol.getSession();
- clientSession.handleLockNotification(lockChangeInfo, null);
- }
-
- public void sendRemoteSessionNotification(InternalSession sender, byte opcode)
- {
- throw new UnsupportedOperationException();
- }
-
- public void sendRemoteMessageNotification(InternalSession sender, CDORemoteSessionMessage message)
- {
- throw new UnsupportedOperationException();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.embedded; + +import org.eclipse.emf.cdo.common.CDOCommonRepository; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; +import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; +import org.eclipse.emf.cdo.spi.server.ISessionProtocol; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalSession; + +import org.eclipse.net4j.util.lifecycle.Lifecycle; + +/** + * @author Eike Stepper + * @deprecated Not yet supported. + */ +@Deprecated +public class EmbeddedServerSessionProtocol extends Lifecycle implements ISessionProtocol +{ + // A separate session protocol instance is required because the getSession() methods are ambiguous! + private EmbeddedClientSessionProtocol clientSessionProtocol; + + private InternalSession session; + + public EmbeddedServerSessionProtocol(EmbeddedClientSessionProtocol clientSessionProtocol) + { + this.clientSessionProtocol = clientSessionProtocol; + } + + public EmbeddedClientSessionProtocol getClientSessionProtocol() + { + return clientSessionProtocol; + } + + public InternalSession openSession(InternalRepository repository, boolean passiveUpdateEnabled) + { + session = repository.getSessionManager().openSession(this); + session.setPassiveUpdateEnabled(passiveUpdateEnabled); + return session; + } + + public InternalSession getSession() + { + return session; + } + + public CDOAuthenticationResult sendAuthenticationChallenge(byte[] randomToken) throws Exception + { + return clientSessionProtocol.handleAuthenticationChallenge(randomToken); + } + + public void sendRepositoryTypeNotification(CDOCommonRepository.Type oldType, CDOCommonRepository.Type newType) + { + EmbeddedClientSession clientSession = clientSessionProtocol.getSession(); + clientSession.handleRepositoryTypeChanged(oldType, newType); + } + + @Deprecated + public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState) + { + sendRepositoryStateNotification(oldState, newState, null); + } + + public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState, + CDOID rootResourceID) + { + EmbeddedClientSession clientSession = clientSessionProtocol.getSession(); + clientSession.handleRepositoryStateChanged(oldState, newState); + } + + public void sendBranchNotification(InternalCDOBranch branch) + { + EmbeddedClientSession clientSession = clientSessionProtocol.getSession(); + clientSession.handleBranchNotification(branch); + } + + public void sendCommitNotification(CDOCommitInfo commitInfo) + { + EmbeddedClientSession clientSession = clientSessionProtocol.getSession(); + clientSession.handleCommitNotification(commitInfo); + } + + public void sendLockNotification(CDOLockChangeInfo lockChangeInfo) + { + EmbeddedClientSession clientSession = clientSessionProtocol.getSession(); + clientSession.handleLockNotification(lockChangeInfo, null); + } + + public void sendRemoteSessionNotification(InternalSession sender, byte opcode) + { + throw new UnsupportedOperationException(); + } + + public void sendRemoteMessageNotification(InternalSession sender, CDORemoteSessionMessage message) + { + 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 055433a660..c98d2924dd 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 @@ -1,1310 +1,1310 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Simon McDuff - bug 233273
- * Eike Stepper - maintenance
- * Andre Dietisheim - bug 256649
- */
-package org.eclipse.emf.cdo.internal.server.mem;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.lock.CDOLockUtil;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea.Handler;
-import org.eclipse.emf.cdo.common.model.CDOModelConstants;
-import org.eclipse.emf.cdo.common.protocol.CDODataInput;
-import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking2;
-import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
-import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.server.IView;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.server.mem.IMEMStore;
-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.commit.CDOChangeSetSegment;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision;
-import org.eclipse.emf.cdo.spi.server.InternalLockManager;
-import org.eclipse.emf.cdo.spi.server.LongIDStore;
-import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
-
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.CharArrayReader;
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * @author Simon McDuff
- */
-public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader, DurableLocking2
-{
- public static final String TYPE = "mem"; //$NON-NLS-1$
-
- private long creationTime;
-
- private Map<String, String> properties = new HashMap<String, String>();
-
- 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>();
-
- private Map<CDOID, EClass> objectTypes = new HashMap<CDOID, EClass>();
-
- private Map<String, LockArea> lockAreas = new HashMap<String, LockArea>();
-
- private Map<String, Object> lobs = new HashMap<String, Object>();
-
- private int listLimit;
-
- @ExcludeFromDump
- private transient EStructuralFeature resourceNameFeature;
-
- /**
- * @param listLimit
- * See {@link #setListLimit(int)}.
- * @since 2.0
- */
- public MEMStore(int listLimit)
- {
- super(TYPE, set(ChangeFormat.REVISION, ChangeFormat.DELTA), set(RevisionTemporality.NONE,
- RevisionTemporality.AUDITING), set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING));
- setRevisionTemporality(RevisionTemporality.AUDITING);
- setRevisionParallelism(RevisionParallelism.BRANCHING);
- this.listLimit = listLimit;
- }
-
- public MEMStore()
- {
- this(UNLIMITED);
- }
-
- @Override
- public CDOID createObjectID(String val)
- {
- if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT)
- {
- byte[] decoded = CDOIDUtil.decodeUUID(val);
- return CDOIDUtil.createUUID(decoded);
- }
-
- return super.createObjectID(val);
- }
-
- @Override
- public boolean isLocal(CDOID id)
- {
- if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT)
- {
- return false;
- }
-
- return super.isLocal(id);
- }
-
- @Override
- public void ensureLastObjectID(CDOID id)
- {
- if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT)
- {
- return;
- }
-
- super.ensureLastObjectID(id);
- }
-
- public synchronized Map<String, String> getPersistentProperties(Set<String> names)
- {
- if (names == null || names.isEmpty())
- {
- return new HashMap<String, String>(properties);
- }
-
- Map<String, String> result = new HashMap<String, String>();
- for (String name : names)
- {
- String value = properties.get(name);
- if (value != null)
- {
- result.put(name, value);
- }
- }
-
- return result;
- }
-
- public synchronized void setPersistentProperties(Map<String, String> properties)
- {
- this.properties.putAll(properties);
- }
-
- public synchronized void removePersistentProperties(Set<String> names)
- {
- for (String name : names)
- {
- properties.remove(name);
- }
- }
-
- public synchronized Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
- {
- if (branchID == NEW_BRANCH)
- {
- branchID = ++lastBranchID;
- }
- else if (branchID == NEW_LOCAL_BRANCH)
- {
- branchID = --lastLocalBranchID;
- }
-
- branchInfos.put(branchID, branchInfo);
- return new Pair<Integer, Long>(branchID, branchInfo.getBaseTimeStamp());
- }
-
- public synchronized BranchInfo loadBranch(int branchID)
- {
- return branchInfos.get(branchID);
- }
-
- public synchronized SubBranchInfo[] loadSubBranches(int branchID)
- {
- List<SubBranchInfo> result = new ArrayList<SubBranchInfo>();
- for (Entry<Integer, BranchInfo> entry : branchInfos.entrySet())
- {
- BranchInfo branchInfo = entry.getValue();
- if (branchInfo.getBaseBranchID() == branchID)
- {
- int id = entry.getKey();
- result.add(new SubBranchInfo(id, branchInfo.getName(), branchInfo.getBaseTimeStamp()));
- }
- }
-
- return result.toArray(new SubBranchInfo[result.size()]);
- }
-
- public synchronized int loadBranches(int startID, int endID, CDOBranchHandler handler)
- {
- int count = 0;
- InternalCDOBranchManager branchManager = getRepository().getBranchManager();
- for (Entry<Integer, BranchInfo> entry : branchInfos.entrySet())
- {
- int id = entry.getKey();
- if (startID <= id && (id <= endID || endID == 0))
- {
- BranchInfo branchInfo = entry.getValue();
- InternalCDOBranch branch = branchManager.getBranch(id, branchInfo);
- handler.handleBranch(branch);
- ++count;
- }
- }
-
- return count;
- }
-
- public synchronized void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
- {
- InternalCDOCommitInfoManager manager = getRepository().getCommitInfoManager();
- for (int i = 0; i < commitInfos.size(); i++)
- {
- CommitInfo info = commitInfos.get(i);
- if (startTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() < startTime)
- {
- continue;
- }
-
- if (endTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() > endTime)
- {
- continue;
- }
-
- if (branch != null && !ObjectUtil.equals(info.getBranch(), branch))
- {
- continue;
- }
-
- info.handle(manager, handler);
- }
- }
-
- public synchronized Set<CDOID> readChangeSet(CDOChangeSetSegment[] segments)
- {
- Set<CDOID> ids = new HashSet<CDOID>();
- for (CDOChangeSetSegment segment : segments)
- {
- for (List<InternalCDORevision> list : revisions.values())
- {
- readChangeSet(segment, list, ids);
- }
- }
-
- return ids;
- }
-
- private void readChangeSet(CDOChangeSetSegment segment, List<InternalCDORevision> list, Set<CDOID> ids)
- {
- long startTime = segment.getTimeStamp();
- long endTime = segment.getEndTime();
- boolean listCheckDone = false;
- for (InternalCDORevision revision : list)
- {
- CDOID id = revision.getID();
- if (!listCheckDone)
- {
- if (ids.contains(id))
- {
- return;
- }
-
- if (!ObjectUtil.equals(revision.getBranch(), segment.getBranch()))
- {
- return;
- }
-
- listCheckDone = true;
- }
-
- if (CDOCommonUtil.isValidTimeStamp(revision.getTimeStamp(), startTime, endTime))
- {
- ids.add(id);
- }
- }
- }
-
- public synchronized void handleRevisions(EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime,
- CDORevisionHandler handler)
- {
- for (List<InternalCDORevision> list : revisions.values())
- {
- for (InternalCDORevision revision : list)
- {
- if (!handleRevision(revision, eClass, branch, timeStamp, exactTime, handler))
- {
- return;
- }
- }
- }
- }
-
- private boolean handleRevision(InternalCDORevision revision, EClass eClass, CDOBranch branch, long timeStamp,
- boolean exactTime, CDORevisionHandler handler)
- {
- if (eClass != null && revision.getEClass() != eClass)
- {
- return true;
- }
-
- if (branch != null && !ObjectUtil.equals(revision.getBranch(), branch))
- {
- return true;
- }
-
- if (timeStamp != CDOBranchPoint.INVALID_DATE)
- {
- if (exactTime)
- {
- if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE && revision.getTimeStamp() != timeStamp)
- {
- return true;
- }
- }
- else
- {
- if (!revision.isValid(timeStamp))
- {
- return true;
- }
- }
- }
-
- return handler.handleRevision(revision);
- }
-
- /**
- * @since 2.0
- */
- public int getListLimit()
- {
- return listLimit;
- }
-
- /**
- * @since 2.0
- */
- public synchronized void setListLimit(int listLimit)
- {
- if (listLimit != UNLIMITED && this.listLimit != listLimit)
- {
- for (List<InternalCDORevision> list : revisions.values())
- {
- enforceListLimit(list);
- }
- }
-
- this.listLimit = listLimit;
- }
-
- /**
- * @since 2.0
- */
- public synchronized List<InternalCDORevision> getCurrentRevisions()
- {
- ArrayList<InternalCDORevision> simpleRevisions = new ArrayList<InternalCDORevision>();
- Iterator<List<InternalCDORevision>> itr = revisions.values().iterator();
- while (itr.hasNext())
- {
- List<InternalCDORevision> list = itr.next();
- InternalCDORevision revision = list.get(list.size() - 1);
- simpleRevisions.add(revision);
- }
-
- return simpleRevisions;
- }
-
- public synchronized InternalCDORevision getRevisionByVersion(CDOID id, CDOBranchVersion branchVersion)
- {
- Object listKey = getListKey(id, branchVersion.getBranch());
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list == null)
- {
- return null;
- }
-
- return getRevisionByVersion(list, branchVersion.getVersion());
- }
-
- /**
- * @since 2.0
- */
- public synchronized InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint)
- {
- Object listKey = getListKey(id, branchPoint.getBranch());
- if (branchPoint.getTimeStamp() == CDORevision.UNSPECIFIED_DATE)
- {
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list == null)
- {
- return null;
- }
-
- return list.get(list.size() - 1);
- }
-
- if (!getRepository().isSupportingAudits())
- {
- throw new UnsupportedOperationException("Auditing not supported");
- }
-
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list == null)
- {
- return null;
- }
-
- return getRevision(list, branchPoint);
- }
-
- public synchronized void addRevision(InternalCDORevision revision, boolean raw)
- {
- Object listKey = getListKey(revision.getID(), revision.getBranch());
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list == null)
- {
- list = new ArrayList<InternalCDORevision>();
- revisions.put(listKey, list);
- }
-
- addRevision(list, revision, raw);
-
- if (raw)
- {
- ensureLastObjectID(revision.getID());
- }
- }
-
- public synchronized void addCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID,
- String comment)
- {
- int index = commitInfos.size() - 1;
- while (index >= 0)
- {
- CommitInfo info = commitInfos.get(index);
- if (timeStamp > info.getTimeStamp())
- {
- break;
- }
-
- --index;
- }
-
- CommitInfo commitInfo = new CommitInfo(branch, timeStamp, previousTimeStamp, userID, comment);
- commitInfos.add(index + 1, commitInfo);
- }
-
- /**
- * @since 2.0
- */
- public synchronized boolean rollbackRevision(InternalCDORevision revision)
- {
- CDOID id = revision.getID();
- CDOBranch branch = revision.getBranch();
- int version = revision.getVersion();
-
- Object listKey = getListKey(id, branch);
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list == null)
- {
- return false;
- }
-
- for (Iterator<InternalCDORevision> it = list.iterator(); it.hasNext();)
- {
- InternalCDORevision rev = it.next();
- if (rev.getVersion() == version)
- {
- it.remove();
- return true;
- }
- else if (rev.getVersion() == version - 1)
- {
- rev.setRevised(CDORevision.UNSPECIFIED_DATE);
- }
- }
-
- return false;
- }
-
- /**
- * @since 3.0
- */
- public synchronized DetachedCDORevision detachObject(CDOID id, CDOBranch branch, long timeStamp)
- {
- Object listKey = getListKey(id, branch);
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list != null)
- {
- InternalCDORevision revision = getRevision(list, branch.getHead());
- if (revision != null)
- {
- revision.setRevised(timeStamp - 1);
- }
- }
-
- int version;
- if (list == null)
- {
- list = new ArrayList<InternalCDORevision>();
- revisions.put(listKey, list);
- version = CDOBranchVersion.FIRST_VERSION;
- }
- else
- {
- version = getHighestVersion(list) + 1;
- }
-
- EClass eClass = getObjectType(id);
- DetachedCDORevision detached = new DetachedCDORevision(eClass, id, branch, version, timeStamp);
- addRevision(list, detached, false);
- return detached;
- }
-
- /**
- * @since 2.0
- */
- public synchronized void queryResources(IStoreAccessor.QueryResourcesContext context)
- {
- CDOID folderID = context.getFolderID();
- String name = context.getName();
- boolean exactMatch = context.exactMatch();
- for (Entry<Object, List<InternalCDORevision>> entry : revisions.entrySet())
- {
- CDOBranch branch = getBranch(entry.getKey());
- if (!ObjectUtil.equals(branch, context.getBranch()))
- {
- continue;
- }
-
- List<InternalCDORevision> list = entry.getValue();
- if (list.isEmpty())
- {
- continue;
- }
-
- InternalCDORevision revision = list.get(0);
- if (revision instanceof SyntheticCDORevision)
- {
- continue;
- }
-
- if (!revision.isResourceNode())
- {
- continue;
- }
-
- revision = getRevision(list, context);
- if (revision == null || revision instanceof DetachedCDORevision)
- {
- continue;
- }
-
- CDOID revisionFolder = (CDOID)revision.data().getContainerID();
- if (!CDOIDUtil.equals(revisionFolder, folderID))
- {
- continue;
- }
-
- String revisionName = (String)revision.data().get(resourceNameFeature, 0);
- boolean useEquals = exactMatch || revisionName == null || name == null;
- boolean match = useEquals ? ObjectUtil.equals(revisionName, name) : revisionName.startsWith(name);
-
- if (match)
- {
- if (!context.addResource(revision.getID()))
- {
- // No more results allowed
- break;
- }
- }
- }
- }
-
- public synchronized void queryXRefs(QueryXRefsContext context)
- {
- Set<CDOID> targetIDs = context.getTargetObjects().keySet();
- Map<EClass, List<EReference>> sourceCandidates = context.getSourceCandidates();
-
- for (Entry<Object, List<InternalCDORevision>> entry : revisions.entrySet())
- {
- CDOBranch branch = getBranch(entry.getKey());
- if (!ObjectUtil.equals(branch, context.getBranch()))
- {
- continue;
- }
-
- List<InternalCDORevision> list = entry.getValue();
- if (list.isEmpty())
- {
- continue;
- }
-
- InternalCDORevision revision = getRevision(list, context);
- if (revision == null || revision instanceof SyntheticCDORevision)
- {
- continue;
- }
-
- EClass eClass = revision.getEClass();
- CDOID sourceID = revision.getID();
-
- List<EReference> eReferences = sourceCandidates.get(eClass);
- if (eReferences != null)
- {
- for (EReference eReference : eReferences)
- {
- Object value = revision.getValue(eReference);
- if (value != null)
- {
- if (eReference.isMany())
- {
- @SuppressWarnings("unchecked")
- List<CDOID> ids = (List<CDOID>)value;
- int index = 0;
- for (CDOID id : ids)
- {
- if (!queryXRefs(context, targetIDs, id, sourceID, eReference, index++))
- {
- return;
- }
- }
- }
- else
- {
- CDOID id = (CDOID)value;
- if (!queryXRefs(context, targetIDs, id, sourceID, eReference, 0))
- {
- return;
- }
- }
- }
- }
- }
- }
- }
-
- private boolean queryXRefs(QueryXRefsContext context, Set<CDOID> targetIDs, CDOID targetID, CDOID sourceID,
- EReference sourceReference, int index)
- {
- for (CDOID id : targetIDs)
- {
- if (id.equals(targetID))
- {
- if (!context.addXRef(targetID, sourceID, sourceReference, index))
- {
- // No more results allowed
- return false;
- }
- }
- }
-
- return true;
- }
-
- public synchronized void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime,
- long toCommitTime)
- {
- // TODO: implement MEMStore.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime)
- throw new UnsupportedOperationException();
- }
-
- public synchronized void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime,
- long toCommitTime, OMMonitor monitor)
- {
- // TODO: implement MEMStore.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime, monitor)
- throw new UnsupportedOperationException();
- }
-
- public synchronized void rawDelete(CDOID id, int version, CDOBranch branch)
- {
- Object listKey = getListKey(id, branch);
- List<InternalCDORevision> list = revisions.get(listKey);
- if (list != null)
- {
- for (Iterator<InternalCDORevision> it = list.iterator(); it.hasNext();)
- {
- InternalCDORevision rev = it.next();
- if (rev.getVersion() == version)
- {
- it.remove();
- break;
- }
- }
- }
- }
-
- public synchronized LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly,
- Map<CDOID, LockGrade> locks)
- {
- return createLockArea(null, userID, branchPoint, readOnly, locks);
- }
-
- public synchronized LockArea createLockArea(String durableLockingID, String userID, CDOBranchPoint branchPoint,
- boolean readOnly, Map<CDOID, LockGrade> locks)
- {
- if (durableLockingID != null)
- {
- // If the caller is specifying the ID, make sure there is no area with this ID yet
- if (lockAreas.containsKey(durableLockingID))
- {
- throw new LockAreaAlreadyExistsException(durableLockingID);
- }
- }
- else
- {
- do
- {
- durableLockingID = CDOLockUtil.createDurableLockingID();
- } while (lockAreas.containsKey(durableLockingID));
- }
-
- LockArea area = CDOLockUtil.createLockArea(durableLockingID, userID, branchPoint, readOnly, locks);
- lockAreas.put(durableLockingID, area);
- return area;
- }
-
- public synchronized void updateLockArea(LockArea lockArea)
- {
- String durableLockingID = lockArea.getDurableLockingID();
- lockAreas.put(durableLockingID, lockArea);
- }
-
- public synchronized LockArea getLockArea(String durableLockingID) throws LockAreaNotFoundException
- {
- LockArea area = lockAreas.get(durableLockingID);
- if (area == null)
- {
- throw new LockAreaNotFoundException(durableLockingID);
- }
-
- return area;
- }
-
- public synchronized void getLockAreas(String userIDPrefix, Handler handler)
- {
- for (LockArea area : lockAreas.values())
- {
- String userID = area.getUserID();
- if (userID == null || userID.startsWith(userIDPrefix))
- {
- if (!handler.handleLockArea(area))
- {
- return;
- }
- }
- }
- }
-
- public synchronized void deleteLockArea(String durableLockingID)
- {
- lockAreas.remove(durableLockingID);
- }
-
- public synchronized void lock(String durableLockingID, LockType type, Collection<? extends Object> objectsToLock)
- {
- LockArea area = getLockArea(durableLockingID);
- Map<CDOID, LockGrade> locks = area.getLocks();
-
- InternalLockManager lockManager = getRepository().getLockingManager();
- for (Object objectToLock : objectsToLock)
- {
- CDOID id = lockManager.getLockKeyID(objectToLock);
- LockGrade grade = locks.get(id);
- if (grade != null)
- {
- grade = grade.getUpdated(type, true);
- }
- else
- {
- grade = LockGrade.get(type);
- }
-
- locks.put(id, grade);
- }
- }
-
- public synchronized void unlock(String durableLockingID, LockType type, Collection<? extends Object> objectsToUnlock)
- {
- LockArea area = getLockArea(durableLockingID);
- Map<CDOID, LockGrade> locks = area.getLocks();
-
- InternalLockManager lockManager = getRepository().getLockingManager();
- for (Object objectToUnlock : objectsToUnlock)
- {
- CDOID id = lockManager.getLockKeyID(objectToUnlock);
- LockGrade grade = locks.get(id);
- if (grade != null)
- {
- grade = grade.getUpdated(type, false);
- if (grade == LockGrade.NONE)
- {
- locks.remove(id);
- }
- }
- }
- }
-
- public synchronized void unlock(String durableLockingID)
- {
- LockArea area = getLockArea(durableLockingID);
- Map<CDOID, LockGrade> locks = area.getLocks();
- locks.clear();
- }
-
- public synchronized void queryLobs(List<byte[]> ids)
- {
- for (Iterator<byte[]> it = ids.iterator(); it.hasNext();)
- {
- byte[] id = it.next();
- String key = HexUtil.bytesToHex(id);
- if (!lobs.containsKey(key))
- {
- it.remove();
- }
- }
- }
-
- public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException
- {
- for (Entry<String, Object> entry : lobs.entrySet())
- {
- byte[] id = HexUtil.hexToBytes(entry.getKey());
- Object lob = entry.getValue();
- if (lob instanceof byte[])
- {
- byte[] blob = (byte[])lob;
- ByteArrayInputStream in = new ByteArrayInputStream(blob);
- OutputStream out = handler.handleBlob(id, blob.length);
- if (out != null)
- {
- try
- {
- IOUtil.copyBinary(in, out, blob.length);
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- }
- else
- {
- char[] clob = (char[])lob;
- CharArrayReader in = new CharArrayReader(clob);
- Writer out = handler.handleClob(id, clob.length);
- if (out != null)
- {
- try
- {
- IOUtil.copyCharacter(in, out, clob.length);
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- }
- }
- }
-
- public synchronized void loadLob(byte[] id, OutputStream out) throws IOException
- {
- String key = HexUtil.bytesToHex(id);
- Object lob = lobs.get(key);
- if (lob == null)
- {
- throw new IOException("Lob not found: " + key);
- }
-
- if (lob instanceof byte[])
- {
- byte[] blob = (byte[])lob;
- ByteArrayInputStream in = new ByteArrayInputStream(blob);
- IOUtil.copyBinary(in, out, blob.length);
- }
- else
- {
- char[] clob = (char[])lob;
- CharArrayReader in = new CharArrayReader(clob);
- IOUtil.copyCharacter(in, new OutputStreamWriter(out), clob.length);
- }
- }
-
- public synchronized void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- IOUtil.copyBinary(inputStream, out, size);
- lobs.put(HexUtil.bytesToHex(id), out.toByteArray());
- }
-
- public synchronized void writeClob(byte[] id, long size, Reader reader) throws IOException
- {
- CharArrayWriter out = new CharArrayWriter();
- IOUtil.copyCharacter(reader, out, size);
- lobs.put(HexUtil.bytesToHex(id), out.toCharArray());
- }
-
- @Override
- public MEMStoreAccessor createReader(ISession session)
- {
- return new MEMStoreAccessor(this, session);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public MEMStoreAccessor createWriter(ITransaction transaction)
- {
- return new MEMStoreAccessor(this, transaction);
- }
-
- /**
- * @since 2.0
- */
- public long getCreationTime()
- {
- return creationTime;
- }
-
- public void setCreationTime(long creationTime)
- {
- this.creationTime = creationTime;
- }
-
- public boolean isFirstStart()
- {
- return true;
- }
-
- public synchronized Map<CDOBranch, List<CDORevision>> getAllRevisions()
- {
- Map<CDOBranch, List<CDORevision>> result = new HashMap<CDOBranch, List<CDORevision>>();
- InternalCDOBranchManager branchManager = getRepository().getBranchManager();
- result.put(branchManager.getMainBranch(), new ArrayList<CDORevision>());
-
- for (Integer branchID : branchInfos.keySet())
- {
- InternalCDOBranch branch = branchManager.getBranch(branchID);
- result.put(branch, new ArrayList<CDORevision>());
- }
-
- for (List<InternalCDORevision> list : revisions.values())
- {
- for (InternalCDORevision revision : list)
- {
- CDOBranch branch = revision.getBranch();
- List<CDORevision> resultList = result.get(branch);
- resultList.add(revision);
- }
- }
-
- return result;
- }
-
- public synchronized EClass getObjectType(CDOID id)
- {
- return objectTypes.get(id);
- }
-
- /**
- * @since 2.0
- */
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- creationTime = getRepository().getTimeStamp();
-
- if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT)
- {
- setObjectIDTypes(Collections.singleton(CDOID.ObjectType.UUID));
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- revisions.clear();
- branchInfos.clear();
- commitInfos.clear();
- objectTypes.clear();
- properties.clear();
- resourceNameFeature = null;
- lastBranchID = 0;
- lastLocalBranchID = 0;
- super.doDeactivate();
- }
-
- @Override
- protected StoreAccessorPool getReaderPool(ISession session, boolean forReleasing)
- {
- // Pooling of store accessors not supported
- return null;
- }
-
- @Override
- protected StoreAccessorPool getWriterPool(IView view, boolean forReleasing)
- {
- // Pooling of store accessors not supported
- return null;
- }
-
- private Object getListKey(CDOID id, CDOBranch branch)
- {
- if (getRevisionParallelism() == RevisionParallelism.NONE)
- {
- return id;
- }
-
- return new ListKey(id, branch);
- }
-
- private CDOBranch getBranch(Object key)
- {
- if (key instanceof ListKey)
- {
- return ((ListKey)key).getBranch();
- }
-
- return getRepository().getBranchManager().getMainBranch();
- }
-
- private int getHighestVersion(List<InternalCDORevision> list)
- {
- int version = CDOBranchVersion.UNSPECIFIED_VERSION;
- for (InternalCDORevision revision : list)
- {
- if (revision.getVersion() > version)
- {
- version = revision.getVersion();
- }
- }
-
- return version;
- }
-
- private InternalCDORevision getRevisionByVersion(List<InternalCDORevision> list, int version)
- {
- for (InternalCDORevision revision : list)
- {
- if (revision.getVersion() == version)
- {
- return revision;
- }
- }
-
- return null;
- }
-
- private InternalCDORevision getRevision(List<InternalCDORevision> list, CDOBranchPoint branchPoint)
- {
- long timeStamp = branchPoint.getTimeStamp();
- for (InternalCDORevision revision : list)
- {
- if (timeStamp == CDORevision.UNSPECIFIED_DATE)
- {
- if (!revision.isHistorical())
- {
- return revision;
- }
- }
- else
- {
- if (revision.isValid(timeStamp))
- {
- return revision;
- }
- }
- }
-
- return null;
- }
-
- private void addRevision(List<InternalCDORevision> list, InternalCDORevision revision, boolean raw)
- {
- boolean resource = !(revision instanceof SyntheticCDORevision) && revision.isResource();
- if (resource && resourceNameFeature == null)
- {
- resourceNameFeature = revision.getEClass().getEStructuralFeature(CDOModelConstants.RESOURCE_NODE_NAME_ATTRIBUTE);
- }
-
- if (!raw)
- {
- // Check version conflict
- int version = revision.getVersion();
- InternalCDORevision rev = getRevisionByVersion(list, version);
- if (rev != null)
- {
- rev = getRevisionByVersion(list, version);
- throw new IllegalStateException("Concurrent modification of " + rev.getEClass().getName() + "@" + rev.getID());
- }
-
- // Revise old revision
- int oldVersion = version - 1;
- if (oldVersion >= CDORevision.UNSPECIFIED_VERSION)
- {
- InternalCDORevision oldRevision = getRevisionByVersion(list, oldVersion);
- if (oldRevision != null)
- {
- if (getRepository().isSupportingAudits())
- {
- oldRevision.setRevised(revision.getTimeStamp() - 1);
- }
- else
- {
- list.remove(oldRevision);
- }
- }
- }
-
- // Check duplicate resource
- if (resource)
- {
- checkDuplicateResource(revision);
- }
- }
-
- // Adjust the list
- list.add(revision);
- if (listLimit != UNLIMITED)
- {
- enforceListLimit(list);
- }
-
- CDOID id = revision.getID();
- if (!objectTypes.containsKey(id))
- {
- objectTypes.put(id, revision.getEClass());
- }
- }
-
- private void checkDuplicateResource(InternalCDORevision revision)
- {
- CDOID revisionFolder = (CDOID)revision.data().getContainerID();
- String revisionName = (String)revision.data().get(resourceNameFeature, 0);
-
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
-
- CDOID resourceID = accessor.readResourceID(revisionFolder, revisionName, revision);
- if (!CDOIDUtil.isNull(resourceID))
- {
- throw new IllegalStateException("Duplicate resource: name=" + revisionName + ", folderID=" + revisionFolder); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- private void enforceListLimit(List<InternalCDORevision> list)
- {
- while (list.size() > listLimit)
- {
- list.remove(0);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class ListKey
- {
- private CDOID id;
-
- private CDOBranch branch;
-
- public ListKey(CDOID id, CDOBranch branch)
- {
- this.id = id;
- this.branch = branch;
- }
-
- public CDOID getID()
- {
- return id;
- }
-
- public CDOBranch getBranch()
- {
- return branch;
- }
-
- @Override
- public int hashCode()
- {
- return id.hashCode() ^ branch.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof ListKey)
- {
- ListKey that = (ListKey)obj;
- return ObjectUtil.equals(id, that.getID()) && ObjectUtil.equals(branch, that.getBranch());
- }
-
- return false;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("{0}:{1}", id, branch.getID());
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class CommitInfo
- {
- private CDOBranch branch;
-
- private long timeStamp;
-
- private long previousTimeStamp;
-
- private String userID;
-
- private String comment;
-
- public CommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, String comment)
- {
- this.branch = branch;
- this.timeStamp = timeStamp;
- this.previousTimeStamp = previousTimeStamp;
- this.userID = userID;
- this.comment = comment;
- }
-
- public CDOBranch getBranch()
- {
- return branch;
- }
-
- public long getTimeStamp()
- {
- return timeStamp;
- }
-
- public void handle(InternalCDOCommitInfoManager manager, CDOCommitInfoHandler handler)
- {
- CDOCommitInfo commitInfo = manager.createCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, null);
- handler.handleCommitInfo(commitInfo);
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CommitInfo[{0}, {1}, {2}, {3}, {4}]", branch, timeStamp, previousTimeStamp, userID,
- comment);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Simon McDuff - bug 233273 + * Eike Stepper - maintenance + * Andre Dietisheim - bug 256649 + */ +package org.eclipse.emf.cdo.internal.server.mem; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchHandler; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.branch.CDOBranchVersion; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.lob.CDOLobHandler; +import org.eclipse.emf.cdo.common.lock.CDOLockUtil; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea.Handler; +import org.eclipse.emf.cdo.common.model.CDOModelConstants; +import org.eclipse.emf.cdo.common.protocol.CDODataInput; +import org.eclipse.emf.cdo.common.protocol.CDODataOutput; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; +import org.eclipse.emf.cdo.common.util.CDOCommonUtil; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking2; +import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext; +import org.eclipse.emf.cdo.server.ITransaction; +import org.eclipse.emf.cdo.server.IView; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.server.mem.IMEMStore; +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.commit.CDOChangeSetSegment; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision; +import org.eclipse.emf.cdo.spi.server.InternalLockManager; +import org.eclipse.emf.cdo.spi.server.LongIDStore; +import org.eclipse.emf.cdo.spi.server.StoreAccessorPool; + +import org.eclipse.net4j.util.HexUtil; +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.collection.Pair; +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; +import org.eclipse.net4j.util.io.IOUtil; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.CharArrayReader; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * @author Simon McDuff + */ +public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader, DurableLocking2 +{ + public static final String TYPE = "mem"; //$NON-NLS-1$ + + private long creationTime; + + private Map<String, String> properties = new HashMap<String, String>(); + + 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>(); + + private Map<CDOID, EClass> objectTypes = new HashMap<CDOID, EClass>(); + + private Map<String, LockArea> lockAreas = new HashMap<String, LockArea>(); + + private Map<String, Object> lobs = new HashMap<String, Object>(); + + private int listLimit; + + @ExcludeFromDump + private transient EStructuralFeature resourceNameFeature; + + /** + * @param listLimit + * See {@link #setListLimit(int)}. + * @since 2.0 + */ + public MEMStore(int listLimit) + { + super(TYPE, set(ChangeFormat.REVISION, ChangeFormat.DELTA), set(RevisionTemporality.NONE, + RevisionTemporality.AUDITING), set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING)); + setRevisionTemporality(RevisionTemporality.AUDITING); + setRevisionParallelism(RevisionParallelism.BRANCHING); + this.listLimit = listLimit; + } + + public MEMStore() + { + this(UNLIMITED); + } + + @Override + public CDOID createObjectID(String val) + { + if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT) + { + byte[] decoded = CDOIDUtil.decodeUUID(val); + return CDOIDUtil.createUUID(decoded); + } + + return super.createObjectID(val); + } + + @Override + public boolean isLocal(CDOID id) + { + if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT) + { + return false; + } + + return super.isLocal(id); + } + + @Override + public void ensureLastObjectID(CDOID id) + { + if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT) + { + return; + } + + super.ensureLastObjectID(id); + } + + public synchronized Map<String, String> getPersistentProperties(Set<String> names) + { + if (names == null || names.isEmpty()) + { + return new HashMap<String, String>(properties); + } + + Map<String, String> result = new HashMap<String, String>(); + for (String name : names) + { + String value = properties.get(name); + if (value != null) + { + result.put(name, value); + } + } + + return result; + } + + public synchronized void setPersistentProperties(Map<String, String> properties) + { + this.properties.putAll(properties); + } + + public synchronized void removePersistentProperties(Set<String> names) + { + for (String name : names) + { + properties.remove(name); + } + } + + public synchronized Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo) + { + if (branchID == NEW_BRANCH) + { + branchID = ++lastBranchID; + } + else if (branchID == NEW_LOCAL_BRANCH) + { + branchID = --lastLocalBranchID; + } + + branchInfos.put(branchID, branchInfo); + return new Pair<Integer, Long>(branchID, branchInfo.getBaseTimeStamp()); + } + + public synchronized BranchInfo loadBranch(int branchID) + { + return branchInfos.get(branchID); + } + + public synchronized SubBranchInfo[] loadSubBranches(int branchID) + { + List<SubBranchInfo> result = new ArrayList<SubBranchInfo>(); + for (Entry<Integer, BranchInfo> entry : branchInfos.entrySet()) + { + BranchInfo branchInfo = entry.getValue(); + if (branchInfo.getBaseBranchID() == branchID) + { + int id = entry.getKey(); + result.add(new SubBranchInfo(id, branchInfo.getName(), branchInfo.getBaseTimeStamp())); + } + } + + return result.toArray(new SubBranchInfo[result.size()]); + } + + public synchronized int loadBranches(int startID, int endID, CDOBranchHandler handler) + { + int count = 0; + InternalCDOBranchManager branchManager = getRepository().getBranchManager(); + for (Entry<Integer, BranchInfo> entry : branchInfos.entrySet()) + { + int id = entry.getKey(); + if (startID <= id && (id <= endID || endID == 0)) + { + BranchInfo branchInfo = entry.getValue(); + InternalCDOBranch branch = branchManager.getBranch(id, branchInfo); + handler.handleBranch(branch); + ++count; + } + } + + return count; + } + + public synchronized void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler) + { + InternalCDOCommitInfoManager manager = getRepository().getCommitInfoManager(); + for (int i = 0; i < commitInfos.size(); i++) + { + CommitInfo info = commitInfos.get(i); + if (startTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() < startTime) + { + continue; + } + + if (endTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() > endTime) + { + continue; + } + + if (branch != null && !ObjectUtil.equals(info.getBranch(), branch)) + { + continue; + } + + info.handle(manager, handler); + } + } + + public synchronized Set<CDOID> readChangeSet(CDOChangeSetSegment[] segments) + { + Set<CDOID> ids = new HashSet<CDOID>(); + for (CDOChangeSetSegment segment : segments) + { + for (List<InternalCDORevision> list : revisions.values()) + { + readChangeSet(segment, list, ids); + } + } + + return ids; + } + + private void readChangeSet(CDOChangeSetSegment segment, List<InternalCDORevision> list, Set<CDOID> ids) + { + long startTime = segment.getTimeStamp(); + long endTime = segment.getEndTime(); + boolean listCheckDone = false; + for (InternalCDORevision revision : list) + { + CDOID id = revision.getID(); + if (!listCheckDone) + { + if (ids.contains(id)) + { + return; + } + + if (!ObjectUtil.equals(revision.getBranch(), segment.getBranch())) + { + return; + } + + listCheckDone = true; + } + + if (CDOCommonUtil.isValidTimeStamp(revision.getTimeStamp(), startTime, endTime)) + { + ids.add(id); + } + } + } + + public synchronized void handleRevisions(EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime, + CDORevisionHandler handler) + { + for (List<InternalCDORevision> list : revisions.values()) + { + for (InternalCDORevision revision : list) + { + if (!handleRevision(revision, eClass, branch, timeStamp, exactTime, handler)) + { + return; + } + } + } + } + + private boolean handleRevision(InternalCDORevision revision, EClass eClass, CDOBranch branch, long timeStamp, + boolean exactTime, CDORevisionHandler handler) + { + if (eClass != null && revision.getEClass() != eClass) + { + return true; + } + + if (branch != null && !ObjectUtil.equals(revision.getBranch(), branch)) + { + return true; + } + + if (timeStamp != CDOBranchPoint.INVALID_DATE) + { + if (exactTime) + { + if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE && revision.getTimeStamp() != timeStamp) + { + return true; + } + } + else + { + if (!revision.isValid(timeStamp)) + { + return true; + } + } + } + + return handler.handleRevision(revision); + } + + /** + * @since 2.0 + */ + public int getListLimit() + { + return listLimit; + } + + /** + * @since 2.0 + */ + public synchronized void setListLimit(int listLimit) + { + if (listLimit != UNLIMITED && this.listLimit != listLimit) + { + for (List<InternalCDORevision> list : revisions.values()) + { + enforceListLimit(list); + } + } + + this.listLimit = listLimit; + } + + /** + * @since 2.0 + */ + public synchronized List<InternalCDORevision> getCurrentRevisions() + { + ArrayList<InternalCDORevision> simpleRevisions = new ArrayList<InternalCDORevision>(); + Iterator<List<InternalCDORevision>> itr = revisions.values().iterator(); + while (itr.hasNext()) + { + List<InternalCDORevision> list = itr.next(); + InternalCDORevision revision = list.get(list.size() - 1); + simpleRevisions.add(revision); + } + + return simpleRevisions; + } + + public synchronized InternalCDORevision getRevisionByVersion(CDOID id, CDOBranchVersion branchVersion) + { + Object listKey = getListKey(id, branchVersion.getBranch()); + List<InternalCDORevision> list = revisions.get(listKey); + if (list == null) + { + return null; + } + + return getRevisionByVersion(list, branchVersion.getVersion()); + } + + /** + * @since 2.0 + */ + public synchronized InternalCDORevision getRevision(CDOID id, CDOBranchPoint branchPoint) + { + Object listKey = getListKey(id, branchPoint.getBranch()); + if (branchPoint.getTimeStamp() == CDORevision.UNSPECIFIED_DATE) + { + List<InternalCDORevision> list = revisions.get(listKey); + if (list == null) + { + return null; + } + + return list.get(list.size() - 1); + } + + if (!getRepository().isSupportingAudits()) + { + throw new UnsupportedOperationException("Auditing not supported"); + } + + List<InternalCDORevision> list = revisions.get(listKey); + if (list == null) + { + return null; + } + + return getRevision(list, branchPoint); + } + + public synchronized void addRevision(InternalCDORevision revision, boolean raw) + { + Object listKey = getListKey(revision.getID(), revision.getBranch()); + List<InternalCDORevision> list = revisions.get(listKey); + if (list == null) + { + list = new ArrayList<InternalCDORevision>(); + revisions.put(listKey, list); + } + + addRevision(list, revision, raw); + + if (raw) + { + ensureLastObjectID(revision.getID()); + } + } + + public synchronized void addCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, + String comment) + { + int index = commitInfos.size() - 1; + while (index >= 0) + { + CommitInfo info = commitInfos.get(index); + if (timeStamp > info.getTimeStamp()) + { + break; + } + + --index; + } + + CommitInfo commitInfo = new CommitInfo(branch, timeStamp, previousTimeStamp, userID, comment); + commitInfos.add(index + 1, commitInfo); + } + + /** + * @since 2.0 + */ + public synchronized boolean rollbackRevision(InternalCDORevision revision) + { + CDOID id = revision.getID(); + CDOBranch branch = revision.getBranch(); + int version = revision.getVersion(); + + Object listKey = getListKey(id, branch); + List<InternalCDORevision> list = revisions.get(listKey); + if (list == null) + { + return false; + } + + for (Iterator<InternalCDORevision> it = list.iterator(); it.hasNext();) + { + InternalCDORevision rev = it.next(); + if (rev.getVersion() == version) + { + it.remove(); + return true; + } + else if (rev.getVersion() == version - 1) + { + rev.setRevised(CDORevision.UNSPECIFIED_DATE); + } + } + + return false; + } + + /** + * @since 3.0 + */ + public synchronized DetachedCDORevision detachObject(CDOID id, CDOBranch branch, long timeStamp) + { + Object listKey = getListKey(id, branch); + List<InternalCDORevision> list = revisions.get(listKey); + if (list != null) + { + InternalCDORevision revision = getRevision(list, branch.getHead()); + if (revision != null) + { + revision.setRevised(timeStamp - 1); + } + } + + int version; + if (list == null) + { + list = new ArrayList<InternalCDORevision>(); + revisions.put(listKey, list); + version = CDOBranchVersion.FIRST_VERSION; + } + else + { + version = getHighestVersion(list) + 1; + } + + EClass eClass = getObjectType(id); + DetachedCDORevision detached = new DetachedCDORevision(eClass, id, branch, version, timeStamp); + addRevision(list, detached, false); + return detached; + } + + /** + * @since 2.0 + */ + public synchronized void queryResources(IStoreAccessor.QueryResourcesContext context) + { + CDOID folderID = context.getFolderID(); + String name = context.getName(); + boolean exactMatch = context.exactMatch(); + for (Entry<Object, List<InternalCDORevision>> entry : revisions.entrySet()) + { + CDOBranch branch = getBranch(entry.getKey()); + if (!ObjectUtil.equals(branch, context.getBranch())) + { + continue; + } + + List<InternalCDORevision> list = entry.getValue(); + if (list.isEmpty()) + { + continue; + } + + InternalCDORevision revision = list.get(0); + if (revision instanceof SyntheticCDORevision) + { + continue; + } + + if (!revision.isResourceNode()) + { + continue; + } + + revision = getRevision(list, context); + if (revision == null || revision instanceof DetachedCDORevision) + { + continue; + } + + CDOID revisionFolder = (CDOID)revision.data().getContainerID(); + if (!CDOIDUtil.equals(revisionFolder, folderID)) + { + continue; + } + + String revisionName = (String)revision.data().get(resourceNameFeature, 0); + boolean useEquals = exactMatch || revisionName == null || name == null; + boolean match = useEquals ? ObjectUtil.equals(revisionName, name) : revisionName.startsWith(name); + + if (match) + { + if (!context.addResource(revision.getID())) + { + // No more results allowed + break; + } + } + } + } + + public synchronized void queryXRefs(QueryXRefsContext context) + { + Set<CDOID> targetIDs = context.getTargetObjects().keySet(); + Map<EClass, List<EReference>> sourceCandidates = context.getSourceCandidates(); + + for (Entry<Object, List<InternalCDORevision>> entry : revisions.entrySet()) + { + CDOBranch branch = getBranch(entry.getKey()); + if (!ObjectUtil.equals(branch, context.getBranch())) + { + continue; + } + + List<InternalCDORevision> list = entry.getValue(); + if (list.isEmpty()) + { + continue; + } + + InternalCDORevision revision = getRevision(list, context); + if (revision == null || revision instanceof SyntheticCDORevision) + { + continue; + } + + EClass eClass = revision.getEClass(); + CDOID sourceID = revision.getID(); + + List<EReference> eReferences = sourceCandidates.get(eClass); + if (eReferences != null) + { + for (EReference eReference : eReferences) + { + Object value = revision.getValue(eReference); + if (value != null) + { + if (eReference.isMany()) + { + @SuppressWarnings("unchecked") + List<CDOID> ids = (List<CDOID>)value; + int index = 0; + for (CDOID id : ids) + { + if (!queryXRefs(context, targetIDs, id, sourceID, eReference, index++)) + { + return; + } + } + } + else + { + CDOID id = (CDOID)value; + if (!queryXRefs(context, targetIDs, id, sourceID, eReference, 0)) + { + return; + } + } + } + } + } + } + } + + private boolean queryXRefs(QueryXRefsContext context, Set<CDOID> targetIDs, CDOID targetID, CDOID sourceID, + EReference sourceReference, int index) + { + for (CDOID id : targetIDs) + { + if (id.equals(targetID)) + { + if (!context.addXRef(targetID, sourceID, sourceReference, index)) + { + // No more results allowed + return false; + } + } + } + + return true; + } + + public synchronized void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, + long toCommitTime) + { + // TODO: implement MEMStore.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime) + throw new UnsupportedOperationException(); + } + + public synchronized void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, + long toCommitTime, OMMonitor monitor) + { + // TODO: implement MEMStore.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime, monitor) + throw new UnsupportedOperationException(); + } + + public synchronized void rawDelete(CDOID id, int version, CDOBranch branch) + { + Object listKey = getListKey(id, branch); + List<InternalCDORevision> list = revisions.get(listKey); + if (list != null) + { + for (Iterator<InternalCDORevision> it = list.iterator(); it.hasNext();) + { + InternalCDORevision rev = it.next(); + if (rev.getVersion() == version) + { + it.remove(); + break; + } + } + } + } + + public synchronized LockArea createLockArea(String userID, CDOBranchPoint branchPoint, boolean readOnly, + Map<CDOID, LockGrade> locks) + { + return createLockArea(null, userID, branchPoint, readOnly, locks); + } + + public synchronized LockArea createLockArea(String durableLockingID, String userID, CDOBranchPoint branchPoint, + boolean readOnly, Map<CDOID, LockGrade> locks) + { + if (durableLockingID != null) + { + // If the caller is specifying the ID, make sure there is no area with this ID yet + if (lockAreas.containsKey(durableLockingID)) + { + throw new LockAreaAlreadyExistsException(durableLockingID); + } + } + else + { + do + { + durableLockingID = CDOLockUtil.createDurableLockingID(); + } while (lockAreas.containsKey(durableLockingID)); + } + + LockArea area = CDOLockUtil.createLockArea(durableLockingID, userID, branchPoint, readOnly, locks); + lockAreas.put(durableLockingID, area); + return area; + } + + public synchronized void updateLockArea(LockArea lockArea) + { + String durableLockingID = lockArea.getDurableLockingID(); + lockAreas.put(durableLockingID, lockArea); + } + + public synchronized LockArea getLockArea(String durableLockingID) throws LockAreaNotFoundException + { + LockArea area = lockAreas.get(durableLockingID); + if (area == null) + { + throw new LockAreaNotFoundException(durableLockingID); + } + + return area; + } + + public synchronized void getLockAreas(String userIDPrefix, Handler handler) + { + for (LockArea area : lockAreas.values()) + { + String userID = area.getUserID(); + if (userID == null || userID.startsWith(userIDPrefix)) + { + if (!handler.handleLockArea(area)) + { + return; + } + } + } + } + + public synchronized void deleteLockArea(String durableLockingID) + { + lockAreas.remove(durableLockingID); + } + + public synchronized void lock(String durableLockingID, LockType type, Collection<? extends Object> objectsToLock) + { + LockArea area = getLockArea(durableLockingID); + Map<CDOID, LockGrade> locks = area.getLocks(); + + InternalLockManager lockManager = getRepository().getLockingManager(); + for (Object objectToLock : objectsToLock) + { + CDOID id = lockManager.getLockKeyID(objectToLock); + LockGrade grade = locks.get(id); + if (grade != null) + { + grade = grade.getUpdated(type, true); + } + else + { + grade = LockGrade.get(type); + } + + locks.put(id, grade); + } + } + + public synchronized void unlock(String durableLockingID, LockType type, Collection<? extends Object> objectsToUnlock) + { + LockArea area = getLockArea(durableLockingID); + Map<CDOID, LockGrade> locks = area.getLocks(); + + InternalLockManager lockManager = getRepository().getLockingManager(); + for (Object objectToUnlock : objectsToUnlock) + { + CDOID id = lockManager.getLockKeyID(objectToUnlock); + LockGrade grade = locks.get(id); + if (grade != null) + { + grade = grade.getUpdated(type, false); + if (grade == LockGrade.NONE) + { + locks.remove(id); + } + } + } + } + + public synchronized void unlock(String durableLockingID) + { + LockArea area = getLockArea(durableLockingID); + Map<CDOID, LockGrade> locks = area.getLocks(); + locks.clear(); + } + + public synchronized void queryLobs(List<byte[]> ids) + { + for (Iterator<byte[]> it = ids.iterator(); it.hasNext();) + { + byte[] id = it.next(); + String key = HexUtil.bytesToHex(id); + if (!lobs.containsKey(key)) + { + it.remove(); + } + } + } + + public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException + { + for (Entry<String, Object> entry : lobs.entrySet()) + { + byte[] id = HexUtil.hexToBytes(entry.getKey()); + Object lob = entry.getValue(); + if (lob instanceof byte[]) + { + byte[] blob = (byte[])lob; + ByteArrayInputStream in = new ByteArrayInputStream(blob); + OutputStream out = handler.handleBlob(id, blob.length); + if (out != null) + { + try + { + IOUtil.copyBinary(in, out, blob.length); + } + finally + { + IOUtil.close(out); + } + } + } + else + { + char[] clob = (char[])lob; + CharArrayReader in = new CharArrayReader(clob); + Writer out = handler.handleClob(id, clob.length); + if (out != null) + { + try + { + IOUtil.copyCharacter(in, out, clob.length); + } + finally + { + IOUtil.close(out); + } + } + } + } + } + + public synchronized void loadLob(byte[] id, OutputStream out) throws IOException + { + String key = HexUtil.bytesToHex(id); + Object lob = lobs.get(key); + if (lob == null) + { + throw new IOException("Lob not found: " + key); + } + + if (lob instanceof byte[]) + { + byte[] blob = (byte[])lob; + ByteArrayInputStream in = new ByteArrayInputStream(blob); + IOUtil.copyBinary(in, out, blob.length); + } + else + { + char[] clob = (char[])lob; + CharArrayReader in = new CharArrayReader(clob); + IOUtil.copyCharacter(in, new OutputStreamWriter(out), clob.length); + } + } + + public synchronized void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + IOUtil.copyBinary(inputStream, out, size); + lobs.put(HexUtil.bytesToHex(id), out.toByteArray()); + } + + public synchronized void writeClob(byte[] id, long size, Reader reader) throws IOException + { + CharArrayWriter out = new CharArrayWriter(); + IOUtil.copyCharacter(reader, out, size); + lobs.put(HexUtil.bytesToHex(id), out.toCharArray()); + } + + @Override + public MEMStoreAccessor createReader(ISession session) + { + return new MEMStoreAccessor(this, session); + } + + /** + * @since 2.0 + */ + @Override + public MEMStoreAccessor createWriter(ITransaction transaction) + { + return new MEMStoreAccessor(this, transaction); + } + + /** + * @since 2.0 + */ + public long getCreationTime() + { + return creationTime; + } + + public void setCreationTime(long creationTime) + { + this.creationTime = creationTime; + } + + public boolean isFirstStart() + { + return true; + } + + public synchronized Map<CDOBranch, List<CDORevision>> getAllRevisions() + { + Map<CDOBranch, List<CDORevision>> result = new HashMap<CDOBranch, List<CDORevision>>(); + InternalCDOBranchManager branchManager = getRepository().getBranchManager(); + result.put(branchManager.getMainBranch(), new ArrayList<CDORevision>()); + + for (Integer branchID : branchInfos.keySet()) + { + InternalCDOBranch branch = branchManager.getBranch(branchID); + result.put(branch, new ArrayList<CDORevision>()); + } + + for (List<InternalCDORevision> list : revisions.values()) + { + for (InternalCDORevision revision : list) + { + CDOBranch branch = revision.getBranch(); + List<CDORevision> resultList = result.get(branch); + resultList.add(revision); + } + } + + return result; + } + + public synchronized EClass getObjectType(CDOID id) + { + return objectTypes.get(id); + } + + /** + * @since 2.0 + */ + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + creationTime = getRepository().getTimeStamp(); + + if (getRepository().getIDGenerationLocation() == IDGenerationLocation.CLIENT) + { + setObjectIDTypes(Collections.singleton(CDOID.ObjectType.UUID)); + } + } + + @Override + protected void doDeactivate() throws Exception + { + revisions.clear(); + branchInfos.clear(); + commitInfos.clear(); + objectTypes.clear(); + properties.clear(); + resourceNameFeature = null; + lastBranchID = 0; + lastLocalBranchID = 0; + super.doDeactivate(); + } + + @Override + protected StoreAccessorPool getReaderPool(ISession session, boolean forReleasing) + { + // Pooling of store accessors not supported + return null; + } + + @Override + protected StoreAccessorPool getWriterPool(IView view, boolean forReleasing) + { + // Pooling of store accessors not supported + return null; + } + + private Object getListKey(CDOID id, CDOBranch branch) + { + if (getRevisionParallelism() == RevisionParallelism.NONE) + { + return id; + } + + return new ListKey(id, branch); + } + + private CDOBranch getBranch(Object key) + { + if (key instanceof ListKey) + { + return ((ListKey)key).getBranch(); + } + + return getRepository().getBranchManager().getMainBranch(); + } + + private int getHighestVersion(List<InternalCDORevision> list) + { + int version = CDOBranchVersion.UNSPECIFIED_VERSION; + for (InternalCDORevision revision : list) + { + if (revision.getVersion() > version) + { + version = revision.getVersion(); + } + } + + return version; + } + + private InternalCDORevision getRevisionByVersion(List<InternalCDORevision> list, int version) + { + for (InternalCDORevision revision : list) + { + if (revision.getVersion() == version) + { + return revision; + } + } + + return null; + } + + private InternalCDORevision getRevision(List<InternalCDORevision> list, CDOBranchPoint branchPoint) + { + long timeStamp = branchPoint.getTimeStamp(); + for (InternalCDORevision revision : list) + { + if (timeStamp == CDORevision.UNSPECIFIED_DATE) + { + if (!revision.isHistorical()) + { + return revision; + } + } + else + { + if (revision.isValid(timeStamp)) + { + return revision; + } + } + } + + return null; + } + + private void addRevision(List<InternalCDORevision> list, InternalCDORevision revision, boolean raw) + { + boolean resource = !(revision instanceof SyntheticCDORevision) && revision.isResource(); + if (resource && resourceNameFeature == null) + { + resourceNameFeature = revision.getEClass().getEStructuralFeature(CDOModelConstants.RESOURCE_NODE_NAME_ATTRIBUTE); + } + + if (!raw) + { + // Check version conflict + int version = revision.getVersion(); + InternalCDORevision rev = getRevisionByVersion(list, version); + if (rev != null) + { + rev = getRevisionByVersion(list, version); + throw new IllegalStateException("Concurrent modification of " + rev.getEClass().getName() + "@" + rev.getID()); + } + + // Revise old revision + int oldVersion = version - 1; + if (oldVersion >= CDORevision.UNSPECIFIED_VERSION) + { + InternalCDORevision oldRevision = getRevisionByVersion(list, oldVersion); + if (oldRevision != null) + { + if (getRepository().isSupportingAudits()) + { + oldRevision.setRevised(revision.getTimeStamp() - 1); + } + else + { + list.remove(oldRevision); + } + } + } + + // Check duplicate resource + if (resource) + { + checkDuplicateResource(revision); + } + } + + // Adjust the list + list.add(revision); + if (listLimit != UNLIMITED) + { + enforceListLimit(list); + } + + CDOID id = revision.getID(); + if (!objectTypes.containsKey(id)) + { + objectTypes.put(id, revision.getEClass()); + } + } + + private void checkDuplicateResource(InternalCDORevision revision) + { + CDOID revisionFolder = (CDOID)revision.data().getContainerID(); + String revisionName = (String)revision.data().get(resourceNameFeature, 0); + + IStoreAccessor accessor = StoreThreadLocal.getAccessor(); + + CDOID resourceID = accessor.readResourceID(revisionFolder, revisionName, revision); + if (!CDOIDUtil.isNull(resourceID)) + { + throw new IllegalStateException("Duplicate resource: name=" + revisionName + ", folderID=" + revisionFolder); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + private void enforceListLimit(List<InternalCDORevision> list) + { + while (list.size() > listLimit) + { + list.remove(0); + } + } + + /** + * @author Eike Stepper + */ + private static final class ListKey + { + private CDOID id; + + private CDOBranch branch; + + public ListKey(CDOID id, CDOBranch branch) + { + this.id = id; + this.branch = branch; + } + + public CDOID getID() + { + return id; + } + + public CDOBranch getBranch() + { + return branch; + } + + @Override + public int hashCode() + { + return id.hashCode() ^ branch.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + + if (obj instanceof ListKey) + { + ListKey that = (ListKey)obj; + return ObjectUtil.equals(id, that.getID()) && ObjectUtil.equals(branch, that.getBranch()); + } + + return false; + } + + @Override + public String toString() + { + return MessageFormat.format("{0}:{1}", id, branch.getID()); + } + } + + /** + * @author Eike Stepper + */ + private static final class CommitInfo + { + private CDOBranch branch; + + private long timeStamp; + + private long previousTimeStamp; + + private String userID; + + private String comment; + + public CommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, String comment) + { + this.branch = branch; + this.timeStamp = timeStamp; + this.previousTimeStamp = previousTimeStamp; + this.userID = userID; + this.comment = comment; + } + + public CDOBranch getBranch() + { + return branch; + } + + public long getTimeStamp() + { + return timeStamp; + } + + public void handle(InternalCDOCommitInfoManager manager, CDOCommitInfoHandler handler) + { + CDOCommitInfo commitInfo = manager.createCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, null); + handler.handleCommitInfo(commitInfo); + } + + @Override + public String toString() + { + return MessageFormat.format("CommitInfo[{0}, {1}, {2}, {3}, {4}]", branch, timeStamp, previousTimeStamp, userID, + comment); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreChunkReader.java index 5fba594b19..2f1aa7c0cb 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreChunkReader.java @@ -1,67 +1,67 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server.mem;
-
-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.server.IStoreAccessor;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.server.StoreChunkReader;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.List;
-
-/**
- * @author Simon McDuff
- */
-public class MEMStoreChunkReader extends StoreChunkReader
-{
- /**
- * @since 2.0
- */
- public MEMStoreChunkReader(IStoreAccessor accessor, CDORevision revision, EStructuralFeature feature)
- {
- super(accessor, revision, feature);
- }
-
- public List<Chunk> executeRead()
- {
- CDOID id = getRevision().getID();
- CDOBranchVersion branchVersion = getRevision();
-
- MEMStore store = getAccessor().getStore();
- List<Chunk> chunks = getChunks();
- for (Chunk chunk : chunks)
- {
- int startIndex = chunk.getStartIndex();
- InternalCDORevision revision = store.getRevisionByVersion(id, branchVersion);
- for (int i = 0; i < chunk.size(); i++)
- {
- Object object = revision.get(getFeature(), startIndex + i);
- chunk.add(i, object);
- }
- }
-
- return chunks;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public MEMStoreAccessor getAccessor()
- {
- return (MEMStoreAccessor)super.getAccessor();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server.mem; + +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.server.IStoreAccessor; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.server.StoreChunkReader; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.List; + +/** + * @author Simon McDuff + */ +public class MEMStoreChunkReader extends StoreChunkReader +{ + /** + * @since 2.0 + */ + public MEMStoreChunkReader(IStoreAccessor accessor, CDORevision revision, EStructuralFeature feature) + { + super(accessor, revision, feature); + } + + public List<Chunk> executeRead() + { + CDOID id = getRevision().getID(); + CDOBranchVersion branchVersion = getRevision(); + + MEMStore store = getAccessor().getStore(); + List<Chunk> chunks = getChunks(); + for (Chunk chunk : chunks) + { + int startIndex = chunk.getStartIndex(); + InternalCDORevision revision = store.getRevisionByVersion(id, branchVersion); + for (int i = 0; i < chunk.size(); i++) + { + Object object = revision.get(getFeature(), startIndex + i); + chunk.add(i, object); + } + } + + return chunks; + } + + /** + * @since 2.0 + */ + @Override + public MEMStoreAccessor getAccessor() + { + return (MEMStoreAccessor)super.getAccessor(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreFactory.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreFactory.java index 85ddafc8d7..e2f9186513 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreFactory.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreFactory.java @@ -1,39 +1,39 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server.mem;
-
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreFactory;
-
-import org.w3c.dom.Element;
-
-import java.util.Map;
-
-/**
- * @author Simon McDuff
- */
-public class MEMStoreFactory implements IStoreFactory
-{
- public MEMStoreFactory()
- {
- }
-
- public String getStoreType()
- {
- return MEMStore.TYPE;
- }
-
- public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig)
- {
- return new MEMStore();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server.mem; + +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStoreFactory; + +import org.w3c.dom.Element; + +import java.util.Map; + +/** + * @author Simon McDuff + */ +public class MEMStoreFactory implements IStoreFactory +{ + public MEMStoreFactory() + { + } + + public String getStoreType() + { + return MEMStore.TYPE; + } + + public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig) + { + return new MEMStore(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/Messages.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/Messages.java index c851acfac5..e5cd831163 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/Messages.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/Messages.java @@ -1,41 +1,41 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Victor Roldan Betancort - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.internal.server.messages;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @author Victor Roldan Betancort
- */
-public class Messages
-{
- private static final String BUNDLE_NAME = "org.eclipse.emf.cdo.internal.server.messages.messages"; //$NON-NLS-1$
-
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
-
- private Messages()
- {
- }
-
- public static String getString(String key)
- {
- try
- {
- return RESOURCE_BUNDLE.getString(key);
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Victor Roldan Betancort - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.internal.server.messages; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * @author Victor Roldan Betancort + */ +public class Messages +{ + private static final String BUNDLE_NAME = "org.eclipse.emf.cdo.internal.server.messages.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/messages.properties b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/messages.properties index d5dabe5342..0943b4030f 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/messages.properties +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/messages/messages.properties @@ -1,16 +1,16 @@ -# Copyright (c) 2004 - 2012 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:
-# Victor Roldan Betancort - initial API and implementation
-# Eike Stepper - maintenance
-
-CDOServerApplication.1=CDO server starting
-CDOServerApplication.6=CDO server started
-CDOServerApplication.7=CDO server stopping
-CDOServerApplication.8=CDO server stopped
-CDOServerApplication.5=CDO server configuration not found:
-CDOServerApplication.3=No CDO repositories configured:
+# Copyright (c) 2004 - 2012 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: +# Victor Roldan Betancort - initial API and implementation +# Eike Stepper - maintenance + +CDOServerApplication.1=CDO server starting +CDOServerApplication.6=CDO server started +CDOServerApplication.7=CDO server stopping +CDOServerApplication.8=CDO server stopped +CDOServerApplication.5=CDO server configuration not found: +CDOServerApplication.3=No CDO repositories configured: diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/FailoverParticipant.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/FailoverParticipant.java index 30a5c374a1..9ef66621a5 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/FailoverParticipant.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/FailoverParticipant.java @@ -1,131 +1,131 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.syncing;
-
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalFailoverParticipant;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-/**
- * @author Eike Stepper
- */
-public class FailoverParticipant extends SynchronizableRepository implements InternalFailoverParticipant
-{
- private boolean allowBackupCommits;
-
- public FailoverParticipant()
- {
- setState(OFFLINE);
- }
-
- public boolean isAllowBackupCommits()
- {
- return allowBackupCommits;
- }
-
- public void setAllowBackupCommits(boolean allowBackupCommits)
- {
- this.allowBackupCommits = allowBackupCommits;
- }
-
- @Override
- public void setType(Type type)
- {
- checkArg(type == MASTER || type == BACKUP, "Type must be MASTER or BACKUP");
- super.setType(type);
- }
-
- @Override
- protected void changingType(Type oldType, Type newType)
- {
- if (isActive())
- {
- if (newType == MASTER)
- {
- // Switch off synchronizer
- doStopSynchronization();
- }
- else
- {
- // Bug 312879
- setReplicationCountersToLatest();
-
- // Switch on synchronizer
- doStartSynchronization();
- }
- }
-
- super.changingType(oldType, newType);
- }
-
- @Override
- protected void initRootResource()
- {
- if (getType() == BACKUP)
- {
- super.initRootResource();
- }
- else
- {
- doInitRootResource();
- }
- }
-
- protected void doStartSynchronization()
- {
- super.startSynchronization();
- }
-
- protected void doStopSynchronization()
- {
- super.stopSynchronization();
- }
-
- @Override
- protected void startSynchronization()
- {
- if (getType() == BACKUP)
- {
- doStartSynchronization();
- }
- }
-
- @Override
- protected void stopSynchronization()
- {
- if (getType() == BACKUP)
- {
- doStopSynchronization();
- }
- }
-
- @Override
- public InternalCommitContext createCommitContext(InternalTransaction transaction)
- {
- if (getType() == BACKUP)
- {
- if (getState() != ONLINE)
- {
- throw new IllegalStateException("Backup repository is not online");
- }
-
- if (allowBackupCommits || transaction.getSession() == getReplicatorSession())
- {
- return createWriteThroughCommitContext(transaction);
- }
-
- throw new IllegalStateException(
- "Only the repository synchronizer is allowed to commit transactions to a backup repository");
- }
-
- return createNormalCommitContext(transaction);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.syncing; + +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; +import org.eclipse.emf.cdo.spi.server.InternalFailoverParticipant; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +/** + * @author Eike Stepper + */ +public class FailoverParticipant extends SynchronizableRepository implements InternalFailoverParticipant +{ + private boolean allowBackupCommits; + + public FailoverParticipant() + { + setState(OFFLINE); + } + + public boolean isAllowBackupCommits() + { + return allowBackupCommits; + } + + public void setAllowBackupCommits(boolean allowBackupCommits) + { + this.allowBackupCommits = allowBackupCommits; + } + + @Override + public void setType(Type type) + { + checkArg(type == MASTER || type == BACKUP, "Type must be MASTER or BACKUP"); + super.setType(type); + } + + @Override + protected void changingType(Type oldType, Type newType) + { + if (isActive()) + { + if (newType == MASTER) + { + // Switch off synchronizer + doStopSynchronization(); + } + else + { + // Bug 312879 + setReplicationCountersToLatest(); + + // Switch on synchronizer + doStartSynchronization(); + } + } + + super.changingType(oldType, newType); + } + + @Override + protected void initRootResource() + { + if (getType() == BACKUP) + { + super.initRootResource(); + } + else + { + doInitRootResource(); + } + } + + protected void doStartSynchronization() + { + super.startSynchronization(); + } + + protected void doStopSynchronization() + { + super.stopSynchronization(); + } + + @Override + protected void startSynchronization() + { + if (getType() == BACKUP) + { + doStartSynchronization(); + } + } + + @Override + protected void stopSynchronization() + { + if (getType() == BACKUP) + { + doStopSynchronization(); + } + } + + @Override + public InternalCommitContext createCommitContext(InternalTransaction transaction) + { + if (getType() == BACKUP) + { + if (getState() != ONLINE) + { + throw new IllegalStateException("Backup repository is not online"); + } + + if (allowBackupCommits || transaction.getSession() == getReplicatorSession()) + { + return createWriteThroughCommitContext(transaction); + } + + throw new IllegalStateException( + "Only the repository synchronizer is allowed to commit transactions to a backup repository"); + } + + return createNormalCommitContext(transaction); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/OfflineClone.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/OfflineClone.java index 7c6c029038..21795fffb9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/OfflineClone.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/OfflineClone.java @@ -1,111 +1,111 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.syncing;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.internal.server.TransactionCommitContext;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-import org.eclipse.net4j.util.om.monitor.Monitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-/**
- * @author Eike Stepper
- */
-public class OfflineClone extends SynchronizableRepository
-{
- public OfflineClone()
- {
- setState(OFFLINE);
- }
-
- @Override
- public final Type getType()
- {
- return CLONE;
- }
-
- @Override
- public final void setType(Type type)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public InternalCommitContext createCommitContext(InternalTransaction transaction)
- {
- CDOBranch branch = transaction.getBranch();
- if (branch.isLocal())
- {
- return createNormalCommitContext(transaction);
- }
-
- if (getState() != ONLINE)
- {
- return createBranchingCommitContext(transaction, branch);
- }
-
- return createWriteThroughCommitContext(transaction);
- }
-
- protected InternalCommitContext createBranchingCommitContext(InternalTransaction transaction, CDOBranch branch)
- {
- long[] times = createCommitTimeStamp(new Monitor());
- CDOBranch offlineBranch = createOfflineBranch(branch, times[0] - 1L);
- transaction.setBranchPoint(offlineBranch.getHead());
- return new BranchingCommitContext(transaction, times);
- }
-
- protected CDOBranch createOfflineBranch(CDOBranch baseBranch, long baseTimeStamp)
- {
- try
- {
- StoreThreadLocal.setSession(getReplicatorSession());
- InternalCDOBranchManager branchManager = getBranchManager();
- return branchManager.createBranch(NEW_LOCAL_BRANCH,
- "Offline-" + baseTimeStamp, (InternalCDOBranch)baseBranch, baseTimeStamp); //$NON-NLS-1$
- }
- finally
- {
- StoreThreadLocal.release();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- protected final class BranchingCommitContext extends TransactionCommitContext
- {
- private long[] times;
-
- public BranchingCommitContext(InternalTransaction transaction, long[] times)
- {
- super(transaction);
- this.times = times;
- }
-
- @Override
- protected void lockObjects() throws InterruptedException
- {
- // Do nothing
- }
-
- @Override
- protected long[] createTimeStamp(OMMonitor monitor)
- {
- return times;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.syncing; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.internal.server.TransactionCommitContext; +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +import org.eclipse.net4j.util.om.monitor.Monitor; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +/** + * @author Eike Stepper + */ +public class OfflineClone extends SynchronizableRepository +{ + public OfflineClone() + { + setState(OFFLINE); + } + + @Override + public final Type getType() + { + return CLONE; + } + + @Override + public final void setType(Type type) + { + throw new UnsupportedOperationException(); + } + + @Override + public InternalCommitContext createCommitContext(InternalTransaction transaction) + { + CDOBranch branch = transaction.getBranch(); + if (branch.isLocal()) + { + return createNormalCommitContext(transaction); + } + + if (getState() != ONLINE) + { + return createBranchingCommitContext(transaction, branch); + } + + return createWriteThroughCommitContext(transaction); + } + + protected InternalCommitContext createBranchingCommitContext(InternalTransaction transaction, CDOBranch branch) + { + long[] times = createCommitTimeStamp(new Monitor()); + CDOBranch offlineBranch = createOfflineBranch(branch, times[0] - 1L); + transaction.setBranchPoint(offlineBranch.getHead()); + return new BranchingCommitContext(transaction, times); + } + + protected CDOBranch createOfflineBranch(CDOBranch baseBranch, long baseTimeStamp) + { + try + { + StoreThreadLocal.setSession(getReplicatorSession()); + InternalCDOBranchManager branchManager = getBranchManager(); + return branchManager.createBranch(NEW_LOCAL_BRANCH, + "Offline-" + baseTimeStamp, (InternalCDOBranch)baseBranch, baseTimeStamp); //$NON-NLS-1$ + } + finally + { + StoreThreadLocal.release(); + } + } + + /** + * @author Eike Stepper + */ + protected final class BranchingCommitContext extends TransactionCommitContext + { + private long[] times; + + public BranchingCommitContext(InternalTransaction transaction, long[] times) + { + super(transaction); + this.times = times; + } + + @Override + protected void lockObjects() throws InterruptedException + { + // Do nothing + } + + @Override + protected long[] createTimeStamp(OMMonitor monitor) + { + return times; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/ReplicatorCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/ReplicatorCommitContext.java index 1e8e6db72f..e43a7a493b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/ReplicatorCommitContext.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/ReplicatorCommitContext.java @@ -1,171 +1,171 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.server.syncing;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.internal.server.TransactionCommitContext;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalTransaction;
-
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import java.util.List;
-
-/**
- * TODO Optimize createCommitInfo()
- *
- * @author Eike Stepper
- */
-public final class ReplicatorCommitContext extends TransactionCommitContext
-{
- private final CDOCommitInfo commitInfo;
-
- public ReplicatorCommitContext(InternalTransaction transaction, CDOCommitInfo commitInfo)
- {
- super(transaction);
- this.commitInfo = commitInfo;
-
- setCommitComment(commitInfo.getComment());
-
- InternalCDOPackageUnit[] newPackageUnits = getNewPackageUnits(commitInfo, getPackageRegistry());
- setNewPackageUnits(newPackageUnits);
-
- InternalCDORevision[] newObjects = getNewObjects(commitInfo);
- setNewObjects(newObjects);
-
- InternalCDORevisionDelta[] dirtyObjectDeltas = getDirtyObjectDeltas(commitInfo);
- setDirtyObjectDeltas(dirtyObjectDeltas);
-
- CDOID[] detachedObjects = getDetachedObjects(commitInfo);
- setDetachedObjects(detachedObjects);
- }
-
- @Override
- public String getUserID()
- {
- return commitInfo.getUserID();
- }
-
- @Override
- protected long[] createTimeStamp(OMMonitor monitor)
- {
- InternalRepository repository = getTransaction().getSession().getManager().getRepository();
-
- long commitTimeStamp = commitInfo.getTimeStamp();
- if (commitTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE)
- {
- commitTimeStamp = repository.getTimeStamp();
- }
-
- return repository.forceCommitTimeStamp(commitInfo.getTimeStamp(), monitor);
- }
-
- @Override
- protected void adjustForCommit()
- {
- // Do nothing
- }
-
- @Override
- public void applyIDMappings(OMMonitor monitor)
- {
- monitor.begin();
-
- try
- {
- notifyBeforeCommitting(monitor);
- }
- finally
- {
- monitor.done();
- }
- }
-
- @Override
- protected void lockObjects() throws InterruptedException
- {
- // Do nothing
- }
-
- @Override
- protected void checkXRefs()
- {
- // Do nothing
- }
-
- private static InternalCDOPackageUnit[] getNewPackageUnits(CDOCommitInfo commitInfo,
- InternalCDOPackageRegistry packageRegistry)
- {
- List<CDOPackageUnit> list = commitInfo.getNewPackageUnits();
- InternalCDOPackageUnit[] result = new InternalCDOPackageUnit[list.size()];
-
- int i = 0;
- for (CDOPackageUnit packageUnit : list)
- {
- result[i] = (InternalCDOPackageUnit)packageUnit;
- packageRegistry.putPackageUnit(result[i]);
- ++i;
- }
-
- return result;
- }
-
- private static InternalCDORevision[] getNewObjects(CDOCommitInfo commitInfo)
- {
- List<CDOIDAndVersion> list = commitInfo.getNewObjects();
- InternalCDORevision[] result = new InternalCDORevision[list.size()];
-
- int i = 0;
- for (CDOIDAndVersion revision : list)
- {
- result[i++] = (InternalCDORevision)revision;
- }
-
- return result;
- }
-
- private static InternalCDORevisionDelta[] getDirtyObjectDeltas(CDOCommitInfo commitInfo)
- {
- List<CDORevisionKey> list = commitInfo.getChangedObjects();
- InternalCDORevisionDelta[] result = new InternalCDORevisionDelta[list.size()];
-
- int i = 0;
- for (CDORevisionKey delta : list)
- {
- result[i++] = (InternalCDORevisionDelta)delta;
- }
-
- return result;
- }
-
- private static CDOID[] getDetachedObjects(CDOCommitInfo commitInfo)
- {
- List<CDOIDAndVersion> list = commitInfo.getDetachedObjects();
- CDOID[] result = new CDOID[list.size()];
-
- int i = 0;
- for (CDOIDAndVersion key : list)
- {
- result[i++] = key.getID();
- }
-
- return result;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.server.syncing; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.internal.server.TransactionCommitContext; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; +import org.eclipse.emf.cdo.spi.server.InternalRepository; +import org.eclipse.emf.cdo.spi.server.InternalTransaction; + +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.util.List; + +/** + * TODO Optimize createCommitInfo() + * + * @author Eike Stepper + */ +public final class ReplicatorCommitContext extends TransactionCommitContext +{ + private final CDOCommitInfo commitInfo; + + public ReplicatorCommitContext(InternalTransaction transaction, CDOCommitInfo commitInfo) + { + super(transaction); + this.commitInfo = commitInfo; + + setCommitComment(commitInfo.getComment()); + + InternalCDOPackageUnit[] newPackageUnits = getNewPackageUnits(commitInfo, getPackageRegistry()); + setNewPackageUnits(newPackageUnits); + + InternalCDORevision[] newObjects = getNewObjects(commitInfo); + setNewObjects(newObjects); + + InternalCDORevisionDelta[] dirtyObjectDeltas = getDirtyObjectDeltas(commitInfo); + setDirtyObjectDeltas(dirtyObjectDeltas); + + CDOID[] detachedObjects = getDetachedObjects(commitInfo); + setDetachedObjects(detachedObjects); + } + + @Override + public String getUserID() + { + return commitInfo.getUserID(); + } + + @Override + protected long[] createTimeStamp(OMMonitor monitor) + { + InternalRepository repository = getTransaction().getSession().getManager().getRepository(); + + long commitTimeStamp = commitInfo.getTimeStamp(); + if (commitTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE) + { + commitTimeStamp = repository.getTimeStamp(); + } + + return repository.forceCommitTimeStamp(commitInfo.getTimeStamp(), monitor); + } + + @Override + protected void adjustForCommit() + { + // Do nothing + } + + @Override + public void applyIDMappings(OMMonitor monitor) + { + monitor.begin(); + + try + { + notifyBeforeCommitting(monitor); + } + finally + { + monitor.done(); + } + } + + @Override + protected void lockObjects() throws InterruptedException + { + // Do nothing + } + + @Override + protected void checkXRefs() + { + // Do nothing + } + + private static InternalCDOPackageUnit[] getNewPackageUnits(CDOCommitInfo commitInfo, + InternalCDOPackageRegistry packageRegistry) + { + List<CDOPackageUnit> list = commitInfo.getNewPackageUnits(); + InternalCDOPackageUnit[] result = new InternalCDOPackageUnit[list.size()]; + + int i = 0; + for (CDOPackageUnit packageUnit : list) + { + result[i] = (InternalCDOPackageUnit)packageUnit; + packageRegistry.putPackageUnit(result[i]); + ++i; + } + + return result; + } + + private static InternalCDORevision[] getNewObjects(CDOCommitInfo commitInfo) + { + List<CDOIDAndVersion> list = commitInfo.getNewObjects(); + InternalCDORevision[] result = new InternalCDORevision[list.size()]; + + int i = 0; + for (CDOIDAndVersion revision : list) + { + result[i++] = (InternalCDORevision)revision; + } + + return result; + } + + private static InternalCDORevisionDelta[] getDirtyObjectDeltas(CDOCommitInfo commitInfo) + { + List<CDORevisionKey> list = commitInfo.getChangedObjects(); + InternalCDORevisionDelta[] result = new InternalCDORevisionDelta[list.size()]; + + int i = 0; + for (CDORevisionKey delta : list) + { + result[i++] = (InternalCDORevisionDelta)delta; + } + + return result; + } + + private static CDOID[] getDetachedObjects(CDOCommitInfo commitInfo) + { + List<CDOIDAndVersion> list = commitInfo.getDetachedObjects(); + CDOID[] result = new CDOID[list.size()]; + + int i = 0; + for (CDOIDAndVersion key : list) + { + result[i++] = key.getID(); + } + + return result; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ContainmentCycleDetectedException.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ContainmentCycleDetectedException.java index 057905b047..6f24f060e3 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ContainmentCycleDetectedException.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ContainmentCycleDetectedException.java @@ -1,42 +1,42 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-/**
- * An unchecked exception that is thrown from concurrent commit operations if cycles in the tree containmnent structure
- * would result.
- *
- * @author Eike Stepper
- * @since 4.0
- */
-public class ContainmentCycleDetectedException extends IllegalStateException
-{
- private static final long serialVersionUID = 1L;
-
- public ContainmentCycleDetectedException()
- {
- }
-
- public ContainmentCycleDetectedException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public ContainmentCycleDetectedException(String s)
- {
- super(s);
- }
-
- public ContainmentCycleDetectedException(Throwable cause)
- {
- super(cause);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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; + +/** + * An unchecked exception that is thrown from concurrent commit operations if cycles in the tree containmnent structure + * would result. + * + * @author Eike Stepper + * @since 4.0 + */ +public class ContainmentCycleDetectedException extends IllegalStateException +{ + private static final long serialVersionUID = 1L; + + public ContainmentCycleDetectedException() + { + } + + public ContainmentCycleDetectedException(String message, Throwable cause) + { + super(message, cause); + } + + public ContainmentCycleDetectedException(String s) + { + super(s); + } + + public ContainmentCycleDetectedException(Throwable cause) + { + super(cause); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ILockingManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ILockingManager.java index d3989bb6b0..dcf0452d5e 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ILockingManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ILockingManager.java @@ -1,47 +1,47 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Caspar De Groot - initial API and implementation
- */
-package org.eclipse.emf.cdo.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonSession;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager;
-
-/**
- * Manages all persistent aspects of durable CDO views and provides for vetoable
- * {@link #addDurableViewHandler(ILockingManager.DurableViewHandler) interception} of the durable view resumption
- * process.
- *
- * @author Caspar De Groot
- * @since 4.1
- */
-public interface ILockingManager extends IDurableLockingManager
-{
- public void addDurableViewHandler(DurableViewHandler handler);
-
- public void removeDurableViewHandler(DurableViewHandler handler);
-
- public DurableViewHandler[] getDurableViewHandlers();
-
- /**
- * A call-back interface primarily intended to allow implementers to prevent the view from being opened by throwing an
- * exception. See {@link ILockingManager#addDurableViewHandler(DurableViewHandler)}.
- *
- * @author Caspar De Groot
- * @since 4.1
- */
- public interface DurableViewHandler
- {
- /**
- * A call-back method primarily intended to allow implementers to prevent the view from being opened by throwing an
- * exception. See {@link ILockingManager#addDurableViewHandler(DurableViewHandler)}.
- */
- public void openingView(CDOCommonSession session, int viewID, boolean readOnly, LockArea area) throws Exception;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Caspar De Groot - initial API and implementation + */ +package org.eclipse.emf.cdo.server; + +import org.eclipse.emf.cdo.common.CDOCommonSession; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager; + +/** + * Manages all persistent aspects of durable CDO views and provides for vetoable + * {@link #addDurableViewHandler(ILockingManager.DurableViewHandler) interception} of the durable view resumption + * process. + * + * @author Caspar De Groot + * @since 4.1 + */ +public interface ILockingManager extends IDurableLockingManager +{ + public void addDurableViewHandler(DurableViewHandler handler); + + public void removeDurableViewHandler(DurableViewHandler handler); + + public DurableViewHandler[] getDurableViewHandlers(); + + /** + * A call-back interface primarily intended to allow implementers to prevent the view from being opened by throwing an + * exception. See {@link ILockingManager#addDurableViewHandler(DurableViewHandler)}. + * + * @author Caspar De Groot + * @since 4.1 + */ + public interface DurableViewHandler + { + /** + * A call-back method primarily intended to allow implementers to prevent the view from being opened by throwing an + * exception. See {@link ILockingManager#addDurableViewHandler(DurableViewHandler)}. + */ + public void openingView(CDOCommonSession session, int viewID, boolean readOnly, LockArea area) throws Exception; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IMEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IMEMStore.java index 0bfb20c9f4..bf9f1f7c97 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IMEMStore.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IMEMStore.java @@ -1,26 +1,26 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-/**
- * A simple in-memory store.
- *
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @deprecated Use {@link org.eclipse.emf.cdo.server.mem.IMEMStore}
- * @apiviz.exclude
- */
-@Deprecated
-public interface IMEMStore extends org.eclipse.emf.cdo.server.mem.IMEMStore
-{
-}
+/* + * Copyright (c) 2004 - 2012 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; + +/** + * A simple in-memory store. + * + * @author Eike Stepper + * @since 2.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @deprecated Use {@link org.eclipse.emf.cdo.server.mem.IMEMStore} + * @apiviz.exclude + */ +@Deprecated +public interface IMEMStore extends org.eclipse.emf.cdo.server.mem.IMEMStore +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryContext.java index 0c4e24ae62..31e2a144df 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryContext.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryContext.java @@ -1,45 +1,45 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.view.CDOQuery;
-
-/**
- * Represents the execution state of a {@link CDOQuery query} in the server towards a {@link IQueryHandler query
- * handler}.
- *
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.exclude
- */
-public interface IQueryContext extends CDOBranchPoint
-{
- public IView getView();
-
- /**
- * @since 4.0
- */
- public int getResultCount();
-
- /**
- * Adds the given object to the results of the associated query.
- *
- * @param object
- * Support many primitives, CDOID and CDORevision. CDORevision are converted in CDOID and only CDOID are
- * transfered to the client.
- * @return <code>true</code> to indicate that more results can be passed subsequently, <code>false</code> otherwise
- * (i.e. maxResults has been reached or an asynchronous query has been canceled).
- */
- public boolean addResult(Object object);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.view.CDOQuery; + +/** + * Represents the execution state of a {@link CDOQuery query} in the server towards a {@link IQueryHandler query + * handler}. + * + * @author Eike Stepper + * @since 2.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.exclude + */ +public interface IQueryContext extends CDOBranchPoint +{ + public IView getView(); + + /** + * @since 4.0 + */ + public int getResultCount(); + + /** + * Adds the given object to the results of the associated query. + * + * @param object + * Support many primitives, CDOID and CDORevision. CDORevision are converted in CDOID and only CDOID are + * transfered to the client. + * @return <code>true</code> to indicate that more results can be passed subsequently, <code>false</code> otherwise + * (i.e. maxResults has been reached or an asynchronous query has been canceled). + */ + public boolean addResult(Object object); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandler.java index 29af0e1f63..ceef40dd6d 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandler.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandler.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.view.CDOQuery;
-
-/**
- * A query language handler that is capable of executing a {@link CDOQuery query}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public interface IQueryHandler
-{
- /**
- * Executes the {@link CDOQuery query} represented by the specified {@link CDOQueryInfo query info} by
- * {@link IQueryContext#addResult(Object) passing} the query results to the query execution engine represented by the
- * specified {@link IQueryContext execution context}.
- *
- * @since 3.0
- */
- public void executeQuery(CDOQueryInfo info, IQueryContext context);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.view.CDOQuery; + +/** + * A query language handler that is capable of executing a {@link CDOQuery query}. + * + * @author Eike Stepper + * @since 2.0 + */ +public interface IQueryHandler +{ + /** + * Executes the {@link CDOQuery query} represented by the specified {@link CDOQueryInfo query info} by + * {@link IQueryContext#addResult(Object) passing} the query results to the query execution engine represented by the + * specified {@link IQueryContext execution context}. + * + * @since 3.0 + */ + public void executeQuery(CDOQueryInfo info, IQueryContext context); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandlerProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandlerProvider.java index 2d590b6b49..03eaf06e91 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandlerProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IQueryHandlerProvider.java @@ -1,30 +1,30 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.view.CDOQuery;
-
-/**
- * Provides the consumer with {@link IQueryHandler query handlers} that are capable of executing {@link CDOQuery
- * queries} represented by specific {@link CDOQueryInfo query infos}.
- *
- * @author Eike Stepper
- * @since 2.0
- * @apiviz.uses {@link IQueryHandler} - - provides
- */
-public interface IQueryHandlerProvider
-{
- /**
- * @since 3.0
- */
- public IQueryHandler getQueryHandler(CDOQueryInfo info);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.view.CDOQuery; + +/** + * Provides the consumer with {@link IQueryHandler query handlers} that are capable of executing {@link CDOQuery + * queries} represented by specific {@link CDOQueryInfo query infos}. + * + * @author Eike Stepper + * @since 2.0 + * @apiviz.uses {@link IQueryHandler} - - provides + */ +public interface IQueryHandlerProvider +{ + /** + * @since 3.0 + */ + public IQueryHandler getQueryHandler(CDOQueryInfo info); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java index 1a5d4c4746..42a3ad473b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java @@ -1,288 +1,288 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository;
-import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
-
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EPackage.Registry;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A CDO repository.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- * @apiviz.has {@link IStore}
- * @apiviz.has {@link java.util.Map} oneway - - properties
- * @apiviz.has {@link org.eclipse.emf.cdo.common.model.CDOPackageRegistry}
- * @apiviz.has {@link org.eclipse.emf.cdo.common.branch.CDOBranchManager}
- * @apiviz.has {@link org.eclipse.emf.cdo.common.revision.CDORevisionManager}
- * @apiviz.has {@link org.eclipse.emf.cdo.common.lock.IDurableLockingManager}
- * @apiviz.has {@link ISessionManager}
- * @apiviz.has {@link IQueryHandlerProvider}
- * @apiviz.composedOf {@link org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler}
- * @apiviz.composedOf {@link IRepository.Handler} - - accessHandlers
- */
-public interface IRepository extends CDOCommonRepository, IQueryHandlerProvider, IContainer<Object>
-{
- /**
- * @since 3.0
- */
- public static final String SYSTEM_USER_ID = "CDO_SYSTEM"; //$NON-NLS-1$
-
- public IStore getStore();
-
- public Map<String, String> getProperties();
-
- /**
- * Returns the EMF {@link Registry package registry} that is used by this repository.
- *
- * @since 2.0
- */
- public CDOPackageRegistry getPackageRegistry();
-
- /**
- * @since 3.0
- */
- public CDOBranchManager getBranchManager();
-
- /**
- * @since 3.0
- */
- public CDORevisionManager getRevisionManager();
-
- public ISessionManager getSessionManager();
-
- /**
- * @since 4.0
- * @deprecated As of 4.1 use {@link #getLockingManager()}.
- */
- @Deprecated
- public IDurableLockingManager getLockManager();
-
- /**
- * @since 4.1
- */
- public ILockingManager getLockingManager();
-
- /**
- * @since 2.0
- */
- public IQueryHandlerProvider getQueryHandlerProvider();
-
- /**
- * Returns the time stamp of the last commit operation.
- *
- * @since 3.0
- */
- public long getLastCommitTimeStamp();
-
- /**
- * Blocks the calling thread until the next commit operation has succeeded and returns the last (highest) commit time
- * stamp.
- *
- * @since 3.0
- */
- public long waitForCommit(long timeout);
-
- /**
- * Validates the given timeStamp against the repository time.
- *
- * @throws IllegalArgumentException
- * if the given timeStamp is less than the repository creation time or greater than the current repository
- * time.
- * @since 2.0
- */
- public void validateTimeStamp(long timeStamp) throws IllegalArgumentException;
-
- /**
- * @since 4.1
- */
- public CDOCommitInfoHandler[] getCommitInfoHandlers();
-
- /**
- * @since 4.0
- */
- public void addCommitInfoHandler(CDOCommitInfoHandler handler);
-
- /**
- * @since 4.0
- */
- public void removeCommitInfoHandler(CDOCommitInfoHandler handler);
-
- /**
- * @since 4.1
- */
- public Set<Handler> getHandlers();
-
- /**
- * @since 2.0
- */
- public void addHandler(Handler handler);
-
- /**
- * @since 2.0
- */
- public void removeHandler(Handler handler);
-
- /**
- * @since 4.0
- */
- public void setInitialPackages(EPackage... initialPackages);
-
- /**
- * A marker interface to indicate valid arguments to {@link IRepository#addHandler(Handler)} and
- * {@link IRepository#removeHandler(Handler)}.
- *
- * @see ReadAccessHandler
- * @see WriteAccessHandler
- * @author Eike Stepper
- * @since 2.0
- */
- public interface Handler
- {
- }
-
- /**
- * Provides a way to handle revisions that are to be sent to the client.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public interface ReadAccessHandler extends Handler
- {
- /**
- * Provides a way to handle revisions that are to be sent to the client.
- *
- * @param session
- * The session that is going to send the revisions.
- * @param revisions
- * The revisions that are requested by the client. If the client must not see any of these revisions an
- * unchecked exception must be thrown.
- * @param additionalRevisions
- * The additional revisions that are to be sent to the client because internal optimizers believe that they
- * will be needed soon. If the client must not see any of these revisions they should be removed from the
- * list.
- * @throws RuntimeException
- * to indicate that none of the revisions must be sent to the client. This exception will be visible at
- * the client side!
- */
- public void handleRevisionsBeforeSending(ISession session, CDORevision[] revisions,
- List<CDORevision> additionalRevisions) throws RuntimeException;
- }
-
- /**
- * Provides a way to handle commits that are received from a client.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public interface WriteAccessHandler extends Handler
- {
- /**
- * Provides a way to handle transactions that are to be committed to the backend store.
- *
- * @param transaction
- * The transaction that is going to be committed.
- * @param commitContext
- * The context of the commit operation that is to be executed against the backend store. The context can be
- * used to introspect all aspects of the current commit operation. <b>Note that you must not alter the
- * internal state of the commit context in any way!</b>
- * @param monitor
- * A monitor that should be used by the implementor to avoid timeouts.
- * @throws RuntimeException
- * to indicate that the commit operation must not be executed against the backend store. This exception
- * will be visible at the client side!
- */
- public void handleTransactionBeforeCommitting(ITransaction transaction, IStoreAccessor.CommitContext commitContext,
- OMMonitor monitor) throws RuntimeException;
-
- /**
- * Provides a way to handle transactions after they have been committed to the backend store.
- *
- * @param transaction
- * The transaction that has been committed.
- * @param commitContext
- * The context of the commit operation that was executed against the backend store. The context can be used
- * to introspect all aspects of the current commit operation. <b>Note that you must not alter the internal
- * state of the commit context in any way!</b>
- * @param monitor
- * A monitor that should be used by the implementor to avoid timeouts.
- * @since 3.0
- */
- public void handleTransactionAfterCommitted(ITransaction transaction, IStoreAccessor.CommitContext commitContext,
- OMMonitor monitor);
- }
-
- /**
- * Contains symbolic constants that specifiy valid keys of {@link IRepository#getProperties() repository properties}.
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This interface is not intended to be extended by clients.
- * @apiviz.exclude
- */
- public interface Props
- {
- /**
- * Used to override the automatic UUID generation during first startup of a repository. Passing the empty string
- * causes the UUID of the repository to be set to its {@link IRepository#getName() name}.
- *
- * @since 2.0
- */
- public static final String OVERRIDE_UUID = "overrideUUID"; //$NON-NLS-1$
-
- /**
- * @since 2.0
- */
- public static final String SUPPORTING_AUDITS = "supportingAudits"; //$NON-NLS-1$
-
- /**
- * @since 3.0
- */
- public static final String SUPPORTING_BRANCHES = "supportingBranches"; //$NON-NLS-1$
-
- /**
- * @since 4.0
- */
- public static final String SUPPORTING_ECORE = "supportingEcore"; //$NON-NLS-1$
-
- /**
- * @since 3.0
- */
- public static final String ENSURE_REFERENTIAL_INTEGRITY = "ensureReferentialIntegrity"; //$NON-NLS-1$
-
- /**
- * @since 4.0
- */
- public static final String ALLOW_INTERRUPT_RUNNING_QUERIES = "allowInterruptRunningQueries"; //$NON-NLS-1$
-
- /**
- * @since 4.1
- */
- public static final String ID_GENERATION_LOCATION = "idGenerationLocation"; //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.CDOCommonRepository; +import org.eclipse.emf.cdo.common.branch.CDOBranchManager; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager; +import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionManager; + +import org.eclipse.net4j.util.container.IContainer; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EPackage.Registry; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A CDO repository. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + * @apiviz.has {@link IStore} + * @apiviz.has {@link java.util.Map} oneway - - properties + * @apiviz.has {@link org.eclipse.emf.cdo.common.model.CDOPackageRegistry} + * @apiviz.has {@link org.eclipse.emf.cdo.common.branch.CDOBranchManager} + * @apiviz.has {@link org.eclipse.emf.cdo.common.revision.CDORevisionManager} + * @apiviz.has {@link org.eclipse.emf.cdo.common.lock.IDurableLockingManager} + * @apiviz.has {@link ISessionManager} + * @apiviz.has {@link IQueryHandlerProvider} + * @apiviz.composedOf {@link org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler} + * @apiviz.composedOf {@link IRepository.Handler} - - accessHandlers + */ +public interface IRepository extends CDOCommonRepository, IQueryHandlerProvider, IContainer<Object> +{ + /** + * @since 3.0 + */ + public static final String SYSTEM_USER_ID = "CDO_SYSTEM"; //$NON-NLS-1$ + + public IStore getStore(); + + public Map<String, String> getProperties(); + + /** + * Returns the EMF {@link Registry package registry} that is used by this repository. + * + * @since 2.0 + */ + public CDOPackageRegistry getPackageRegistry(); + + /** + * @since 3.0 + */ + public CDOBranchManager getBranchManager(); + + /** + * @since 3.0 + */ + public CDORevisionManager getRevisionManager(); + + public ISessionManager getSessionManager(); + + /** + * @since 4.0 + * @deprecated As of 4.1 use {@link #getLockingManager()}. + */ + @Deprecated + public IDurableLockingManager getLockManager(); + + /** + * @since 4.1 + */ + public ILockingManager getLockingManager(); + + /** + * @since 2.0 + */ + public IQueryHandlerProvider getQueryHandlerProvider(); + + /** + * Returns the time stamp of the last commit operation. + * + * @since 3.0 + */ + public long getLastCommitTimeStamp(); + + /** + * Blocks the calling thread until the next commit operation has succeeded and returns the last (highest) commit time + * stamp. + * + * @since 3.0 + */ + public long waitForCommit(long timeout); + + /** + * Validates the given timeStamp against the repository time. + * + * @throws IllegalArgumentException + * if the given timeStamp is less than the repository creation time or greater than the current repository + * time. + * @since 2.0 + */ + public void validateTimeStamp(long timeStamp) throws IllegalArgumentException; + + /** + * @since 4.1 + */ + public CDOCommitInfoHandler[] getCommitInfoHandlers(); + + /** + * @since 4.0 + */ + public void addCommitInfoHandler(CDOCommitInfoHandler handler); + + /** + * @since 4.0 + */ + public void removeCommitInfoHandler(CDOCommitInfoHandler handler); + + /** + * @since 4.1 + */ + public Set<Handler> getHandlers(); + + /** + * @since 2.0 + */ + public void addHandler(Handler handler); + + /** + * @since 2.0 + */ + public void removeHandler(Handler handler); + + /** + * @since 4.0 + */ + public void setInitialPackages(EPackage... initialPackages); + + /** + * A marker interface to indicate valid arguments to {@link IRepository#addHandler(Handler)} and + * {@link IRepository#removeHandler(Handler)}. + * + * @see ReadAccessHandler + * @see WriteAccessHandler + * @author Eike Stepper + * @since 2.0 + */ + public interface Handler + { + } + + /** + * Provides a way to handle revisions that are to be sent to the client. + * + * @author Eike Stepper + * @since 2.0 + */ + public interface ReadAccessHandler extends Handler + { + /** + * Provides a way to handle revisions that are to be sent to the client. + * + * @param session + * The session that is going to send the revisions. + * @param revisions + * The revisions that are requested by the client. If the client must not see any of these revisions an + * unchecked exception must be thrown. + * @param additionalRevisions + * The additional revisions that are to be sent to the client because internal optimizers believe that they + * will be needed soon. If the client must not see any of these revisions they should be removed from the + * list. + * @throws RuntimeException + * to indicate that none of the revisions must be sent to the client. This exception will be visible at + * the client side! + */ + public void handleRevisionsBeforeSending(ISession session, CDORevision[] revisions, + List<CDORevision> additionalRevisions) throws RuntimeException; + } + + /** + * Provides a way to handle commits that are received from a client. + * + * @author Eike Stepper + * @since 2.0 + */ + public interface WriteAccessHandler extends Handler + { + /** + * Provides a way to handle transactions that are to be committed to the backend store. + * + * @param transaction + * The transaction that is going to be committed. + * @param commitContext + * The context of the commit operation that is to be executed against the backend store. The context can be + * used to introspect all aspects of the current commit operation. <b>Note that you must not alter the + * internal state of the commit context in any way!</b> + * @param monitor + * A monitor that should be used by the implementor to avoid timeouts. + * @throws RuntimeException + * to indicate that the commit operation must not be executed against the backend store. This exception + * will be visible at the client side! + */ + public void handleTransactionBeforeCommitting(ITransaction transaction, IStoreAccessor.CommitContext commitContext, + OMMonitor monitor) throws RuntimeException; + + /** + * Provides a way to handle transactions after they have been committed to the backend store. + * + * @param transaction + * The transaction that has been committed. + * @param commitContext + * The context of the commit operation that was executed against the backend store. The context can be used + * to introspect all aspects of the current commit operation. <b>Note that you must not alter the internal + * state of the commit context in any way!</b> + * @param monitor + * A monitor that should be used by the implementor to avoid timeouts. + * @since 3.0 + */ + public void handleTransactionAfterCommitted(ITransaction transaction, IStoreAccessor.CommitContext commitContext, + OMMonitor monitor); + } + + /** + * Contains symbolic constants that specifiy valid keys of {@link IRepository#getProperties() repository properties}. + * + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + * @apiviz.exclude + */ + public interface Props + { + /** + * Used to override the automatic UUID generation during first startup of a repository. Passing the empty string + * causes the UUID of the repository to be set to its {@link IRepository#getName() name}. + * + * @since 2.0 + */ + public static final String OVERRIDE_UUID = "overrideUUID"; //$NON-NLS-1$ + + /** + * @since 2.0 + */ + public static final String SUPPORTING_AUDITS = "supportingAudits"; //$NON-NLS-1$ + + /** + * @since 3.0 + */ + public static final String SUPPORTING_BRANCHES = "supportingBranches"; //$NON-NLS-1$ + + /** + * @since 4.0 + */ + public static final String SUPPORTING_ECORE = "supportingEcore"; //$NON-NLS-1$ + + /** + * @since 3.0 + */ + public static final String ENSURE_REFERENTIAL_INTEGRITY = "ensureReferentialIntegrity"; //$NON-NLS-1$ + + /** + * @since 4.0 + */ + public static final String ALLOW_INTERRUPT_RUNNING_QUERIES = "allowInterruptRunningQueries"; //$NON-NLS-1$ + + /** + * @since 4.1 + */ + public static final String ID_GENERATION_LOCATION = "idGenerationLocation"; //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositoryProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositoryProvider.java index 474393c73a..9ec5fd9a6b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositoryProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositoryProvider.java @@ -1,22 +1,22 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-/**
- * Provides the consumer with CDO {@link IRepository repositories} specified by their name.
- *
- * @author Eike Stepper
- * @apiviz.uses {@link IRepository} - - provides
- */
-public interface IRepositoryProvider
-{
- public IRepository getRepository(String name);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +/** + * Provides the consumer with CDO {@link IRepository repositories} specified by their name. + * + * @author Eike Stepper + * @apiviz.uses {@link IRepository} - - provides + */ +public interface IRepositoryProvider +{ + public IRepository getRepository(String name); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositorySynchronizer.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositorySynchronizer.java index 4ced985246..46b58a21e6 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositorySynchronizer.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepositorySynchronizer.java @@ -1,54 +1,54 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
-
-import org.eclipse.net4j.util.event.INotifier;
-
-/**
- * Synchronizes a {@link ISynchronizableRepository synchronizable repository} with a master repository.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- * @apiviz.has {@link org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory} oneway - - remote
- */
-public interface IRepositorySynchronizer extends INotifier
-{
- public int getRetryInterval();
-
- public void setRetryInterval(int retryInterval);
-
- public ISynchronizableRepository getLocalRepository();
-
- public CDOSessionConfigurationFactory getRemoteSessionConfigurationFactory();
-
- public CDOSession getRemoteSession();
-
- public boolean isRawReplication();
-
- /**
- * @since 4.0
- */
- public void setRawReplication(boolean rawReplication);
-
- public int getMaxRecommits();
-
- public void setMaxRecommits(int maxRecommits);
-
- public int getRecommitInterval();
-
- public void setRecommitInterval(int recommitInterval);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; + +import org.eclipse.net4j.util.event.INotifier; + +/** + * Synchronizes a {@link ISynchronizableRepository synchronizable repository} with a master repository. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + * @apiviz.has {@link org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory} oneway - - remote + */ +public interface IRepositorySynchronizer extends INotifier +{ + public int getRetryInterval(); + + public void setRetryInterval(int retryInterval); + + public ISynchronizableRepository getLocalRepository(); + + public CDOSessionConfigurationFactory getRemoteSessionConfigurationFactory(); + + public CDOSession getRemoteSession(); + + public boolean isRawReplication(); + + /** + * @since 4.0 + */ + public void setRawReplication(boolean rawReplication); + + public int getMaxRecommits(); + + public void setMaxRecommits(int maxRecommits); + + public int getRecommitInterval(); + + public void setRecommitInterval(int recommitInterval); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISession.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISession.java index b7f6695df8..e88b48df4f 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISession.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISession.java @@ -1,63 +1,63 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 230832
- */
-package org.eclipse.emf.cdo.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonSession;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.spi.server.ISessionProtocol;
-
-import org.eclipse.net4j.util.container.IContainer;
-
-/**
- * The server-side representation of a client {@link CDOSession session}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- * @apiviz.has {@link org.eclipse.emf.cdo.spi.server.ISessionProtocol}
- * @apiviz.composedOf {@link IView} - - views
- * @apiviz.composedOf {@link ITransaction} - - transactions
- */
-public interface ISession extends CDOCommonSession, IContainer<IView>
-{
- /**
- * @since 3.0
- */
- public ISessionManager getManager();
-
- /**
- * @since 3.0
- */
- public ISessionProtocol getProtocol();
-
- /**
- * @since 4.0
- */
- public long getLastUpdateTime();
-
- /**
- * @since 2.0
- */
- public boolean isSubscribed();
-
- /**
- * @since 3.0
- */
- public IView openView(int viewID, CDOBranchPoint branchPoint);
-
- /**
- * @since 3.0
- */
- public ITransaction openTransaction(int viewID, CDOBranchPoint branchPoint);
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 230832 + */ +package org.eclipse.emf.cdo.server; + +import org.eclipse.emf.cdo.common.CDOCommonSession; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.spi.server.ISessionProtocol; + +import org.eclipse.net4j.util.container.IContainer; + +/** + * The server-side representation of a client {@link CDOSession session}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + * @apiviz.has {@link org.eclipse.emf.cdo.spi.server.ISessionProtocol} + * @apiviz.composedOf {@link IView} - - views + * @apiviz.composedOf {@link ITransaction} - - transactions + */ +public interface ISession extends CDOCommonSession, IContainer<IView> +{ + /** + * @since 3.0 + */ + public ISessionManager getManager(); + + /** + * @since 3.0 + */ + public ISessionProtocol getProtocol(); + + /** + * @since 4.0 + */ + public long getLastUpdateTime(); + + /** + * @since 2.0 + */ + public boolean isSubscribed(); + + /** + * @since 3.0 + */ + public IView openView(int viewID, CDOBranchPoint branchPoint); + + /** + * @since 3.0 + */ + public ITransaction openTransaction(int viewID, CDOBranchPoint branchPoint); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISessionManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISessionManager.java index 2d27504ccb..b1e4bab6c6 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISessionManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISessionManager.java @@ -1,37 +1,37 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.net4j.util.container.IContainer;
-
-/**
- * Manages the user {@link ISession sessions} of a {@link IRepository repository}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- * @apiviz.composedOf {@link ISession}
- */
-public interface ISessionManager extends IContainer<ISession>
-{
- /**
- * @since 2.0
- */
- public IRepository getRepository();
-
- public ISession[] getSessions();
-
- /**
- * @since 2.0
- */
- public ISession getSession(int sessionID);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.net4j.util.container.IContainer; + +/** + * Manages the user {@link ISession sessions} of a {@link IRepository repository}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + * @apiviz.composedOf {@link ISession} + */ +public interface ISessionManager extends IContainer<ISession> +{ + /** + * @since 2.0 + */ + public IRepository getRepository(); + + public ISession[] getSessions(); + + /** + * @since 2.0 + */ + public ISession getSession(int sessionID); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java index 84830969a1..531c54c79b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java @@ -1,248 +1,248 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-
-import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Represents the physical data storage back-end of a CDO {@link IRepository repository}, such as a database or a file
- * system folder.
- *
- * @author Eike Stepper
- * @apiviz.landmark
- * @apiviz.has {@link IStore.ChangeFormat}
- * @apiviz.has {@link IStore.RevisionTemporality}
- * @apiviz.has {@link IStore.RevisionParallelism}
- * @apiviz.uses {@link IStoreAccessor} - - creates
- */
-public interface IStore
-{
- /**
- * @since 2.0
- */
- public IRepository getRepository();
-
- /**
- * @since 2.0
- */
- public String getType();
-
- /**
- * @since 3.0
- */
- public Set<CDOID.ObjectType> getObjectIDTypes();
-
- /**
- * @since 4.0
- */
- public CDOID createObjectID(String val);
-
- /**
- * @since 2.0
- */
- public Set<ChangeFormat> getSupportedChangeFormats();
-
- /**
- * @since 2.0
- */
- public Set<RevisionTemporality> getSupportedRevisionTemporalities();
-
- /**
- * @since 2.0
- */
- public Set<RevisionParallelism> getSupportedRevisionParallelisms();
-
- /**
- * @since 2.0
- */
- public RevisionTemporality getRevisionTemporality();
-
- /**
- * @since 2.0
- */
- public RevisionParallelism getRevisionParallelism();
-
- /**
- * Returns <code>true</code>if this store was activated for the first time, <code>false</code> otherwise.
- *
- * @since 4.0
- */
- public boolean isFirstStart();
-
- /**
- * Returns the store creation time.
- *
- * @since 2.0
- */
- public long getCreationTime();
-
- /**
- * Returns the id of the last branch that has been created in this store.
- *
- * @since 3.0
- */
- public int getLastBranchID();
-
- /**
- * Returns the id of the last local branch that has been created in this store.
- *
- * @since 3.0
- */
- public int getLastLocalBranchID();
-
- /**
- * Returns the time stamp of the last successful commit operation.
- *
- * @since 3.0
- */
- public long getLastCommitTime();
-
- /**
- * Returns the time stamp of the last successful commit operation to a non-local {@link CDOBranch branch}.
- *
- * @since 3.0
- */
- public long getLastNonLocalCommitTime();
-
- /**
- * Returns a map filled with the property entries for the requested property <code>names</code> if names is not
- * <code>null</code> and not {@link Collection#isEmpty() empty}, all existing property entries otherwise.
- *
- * @since 4.0
- */
- public Map<String, String> getPersistentProperties(Set<String> names);
-
- /**
- * @since 4.0
- */
- public void setPersistentProperties(Map<String, String> properties);
-
- /**
- * @since 4.0
- */
- public void removePersistentProperties(Set<String> names);
-
- /**
- * Returns a reader that can be used to read from this store in the context of the given session.
- *
- * @param session
- * The session that should be used as a context for read access or <code>null</code>. The store implementor
- * is free to interpret and use the session in a manner suitable for him or ignore it at all. It is meant
- * only as a hint. Implementor can use it as a key into a cache and/or register a
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter LifecycleEventAdapter} with it to intercept
- * cleanup on session close. Note however that the session can be <code>null</code>, for example during
- * startup of the server while the repositories are initialized but before any user session has been opened.
- * @return a reader that can be used to read from this store in the context of the given session, never
- * <code>null</code>.
- * @since 2.0
- */
- public IStoreAccessor getReader(ISession session);
-
- /**
- * Returns a writer that can be used to write to this store in the context of the given view. The given view is always
- * marked as a transaction.
- *
- * @param transaction
- * The view that must be used as a context for write access. The store implementor is free to interpret and
- * use the view in a manner suitable for him or ignore it at all. It is meant only as a hint. Implementor can
- * use it as a key into a cache and/or register a
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter LifecycleEventAdapter} with it to intercept
- * cleanup on view close.
- * @return a writer that can be used to write to this store in the context of the given view, never <code>null</code>.
- * @since 2.0
- */
- public IStoreAccessor getWriter(ITransaction transaction);
-
- /**
- * @since 2.0
- */
- public ProgressDistributor getIndicatingCommitDistributor();
-
- /**
- * Enumerates the possible data formats a {@link IStore store} can accept for commit operations.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public enum ChangeFormat
- {
- /**
- * An indication that the store accepts full {@link CDORevision revisions} for dirty objects.
- */
- REVISION,
-
- /**
- * An indication that the store accepts incremental {@link CDORevisionDelta revision deltas} for dirty objects.
- */
- DELTA
- }
-
- /**
- * Enumerates the possible history recording options a {@link IStore store} can accept.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public enum RevisionTemporality
- {
- /**
- * An indication that the store can work <b>without</b> <i>auditing</i>.
- */
- NONE,
-
- /**
- * An indication that the store can work <b>with</b> <i>auditing</i>.
- */
- AUDITING
- }
-
- /**
- * Enumerates the possible branching options a {@link IStore store} can accept.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public enum RevisionParallelism
- {
- /**
- * An indication that the store can work <b>without</b> <i>branching</i>.
- */
- NONE,
-
- /**
- * An indication that the store can work <b>with</b> <i>branching</i>.
- */
- BRANCHING
- }
-
- /**
- * A marker interface for {@link IStore stores} that can handle {@link CDOID IDs} assigned by a
- * {@link IDGenerationLocation#CLIENT client}, typically {@link ObjectType#UUID UUIDs}.
- *
- * @author Eike Stepper
- * @since 4.1
- * @apiviz.exclude
- */
- public interface CanHandleClientAssignedIDs
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOID.ObjectType; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; + +import org.eclipse.net4j.util.om.monitor.ProgressDistributor; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +/** + * Represents the physical data storage back-end of a CDO {@link IRepository repository}, such as a database or a file + * system folder. + * + * @author Eike Stepper + * @apiviz.landmark + * @apiviz.has {@link IStore.ChangeFormat} + * @apiviz.has {@link IStore.RevisionTemporality} + * @apiviz.has {@link IStore.RevisionParallelism} + * @apiviz.uses {@link IStoreAccessor} - - creates + */ +public interface IStore +{ + /** + * @since 2.0 + */ + public IRepository getRepository(); + + /** + * @since 2.0 + */ + public String getType(); + + /** + * @since 3.0 + */ + public Set<CDOID.ObjectType> getObjectIDTypes(); + + /** + * @since 4.0 + */ + public CDOID createObjectID(String val); + + /** + * @since 2.0 + */ + public Set<ChangeFormat> getSupportedChangeFormats(); + + /** + * @since 2.0 + */ + public Set<RevisionTemporality> getSupportedRevisionTemporalities(); + + /** + * @since 2.0 + */ + public Set<RevisionParallelism> getSupportedRevisionParallelisms(); + + /** + * @since 2.0 + */ + public RevisionTemporality getRevisionTemporality(); + + /** + * @since 2.0 + */ + public RevisionParallelism getRevisionParallelism(); + + /** + * Returns <code>true</code>if this store was activated for the first time, <code>false</code> otherwise. + * + * @since 4.0 + */ + public boolean isFirstStart(); + + /** + * Returns the store creation time. + * + * @since 2.0 + */ + public long getCreationTime(); + + /** + * Returns the id of the last branch that has been created in this store. + * + * @since 3.0 + */ + public int getLastBranchID(); + + /** + * Returns the id of the last local branch that has been created in this store. + * + * @since 3.0 + */ + public int getLastLocalBranchID(); + + /** + * Returns the time stamp of the last successful commit operation. + * + * @since 3.0 + */ + public long getLastCommitTime(); + + /** + * Returns the time stamp of the last successful commit operation to a non-local {@link CDOBranch branch}. + * + * @since 3.0 + */ + public long getLastNonLocalCommitTime(); + + /** + * Returns a map filled with the property entries for the requested property <code>names</code> if names is not + * <code>null</code> and not {@link Collection#isEmpty() empty}, all existing property entries otherwise. + * + * @since 4.0 + */ + public Map<String, String> getPersistentProperties(Set<String> names); + + /** + * @since 4.0 + */ + public void setPersistentProperties(Map<String, String> properties); + + /** + * @since 4.0 + */ + public void removePersistentProperties(Set<String> names); + + /** + * Returns a reader that can be used to read from this store in the context of the given session. + * + * @param session + * The session that should be used as a context for read access or <code>null</code>. The store implementor + * is free to interpret and use the session in a manner suitable for him or ignore it at all. It is meant + * only as a hint. Implementor can use it as a key into a cache and/or register a + * {@link org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter LifecycleEventAdapter} with it to intercept + * cleanup on session close. Note however that the session can be <code>null</code>, for example during + * startup of the server while the repositories are initialized but before any user session has been opened. + * @return a reader that can be used to read from this store in the context of the given session, never + * <code>null</code>. + * @since 2.0 + */ + public IStoreAccessor getReader(ISession session); + + /** + * Returns a writer that can be used to write to this store in the context of the given view. The given view is always + * marked as a transaction. + * + * @param transaction + * The view that must be used as a context for write access. The store implementor is free to interpret and + * use the view in a manner suitable for him or ignore it at all. It is meant only as a hint. Implementor can + * use it as a key into a cache and/or register a + * {@link org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter LifecycleEventAdapter} with it to intercept + * cleanup on view close. + * @return a writer that can be used to write to this store in the context of the given view, never <code>null</code>. + * @since 2.0 + */ + public IStoreAccessor getWriter(ITransaction transaction); + + /** + * @since 2.0 + */ + public ProgressDistributor getIndicatingCommitDistributor(); + + /** + * Enumerates the possible data formats a {@link IStore store} can accept for commit operations. + * + * @author Eike Stepper + * @since 2.0 + */ + public enum ChangeFormat + { + /** + * An indication that the store accepts full {@link CDORevision revisions} for dirty objects. + */ + REVISION, + + /** + * An indication that the store accepts incremental {@link CDORevisionDelta revision deltas} for dirty objects. + */ + DELTA + } + + /** + * Enumerates the possible history recording options a {@link IStore store} can accept. + * + * @author Eike Stepper + * @since 2.0 + */ + public enum RevisionTemporality + { + /** + * An indication that the store can work <b>without</b> <i>auditing</i>. + */ + NONE, + + /** + * An indication that the store can work <b>with</b> <i>auditing</i>. + */ + AUDITING + } + + /** + * Enumerates the possible branching options a {@link IStore store} can accept. + * + * @author Eike Stepper + * @since 2.0 + */ + public enum RevisionParallelism + { + /** + * An indication that the store can work <b>without</b> <i>branching</i>. + */ + NONE, + + /** + * An indication that the store can work <b>with</b> <i>branching</i>. + */ + BRANCHING + } + + /** + * A marker interface for {@link IStore stores} that can handle {@link CDOID IDs} assigned by a + * {@link IDGenerationLocation#CLIENT client}, typically {@link ObjectType#UUID UUIDs}. + * + * @author Eike Stepper + * @since 4.1 + * @apiviz.exclude + */ + public interface CanHandleClientAssignedIDs + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreChunkReader.java index df8e8f28e0..bf12820535 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreChunkReader.java @@ -1,127 +1,127 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 210868
- */
-package org.eclipse.emf.cdo.server;
-
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.List;
-
-/**
- * Reads {@link Chunk chunks} of
- * {@link org.eclipse.emf.cdo.session.CDOSession.Options#setCollectionLoadingPolicy(CDOCollectionLoadingPolicy)
- * partially loaded} lists from a physical data storage backend.
- *
- * @author Eike Stepper
- * @apiviz.uses {@link IStoreChunkReader.Chunk} - - reads
- */
-public interface IStoreChunkReader
-{
- /**
- * @since 2.0
- */
- public IStoreAccessor getAccessor();
-
- public CDORevision getRevision();
-
- /**
- * @since 2.0
- */
- public EStructuralFeature getFeature();
-
- public void addSimpleChunk(int index);
-
- /**
- * @param fromIndex
- * Inclusive value.
- * @param toIndex
- * Exclusive value.
- */
- public void addRangedChunk(int fromIndex, int toIndex);
-
- public List<Chunk> executeRead();
-
- /**
- * Represents a {@link List#subList(int, int) sublist} of consecutive elements that are subject to <i>partial
- * collection loading</i>.
- *
- * @author Eike Stepper
- */
- public static class Chunk
- {
- private int startIndex;
-
- private Object ids;
-
- public Chunk(int startIndex)
- {
- this.startIndex = startIndex;
- }
-
- public Chunk(int startIndex, int size)
- {
- this(startIndex);
- ids = new Object[size];
- }
-
- public int getStartIndex()
- {
- return startIndex;
- }
-
- public int size()
- {
- return ids instanceof Object[] ? ((Object[])ids).length : 1;
- }
-
- /**
- * @since 2.0
- */
- public Object get(int indexInChunk)
- {
- if (ids instanceof Object[])
- {
- return ((Object[])ids)[indexInChunk];
- }
-
- if (indexInChunk == 0)
- {
- return ids;
- }
-
- throw new ArrayIndexOutOfBoundsException(indexInChunk);
- }
-
- /**
- * @since 2.0
- */
- public void add(int indexInChunk, Object value)
- {
- if (ids instanceof Object[])
- {
- ((Object[])ids)[indexInChunk] = value;
- }
- else
- {
- if (indexInChunk == 0)
- {
- ids = value;
- return;
- }
-
- throw new ArrayIndexOutOfBoundsException(indexInChunk);
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 210868 + */ +package org.eclipse.emf.cdo.server; + +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.List; + +/** + * Reads {@link Chunk chunks} of + * {@link org.eclipse.emf.cdo.session.CDOSession.Options#setCollectionLoadingPolicy(CDOCollectionLoadingPolicy) + * partially loaded} lists from a physical data storage backend. + * + * @author Eike Stepper + * @apiviz.uses {@link IStoreChunkReader.Chunk} - - reads + */ +public interface IStoreChunkReader +{ + /** + * @since 2.0 + */ + public IStoreAccessor getAccessor(); + + public CDORevision getRevision(); + + /** + * @since 2.0 + */ + public EStructuralFeature getFeature(); + + public void addSimpleChunk(int index); + + /** + * @param fromIndex + * Inclusive value. + * @param toIndex + * Exclusive value. + */ + public void addRangedChunk(int fromIndex, int toIndex); + + public List<Chunk> executeRead(); + + /** + * Represents a {@link List#subList(int, int) sublist} of consecutive elements that are subject to <i>partial + * collection loading</i>. + * + * @author Eike Stepper + */ + public static class Chunk + { + private int startIndex; + + private Object ids; + + public Chunk(int startIndex) + { + this.startIndex = startIndex; + } + + public Chunk(int startIndex, int size) + { + this(startIndex); + ids = new Object[size]; + } + + public int getStartIndex() + { + return startIndex; + } + + public int size() + { + return ids instanceof Object[] ? ((Object[])ids).length : 1; + } + + /** + * @since 2.0 + */ + public Object get(int indexInChunk) + { + if (ids instanceof Object[]) + { + return ((Object[])ids)[indexInChunk]; + } + + if (indexInChunk == 0) + { + return ids; + } + + throw new ArrayIndexOutOfBoundsException(indexInChunk); + } + + /** + * @since 2.0 + */ + public void add(int indexInChunk, Object value) + { + if (ids instanceof Object[]) + { + ((Object[])ids)[indexInChunk] = value; + } + else + { + if (indexInChunk == 0) + { + ids = value; + return; + } + + throw new ArrayIndexOutOfBoundsException(indexInChunk); + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreFactory.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreFactory.java index c046fbcfff..86107bedff 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreFactory.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreFactory.java @@ -1,31 +1,31 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.w3c.dom.Element;
-
-import java.util.Map;
-
-/**
- * Creates {@link IStore stores}.
- *
- * @author Eike Stepper
- * @apiviz.uses {@link IStore} - - creates
- */
-public interface IStoreFactory
-{
- public String getStoreType();
-
- /**
- * @since 4.0
- */
- public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig);
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.w3c.dom.Element; + +import java.util.Map; + +/** + * Creates {@link IStore stores}. + * + * @author Eike Stepper + * @apiviz.uses {@link IStore} - - creates + */ +public interface IStoreFactory +{ + public String getStoreType(); + + /** + * @since 4.0 + */ + public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISynchronizableRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISynchronizableRepository.java index f46281d104..ffba11b3be 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISynchronizableRepository.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ISynchronizableRepository.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-/**
- * A repository with the ability to {@link IRepositorySynchronizer synchronize} its content with another repository.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- * @apiviz.has {@link IRepositorySynchronizer}
- * @apiviz.has {@link ISession} oneway - - replicatorSession
- */
-public interface ISynchronizableRepository extends IRepository
-{
- public IRepositorySynchronizer getSynchronizer();
-
- public ISession getReplicatorSession();
-
- public int getLastReplicatedBranchID();
-
- public long getLastReplicatedCommitTime();
-
- /**
- * @since 4.1
- */
- public void goOnline();
-
- /**
- * @since 4.1
- */
- public void goOffline();
-}
+/* + * Copyright (c) 2004 - 2012 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; + +/** + * A repository with the ability to {@link IRepositorySynchronizer synchronize} its content with another repository. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + * @apiviz.has {@link IRepositorySynchronizer} + * @apiviz.has {@link ISession} oneway - - replicatorSession + */ +public interface ISynchronizableRepository extends IRepository +{ + public IRepositorySynchronizer getSynchronizer(); + + public ISession getReplicatorSession(); + + public int getLastReplicatedBranchID(); + + public long getLastReplicatedCommitTime(); + + /** + * @since 4.1 + */ + public void goOnline(); + + /** + * @since 4.1 + */ + public void goOffline(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITransaction.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITransaction.java index 6993301cb1..888329a3c9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITransaction.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITransaction.java @@ -1,27 +1,27 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonTransaction;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-
-/**
- * The server-side representation of a client {@link CDOTransaction transaction}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- */
-public interface ITransaction extends IView, CDOCommonTransaction
-{
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 213402 + */ +package org.eclipse.emf.cdo.server; + +import org.eclipse.emf.cdo.common.CDOCommonTransaction; +import org.eclipse.emf.cdo.transaction.CDOTransaction; + +/** + * The server-side representation of a client {@link CDOTransaction transaction}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + */ +public interface ITransaction extends IView, CDOCommonTransaction +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java index 7ca112917b..5448eb746d 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.CDOCommonView;
-import org.eclipse.emf.cdo.view.CDOView;
-
-/**
- * The server-side representation of a client {@link CDOView view}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark
- */
-public interface IView extends CDOCommonView
-{
- /**
- * @since 2.0
- */
- public IRepository getRepository();
-
- public ISession getSession();
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.CDOCommonView; +import org.eclipse.emf.cdo.view.CDOView; + +/** + * The server-side representation of a client {@link CDOView view}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @apiviz.landmark + */ +public interface IView extends CDOCommonView +{ + /** + * @since 2.0 + */ + public IRepository getRepository(); + + public ISession getSession(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/RepositoryNotFoundException.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/RepositoryNotFoundException.java index 1c1054b06b..cba98867b8 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/RepositoryNotFoundException.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/RepositoryNotFoundException.java @@ -1,41 +1,41 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.common.util.CDOException;
-import org.eclipse.emf.cdo.session.CDOSession;
-
-/**
- * An unchecked exception being thrown when opening a {@link CDOSession session} to a named {@link IRepository
- * repository} that cannot be found.
- *
- * @author Eike Stepper
- */
-public class RepositoryNotFoundException extends CDOException
-{
- private static final long serialVersionUID = 1L;
-
- public RepositoryNotFoundException(String repositoryName)
- {
- super(repositoryName);
- }
-
- public String getRepositoryName()
- {
- return super.getMessage();
- }
-
- @Override
- public String getMessage()
- {
- return "Repository not found: " + getRepositoryName(); //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.common.util.CDOException; +import org.eclipse.emf.cdo.session.CDOSession; + +/** + * An unchecked exception being thrown when opening a {@link CDOSession session} to a named {@link IRepository + * repository} that cannot be found. + * + * @author Eike Stepper + */ +public class RepositoryNotFoundException extends CDOException +{ + private static final long serialVersionUID = 1L; + + public RepositoryNotFoundException(String repositoryName) + { + super(repositoryName); + } + + public String getRepositoryName() + { + return super.getMessage(); + } + + @Override + public String getMessage() + { + return "Repository not found: " + getRepositoryName(); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java index b91ebe054c..7e78d651c5 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java @@ -1,123 +1,123 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-/**
- * Provides server-side consumers with the {@link IStoreAccessor store accessor} that is valid in the context of a
- * specific {@link ISession session} during read operations or a specific {@link CommitContext commit context} during
- * write operations.
- *
- * @author Eike Stepper
- * @since 2.0
- * @apiviz.exclude
- */
-public final class StoreThreadLocal
-{
- private static final ThreadLocal<InternalSession> SESSION = new InheritableThreadLocal<InternalSession>();
-
- private static final ThreadLocal<IStoreAccessor> ACCESSOR = new InheritableThreadLocal<IStoreAccessor>();
-
- private static final ThreadLocal<IStoreAccessor.CommitContext> COMMIT_CONTEXT = new InheritableThreadLocal<IStoreAccessor.CommitContext>();
-
- private StoreThreadLocal()
- {
- }
-
- /**
- * @since 3.0
- */
- public static void setSession(InternalSession session)
- {
- SESSION.set(session);
- ACCESSOR.set(null);
- }
-
- /**
- * Returns the session associated with the current thread.
- *
- * @return Never <code>null</code>.
- * @throws IllegalStateException
- * if no session is associated with the current thread.
- * @since 3.0
- */
- public static InternalSession getSession()
- {
- InternalSession session = SESSION.get();
- if (session == null)
- {
- throw new IllegalStateException("session == null"); //$NON-NLS-1$
- }
-
- return session;
- }
-
- public static void setAccessor(IStoreAccessor accessor)
- {
- // IStoreAccessor old = ACCESSOR.get();
- // if (old != null && old != accessor)
- // {
- // throw new IllegalStateException("Attempt to overwrite accessor");
- // }
-
- SESSION.set(accessor == null ? null : accessor.getSession());
- ACCESSOR.set(accessor);
- }
-
- public static IStoreAccessor getAccessor()
- {
- IStoreAccessor accessor = ACCESSOR.get();
- if (accessor == null)
- {
- ISession session = getSession();
- IStore store = session.getManager().getRepository().getStore();
- accessor = store.getReader(session);
- ACCESSOR.set(accessor);
- }
-
- return accessor;
- }
-
- public static void setCommitContext(IStoreAccessor.CommitContext commitContext)
- {
- COMMIT_CONTEXT.set(commitContext);
- }
-
- public static IStoreAccessor.CommitContext getCommitContext()
- {
- return COMMIT_CONTEXT.get();
- }
-
- public static void release()
- {
- try
- {
- IStoreAccessor accessor = ACCESSOR.get();
- if (accessor != null)
- {
- if (LifecycleUtil.isActive(accessor))
- {
- accessor.release();
- }
- }
- }
- finally
- {
- ACCESSOR.set(null);
- SESSION.set(null);
- COMMIT_CONTEXT.set(null);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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; + +import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext; +import org.eclipse.emf.cdo.spi.server.InternalSession; + +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; + +/** + * Provides server-side consumers with the {@link IStoreAccessor store accessor} that is valid in the context of a + * specific {@link ISession session} during read operations or a specific {@link CommitContext commit context} during + * write operations. + * + * @author Eike Stepper + * @since 2.0 + * @apiviz.exclude + */ +public final class StoreThreadLocal +{ + private static final ThreadLocal<InternalSession> SESSION = new InheritableThreadLocal<InternalSession>(); + + private static final ThreadLocal<IStoreAccessor> ACCESSOR = new InheritableThreadLocal<IStoreAccessor>(); + + private static final ThreadLocal<IStoreAccessor.CommitContext> COMMIT_CONTEXT = new InheritableThreadLocal<IStoreAccessor.CommitContext>(); + + private StoreThreadLocal() + { + } + + /** + * @since 3.0 + */ + public static void setSession(InternalSession session) + { + SESSION.set(session); + ACCESSOR.set(null); + } + + /** + * Returns the session associated with the current thread. + * + * @return Never <code>null</code>. + * @throws IllegalStateException + * if no session is associated with the current thread. + * @since 3.0 + */ + public static InternalSession getSession() + { + InternalSession session = SESSION.get(); + if (session == null) + { + throw new IllegalStateException("session == null"); //$NON-NLS-1$ + } + + return session; + } + + public static void setAccessor(IStoreAccessor accessor) + { + // IStoreAccessor old = ACCESSOR.get(); + // if (old != null && old != accessor) + // { + // throw new IllegalStateException("Attempt to overwrite accessor"); + // } + + SESSION.set(accessor == null ? null : accessor.getSession()); + ACCESSOR.set(accessor); + } + + public static IStoreAccessor getAccessor() + { + IStoreAccessor accessor = ACCESSOR.get(); + if (accessor == null) + { + ISession session = getSession(); + IStore store = session.getManager().getRepository().getStore(); + accessor = store.getReader(session); + ACCESSOR.set(accessor); + } + + return accessor; + } + + public static void setCommitContext(IStoreAccessor.CommitContext commitContext) + { + COMMIT_CONTEXT.set(commitContext); + } + + public static IStoreAccessor.CommitContext getCommitContext() + { + return COMMIT_CONTEXT.get(); + } + + public static void release() + { + try + { + IStoreAccessor accessor = ACCESSOR.get(); + if (accessor != null) + { + if (LifecycleUtil.isActive(accessor)) + { + accessor.release(); + } + } + } + finally + { + ACCESSOR.set(null); + SESSION.set(null); + COMMIT_CONTEXT.set(null); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSession.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSession.java index c1e5cbae8b..07aac54e45 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSession.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSession.java @@ -1,25 +1,25 @@ -/*
- * Copyright (c) 2004 - 2012 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;
-
-/**
- * Deprecated, not yet supported.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @deprecated Not yet supported.
- */
-@Deprecated
-public interface CDOSession extends org.eclipse.emf.cdo.session.CDOSession
-{
-}
+/* + * Copyright (c) 2004 - 2012 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; + +/** + * Deprecated, not yet supported. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @deprecated Not yet supported. + */ +@Deprecated +public interface CDOSession extends org.eclipse.emf.cdo.session.CDOSession +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSessionConfiguration.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSessionConfiguration.java index abe43f3a7a..89e6e4901c 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSessionConfiguration.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/CDOSessionConfiguration.java @@ -1,37 +1,37 @@ -/*
- * Copyright (c) 2004 - 2012 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.revision.CDORevisionManager;
-import org.eclipse.emf.cdo.server.IRepository;
-
-/**
- * Deprecated, not yet supported.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @deprecated Not yet supported.
- */
-@Deprecated
-public interface CDOSessionConfiguration extends org.eclipse.emf.cdo.session.CDOSessionConfiguration
-{
- public IRepository getRepository();
-
- public void setRepository(IRepository repository);
-
- public CDORevisionManager getRevisionManager();
-
- public void setRevisionManager(CDORevisionManager revisionManager);
-
- public org.eclipse.emf.cdo.server.embedded.CDOSession openSession();
-}
+/* + * Copyright (c) 2004 - 2012 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.revision.CDORevisionManager; +import org.eclipse.emf.cdo.server.IRepository; + +/** + * Deprecated, not yet supported. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @deprecated Not yet supported. + */ +@Deprecated +public interface CDOSessionConfiguration extends org.eclipse.emf.cdo.session.CDOSessionConfiguration +{ + public IRepository getRepository(); + + public void setRepository(IRepository repository); + + public CDORevisionManager getRevisionManager(); + + public void setRevisionManager(CDORevisionManager revisionManager); + + public org.eclipse.emf.cdo.server.embedded.CDOSession openSession(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/package-info.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/package-info.java index 3de3023d2d..3714c908d7 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/package-info.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/embedded/package-info.java @@ -1,15 +1,15 @@ -/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Server concepts for dealing with embedded sessions.
- */
-package org.eclipse.emf.cdo.server.embedded;
+/* + * Copyright (c) 2004 - 2012 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 + */ + +/** + * Server concepts for dealing with embedded sessions. + */ +package org.eclipse.emf.cdo.server.embedded; diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/IMEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/IMEMStore.java index 464ed6240c..a4e35be12c 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/IMEMStore.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/IMEMStore.java @@ -1,56 +1,56 @@ -/*
- * Copyright (c) 2004 - 2012 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.mem;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDOAllRevisionsProvider;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStore.CanHandleClientAssignedIDs;
-
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-import org.eclipse.emf.ecore.EClass;
-
-/**
- * A simple in-memory {@link IStore store}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @since 4.0
- */
-public interface IMEMStore extends IStore, CDOAllRevisionsProvider, CanHandleClientAssignedIDs
-{
- public static final int UNLIMITED = -1;
-
- /**
- * Returns the number of {@link CDORevision revisions} per {@link CDOID} that are stored.
- */
- public int getListLimit();
-
- /**
- * Limits the number of {@link CDORevision revisions} per {@link CDOID} to the given value.
- * <p>
- * A value of 2, for example, stores the current and the immediately preceding revisions whereas older revisions are
- * dropped from thids store. A value of 1 only stores the current revisions. A value of {@link #UNLIMITED} does not
- * limit the number of revisions to be stored for any id.
- * <p>
- * The list limit can be set and enforced at any time before or after the {@link LifecycleUtil#activate(Object)
- * activation} of this store.
- */
- public void setListLimit(int listLimit);
-
- /**
- * @since 3.0
- */
- public EClass getObjectType(CDOID id);
-}
+/* + * Copyright (c) 2004 - 2012 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.mem; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDOAllRevisionsProvider; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStore.CanHandleClientAssignedIDs; + +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; + +import org.eclipse.emf.ecore.EClass; + +/** + * A simple in-memory {@link IStore store}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @since 4.0 + */ +public interface IMEMStore extends IStore, CDOAllRevisionsProvider, CanHandleClientAssignedIDs +{ + public static final int UNLIMITED = -1; + + /** + * Returns the number of {@link CDORevision revisions} per {@link CDOID} that are stored. + */ + public int getListLimit(); + + /** + * Limits the number of {@link CDORevision revisions} per {@link CDOID} to the given value. + * <p> + * A value of 2, for example, stores the current and the immediately preceding revisions whereas older revisions are + * dropped from thids store. A value of 1 only stores the current revisions. A value of {@link #UNLIMITED} does not + * limit the number of revisions to be stored for any id. + * <p> + * The list limit can be set and enforced at any time before or after the {@link LifecycleUtil#activate(Object) + * activation} of this store. + */ + public void setListLimit(int listLimit); + + /** + * @since 3.0 + */ + public EClass getObjectType(CDOID id); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/MEMStoreUtil.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/MEMStoreUtil.java index 8f3e748627..91a0d6cab8 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/MEMStoreUtil.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/MEMStoreUtil.java @@ -1,36 +1,36 @@ -/*
- * Copyright (c) 2004 - 2012 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.mem;
-
-import org.eclipse.emf.cdo.internal.server.mem.MEMStore;
-
-/**
- * Creates {@link IMEMStore} instances.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public final class MEMStoreUtil
-{
- private MEMStoreUtil()
- {
- }
-
- /**
- * Creates a {@link IMEMStore} instance.
- *
- * @since 4.0
- */
- public static IMEMStore createMEMStore()
- {
- return new MEMStore();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.mem; + +import org.eclipse.emf.cdo.internal.server.mem.MEMStore; + +/** + * Creates {@link IMEMStore} instances. + * + * @author Eike Stepper + * @since 2.0 + */ +public final class MEMStoreUtil +{ + private MEMStoreUtil() + { + } + + /** + * Creates a {@link IMEMStore} instance. + * + * @since 4.0 + */ + public static IMEMStore createMEMStore() + { + return new MEMStore(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/package-info.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/package-info.java index d333025ad1..511f971b3f 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/package-info.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/mem/package-info.java @@ -1,15 +1,15 @@ -/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Server concepts for dealing with in-memory stores.
- */
-package org.eclipse.emf.cdo.server.mem;
+/* + * Copyright (c) 2004 - 2012 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 + */ + +/** + * Server concepts for dealing with in-memory stores. + */ +package org.eclipse.emf.cdo.server.mem; diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/package-info.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/package-info.java index d4531db43d..fd0f879592 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/package-info.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/package-info.java @@ -1,23 +1,23 @@ -/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Server concepts for dealing with repositories and stores.
- *
- * @apiviz.exclude .*\.CDOServerBrowser.*
- * @apiviz.exclude .*\.CommitInfoLoader
- * @apiviz.exclude .*\.BranchLoader
- * @apiviz.exclude .*\.IContainer
- * @apiviz.exclude .*\.INotifier
- * @apiviz.exclude .*Exception
- */
-package org.eclipse.emf.cdo.server;
-
+/* + * Copyright (c) 2004 - 2012 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 + */ + +/** + * Server concepts for dealing with repositories and stores. + * + * @apiviz.exclude .*\.CDOServerBrowser.* + * @apiviz.exclude .*\.CommitInfoLoader + * @apiviz.exclude .*\.BranchLoader + * @apiviz.exclude .*\.IContainer + * @apiviz.exclude .*\.INotifier + * @apiviz.exclude .*Exception + */ +package org.eclipse.emf.cdo.server; + diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerQueryHandlerProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerQueryHandlerProvider.java index 5b4e2a9606..5364dbeaf9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerQueryHandlerProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerQueryHandlerProvider.java @@ -1,44 +1,44 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.server.IQueryHandler;
-import org.eclipse.emf.cdo.server.IQueryHandlerProvider;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class ContainerQueryHandlerProvider implements IQueryHandlerProvider
-{
- private IManagedContainer container;
-
- public ContainerQueryHandlerProvider(IManagedContainer container)
- {
- this.container = container;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- /**
- * @since 3.0
- */
- public IQueryHandler getQueryHandler(CDOQueryInfo info)
- {
- return (IQueryHandler)container.getElement(QueryHandlerFactory.PRODUCT_GROUP, info.getQueryLanguage(), null);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.server.IQueryHandler; +import org.eclipse.emf.cdo.server.IQueryHandlerProvider; + +import org.eclipse.net4j.util.container.IManagedContainer; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class ContainerQueryHandlerProvider implements IQueryHandlerProvider +{ + private IManagedContainer container; + + public ContainerQueryHandlerProvider(IManagedContainer container) + { + this.container = container; + } + + public IManagedContainer getContainer() + { + return container; + } + + /** + * @since 3.0 + */ + public IQueryHandler getQueryHandler(CDOQueryInfo info) + { + return (IQueryHandler)container.getElement(QueryHandlerFactory.PRODUCT_GROUP, info.getQueryLanguage(), null); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerRepositoryProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerRepositoryProvider.java index eb1d6821f9..305776ce6f 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerRepositoryProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ContainerRepositoryProvider.java @@ -1,49 +1,49 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IRepositoryProvider;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class ContainerRepositoryProvider implements IRepositoryProvider
-{
- private IManagedContainer container;
-
- public ContainerRepositoryProvider(IManagedContainer container)
- {
- this.container = container;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public IRepository getRepository(String name)
- {
- try
- {
- return RepositoryFactory.get(container, name);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- return null;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.internal.server.bundle.OM; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IRepositoryProvider; + +import org.eclipse.net4j.util.container.IManagedContainer; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class ContainerRepositoryProvider implements IRepositoryProvider +{ + private IManagedContainer container; + + public ContainerRepositoryProvider(IManagedContainer container) + { + this.container = container; + } + + public IManagedContainer getContainer() + { + return container; + } + + public IRepository getRepository(String name) + { + try + { + return RepositoryFactory.get(container, name); + } + catch (Exception ex) + { + OM.LOG.error(ex); + return null; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/DurableLockArea.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/DurableLockArea.java index ba7f5a5b88..ae037e316f 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/DurableLockArea.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/DurableLockArea.java @@ -1,108 +1,108 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-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.lock.CDOLockUtil;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockGrade;
-
-import java.text.MessageFormat;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- * @noextend This interface is not intended to be extended by clients.
- * @deprecated Use {@link CDOLockUtil#createLockArea(String, String, CDOBranchPoint, boolean, Map)} instead
- */
-@Deprecated
-public class DurableLockArea implements LockArea
-{
- public static final int DEFAULT_DURABLE_LOCKING_ID_BYTES = 32;
-
- private String durableLockingID;
-
- private String userID;
-
- private CDOBranchPoint branchPoint;
-
- private boolean readOnly;
-
- private Map<CDOID, LockGrade> locks;
-
- public DurableLockArea(String durableLockingID, String userID, CDOBranchPoint branchPoint, boolean readOnly,
- Map<CDOID, LockGrade> locks)
- {
- this.durableLockingID = durableLockingID;
- this.userID = userID;
- this.branchPoint = branchPoint;
- this.readOnly = readOnly;
- this.locks = locks;
- }
-
- public String getDurableLockingID()
- {
- return durableLockingID;
- }
-
- public String getUserID()
- {
- return userID;
- }
-
- public CDOBranch getBranch()
- {
- return branchPoint.getBranch();
- }
-
- public long getTimeStamp()
- {
- return branchPoint.getTimeStamp();
- }
-
- public boolean isReadOnly()
- {
- return readOnly;
- }
-
- public Map<CDOID, LockGrade> getLocks()
- {
- return locks;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("DurableLockArea\nid={0}\nuser={1}\nbranchPoint={2}\nreadOnly={3}\nlocks={4}",
- durableLockingID, userID, branchPoint, readOnly, locks);
- }
-
- public static String createDurableLockingID()
- {
- return CDOLockUtil.createDurableLockingID();
- }
-
- public static String createDurableLockingID(int bytes)
- {
- return CDOLockUtil.createDurableLockingID(bytes);
- }
-
- /**
- * @since 4.1
- */
- public boolean isMissing()
- {
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +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.lock.CDOLockUtil; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockGrade; + +import java.text.MessageFormat; +import java.util.Map; + +/** + * @author Eike Stepper + * @since 4.0 + * @noextend This interface is not intended to be extended by clients. + * @deprecated Use {@link CDOLockUtil#createLockArea(String, String, CDOBranchPoint, boolean, Map)} instead + */ +@Deprecated +public class DurableLockArea implements LockArea +{ + public static final int DEFAULT_DURABLE_LOCKING_ID_BYTES = 32; + + private String durableLockingID; + + private String userID; + + private CDOBranchPoint branchPoint; + + private boolean readOnly; + + private Map<CDOID, LockGrade> locks; + + public DurableLockArea(String durableLockingID, String userID, CDOBranchPoint branchPoint, boolean readOnly, + Map<CDOID, LockGrade> locks) + { + this.durableLockingID = durableLockingID; + this.userID = userID; + this.branchPoint = branchPoint; + this.readOnly = readOnly; + this.locks = locks; + } + + public String getDurableLockingID() + { + return durableLockingID; + } + + public String getUserID() + { + return userID; + } + + public CDOBranch getBranch() + { + return branchPoint.getBranch(); + } + + public long getTimeStamp() + { + return branchPoint.getTimeStamp(); + } + + public boolean isReadOnly() + { + return readOnly; + } + + public Map<CDOID, LockGrade> getLocks() + { + return locks; + } + + @Override + public String toString() + { + return MessageFormat.format("DurableLockArea\nid={0}\nuser={1}\nbranchPoint={2}\nreadOnly={3}\nlocks={4}", + durableLockingID, userID, branchPoint, readOnly, locks); + } + + public static String createDurableLockingID() + { + return CDOLockUtil.createDurableLockingID(); + } + + public static String createDurableLockingID(int bytes) + { + return CDOLockUtil.createDurableLockingID(bytes); + } + + /** + * @since 4.1 + */ + public boolean isMissing() + { + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/FactoriesQueryHandlerProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/FactoriesQueryHandlerProvider.java index 344527a70b..a8c3f4b0cb 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/FactoriesQueryHandlerProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/FactoriesQueryHandlerProvider.java @@ -1,76 +1,76 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.server.IQueryHandler;
-import org.eclipse.emf.cdo.server.IQueryHandlerProvider;
-
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class FactoriesQueryHandlerProvider implements IQueryHandlerProvider
-{
- private IRegistry<String, IFactory> registry;
-
- public FactoriesQueryHandlerProvider()
- {
- }
-
- public FactoriesQueryHandlerProvider(IRegistry<String, IFactory> registry)
- {
- setRegistry(registry);
- }
-
- public FactoriesQueryHandlerProvider(IFactory factory)
- {
- addFactory(factory);
- }
-
- public IRegistry<String, IFactory> getRegistry()
- {
- if (registry == null)
- {
- registry = new HashMapRegistry<String, IFactory>();
- }
-
- return registry;
- }
-
- public void setRegistry(IRegistry<String, IFactory> registry)
- {
- this.registry = registry;
- }
-
- public void addFactory(IFactory factory)
- {
- getRegistry().put(factory.getKey().getType(), factory);
- }
-
- /**
- * @since 3.0
- */
- public IQueryHandler getQueryHandler(CDOQueryInfo info)
- {
- IFactory factory = registry.get(info.getQueryLanguage());
- if (factory != null)
- {
- return (IQueryHandler)factory.create(null);
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.server.IQueryHandler; +import org.eclipse.emf.cdo.server.IQueryHandlerProvider; + +import org.eclipse.net4j.util.factory.IFactory; +import org.eclipse.net4j.util.registry.HashMapRegistry; +import org.eclipse.net4j.util.registry.IRegistry; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class FactoriesQueryHandlerProvider implements IQueryHandlerProvider +{ + private IRegistry<String, IFactory> registry; + + public FactoriesQueryHandlerProvider() + { + } + + public FactoriesQueryHandlerProvider(IRegistry<String, IFactory> registry) + { + setRegistry(registry); + } + + public FactoriesQueryHandlerProvider(IFactory factory) + { + addFactory(factory); + } + + public IRegistry<String, IFactory> getRegistry() + { + if (registry == null) + { + registry = new HashMapRegistry<String, IFactory>(); + } + + return registry; + } + + public void setRegistry(IRegistry<String, IFactory> registry) + { + this.registry = registry; + } + + public void addFactory(IFactory factory) + { + getRegistry().put(factory.getKey().getType(), factory); + } + + /** + * @since 3.0 + */ + public IQueryHandler getQueryHandler(CDOQueryInfo info) + { + IFactory factory = registry.get(info.getQueryLanguage()); + if (factory != null) + { + return (IQueryHandler)factory.create(null); + } + + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/IAppExtension.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/IAppExtension.java index 455af2c114..ccbca72be2 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/IAppExtension.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/IAppExtension.java @@ -1,26 +1,26 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import java.io.File;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- */
-public interface IAppExtension
-{
- public static final String EXT_POINT = "appExtensions"; //$NON-NLS-1$
-
- public void start(File configFile) throws Exception;
-
- public void stop() throws Exception;
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import java.io.File; + +/** + * @author Eike Stepper + * @since 3.0 + */ +public interface IAppExtension +{ + public static final String EXT_POINT = "appExtensions"; //$NON-NLS-1$ + + public void start(File configFile) throws Exception; + + public void stop() throws Exception; +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ISessionProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ISessionProtocol.java index ee51f0c6d0..97cca82c49 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ISessionProtocol.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ISessionProtocol.java @@ -1,63 +1,63 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
-import org.eclipse.emf.cdo.common.protocol.CDOProtocol;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface ISessionProtocol extends CDOProtocol
-{
- /**
- * @since 4.0
- */
- public CDOAuthenticationResult sendAuthenticationChallenge(byte[] randomToken) throws Exception;
-
- public void sendRepositoryTypeNotification(CDOCommonRepository.Type oldType, CDOCommonRepository.Type newType)
- throws Exception;
-
- /**
- * @deprecated
- */
- @Deprecated
- public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState)
- throws Exception;
-
- /**
- * @since 4.1
- */
- public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState,
- CDOID rootResourceID) throws Exception;
-
- public void sendBranchNotification(InternalCDOBranch branch) throws Exception;
-
- public void sendCommitNotification(CDOCommitInfo commitInfo) throws Exception;
-
- public void sendRemoteSessionNotification(InternalSession sender, byte opcode) throws Exception;
-
- public void sendRemoteMessageNotification(InternalSession sender, CDORemoteSessionMessage message) throws Exception;
-
- /**
- * @since 4.1
- */
- public void sendLockNotification(CDOLockChangeInfo lockChangeInfo) throws Exception;
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.CDOCommonRepository; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo; +import org.eclipse.emf.cdo.common.protocol.CDOProtocol; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; +import org.eclipse.emf.cdo.spi.common.CDOAuthenticationResult; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ISessionProtocol extends CDOProtocol +{ + /** + * @since 4.0 + */ + public CDOAuthenticationResult sendAuthenticationChallenge(byte[] randomToken) throws Exception; + + public void sendRepositoryTypeNotification(CDOCommonRepository.Type oldType, CDOCommonRepository.Type newType) + throws Exception; + + /** + * @deprecated + */ + @Deprecated + public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState) + throws Exception; + + /** + * @since 4.1 + */ + public void sendRepositoryStateNotification(CDOCommonRepository.State oldState, CDOCommonRepository.State newState, + CDOID rootResourceID) throws Exception; + + public void sendBranchNotification(InternalCDOBranch branch) throws Exception; + + public void sendCommitNotification(CDOCommitInfo commitInfo) throws Exception; + + public void sendRemoteSessionNotification(InternalSession sender, byte opcode) throws Exception; + + public void sendRemoteMessageNotification(InternalSession sender, CDORemoteSessionMessage message) throws Exception; + + /** + * @since 4.1 + */ + public void sendLockNotification(CDOLockChangeInfo lockChangeInfo) throws Exception; +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitContext.java index b3b1cbe22c..fd074bc6d4 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitContext.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitContext.java @@ -1,109 +1,109 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.monitor.ProgressDistributable;
-import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
-
-import org.eclipse.emf.ecore.EClass;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalCommitContext extends IStoreAccessor.CommitContext
-{
- @SuppressWarnings("unchecked")
- public static final ProgressDistributable<InternalCommitContext>[] OPS = ProgressDistributor.array( //
- new ProgressDistributable.Default<InternalCommitContext>()
- {
- public void runLoop(int index, InternalCommitContext commitContext, OMMonitor monitor) throws Exception
- {
- commitContext.write(monitor.fork());
- }
- }, //
-
- new ProgressDistributable.Default<InternalCommitContext>()
- {
- public void runLoop(int index, InternalCommitContext commitContext, OMMonitor monitor) throws Exception
- {
- if (commitContext.getRollbackMessage() == null)
- {
- commitContext.commit(monitor.fork());
- }
- else
- {
- monitor.worked();
- }
- }
- });
-
- public InternalTransaction getTransaction();
-
- public void preWrite();
-
- public void write(OMMonitor monitor);
-
- public void commit(OMMonitor monitor);
-
- public void rollback(String message);
-
- public void postCommit(boolean success);
-
- /**
- * @since 4.0
- */
- public InternalCDORevision[] getDetachedRevisions();
-
- public void setNewPackageUnits(InternalCDOPackageUnit[] newPackageUnits);
-
- /**
- * @since 4.1
- */
- public void setLocksOnNewObjects(CDOLockState[] locksOnNewObjects);
-
- public void setNewObjects(InternalCDORevision[] newObjects);
-
- public void setDirtyObjectDeltas(InternalCDORevisionDelta[] dirtyObjectDeltas);
-
- public void setDetachedObjects(CDOID[] detachedObjects);
-
- /**
- * @since 4.0
- */
- public void setDetachedObjectTypes(Map<CDOID, EClass> detachedObjectTypes);
-
- public void setAutoReleaseLocksEnabled(boolean on);
-
- public void setCommitComment(String comment);
-
- /**
- * @since 4.0
- */
- public void setLobs(ExtendedDataInputStream in);
-
- public void addIDMapping(CDOID oldID, CDOID newID);
-
- public void applyIDMappings(OMMonitor monitor);
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.monitor.ProgressDistributable; +import org.eclipse.net4j.util.om.monitor.ProgressDistributor; + +import org.eclipse.emf.ecore.EClass; + +import java.util.Map; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalCommitContext extends IStoreAccessor.CommitContext +{ + @SuppressWarnings("unchecked") + public static final ProgressDistributable<InternalCommitContext>[] OPS = ProgressDistributor.array( // + new ProgressDistributable.Default<InternalCommitContext>() + { + public void runLoop(int index, InternalCommitContext commitContext, OMMonitor monitor) throws Exception + { + commitContext.write(monitor.fork()); + } + }, // + + new ProgressDistributable.Default<InternalCommitContext>() + { + public void runLoop(int index, InternalCommitContext commitContext, OMMonitor monitor) throws Exception + { + if (commitContext.getRollbackMessage() == null) + { + commitContext.commit(monitor.fork()); + } + else + { + monitor.worked(); + } + } + }); + + public InternalTransaction getTransaction(); + + public void preWrite(); + + public void write(OMMonitor monitor); + + public void commit(OMMonitor monitor); + + public void rollback(String message); + + public void postCommit(boolean success); + + /** + * @since 4.0 + */ + public InternalCDORevision[] getDetachedRevisions(); + + public void setNewPackageUnits(InternalCDOPackageUnit[] newPackageUnits); + + /** + * @since 4.1 + */ + public void setLocksOnNewObjects(CDOLockState[] locksOnNewObjects); + + public void setNewObjects(InternalCDORevision[] newObjects); + + public void setDirtyObjectDeltas(InternalCDORevisionDelta[] dirtyObjectDeltas); + + public void setDetachedObjects(CDOID[] detachedObjects); + + /** + * @since 4.0 + */ + public void setDetachedObjectTypes(Map<CDOID, EClass> detachedObjectTypes); + + public void setAutoReleaseLocksEnabled(boolean on); + + public void setCommitComment(String comment); + + /** + * @since 4.0 + */ + public void setLobs(ExtendedDataInputStream in); + + public void addIDMapping(CDOID oldID, CDOID newID); + + public void applyIDMappings(OMMonitor monitor); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitManager.java index 38772bd8b2..424d0fb989 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalCommitManager.java @@ -1,47 +1,47 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import java.util.concurrent.ExecutionException;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalCommitManager
-{
- public InternalRepository getRepository();
-
- public void setRepository(InternalRepository repository);
-
- /**
- * Create a future to execute commitContext in a different thread.
- */
- public void preCommit(InternalCommitContext commitContext, OMMonitor monitor);
-
- /**
- * Called after a commitContext is done successfully or not.
- */
- public void remove(InternalCommitContext commitContext);
-
- public void rollback(InternalCommitContext commitContext);
-
- /**
- * Waiting for a commit to be done.
- */
- public void waitForTermination(InternalTransaction transaction) throws InterruptedException, ExecutionException;
-
- public InternalCommitContext get(InternalTransaction transaction);
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.util.concurrent.ExecutionException; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalCommitManager +{ + public InternalRepository getRepository(); + + public void setRepository(InternalRepository repository); + + /** + * Create a future to execute commitContext in a different thread. + */ + public void preCommit(InternalCommitContext commitContext, OMMonitor monitor); + + /** + * Called after a commitContext is done successfully or not. + */ + public void remove(InternalCommitContext commitContext); + + public void rollback(InternalCommitContext commitContext); + + /** + * Waiting for a commit to be done. + */ + public void waitForTermination(InternalTransaction transaction) throws InterruptedException, ExecutionException; + + public InternalCommitContext get(InternalTransaction transaction); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalFailoverParticipant.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalFailoverParticipant.java index d1cd3e6382..f4c93988e1 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalFailoverParticipant.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalFailoverParticipant.java @@ -1,24 +1,24 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalFailoverParticipant extends InternalSynchronizableRepository
-{
- public boolean isAllowBackupCommits();
-
- public void setAllowBackupCommits(boolean allowBackupCommits);
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +/** + * @author Eike Stepper + * @since 4.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalFailoverParticipant extends InternalSynchronizableRepository +{ + public boolean isAllowBackupCommits(); + + public void setAllowBackupCommits(boolean allowBackupCommits); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalLockManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalLockManager.java index 41a372e57e..6e8d557dc7 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalLockManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalLockManager.java @@ -1,144 +1,144 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch;
-import org.eclipse.emf.cdo.server.ILockingManager;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IView;
-
-import org.eclipse.net4j.util.concurrent.IRWOLockManager;
-import org.eclipse.net4j.util.concurrent.RWOLockManager.LockState;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The type of the to-be-locked objects is either {@link CDOIDAndBranch} or {@link CDOID}, depending on whether
- * branching is supported by the repository or not.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalLockManager extends IRWOLockManager<Object, IView>, ILockingManager
-{
- public InternalRepository getRepository();
-
- public void setRepository(InternalRepository repository);
-
- /**
- * @since 4.0
- */
- public Object getLockEntryObject(Object key);
-
- /**
- * @since 4.0
- */
- public Object getLockKey(CDOID id, CDOBranch branch);
-
- /**
- * @since 4.0
- */
- public CDOID getLockKeyID(Object key);
-
- /**
- * @since 4.0
- */
- public Map<CDOID, LockGrade> getLocks(IView view);
-
- /**
- * @since 4.0
- */
- @Deprecated
- public void lock(boolean explicit, LockType type, IView context, Collection<? extends Object> objects, long timeout)
- throws InterruptedException;
-
- /**
- * @since 4.1
- */
- public List<LockState<Object, IView>> lock2(boolean explicit, LockType type, IView context,
- Collection<? extends Object> objects, boolean recursive, long timeout) throws InterruptedException;
-
- /**
- * Attempts to release for a given locktype, view and objects.
- *
- * @throws IllegalMonitorStateException
- * Unlocking objects without lock.
- * @since 4.0
- */
- @Deprecated
- public void unlock(boolean explicit, LockType type, IView context, Collection<? extends Object> objects);
-
- /**
- * @since 4.1
- */
- public List<LockState<Object, IView>> unlock2(boolean explicit, LockType type, IView context,
- Collection<? extends Object> objects, boolean recursive);
-
- /**
- * Attempts to release all locks(read and write) for a given view.
- *
- * @since 4.0
- */
- @Deprecated
- public void unlock(boolean explicit, IView context);
-
- /**
- * @since 4.1
- */
- public List<LockState<Object, IView>> unlock2(boolean explicit, IView context);
-
- /**
- * @since 4.0
- */
- public LockArea createLockArea(InternalView view);
-
- /**
- * @since 4.1
- */
- public LockArea createLockArea(InternalView view, String lockAreaID);
-
- /**
- * @since 4.1
- */
- // TODO (CD) I've also added this to DurableLocking2 Refactoring opportunity?
- public void updateLockArea(LockArea lockArea);
-
- /**
- * @since 4.0
- */
- public IView openView(ISession session, int viewID, boolean readOnly, String durableLockingID);
-
- /**
- * @since 4.1
- */
- public LockGrade getLockGrade(Object key);
-
- /**
- * @since 4.1
- */
- public LockState<Object, IView> getLockState(Object key);
-
- /**
- * @since 4.1
- */
- public void setLockState(Object key, LockState<Object, IView> lockState);
-
- /**
- * @since 4.1
- */
- public void reloadLocks();
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch; +import org.eclipse.emf.cdo.server.ILockingManager; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.IView; + +import org.eclipse.net4j.util.concurrent.IRWOLockManager; +import org.eclipse.net4j.util.concurrent.RWOLockManager.LockState; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * The type of the to-be-locked objects is either {@link CDOIDAndBranch} or {@link CDOID}, depending on whether + * branching is supported by the repository or not. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalLockManager extends IRWOLockManager<Object, IView>, ILockingManager +{ + public InternalRepository getRepository(); + + public void setRepository(InternalRepository repository); + + /** + * @since 4.0 + */ + public Object getLockEntryObject(Object key); + + /** + * @since 4.0 + */ + public Object getLockKey(CDOID id, CDOBranch branch); + + /** + * @since 4.0 + */ + public CDOID getLockKeyID(Object key); + + /** + * @since 4.0 + */ + public Map<CDOID, LockGrade> getLocks(IView view); + + /** + * @since 4.0 + */ + @Deprecated + public void lock(boolean explicit, LockType type, IView context, Collection<? extends Object> objects, long timeout) + throws InterruptedException; + + /** + * @since 4.1 + */ + public List<LockState<Object, IView>> lock2(boolean explicit, LockType type, IView context, + Collection<? extends Object> objects, boolean recursive, long timeout) throws InterruptedException; + + /** + * Attempts to release for a given locktype, view and objects. + * + * @throws IllegalMonitorStateException + * Unlocking objects without lock. + * @since 4.0 + */ + @Deprecated + public void unlock(boolean explicit, LockType type, IView context, Collection<? extends Object> objects); + + /** + * @since 4.1 + */ + public List<LockState<Object, IView>> unlock2(boolean explicit, LockType type, IView context, + Collection<? extends Object> objects, boolean recursive); + + /** + * Attempts to release all locks(read and write) for a given view. + * + * @since 4.0 + */ + @Deprecated + public void unlock(boolean explicit, IView context); + + /** + * @since 4.1 + */ + public List<LockState<Object, IView>> unlock2(boolean explicit, IView context); + + /** + * @since 4.0 + */ + public LockArea createLockArea(InternalView view); + + /** + * @since 4.1 + */ + public LockArea createLockArea(InternalView view, String lockAreaID); + + /** + * @since 4.1 + */ + // TODO (CD) I've also added this to DurableLocking2 Refactoring opportunity? + public void updateLockArea(LockArea lockArea); + + /** + * @since 4.0 + */ + public IView openView(ISession session, int viewID, boolean readOnly, String durableLockingID); + + /** + * @since 4.1 + */ + public LockGrade getLockGrade(Object key); + + /** + * @since 4.1 + */ + public LockState<Object, IView> getLockState(Object key); + + /** + * @since 4.1 + */ + public void setLockState(Object key, LockState<Object, IView> lockState); + + /** + * @since 4.1 + */ + public void reloadLocks(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryManager.java index 2d84d402b3..aed0038b58 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryManager.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalQueryManager
-{
- public InternalRepository getRepository();
-
- public void setRepository(InternalRepository repository);
-
- public InternalQueryResult execute(InternalView view, CDOQueryInfo queryInfo);
-
- public boolean isRunning(int queryID);
-
- public void cancel(int queryID);
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalQueryManager +{ + public InternalRepository getRepository(); + + public void setRepository(InternalRepository repository); + + public InternalQueryResult execute(InternalView view, CDOQueryInfo queryInfo); + + public boolean isRunning(int queryID); + + public void cancel(int queryID); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryResult.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryResult.java index 47442b70cb..03eafb0f68 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryResult.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalQueryResult.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.util.BlockingCloseableIterator;
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.common.util.CDOQueryQueue;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalQueryResult extends BlockingCloseableIterator<Object>
-{
- public int getQueryID();
-
- public CDOQueryInfo getQueryInfo();
-
- public InternalView getView();
-
- public CDOQueryQueue<Object> getQueue();
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.util.BlockingCloseableIterator; +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.common.util.CDOQueryQueue; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalQueryResult extends BlockingCloseableIterator<Object> +{ + public int getQueryID(); + + public CDOQueryInfo getQueryInfo(); + + public InternalView getView(); + + public CDOQueryQueue<Object> getQueue(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalRepositorySynchronizer.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalRepositorySynchronizer.java index d1eafc09b0..5093897db9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalRepositorySynchronizer.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalRepositorySynchronizer.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.server.IRepositorySynchronizer;
-import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
-
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalRepositorySynchronizer extends IRepositorySynchronizer, ILifecycle
-{
- public InternalSynchronizableRepository getLocalRepository();
-
- public void setLocalRepository(InternalSynchronizableRepository localRepository);
-
- public void setRemoteSessionConfigurationFactory(CDOSessionConfigurationFactory remoteSessionConfigurationFactory);
-
- public InternalCDOSession getRemoteSession();
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.server.IRepositorySynchronizer; +import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; + +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +import org.eclipse.emf.spi.cdo.InternalCDOSession; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalRepositorySynchronizer extends IRepositorySynchronizer, ILifecycle +{ + public InternalSynchronizableRepository getLocalRepository(); + + public void setLocalRepository(InternalSynchronizableRepository localRepository); + + public void setRemoteSessionConfigurationFactory(CDOSessionConfigurationFactory remoteSessionConfigurationFactory); + + public InternalCDOSession getRemoteSession(); +} 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 e4e06ad68e..71b255874c 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 @@ -1,112 +1,112 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IStore;
-
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- */
-public interface InternalStore extends IStore, ILifecycle
-{
- public InternalRepository getRepository();
-
- public void setRepository(IRepository repository);
-
- public void setRevisionTemporality(RevisionTemporality revisionTemporality);
-
- public void setRevisionParallelism(RevisionParallelism revisionParallelism);
-
- public int getNextBranchID();
-
- public int getNextLocalBranchID();
-
- public void setLastBranchID(int lastBranchID);
-
- public void setLastLocalBranchID(int lastLocalBranchID);
-
- public void setLastCommitTime(long lastCommitTime);
-
- public void setLastNonLocalCommitTime(long lastNonLocalCommitTime);
-
- /**
- * @since 4.0
- */
- public boolean isLocal(CDOID id);
-
- /**
- * @since 4.0
- */
- public boolean isDropAllDataOnActivate();
-
- /**
- * @since 4.0
- */
- public void setDropAllDataOnActivate(boolean dropAllDataOnActivate);
-
- /**
- * @since 4.0
- */
- public void setCreationTime(long creationTime);
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoExternalReferences
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoQueryXRefs
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoLargeObjects
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoFeatureMaps
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoHandleRevisions
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 4.0
- */
- public interface NoRawAccess
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IStore; + +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +/** + * @author Eike Stepper + * @since 3.0 + */ +public interface InternalStore extends IStore, ILifecycle +{ + public InternalRepository getRepository(); + + public void setRepository(IRepository repository); + + public void setRevisionTemporality(RevisionTemporality revisionTemporality); + + public void setRevisionParallelism(RevisionParallelism revisionParallelism); + + public int getNextBranchID(); + + public int getNextLocalBranchID(); + + public void setLastBranchID(int lastBranchID); + + public void setLastLocalBranchID(int lastLocalBranchID); + + public void setLastCommitTime(long lastCommitTime); + + public void setLastNonLocalCommitTime(long lastNonLocalCommitTime); + + /** + * @since 4.0 + */ + public boolean isLocal(CDOID id); + + /** + * @since 4.0 + */ + public boolean isDropAllDataOnActivate(); + + /** + * @since 4.0 + */ + public void setDropAllDataOnActivate(boolean dropAllDataOnActivate); + + /** + * @since 4.0 + */ + public void setCreationTime(long creationTime); + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoExternalReferences + { + } + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoQueryXRefs + { + } + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoLargeObjects + { + } + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoFeatureMaps + { + } + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoHandleRevisions + { + } + + /** + * @author Eike Stepper + * @since 4.0 + */ + public interface NoRawAccess + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalSynchronizableRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalSynchronizableRepository.java index 11119199d6..ef152cb169 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalSynchronizableRepository.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalSynchronizableRepository.java @@ -1,36 +1,36 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfoHandler;
-import org.eclipse.emf.cdo.server.ISynchronizableRepository;
-import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationContext;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalSynchronizableRepository extends ISynchronizableRepository, InternalRepository,
- CDOReplicationContext, CDORawReplicationContext, CDOLockChangeInfoHandler
-{
- public InternalRepositorySynchronizer getSynchronizer();
-
- public void setSynchronizer(InternalRepositorySynchronizer synchronizer);
-
- public InternalSession getReplicatorSession();
-
- public void setLastReplicatedBranchID(int lastReplicatedBranchID);
-
- public void setLastReplicatedCommitTime(long lastReplicatedCommitTime);
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfoHandler; +import org.eclipse.emf.cdo.server.ISynchronizableRepository; +import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext; +import org.eclipse.emf.cdo.spi.common.CDOReplicationContext; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalSynchronizableRepository extends ISynchronizableRepository, InternalRepository, + CDOReplicationContext, CDORawReplicationContext, CDOLockChangeInfoHandler +{ + public InternalRepositorySynchronizer getSynchronizer(); + + public void setSynchronizer(InternalRepositorySynchronizer synchronizer); + + public InternalSession getReplicatorSession(); + + public void setLastReplicatedBranchID(int lastReplicatedBranchID); + + public void setLastReplicatedCommitTime(long lastReplicatedCommitTime); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalTransaction.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalTransaction.java index 0983161ad6..069d561a74 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalTransaction.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalTransaction.java @@ -1,24 +1,24 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.server.ITransaction;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalTransaction extends ITransaction, InternalView
-{
- public InternalCommitContext createCommitContext();
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.server.ITransaction; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalTransaction extends ITransaction, InternalView +{ + public InternalCommitContext createCommitContext(); +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalView.java index c8cad8c149..b8d8671d26 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalView.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalView.java @@ -1,56 +1,56 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.server.IView;
-
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.List;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalView extends IView, ILifecycle
-{
- public InternalSession getSession();
-
- public InternalRepository getRepository();
-
- public void setBranchPoint(CDOBranchPoint branchPoint);
-
- /**
- * @since 4.0
- */
- public void setDurableLockingID(String durableLockingID);
-
- /**
- * @since 4.0
- */
- public void changeTarget(CDOBranchPoint branchPoint, List<CDOID> invalidObjects,
- List<CDORevisionDelta> allChangedObjects, List<CDOID> allDetachedObjects);
-
- public void subscribe(CDOID id);
-
- public void unsubscribe(CDOID id);
-
- public boolean hasSubscription(CDOID id);
-
- public void clearChangeSubscription();
-
- public void doClose();
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.server.IView; + +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +import java.util.List; + +/** + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalView extends IView, ILifecycle +{ + public InternalSession getSession(); + + public InternalRepository getRepository(); + + public void setBranchPoint(CDOBranchPoint branchPoint); + + /** + * @since 4.0 + */ + public void setDurableLockingID(String durableLockingID); + + /** + * @since 4.0 + */ + public void changeTarget(CDOBranchPoint branchPoint, List<CDOID> invalidObjects, + List<CDORevisionDelta> allChangedObjects, List<CDOID> allDetachedObjects); + + public void subscribe(CDOID id); + + public void unsubscribe(CDOID id); + + public boolean hasSubscription(CDOID id); + + public void clearChangeSubscription(); + + public void doClose(); +} 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 e56ccdf7f4..bb21342be8 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 @@ -1,120 +1,120 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class LongIDStore extends Store
-{
- /**
- * @since 3.0
- */
- public static final Set<ObjectType> OBJECT_ID_TYPES = Collections.singleton(CDOID.ObjectType.LONG);
-
- /**
- * @since 3.0
- */
- public static final long NULL = CDOIDUtil.getLong(CDOID.NULL);
-
- @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)
- {
- super(type, OBJECT_ID_TYPES, supportedChangeFormats, supportedRevisionTemporalities, supportedRevisionParallelisms);
- }
-
- /**
- * @since 4.0
- */
- public CDOID createObjectID(String val)
- {
- Long id = Long.valueOf(val);
- return CDOIDUtil.createLong(id);
- }
-
- public long getLastObjectID()
- {
- return lastObjectID.get();
- }
-
- public void setLastObjectID(long lastObjectID)
- {
- this.lastObjectID.set(lastObjectID);
- }
-
- /**
- * @since 3.0
- */
- public long getNextLocalObjectID()
- {
- return nextLocalObjectID.get();
- }
-
- /**
- * @since 3.0
- */
- public void setNextLocalObjectID(long nextLocalObjectID)
- {
- this.nextLocalObjectID.set(nextLocalObjectID);
- }
-
- /**
- * @since 4.0
- */
- public CDOID getNextCDOID(LongIDStoreAccessor accessor, CDORevision revision)
- {
- if (revision.getBranch().isLocal())
- {
- return CDOIDUtil.createLong(nextLocalObjectID.getAndDecrement());
- }
-
- return CDOIDUtil.createLong(lastObjectID.incrementAndGet());
- }
-
- /**
- * @since 4.0
- */
- public boolean isLocal(CDOID id)
- {
- long value = CDOIDUtil.getLong(id);
- return value > nextLocalObjectID.get();
- }
-
- /**
- * @since 4.0
- */
- public void ensureLastObjectID(CDOID id)
- {
- long addedID = CDOIDUtil.getLong(id);
- if (addedID > getLastObjectID())
- {
- setLastObjectID(addedID);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOID.ObjectType; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDORevision; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; + +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class LongIDStore extends Store +{ + /** + * @since 3.0 + */ + public static final Set<ObjectType> OBJECT_ID_TYPES = Collections.singleton(CDOID.ObjectType.LONG); + + /** + * @since 3.0 + */ + public static final long NULL = CDOIDUtil.getLong(CDOID.NULL); + + @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) + { + super(type, OBJECT_ID_TYPES, supportedChangeFormats, supportedRevisionTemporalities, supportedRevisionParallelisms); + } + + /** + * @since 4.0 + */ + public CDOID createObjectID(String val) + { + Long id = Long.valueOf(val); + return CDOIDUtil.createLong(id); + } + + public long getLastObjectID() + { + return lastObjectID.get(); + } + + public void setLastObjectID(long lastObjectID) + { + this.lastObjectID.set(lastObjectID); + } + + /** + * @since 3.0 + */ + public long getNextLocalObjectID() + { + return nextLocalObjectID.get(); + } + + /** + * @since 3.0 + */ + public void setNextLocalObjectID(long nextLocalObjectID) + { + this.nextLocalObjectID.set(nextLocalObjectID); + } + + /** + * @since 4.0 + */ + public CDOID getNextCDOID(LongIDStoreAccessor accessor, CDORevision revision) + { + if (revision.getBranch().isLocal()) + { + return CDOIDUtil.createLong(nextLocalObjectID.getAndDecrement()); + } + + return CDOIDUtil.createLong(lastObjectID.incrementAndGet()); + } + + /** + * @since 4.0 + */ + public boolean isLocal(CDOID id) + { + long value = CDOIDUtil.getLong(id); + return value > nextLocalObjectID.get(); + } + + /** + * @since 4.0 + */ + public void ensureLastObjectID(CDOID id) + { + long addedID = CDOIDUtil.getLong(id); + if (addedID > getLastObjectID()) + { + setLastObjectID(addedID); + } + } +} 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 5002267366..197881b86d 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 @@ -1,50 +1,50 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 201266
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.spi.server;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.ITransaction;
-
-/**
- * @since 2.0
- * @author Eike Stepper
- */
-public abstract class LongIDStoreAccessor extends StoreAccessor
-{
- protected LongIDStoreAccessor(Store store, ISession session)
- {
- super(store, session);
- }
-
- protected LongIDStoreAccessor(Store store, ITransaction transaction)
- {
- super(store, transaction);
- }
-
- /**
- * @since 4.0
- */
- @Override
- public LongIDStore getStore()
- {
- return (LongIDStore)super.getStore();
- }
-
- @Override
- protected CDOID getNextCDOID(CDORevision revision)
- {
- return getStore().getNextCDOID(this, revision);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 201266 + * Simon McDuff - bug 213402 + */ +package org.eclipse.emf.cdo.spi.server; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.ITransaction; + +/** + * @since 2.0 + * @author Eike Stepper + */ +public abstract class LongIDStoreAccessor extends StoreAccessor +{ + protected LongIDStoreAccessor(Store store, ISession session) + { + super(store, session); + } + + protected LongIDStoreAccessor(Store store, ITransaction transaction) + { + super(store, transaction); + } + + /** + * @since 4.0 + */ + @Override + public LongIDStore getStore() + { + return (LongIDStore)super.getStore(); + } + + @Override + protected CDOID getNextCDOID(CDORevision revision) + { + return getStore().getNextCDOID(this, revision); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ObjectWriteAccessHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ObjectWriteAccessHandler.java index 31251f3aba..7d6aac1fe9 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ObjectWriteAccessHandler.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/ObjectWriteAccessHandler.java @@ -1,159 +1,159 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.server.CDOServerUtil;
-import org.eclipse.emf.cdo.server.IRepository.WriteAccessHandler;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
-import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public class ObjectWriteAccessHandler implements WriteAccessHandler
-{
- private boolean legacyModeEnabled;
-
- private IStoreAccessor.CommitContext commitContext;
-
- private CDOView view;
-
- private EObject[] newObjects;
-
- private EObject[] dirtyObjects;
-
- public ObjectWriteAccessHandler()
- {
- }
-
- public ObjectWriteAccessHandler(boolean legacyModeEnabled)
- {
- this.legacyModeEnabled = legacyModeEnabled;
- }
-
- public final boolean isLegacyModeEnabled()
- {
- return legacyModeEnabled;
- }
-
- protected final IStoreAccessor.CommitContext getCommitContext()
- {
- return commitContext;
- }
-
- protected final ITransaction getTransaction()
- {
- return commitContext.getTransaction();
- }
-
- protected final CDOView getView()
- {
- if (view == null)
- {
- view = CDOServerUtil.openView(commitContext, legacyModeEnabled);
- }
-
- return view;
- }
-
- protected final EObject[] getNewObjects()
- {
- if (newObjects == null)
- {
- InternalCDORevision[] newRevisions = commitContext.getNewObjects();
- newObjects = new EObject[newRevisions.length];
- CDOView view = getView();
-
- for (int i = 0; i < newRevisions.length; i++)
- {
- InternalCDORevision newRevision = newRevisions[i];
- CDOObject newObject = view.getObject(newRevision.getID());
- newObjects[i] = CDOUtil.getEObject(newObject);
- }
- }
-
- return newObjects;
- }
-
- protected final EObject[] getDirtyObjects()
- {
- if (dirtyObjects == null)
- {
- InternalCDORevision[] dirtyRevisions = commitContext.getDirtyObjects();
- dirtyObjects = new EObject[dirtyRevisions.length];
- CDOView view = getView();
-
- for (int i = 0; i < dirtyRevisions.length; i++)
- {
- InternalCDORevision dirtyRevision = dirtyRevisions[i];
- CDOObject dirtyObject = view.getObject(dirtyRevision.getID());
- dirtyObjects[i] = CDOUtil.getEObject(dirtyObject);
- }
- }
-
- return dirtyObjects;
- }
-
- public final void handleTransactionBeforeCommitting(ITransaction transaction,
- IStoreAccessor.CommitContext commitContext, OMMonitor monitor) throws RuntimeException
- {
- try
- {
- this.commitContext = commitContext;
- handleTransactionBeforeCommitting(monitor);
- }
- finally
- {
- LifecycleUtil.deactivate(view);
- view = null;
- dirtyObjects = null;
- newObjects = null;
- this.commitContext = null;
- }
- }
-
- public final void handleTransactionAfterCommitted(ITransaction transaction, CommitContext commitContext,
- OMMonitor monitor)
- {
- try
- {
- this.commitContext = commitContext;
- handleTransactionAfterCommitted(monitor);
- }
- finally
- {
- LifecycleUtil.deactivate(view);
- view = null;
- dirtyObjects = null;
- newObjects = null;
- this.commitContext = null;
- }
- }
-
- protected void handleTransactionBeforeCommitting(OMMonitor monitor) throws RuntimeException
- {
- }
-
- protected void handleTransactionAfterCommitted(OMMonitor monitor)
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.server.CDOServerUtil; +import org.eclipse.emf.cdo.server.IRepository.WriteAccessHandler; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext; +import org.eclipse.emf.cdo.server.ITransaction; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import org.eclipse.emf.ecore.EObject; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public class ObjectWriteAccessHandler implements WriteAccessHandler +{ + private boolean legacyModeEnabled; + + private IStoreAccessor.CommitContext commitContext; + + private CDOView view; + + private EObject[] newObjects; + + private EObject[] dirtyObjects; + + public ObjectWriteAccessHandler() + { + } + + public ObjectWriteAccessHandler(boolean legacyModeEnabled) + { + this.legacyModeEnabled = legacyModeEnabled; + } + + public final boolean isLegacyModeEnabled() + { + return legacyModeEnabled; + } + + protected final IStoreAccessor.CommitContext getCommitContext() + { + return commitContext; + } + + protected final ITransaction getTransaction() + { + return commitContext.getTransaction(); + } + + protected final CDOView getView() + { + if (view == null) + { + view = CDOServerUtil.openView(commitContext, legacyModeEnabled); + } + + return view; + } + + protected final EObject[] getNewObjects() + { + if (newObjects == null) + { + InternalCDORevision[] newRevisions = commitContext.getNewObjects(); + newObjects = new EObject[newRevisions.length]; + CDOView view = getView(); + + for (int i = 0; i < newRevisions.length; i++) + { + InternalCDORevision newRevision = newRevisions[i]; + CDOObject newObject = view.getObject(newRevision.getID()); + newObjects[i] = CDOUtil.getEObject(newObject); + } + } + + return newObjects; + } + + protected final EObject[] getDirtyObjects() + { + if (dirtyObjects == null) + { + InternalCDORevision[] dirtyRevisions = commitContext.getDirtyObjects(); + dirtyObjects = new EObject[dirtyRevisions.length]; + CDOView view = getView(); + + for (int i = 0; i < dirtyRevisions.length; i++) + { + InternalCDORevision dirtyRevision = dirtyRevisions[i]; + CDOObject dirtyObject = view.getObject(dirtyRevision.getID()); + dirtyObjects[i] = CDOUtil.getEObject(dirtyObject); + } + } + + return dirtyObjects; + } + + public final void handleTransactionBeforeCommitting(ITransaction transaction, + IStoreAccessor.CommitContext commitContext, OMMonitor monitor) throws RuntimeException + { + try + { + this.commitContext = commitContext; + handleTransactionBeforeCommitting(monitor); + } + finally + { + LifecycleUtil.deactivate(view); + view = null; + dirtyObjects = null; + newObjects = null; + this.commitContext = null; + } + } + + public final void handleTransactionAfterCommitted(ITransaction transaction, CommitContext commitContext, + OMMonitor monitor) + { + try + { + this.commitContext = commitContext; + handleTransactionAfterCommitted(monitor); + } + finally + { + LifecycleUtil.deactivate(view); + view = null; + dirtyObjects = null; + newObjects = null; + this.commitContext = null; + } + } + + protected void handleTransactionBeforeCommitting(OMMonitor monitor) throws RuntimeException + { + } + + protected void handleTransactionAfterCommitted(OMMonitor monitor) + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/PluginRepositoryProvider.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/PluginRepositoryProvider.java index 73581c0222..37431ac34b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/PluginRepositoryProvider.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/PluginRepositoryProvider.java @@ -1,27 +1,27 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.net4j.util.container.IPluginContainer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public final class PluginRepositoryProvider extends ContainerRepositoryProvider
-{
- public static final PluginRepositoryProvider INSTANCE = new PluginRepositoryProvider();
-
- private PluginRepositoryProvider()
- {
- super(IPluginContainer.INSTANCE);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.net4j.util.container.IPluginContainer; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public final class PluginRepositoryProvider extends ContainerRepositoryProvider +{ + public static final PluginRepositoryProvider INSTANCE = new PluginRepositoryProvider(); + + private PluginRepositoryProvider() + { + super(IPluginContainer.INSTANCE); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/QueryHandlerFactory.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/QueryHandlerFactory.java index c45d9318cb..221c2ba20b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/QueryHandlerFactory.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/QueryHandlerFactory.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.server.IQueryHandler;
-
-import org.eclipse.net4j.util.factory.Factory;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class QueryHandlerFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.server.queryHandlerFactories"; //$NON-NLS-1$
-
- public QueryHandlerFactory(String language)
- {
- super(PRODUCT_GROUP, language);
- }
-
- /**
- * @since 3.0
- */
- public abstract IQueryHandler create(String description) throws ProductCreationException;
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.server.IQueryHandler; + +import org.eclipse.net4j.util.factory.Factory; +import org.eclipse.net4j.util.factory.ProductCreationException; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class QueryHandlerFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.server.queryHandlerFactories"; //$NON-NLS-1$ + + public QueryHandlerFactory(String language) + { + super(PRODUCT_GROUP, language); + } + + /** + * @since 3.0 + */ + public abstract IQueryHandler create(String description) throws ProductCreationException; +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryConfigurator.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryConfigurator.java index 749e13fc78..57928e53cd 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryConfigurator.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryConfigurator.java @@ -1,350 +1,350 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Lothar Werzinger - support for configuring user managers
- */
-package org.eclipse.emf.cdo.spi.server;
-
-import org.eclipse.emf.cdo.internal.server.SessionManager;
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.CDOServerUtil;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IRepositoryFactory;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreFactory;
-
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.IUserManager;
-
-import org.eclipse.emf.ecore.EPackage;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public class RepositoryConfigurator
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_REPOSITORY, RepositoryConfigurator.class);
-
- private IManagedContainer container;
-
- private Map<String, IRepositoryFactory> repositoryFactories = new HashMap<String, IRepositoryFactory>();
-
- private Map<String, IStoreFactory> storeFactories = new HashMap<String, IStoreFactory>();
-
- public RepositoryConfigurator()
- {
- this(null);
- }
-
- public RepositoryConfigurator(IManagedContainer container)
- {
- this.container = container;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public Map<String, IRepositoryFactory> getRepositoryFactories()
- {
- return repositoryFactories;
- }
-
- public Map<String, IStoreFactory> getStoreFactories()
- {
- return storeFactories;
- }
-
- public IRepository[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException,
- CoreException
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Configuring CDO server from " + configFile.getAbsolutePath()); //$NON-NLS-1$
- }
-
- List<IRepository> repositories = new ArrayList<IRepository>();
- Document document = getDocument(configFile);
- NodeList elements = document.getElementsByTagName("repository"); //$NON-NLS-1$
- for (int i = 0; i < elements.getLength(); i++)
- {
- Element repositoryConfig = (Element)elements.item(i);
- IRepository repository = getRepository(repositoryConfig);
- repositories.add(repository);
-
- if (container != null)
- {
- CDOServerUtil.addRepository(container, repository);
- }
- }
-
- return repositories.toArray(new IRepository[repositories.size()]);
- }
-
- protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(configFile);
- }
-
- protected IRepositoryFactory getRepositoryFactory(String type) throws CoreException
- {
- IRepositoryFactory factory = repositoryFactories.get(type);
- if (factory == null)
- {
- factory = createExecutableExtension("repositoryFactories", "repositoryFactory", //$NON-NLS-1$ //$NON-NLS-2$
- "repositoryType", type); //$NON-NLS-1$
- }
-
- if (factory == null)
- {
- throw new IllegalStateException("CDORepositoryInfo factory not found: " + type); //$NON-NLS-1$
- }
-
- return factory;
- }
-
- protected IRepository getRepository(Element repositoryConfig) throws CoreException
- {
- String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
- if (StringUtil.isEmpty(repositoryName))
- {
- throw new IllegalArgumentException("CDORepositoryInfo name is missing or empty"); //$NON-NLS-1$
- }
-
- String repositoryType = repositoryConfig.getAttribute("type"); //$NON-NLS-1$
- if (StringUtil.isEmpty(repositoryType))
- {
- repositoryType = RepositoryFactory.TYPE;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Configuring repository {0} (type={1})", repositoryName, repositoryType); //$NON-NLS-1$
- }
-
- Map<String, String> properties = getProperties(repositoryConfig, 1);
-
- Element storeConfig = getStoreConfig(repositoryConfig);
- IStore store = createStore(repositoryName, properties, storeConfig);
-
- InternalRepository repository = (InternalRepository)getRepository(repositoryType);
- repository.setName(repositoryName);
- repository.setStore((InternalStore)store);
- repository.setProperties(properties);
-
- Element userManagerConfig = getUserManagerConfig(repositoryConfig);
- if (userManagerConfig != null)
- {
- IUserManager userManager = getUserManager(userManagerConfig);
- if (userManager != null)
- {
- InternalSessionManager sessionManager = repository.getSessionManager();
- if (sessionManager == null)
- {
- sessionManager = new SessionManager();
- repository.setSessionManager(sessionManager);
- }
-
- sessionManager.setUserManager(userManager);
- }
- }
-
- EPackage[] initialPackages = getInitialPackages(repositoryConfig);
- if (initialPackages.length != 0)
- {
- repository.setInitialPackages(initialPackages);
- }
-
- return repository;
- }
-
- protected IRepository getRepository(String repositoryType) throws CoreException
- {
- IRepositoryFactory factory = getRepositoryFactory(repositoryType);
- return factory.createRepository();
- }
-
- protected Element getUserManagerConfig(Element repositoryConfig)
- {
- NodeList userManagerConfig = repositoryConfig.getElementsByTagName("userManager"); //$NON-NLS-1$
- if (userManagerConfig.getLength() > 1)
- {
- String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
- throw new IllegalStateException("At most one user manager must be configured for repository " + repositoryName); //$NON-NLS-1$
- }
-
- return (Element)(userManagerConfig.getLength() > 0 ? userManagerConfig.item(0) : null);
- }
-
- protected IUserManager getUserManager(Element userManagerConfig) throws CoreException
- {
- String type = userManagerConfig.getAttribute("type"); //$NON-NLS-1$
- String description = userManagerConfig.getAttribute("description"); //$NON-NLS-1$
- return getUserManager(type, description);
- }
-
- protected IUserManager getUserManager(String type, String description) throws CoreException
- {
- IUserManager userManager = (IUserManager)container.getElement("org.eclipse.net4j.userManagers", type, description); //$NON-NLS-1$
- if (userManager == null)
- {
- throw new IllegalStateException("UserManager factory not found: " + type); //$NON-NLS-1$
- }
-
- return userManager;
- }
-
- protected EPackage[] getInitialPackages(Element repositoryConfig)
- {
- List<EPackage> result = new ArrayList<EPackage>();
-
- NodeList initialPackagesConfig = repositoryConfig.getElementsByTagName("initialPackage"); //$NON-NLS-1$
- for (int i = 0; i < initialPackagesConfig.getLength(); i++)
- {
- Element initialPackageConfig = (Element)initialPackagesConfig.item(i);
- String nsURI = initialPackageConfig.getAttribute("nsURI"); //$NON-NLS-1$
- if (nsURI == null)
- {
- throw new IllegalStateException("nsURI missing for initialPackage element"); //$NON-NLS-1$
- }
-
- EPackage initialPackage = EPackage.Registry.INSTANCE.getEPackage(nsURI);
- if (initialPackage == null)
- {
- throw new IllegalStateException("Initial package not found in global package registry: " + nsURI); //$NON-NLS-1$
- }
-
- result.add(initialPackage);
- }
-
- return result.toArray(new EPackage[result.size()]);
- }
-
- protected Element getStoreConfig(Element repositoryConfig)
- {
- NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$
- if (storeConfigs.getLength() == 0)
- {
- String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
- throw new IllegalStateException("A store must be configured for repository " + repositoryName); //$NON-NLS-1$
- }
-
- return (Element)storeConfigs.item(0);
- }
-
- protected IStoreFactory getStoreFactory(String type) throws CoreException
- {
- IStoreFactory factory = storeFactories.get(type);
- if (factory == null)
- {
- factory = createExecutableExtension("storeFactories", "storeFactory", "storeType", type); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- if (factory == null)
- {
- throw new IllegalStateException("Store factory not found: " + type); //$NON-NLS-1$
- }
-
- return factory;
- }
-
- protected IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig)
- throws CoreException
- {
- String type = storeConfig.getAttribute("type"); //$NON-NLS-1$
- IStoreFactory storeFactory = getStoreFactory(type);
- return storeFactory.createStore(repositoryName, repositoryProperties, storeConfig);
- }
-
- public static Map<String, String> getProperties(Element element, int levels)
- {
- Map<String, String> properties = new HashMap<String, String>();
- collectProperties(element, "", properties, levels); //$NON-NLS-1$
- return properties;
- }
-
- private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
- {
- if ("property".equals(element.getNodeName())) //$NON-NLS-1$
- {
- String name = element.getAttribute("name"); //$NON-NLS-1$
- String value = element.getAttribute("value"); //$NON-NLS-1$
- properties.put(prefix + name, value);
- prefix += name + "."; //$NON-NLS-1$
- }
-
- if (levels > 0)
- {
- NodeList childNodes = element.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++)
- {
- Node childNode = childNodes.item(i);
- if (childNode instanceof Element)
- {
- collectProperties((Element)childNode, prefix, properties, levels - 1);
- }
- }
- }
- }
-
- private static <T> T createExecutableExtension(String extPointName, String elementName, String attributeName,
- String type) throws CoreException
- {
- if (OMPlatform.INSTANCE.isExtensionRegistryAvailable())
- {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, extPointName);
- for (IConfigurationElement element : elements)
- {
- if (ObjectUtil.equals(element.getName(), elementName))
- {
- String storeType = element.getAttribute(attributeName);
- if (ObjectUtil.equals(storeType, type))
- {
- @SuppressWarnings("unchecked")
- T result = (T)element.createExecutableExtension("class"); //$NON-NLS-1$
- return result;
- }
- }
- }
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Lothar Werzinger - support for configuring user managers + */ +package org.eclipse.emf.cdo.spi.server; + +import org.eclipse.emf.cdo.internal.server.SessionManager; +import org.eclipse.emf.cdo.internal.server.bundle.OM; +import org.eclipse.emf.cdo.server.CDOServerUtil; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IRepositoryFactory; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStoreFactory; + +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.trace.ContextTracer; +import org.eclipse.net4j.util.security.IUserManager; + +import org.eclipse.emf.ecore.EPackage; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public class RepositoryConfigurator +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_REPOSITORY, RepositoryConfigurator.class); + + private IManagedContainer container; + + private Map<String, IRepositoryFactory> repositoryFactories = new HashMap<String, IRepositoryFactory>(); + + private Map<String, IStoreFactory> storeFactories = new HashMap<String, IStoreFactory>(); + + public RepositoryConfigurator() + { + this(null); + } + + public RepositoryConfigurator(IManagedContainer container) + { + this.container = container; + } + + public IManagedContainer getContainer() + { + return container; + } + + public Map<String, IRepositoryFactory> getRepositoryFactories() + { + return repositoryFactories; + } + + public Map<String, IStoreFactory> getStoreFactories() + { + return storeFactories; + } + + public IRepository[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException, + CoreException + { + if (TRACER.isEnabled()) + { + TRACER.trace("Configuring CDO server from " + configFile.getAbsolutePath()); //$NON-NLS-1$ + } + + List<IRepository> repositories = new ArrayList<IRepository>(); + Document document = getDocument(configFile); + NodeList elements = document.getElementsByTagName("repository"); //$NON-NLS-1$ + for (int i = 0; i < elements.getLength(); i++) + { + Element repositoryConfig = (Element)elements.item(i); + IRepository repository = getRepository(repositoryConfig); + repositories.add(repository); + + if (container != null) + { + CDOServerUtil.addRepository(container, repository); + } + } + + return repositories.toArray(new IRepository[repositories.size()]); + } + + protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + return builder.parse(configFile); + } + + protected IRepositoryFactory getRepositoryFactory(String type) throws CoreException + { + IRepositoryFactory factory = repositoryFactories.get(type); + if (factory == null) + { + factory = createExecutableExtension("repositoryFactories", "repositoryFactory", //$NON-NLS-1$ //$NON-NLS-2$ + "repositoryType", type); //$NON-NLS-1$ + } + + if (factory == null) + { + throw new IllegalStateException("CDORepositoryInfo factory not found: " + type); //$NON-NLS-1$ + } + + return factory; + } + + protected IRepository getRepository(Element repositoryConfig) throws CoreException + { + String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$ + if (StringUtil.isEmpty(repositoryName)) + { + throw new IllegalArgumentException("CDORepositoryInfo name is missing or empty"); //$NON-NLS-1$ + } + + String repositoryType = repositoryConfig.getAttribute("type"); //$NON-NLS-1$ + if (StringUtil.isEmpty(repositoryType)) + { + repositoryType = RepositoryFactory.TYPE; + } + + if (TRACER.isEnabled()) + { + TRACER.format("Configuring repository {0} (type={1})", repositoryName, repositoryType); //$NON-NLS-1$ + } + + Map<String, String> properties = getProperties(repositoryConfig, 1); + + Element storeConfig = getStoreConfig(repositoryConfig); + IStore store = createStore(repositoryName, properties, storeConfig); + + InternalRepository repository = (InternalRepository)getRepository(repositoryType); + repository.setName(repositoryName); + repository.setStore((InternalStore)store); + repository.setProperties(properties); + + Element userManagerConfig = getUserManagerConfig(repositoryConfig); + if (userManagerConfig != null) + { + IUserManager userManager = getUserManager(userManagerConfig); + if (userManager != null) + { + InternalSessionManager sessionManager = repository.getSessionManager(); + if (sessionManager == null) + { + sessionManager = new SessionManager(); + repository.setSessionManager(sessionManager); + } + + sessionManager.setUserManager(userManager); + } + } + + EPackage[] initialPackages = getInitialPackages(repositoryConfig); + if (initialPackages.length != 0) + { + repository.setInitialPackages(initialPackages); + } + + return repository; + } + + protected IRepository getRepository(String repositoryType) throws CoreException + { + IRepositoryFactory factory = getRepositoryFactory(repositoryType); + return factory.createRepository(); + } + + protected Element getUserManagerConfig(Element repositoryConfig) + { + NodeList userManagerConfig = repositoryConfig.getElementsByTagName("userManager"); //$NON-NLS-1$ + if (userManagerConfig.getLength() > 1) + { + String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$ + throw new IllegalStateException("At most one user manager must be configured for repository " + repositoryName); //$NON-NLS-1$ + } + + return (Element)(userManagerConfig.getLength() > 0 ? userManagerConfig.item(0) : null); + } + + protected IUserManager getUserManager(Element userManagerConfig) throws CoreException + { + String type = userManagerConfig.getAttribute("type"); //$NON-NLS-1$ + String description = userManagerConfig.getAttribute("description"); //$NON-NLS-1$ + return getUserManager(type, description); + } + + protected IUserManager getUserManager(String type, String description) throws CoreException + { + IUserManager userManager = (IUserManager)container.getElement("org.eclipse.net4j.userManagers", type, description); //$NON-NLS-1$ + if (userManager == null) + { + throw new IllegalStateException("UserManager factory not found: " + type); //$NON-NLS-1$ + } + + return userManager; + } + + protected EPackage[] getInitialPackages(Element repositoryConfig) + { + List<EPackage> result = new ArrayList<EPackage>(); + + NodeList initialPackagesConfig = repositoryConfig.getElementsByTagName("initialPackage"); //$NON-NLS-1$ + for (int i = 0; i < initialPackagesConfig.getLength(); i++) + { + Element initialPackageConfig = (Element)initialPackagesConfig.item(i); + String nsURI = initialPackageConfig.getAttribute("nsURI"); //$NON-NLS-1$ + if (nsURI == null) + { + throw new IllegalStateException("nsURI missing for initialPackage element"); //$NON-NLS-1$ + } + + EPackage initialPackage = EPackage.Registry.INSTANCE.getEPackage(nsURI); + if (initialPackage == null) + { + throw new IllegalStateException("Initial package not found in global package registry: " + nsURI); //$NON-NLS-1$ + } + + result.add(initialPackage); + } + + return result.toArray(new EPackage[result.size()]); + } + + protected Element getStoreConfig(Element repositoryConfig) + { + NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$ + if (storeConfigs.getLength() == 0) + { + String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$ + throw new IllegalStateException("A store must be configured for repository " + repositoryName); //$NON-NLS-1$ + } + + return (Element)storeConfigs.item(0); + } + + protected IStoreFactory getStoreFactory(String type) throws CoreException + { + IStoreFactory factory = storeFactories.get(type); + if (factory == null) + { + factory = createExecutableExtension("storeFactories", "storeFactory", "storeType", type); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + if (factory == null) + { + throw new IllegalStateException("Store factory not found: " + type); //$NON-NLS-1$ + } + + return factory; + } + + protected IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig) + throws CoreException + { + String type = storeConfig.getAttribute("type"); //$NON-NLS-1$ + IStoreFactory storeFactory = getStoreFactory(type); + return storeFactory.createStore(repositoryName, repositoryProperties, storeConfig); + } + + public static Map<String, String> getProperties(Element element, int levels) + { + Map<String, String> properties = new HashMap<String, String>(); + collectProperties(element, "", properties, levels); //$NON-NLS-1$ + return properties; + } + + private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels) + { + if ("property".equals(element.getNodeName())) //$NON-NLS-1$ + { + String name = element.getAttribute("name"); //$NON-NLS-1$ + String value = element.getAttribute("value"); //$NON-NLS-1$ + properties.put(prefix + name, value); + prefix += name + "."; //$NON-NLS-1$ + } + + if (levels > 0) + { + NodeList childNodes = element.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) + { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) + { + collectProperties((Element)childNode, prefix, properties, levels - 1); + } + } + } + } + + private static <T> T createExecutableExtension(String extPointName, String elementName, String attributeName, + String type) throws CoreException + { + if (OMPlatform.INSTANCE.isExtensionRegistryAvailable()) + { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, extPointName); + for (IConfigurationElement element : elements) + { + if (ObjectUtil.equals(element.getName(), elementName)) + { + String storeType = element.getAttribute(attributeName); + if (ObjectUtil.equals(storeType, type)) + { + @SuppressWarnings("unchecked") + T result = (T)element.createExecutableExtension("class"); //$NON-NLS-1$ + return result; + } + } + } + } + + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryFactory.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryFactory.java index b942e8e4ed..80f944e2ab 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryFactory.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryFactory.java @@ -1,45 +1,45 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.internal.server.Repository;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IRepositoryFactory;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class RepositoryFactory implements IRepositoryFactory
-{
- public static final String TYPE = "default"; //$NON-NLS-1$
-
- public RepositoryFactory()
- {
- }
-
- public String getRepositoryType()
- {
- return TYPE;
- }
-
- public IRepository createRepository()
- {
- return new Repository.Default();
- }
-
- public static IRepository get(IManagedContainer container, String name)
- {
- return (IRepository)container.getElement(PRODUCT_GROUP, TYPE, name);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.internal.server.Repository; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IRepositoryFactory; + +import org.eclipse.net4j.util.container.IManagedContainer; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class RepositoryFactory implements IRepositoryFactory +{ + public static final String TYPE = "default"; //$NON-NLS-1$ + + public RepositoryFactory() + { + } + + public String getRepositoryType() + { + return TYPE; + } + + public IRepository createRepository() + { + return new Repository.Default(); + } + + public static IRepository get(IManagedContainer container, String name) + { + return (IRepository)container.getElement(PRODUCT_GROUP, TYPE, name); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryUserManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryUserManager.java index 125a918789..ac8e3ae70d 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryUserManager.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/RepositoryUserManager.java @@ -1,147 +1,147 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.server.CDOServerUtil;
-import org.eclipse.emf.cdo.server.IRepository;
-
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.security.IUserManager;
-import org.eclipse.net4j.util.security.SecurityUtil;
-import org.eclipse.net4j.util.security.UserManagerFactory;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public abstract class RepositoryUserManager extends Lifecycle implements IUserManager
-{
- private IManagedContainer container;
-
- private String repositoryName;
-
- protected RepositoryUserManager()
- {
- }
-
- private void setContainer(IManagedContainer container)
- {
- this.container = container;
- }
-
- private void setRepositoryName(String repositoryName)
- {
- this.repositoryName = repositoryName;
- }
-
- public void addUser(String userID, char[] password)
- {
- // Cann be overridden in subclasses.
- }
-
- public void removeUser(String userID)
- {
- // Cann be overridden in subclasses.
- }
-
- public byte[] encrypt(String userID, byte[] data, String algorithmName, byte[] salt, int count)
- throws SecurityException
- {
- IRepository repository = getRepository(container, repositoryName);
- if (repository == null)
- {
- throw new SecurityException("Repository not found: " + repositoryName); //$NON-NLS-1$
- }
-
- char[] password = getPassword(repository, userID);
- if (password == null)
- {
- throw new SecurityException("No such user: " + userID); //$NON-NLS-1$
- }
-
- try
- {
- return SecurityUtil.encrypt(data, password, algorithmName, salt, count);
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new SecurityException(ex);
- }
- }
-
- protected IRepository getRepository(IManagedContainer container, String repositoryName)
- {
- return CDOServerUtil.getRepository(container, repositoryName);
- }
-
- protected abstract char[] getPassword(IRepository repository, String userID);
-
- public static void prepareContainer(IManagedContainer container, RepositoryUserManagerFactory factory)
- {
- container.registerFactory(factory);
- container.addPostProcessor(new RepositoryInjector());
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class RepositoryUserManagerFactory extends UserManagerFactory
- {
- protected RepositoryUserManagerFactory(String type)
- {
- super(type);
- }
-
- public final Object create(String description) throws ProductCreationException
- {
- RepositoryUserManager userManager = doCreate(description);
- String repositoryName = getRepositoryName(description);
- userManager.setRepositoryName(repositoryName);
- return userManager;
- }
-
- protected String getRepositoryName(String description)
- {
- return description;
- }
-
- protected abstract RepositoryUserManager doCreate(String description) throws ProductCreationException;
- }
-
- /**
- * @author Eike Stepper
- */
- public static class RepositoryInjector implements IElementProcessor
- {
- public RepositoryInjector()
- {
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof RepositoryUserManager)
- {
- RepositoryUserManager userManager = (RepositoryUserManager)element;
- userManager.setContainer(container);
- }
-
- return element;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.server.CDOServerUtil; +import org.eclipse.emf.cdo.server.IRepository; + +import org.eclipse.net4j.util.container.IElementProcessor; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.factory.ProductCreationException; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.security.IUserManager; +import org.eclipse.net4j.util.security.SecurityUtil; +import org.eclipse.net4j.util.security.UserManagerFactory; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public abstract class RepositoryUserManager extends Lifecycle implements IUserManager +{ + private IManagedContainer container; + + private String repositoryName; + + protected RepositoryUserManager() + { + } + + private void setContainer(IManagedContainer container) + { + this.container = container; + } + + private void setRepositoryName(String repositoryName) + { + this.repositoryName = repositoryName; + } + + public void addUser(String userID, char[] password) + { + // Cann be overridden in subclasses. + } + + public void removeUser(String userID) + { + // Cann be overridden in subclasses. + } + + public byte[] encrypt(String userID, byte[] data, String algorithmName, byte[] salt, int count) + throws SecurityException + { + IRepository repository = getRepository(container, repositoryName); + if (repository == null) + { + throw new SecurityException("Repository not found: " + repositoryName); //$NON-NLS-1$ + } + + char[] password = getPassword(repository, userID); + if (password == null) + { + throw new SecurityException("No such user: " + userID); //$NON-NLS-1$ + } + + try + { + return SecurityUtil.encrypt(data, password, algorithmName, salt, count); + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new SecurityException(ex); + } + } + + protected IRepository getRepository(IManagedContainer container, String repositoryName) + { + return CDOServerUtil.getRepository(container, repositoryName); + } + + protected abstract char[] getPassword(IRepository repository, String userID); + + public static void prepareContainer(IManagedContainer container, RepositoryUserManagerFactory factory) + { + container.registerFactory(factory); + container.addPostProcessor(new RepositoryInjector()); + } + + /** + * @author Eike Stepper + */ + public static abstract class RepositoryUserManagerFactory extends UserManagerFactory + { + protected RepositoryUserManagerFactory(String type) + { + super(type); + } + + public final Object create(String description) throws ProductCreationException + { + RepositoryUserManager userManager = doCreate(description); + String repositoryName = getRepositoryName(description); + userManager.setRepositoryName(repositoryName); + return userManager; + } + + protected String getRepositoryName(String description) + { + return description; + } + + protected abstract RepositoryUserManager doCreate(String description) throws ProductCreationException; + } + + /** + * @author Eike Stepper + */ + public static class RepositoryInjector implements IElementProcessor + { + public RepositoryInjector() + { + } + + public Object process(IManagedContainer container, String productGroup, String factoryType, String description, + Object element) + { + if (element instanceof RepositoryUserManager) + { + RepositoryUserManager userManager = (RepositoryUserManager)element; + userManager.setContainer(container); + } + + return element; + } + } +} 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 16a911406b..e579d8a03f 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 @@ -1,549 +1,549 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-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.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
-import org.eclipse.emf.cdo.internal.server.Repository;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.ISessionManager;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-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.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.container.IContainerDelta.Kind;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
-
-import org.eclipse.emf.ecore.EClass;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Store extends Lifecycle implements InternalStore
-{
- /**
- * @since 3.0
- * @deprecated Use CDOBranchPoint.UNSPECIFIED_DATE
- */
- @Deprecated
- public static final long UNSPECIFIED_DATE = CDOBranchPoint.UNSPECIFIED_DATE;
-
- private String type;
-
- private Set<ObjectType> objectIDTypes;
-
- private Set<ChangeFormat> supportedChangeFormats;
-
- private Set<RevisionTemporality> supportedRevisionTemporalities;
-
- private Set<RevisionParallelism> supportedRevisionParallelisms;
-
- private RevisionTemporality revisionTemporality = RevisionTemporality.NONE;
-
- private RevisionParallelism revisionParallelism = RevisionParallelism.NONE;
-
- private InternalRepository repository;
-
- private boolean dropAllDataOnActivate;
-
- /**
- * Is protected against concurrent thread access through {@link Repository#createBranchLock}.
- */
- @ExcludeFromDump
- private transient int lastBranchID;
-
- /**
- * Is protected against concurrent thread access through {@link Repository#createBranchLock}.
- */
- @ExcludeFromDump
- private transient int lastLocalBranchID;
-
- @ExcludeFromDump
- private transient long lastCommitTime;
-
- @ExcludeFromDump
- private transient Object lastCommitTimeLock = new Object();
-
- @ExcludeFromDump
- private transient long lastNonLocalCommitTime;
-
- @ExcludeFromDump
- private transient Object lastNonLocalCommitTimeLock = new Object();
-
- /**
- * @since 3.0
- */
- @ExcludeFromDump
- private transient ProgressDistributor indicatingCommitDistributor = new ProgressDistributor.Geometric()
- {
- @Override
- public String toString()
- {
- String result = "indicatingCommitDistributor"; //$NON-NLS-1$
- if (repository != null)
- {
- result += ": " + repository.getName(); //$NON-NLS-1$
- }
-
- return result;
- }
- };
-
- /**
- * @since 3.0
- */
- public Store(String type, Set<CDOID.ObjectType> objectIDTypes, Set<ChangeFormat> supportedChangeFormats,
- Set<RevisionTemporality> supportedRevisionTemporalities, Set<RevisionParallelism> supportedRevisionParallelisms)
- {
- checkArg(!StringUtil.isEmpty(type), "Empty type"); //$NON-NLS-1$
- this.type = type;
- this.objectIDTypes = objectIDTypes;
-
- checkArg(supportedChangeFormats != null && !supportedChangeFormats.isEmpty(), "Empty supportedChangeFormats"); //$NON-NLS-1$
- this.supportedChangeFormats = supportedChangeFormats;
-
- checkArg(supportedRevisionTemporalities != null && !supportedRevisionTemporalities.isEmpty(),
- "Empty supportedRevisionTemporalities"); //$NON-NLS-1$
- this.supportedRevisionTemporalities = supportedRevisionTemporalities;
-
- checkArg(supportedRevisionParallelisms != null && !supportedRevisionParallelisms.isEmpty(),
- "Empty supportedRevisionParallelisms"); //$NON-NLS-1$
- this.supportedRevisionParallelisms = supportedRevisionParallelisms;
- }
-
- public final String getType()
- {
- return type;
- }
-
- /**
- * @since 3.0
- */
- public Set<CDOID.ObjectType> getObjectIDTypes()
- {
- return objectIDTypes;
- }
-
- /**
- * @since 4.0
- */
- protected void setObjectIDTypes(Set<ObjectType> objectIDTypes)
- {
- this.objectIDTypes = objectIDTypes;
- }
-
- public Set<ChangeFormat> getSupportedChangeFormats()
- {
- return supportedChangeFormats;
- }
-
- public Set<RevisionTemporality> getSupportedRevisionTemporalities()
- {
- return supportedRevisionTemporalities;
- }
-
- public final Set<RevisionParallelism> getSupportedRevisionParallelisms()
- {
- return supportedRevisionParallelisms;
- }
-
- public RevisionTemporality getRevisionTemporality()
- {
- return revisionTemporality;
- }
-
- public void setRevisionTemporality(RevisionTemporality revisionTemporality)
- {
- checkInactive();
- checkState(supportedRevisionTemporalities.contains(revisionTemporality), "Revision temporality not supported: " //$NON-NLS-1$
- + revisionTemporality);
- this.revisionTemporality = revisionTemporality;
- }
-
- public RevisionParallelism getRevisionParallelism()
- {
- return revisionParallelism;
- }
-
- public void setRevisionParallelism(RevisionParallelism revisionParallelism)
- {
- checkInactive();
- checkState(supportedRevisionParallelisms.contains(revisionParallelism), "Revision parallelism not supported: " //$NON-NLS-1$
- + revisionParallelism);
- this.revisionParallelism = revisionParallelism;
- }
-
- /**
- * @since 3.0
- */
- public InternalRepository getRepository()
- {
- return repository;
- }
-
- public void setRepository(IRepository repository)
- {
- this.repository = (InternalRepository)repository;
- }
-
- /**
- * @since 4.0
- */
- public boolean isDropAllDataOnActivate()
- {
- return dropAllDataOnActivate;
- }
-
- /**
- * @since 4.0
- */
- public void setDropAllDataOnActivate(boolean dropAllDataOnActivate)
- {
- this.dropAllDataOnActivate = dropAllDataOnActivate;
- }
-
- /**
- * @since 3.0
- */
- public int getLastBranchID()
- {
- return lastBranchID;
- }
-
- /**
- * @since 3.0
- */
- public void setLastBranchID(int lastBranchID)
- {
- this.lastBranchID = lastBranchID;
- }
-
- /**
- * @since 3.0
- */
- public int getNextBranchID()
- {
- 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;
- }
-
- /**
- * @since 3.0
- */
- public long getLastCommitTime()
- {
- synchronized (lastCommitTimeLock)
- {
- return lastCommitTime;
- }
- }
-
- /**
- * @since 3.0
- */
- public void setLastCommitTime(long lastCommitTime)
- {
- synchronized (lastCommitTimeLock)
- {
- if (this.lastCommitTime < lastCommitTime)
- {
- this.lastCommitTime = lastCommitTime;
- }
- }
- }
-
- /**
- * @since 3.0
- */
- public long getLastNonLocalCommitTime()
- {
- synchronized (lastNonLocalCommitTimeLock)
- {
- return lastNonLocalCommitTime;
- }
- }
-
- /**
- * @since 3.0
- */
- public void setLastNonLocalCommitTime(long lastNonLocalCommitTime)
- {
- synchronized (lastNonLocalCommitTimeLock)
- {
- if (this.lastNonLocalCommitTime < lastNonLocalCommitTime)
- {
- this.lastNonLocalCommitTime = lastNonLocalCommitTime;
- }
- }
- }
-
- public IStoreAccessor getReader(ISession session)
- {
- IStoreAccessor reader = null;
- StoreAccessorPool pool = getReaderPool(session, false);
- if (pool != null)
- {
- reader = pool.removeStoreAccessor(session);
- }
-
- if (reader == null && session != null)
- {
- CDOCommonView[] views = session.getViews();
- for (CDOCommonView view : views)
- {
- pool = getWriterPool((IView)view, false);
- if (pool != null)
- {
- reader = pool.removeStoreAccessor(view);
- if (reader != null)
- {
- break;
- }
- }
- }
- }
-
- if (reader == null)
- {
- reader = createReader(session);
- LifecycleUtil.activate(reader);
- }
-
- return reader;
- }
-
- public IStoreAccessor getWriter(ITransaction transaction)
- {
- IStoreAccessor writer = null;
- StoreAccessorPool pool = getWriterPool(transaction, false);
- if (pool != null)
- {
- writer = pool.removeStoreAccessor(transaction);
- }
-
- if (writer == null)
- {
- writer = createWriter(transaction);
- LifecycleUtil.activate(writer);
- }
-
- return writer;
- }
-
- public ProgressDistributor getIndicatingCommitDistributor()
- {
- return indicatingCommitDistributor;
- }
-
- /**
- * @since 3.0
- */
- public InternalCDORevision createRevision(EClass eClass, CDOID id)
- {
- CDORevisionFactory factory = repository.getRevisionManager().getFactory();
- InternalCDORevision revision = (InternalCDORevision)factory.createRevision(eClass);
- revision.setID(id);
- return revision;
- }
-
- /**
- * @since 4.0
- */
- protected void releaseAccessor(StoreAccessorBase accessor)
- {
- StoreAccessorPool pool = null;
- if (accessor.isReader())
- {
- pool = getReaderPool(accessor.getSession(), true);
- }
- else
- {
- pool = getWriterPool(accessor.getTransaction(), true);
- }
-
- if (pool != null)
- {
- pool.addStoreAccessor(accessor);
- }
- else
- {
- accessor.deactivate();
- }
- }
-
- /**
- * Returns a {@link StoreAccessorPool pool} that may contain {@link IStoreAccessor} instances that are compatible with
- * the given session. The implementor may return <code>null</code> to indicate that no pooling occurs. It's also left
- * to the implementors choice how to determine the appropriate pool instance to be used for the given session, for
- * example it could always return the same pool instance, regardless of the given session.
- * <p>
- * If the implementor of this method decides to create pools that are only compatible with certain sessions or views,
- * then it is his responsibility to listen to {@link Kind#REMOVED REMOVED} events sent by either the
- * {@link ISessionManager} (indicating that a session is closed) or any of its sessions (indicating that a view is
- * closed). <b>Note:</b> Closing a session <em>implies</em> that all contained views are closed sliently without
- * firing respective events!
- *
- * @param session
- * The context which the pool must be compatible with. Must not be <code>null</code>.
- * @param forReleasing
- * Enables lazy pool creation. The implementor is not supposed to create a new pool if <code>false</code> is
- * passed. If <code>true</code> is passed it's up to the implementor whether to create a new pool or not.
- */
- protected abstract StoreAccessorPool getReaderPool(ISession session, boolean forReleasing);
-
- /**
- * Returns a {@link StoreAccessorPool pool} that may contain {@link IStoreAccessor} instances that are compatible with
- * the given session. The implementor may return <code>null</code> to indicate that no pooling occurs. It's also left
- * to the implementors choice how to determine the appropriate pool instance to be used for the given session, for
- * example it could always return the same pool instance, regardless of the given session.
- * <p>
- * If the implementor of this method decides to create pools that are only compatible with certain sessions or views,
- * then it is his responsibility to listen to {@link Kind#REMOVED REMOVED} events sent by either the
- * {@link ISessionManager} (indicating that a session is closed) or any of its sessions (indicating that a view is
- * closed). <b>Note:</b> Closing a session <em>implies</em> that all contained views are closed sliently without
- * firing respective events!
- *
- * @param view
- * The context which the pool must be compatible with. Must not be <code>null</code>.
- * @param forReleasing
- * Enables lazy pool creation. The implementor is not supposed to create a new pool if <code>false</code> is
- * passed. If <code>true</code> is passed it's up to the implementor whether to create a new pool or not.
- */
- protected abstract StoreAccessorPool getWriterPool(IView view, boolean forReleasing);
-
- /**
- * Creates and returns a <b>new</b> {@link IStoreAccessor} instance. The caller of this method is responsible for
- * {@link Lifecycle#activate() activating} the new instance.
- */
- protected abstract IStoreAccessor createReader(ISession session);
-
- /**
- * Creates and returns a <b>new</b> {@link IStoreAccessor} instance. The caller of this method is responsible for
- * {@link Lifecycle#activate() activating} the new instance.
- */
- protected abstract IStoreAccessor createWriter(ITransaction transaction);
-
- protected static <T> Set<T> set(T... elements)
- {
- return Collections.unmodifiableSet(new HashSet<T>(Arrays.asList(elements)));
- }
-
- /**
- * @since 4.0
- */
- public static String idToString(CDOID id)
- {
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, id);
- return builder.toString();
- }
-
- /**
- * @since 4.0
- */
- public static CDOID stringToID(String string)
- {
- return CDOIDUtil.read(string);
- }
-
- /**
- * @since 3.0
- */
- public static IStoreAccessor.QueryResourcesContext.ExactMatch createExactMatchContext(final CDOID folderID,
- final String name, final CDOBranchPoint branchPoint)
- {
- return new IStoreAccessor.QueryResourcesContext.ExactMatch()
- {
- private CDOID resourceID;
-
- public CDOID getResourceID()
- {
- return resourceID;
- }
-
- public CDOBranch getBranch()
- {
- return branchPoint.getBranch();
- }
-
- public long getTimeStamp()
- {
- return branchPoint.getTimeStamp();
- }
-
- public CDOID getFolderID()
- {
- return folderID;
- }
-
- public String getName()
- {
- return name;
- }
-
- public boolean exactMatch()
- {
- return true;
- }
-
- public int getMaxResults()
- {
- return 1;
- }
-
- public boolean addResource(CDOID resourceID)
- {
- this.resourceID = resourceID;
- return false;
- }
- };
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +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.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDORevisionFactory; +import org.eclipse.emf.cdo.internal.server.Repository; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.ISessionManager; +import org.eclipse.emf.cdo.server.IStoreAccessor; +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.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.container.IContainerDelta.Kind; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.monitor.ProgressDistributor; + +import org.eclipse.emf.ecore.EClass; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class Store extends Lifecycle implements InternalStore +{ + /** + * @since 3.0 + * @deprecated Use CDOBranchPoint.UNSPECIFIED_DATE + */ + @Deprecated + public static final long UNSPECIFIED_DATE = CDOBranchPoint.UNSPECIFIED_DATE; + + private String type; + + private Set<ObjectType> objectIDTypes; + + private Set<ChangeFormat> supportedChangeFormats; + + private Set<RevisionTemporality> supportedRevisionTemporalities; + + private Set<RevisionParallelism> supportedRevisionParallelisms; + + private RevisionTemporality revisionTemporality = RevisionTemporality.NONE; + + private RevisionParallelism revisionParallelism = RevisionParallelism.NONE; + + private InternalRepository repository; + + private boolean dropAllDataOnActivate; + + /** + * Is protected against concurrent thread access through {@link Repository#createBranchLock}. + */ + @ExcludeFromDump + private transient int lastBranchID; + + /** + * Is protected against concurrent thread access through {@link Repository#createBranchLock}. + */ + @ExcludeFromDump + private transient int lastLocalBranchID; + + @ExcludeFromDump + private transient long lastCommitTime; + + @ExcludeFromDump + private transient Object lastCommitTimeLock = new Object(); + + @ExcludeFromDump + private transient long lastNonLocalCommitTime; + + @ExcludeFromDump + private transient Object lastNonLocalCommitTimeLock = new Object(); + + /** + * @since 3.0 + */ + @ExcludeFromDump + private transient ProgressDistributor indicatingCommitDistributor = new ProgressDistributor.Geometric() + { + @Override + public String toString() + { + String result = "indicatingCommitDistributor"; //$NON-NLS-1$ + if (repository != null) + { + result += ": " + repository.getName(); //$NON-NLS-1$ + } + + return result; + } + }; + + /** + * @since 3.0 + */ + public Store(String type, Set<CDOID.ObjectType> objectIDTypes, Set<ChangeFormat> supportedChangeFormats, + Set<RevisionTemporality> supportedRevisionTemporalities, Set<RevisionParallelism> supportedRevisionParallelisms) + { + checkArg(!StringUtil.isEmpty(type), "Empty type"); //$NON-NLS-1$ + this.type = type; + this.objectIDTypes = objectIDTypes; + + checkArg(supportedChangeFormats != null && !supportedChangeFormats.isEmpty(), "Empty supportedChangeFormats"); //$NON-NLS-1$ + this.supportedChangeFormats = supportedChangeFormats; + + checkArg(supportedRevisionTemporalities != null && !supportedRevisionTemporalities.isEmpty(), + "Empty supportedRevisionTemporalities"); //$NON-NLS-1$ + this.supportedRevisionTemporalities = supportedRevisionTemporalities; + + checkArg(supportedRevisionParallelisms != null && !supportedRevisionParallelisms.isEmpty(), + "Empty supportedRevisionParallelisms"); //$NON-NLS-1$ + this.supportedRevisionParallelisms = supportedRevisionParallelisms; + } + + public final String getType() + { + return type; + } + + /** + * @since 3.0 + */ + public Set<CDOID.ObjectType> getObjectIDTypes() + { + return objectIDTypes; + } + + /** + * @since 4.0 + */ + protected void setObjectIDTypes(Set<ObjectType> objectIDTypes) + { + this.objectIDTypes = objectIDTypes; + } + + public Set<ChangeFormat> getSupportedChangeFormats() + { + return supportedChangeFormats; + } + + public Set<RevisionTemporality> getSupportedRevisionTemporalities() + { + return supportedRevisionTemporalities; + } + + public final Set<RevisionParallelism> getSupportedRevisionParallelisms() + { + return supportedRevisionParallelisms; + } + + public RevisionTemporality getRevisionTemporality() + { + return revisionTemporality; + } + + public void setRevisionTemporality(RevisionTemporality revisionTemporality) + { + checkInactive(); + checkState(supportedRevisionTemporalities.contains(revisionTemporality), "Revision temporality not supported: " //$NON-NLS-1$ + + revisionTemporality); + this.revisionTemporality = revisionTemporality; + } + + public RevisionParallelism getRevisionParallelism() + { + return revisionParallelism; + } + + public void setRevisionParallelism(RevisionParallelism revisionParallelism) + { + checkInactive(); + checkState(supportedRevisionParallelisms.contains(revisionParallelism), "Revision parallelism not supported: " //$NON-NLS-1$ + + revisionParallelism); + this.revisionParallelism = revisionParallelism; + } + + /** + * @since 3.0 + */ + public InternalRepository getRepository() + { + return repository; + } + + public void setRepository(IRepository repository) + { + this.repository = (InternalRepository)repository; + } + + /** + * @since 4.0 + */ + public boolean isDropAllDataOnActivate() + { + return dropAllDataOnActivate; + } + + /** + * @since 4.0 + */ + public void setDropAllDataOnActivate(boolean dropAllDataOnActivate) + { + this.dropAllDataOnActivate = dropAllDataOnActivate; + } + + /** + * @since 3.0 + */ + public int getLastBranchID() + { + return lastBranchID; + } + + /** + * @since 3.0 + */ + public void setLastBranchID(int lastBranchID) + { + this.lastBranchID = lastBranchID; + } + + /** + * @since 3.0 + */ + public int getNextBranchID() + { + 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; + } + + /** + * @since 3.0 + */ + public long getLastCommitTime() + { + synchronized (lastCommitTimeLock) + { + return lastCommitTime; + } + } + + /** + * @since 3.0 + */ + public void setLastCommitTime(long lastCommitTime) + { + synchronized (lastCommitTimeLock) + { + if (this.lastCommitTime < lastCommitTime) + { + this.lastCommitTime = lastCommitTime; + } + } + } + + /** + * @since 3.0 + */ + public long getLastNonLocalCommitTime() + { + synchronized (lastNonLocalCommitTimeLock) + { + return lastNonLocalCommitTime; + } + } + + /** + * @since 3.0 + */ + public void setLastNonLocalCommitTime(long lastNonLocalCommitTime) + { + synchronized (lastNonLocalCommitTimeLock) + { + if (this.lastNonLocalCommitTime < lastNonLocalCommitTime) + { + this.lastNonLocalCommitTime = lastNonLocalCommitTime; + } + } + } + + public IStoreAccessor getReader(ISession session) + { + IStoreAccessor reader = null; + StoreAccessorPool pool = getReaderPool(session, false); + if (pool != null) + { + reader = pool.removeStoreAccessor(session); + } + + if (reader == null && session != null) + { + CDOCommonView[] views = session.getViews(); + for (CDOCommonView view : views) + { + pool = getWriterPool((IView)view, false); + if (pool != null) + { + reader = pool.removeStoreAccessor(view); + if (reader != null) + { + break; + } + } + } + } + + if (reader == null) + { + reader = createReader(session); + LifecycleUtil.activate(reader); + } + + return reader; + } + + public IStoreAccessor getWriter(ITransaction transaction) + { + IStoreAccessor writer = null; + StoreAccessorPool pool = getWriterPool(transaction, false); + if (pool != null) + { + writer = pool.removeStoreAccessor(transaction); + } + + if (writer == null) + { + writer = createWriter(transaction); + LifecycleUtil.activate(writer); + } + + return writer; + } + + public ProgressDistributor getIndicatingCommitDistributor() + { + return indicatingCommitDistributor; + } + + /** + * @since 3.0 + */ + public InternalCDORevision createRevision(EClass eClass, CDOID id) + { + CDORevisionFactory factory = repository.getRevisionManager().getFactory(); + InternalCDORevision revision = (InternalCDORevision)factory.createRevision(eClass); + revision.setID(id); + return revision; + } + + /** + * @since 4.0 + */ + protected void releaseAccessor(StoreAccessorBase accessor) + { + StoreAccessorPool pool = null; + if (accessor.isReader()) + { + pool = getReaderPool(accessor.getSession(), true); + } + else + { + pool = getWriterPool(accessor.getTransaction(), true); + } + + if (pool != null) + { + pool.addStoreAccessor(accessor); + } + else + { + accessor.deactivate(); + } + } + + /** + * Returns a {@link StoreAccessorPool pool} that may contain {@link IStoreAccessor} instances that are compatible with + * the given session. The implementor may return <code>null</code> to indicate that no pooling occurs. It's also left + * to the implementors choice how to determine the appropriate pool instance to be used for the given session, for + * example it could always return the same pool instance, regardless of the given session. + * <p> + * If the implementor of this method decides to create pools that are only compatible with certain sessions or views, + * then it is his responsibility to listen to {@link Kind#REMOVED REMOVED} events sent by either the + * {@link ISessionManager} (indicating that a session is closed) or any of its sessions (indicating that a view is + * closed). <b>Note:</b> Closing a session <em>implies</em> that all contained views are closed sliently without + * firing respective events! + * + * @param session + * The context which the pool must be compatible with. Must not be <code>null</code>. + * @param forReleasing + * Enables lazy pool creation. The implementor is not supposed to create a new pool if <code>false</code> is + * passed. If <code>true</code> is passed it's up to the implementor whether to create a new pool or not. + */ + protected abstract StoreAccessorPool getReaderPool(ISession session, boolean forReleasing); + + /** + * Returns a {@link StoreAccessorPool pool} that may contain {@link IStoreAccessor} instances that are compatible with + * the given session. The implementor may return <code>null</code> to indicate that no pooling occurs. It's also left + * to the implementors choice how to determine the appropriate pool instance to be used for the given session, for + * example it could always return the same pool instance, regardless of the given session. + * <p> + * If the implementor of this method decides to create pools that are only compatible with certain sessions or views, + * then it is his responsibility to listen to {@link Kind#REMOVED REMOVED} events sent by either the + * {@link ISessionManager} (indicating that a session is closed) or any of its sessions (indicating that a view is + * closed). <b>Note:</b> Closing a session <em>implies</em> that all contained views are closed sliently without + * firing respective events! + * + * @param view + * The context which the pool must be compatible with. Must not be <code>null</code>. + * @param forReleasing + * Enables lazy pool creation. The implementor is not supposed to create a new pool if <code>false</code> is + * passed. If <code>true</code> is passed it's up to the implementor whether to create a new pool or not. + */ + protected abstract StoreAccessorPool getWriterPool(IView view, boolean forReleasing); + + /** + * Creates and returns a <b>new</b> {@link IStoreAccessor} instance. The caller of this method is responsible for + * {@link Lifecycle#activate() activating} the new instance. + */ + protected abstract IStoreAccessor createReader(ISession session); + + /** + * Creates and returns a <b>new</b> {@link IStoreAccessor} instance. The caller of this method is responsible for + * {@link Lifecycle#activate() activating} the new instance. + */ + protected abstract IStoreAccessor createWriter(ITransaction transaction); + + protected static <T> Set<T> set(T... elements) + { + return Collections.unmodifiableSet(new HashSet<T>(Arrays.asList(elements))); + } + + /** + * @since 4.0 + */ + public static String idToString(CDOID id) + { + StringBuilder builder = new StringBuilder(); + CDOIDUtil.write(builder, id); + return builder.toString(); + } + + /** + * @since 4.0 + */ + public static CDOID stringToID(String string) + { + return CDOIDUtil.read(string); + } + + /** + * @since 3.0 + */ + public static IStoreAccessor.QueryResourcesContext.ExactMatch createExactMatchContext(final CDOID folderID, + final String name, final CDOBranchPoint branchPoint) + { + return new IStoreAccessor.QueryResourcesContext.ExactMatch() + { + private CDOID resourceID; + + public CDOID getResourceID() + { + return resourceID; + } + + public CDOBranch getBranch() + { + return branchPoint.getBranch(); + } + + public long getTimeStamp() + { + return branchPoint.getTimeStamp(); + } + + public CDOID getFolderID() + { + return folderID; + } + + public String getName() + { + return name; + } + + public boolean exactMatch() + { + return true; + } + + public int getMaxResults() + { + return 1; + } + + public boolean addResource(CDOID resourceID) + { + this.resourceID = resourceID; + return false; + } + }; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java index 72ffa451cb..5073d0c710 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessor.java @@ -1,180 +1,180 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 201266
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.spi.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.LimitedInputStream;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class StoreAccessor extends StoreAccessorBase
-{
- protected StoreAccessor(Store store, ISession session)
- {
- super(store, session);
- }
-
- protected StoreAccessor(Store store, ITransaction transaction)
- {
- super(store, transaction);
- }
-
- /**
- * @since 4.0
- */
- @Override
- protected void doWrite(InternalCommitContext context, OMMonitor monitor)
- {
- CDOBranch branch = context.getBranchPoint().getBranch();
- long timeStamp = context.getBranchPoint().getTimeStamp();
- long previousTimeStamp = context.getPreviousTimeStamp();
- String userID = context.getUserID();
- String commitComment = context.getCommitComment();
-
- boolean deltas = getStore().getSupportedChangeFormats().contains(IStore.ChangeFormat.DELTA);
-
- InternalCDOPackageUnit[] newPackageUnits = context.getNewPackageUnits();
- InternalCDORevision[] newObjects = context.getNewObjects();
- CDOID[] detachedObjects = context.getDetachedObjects();
- int dirtyCount = deltas ? context.getDirtyObjectDeltas().length : context.getDirtyObjects().length;
-
- try
- {
- monitor.begin(1 + newPackageUnits.length + 2 + newObjects.length + detachedObjects.length + dirtyCount);
- writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, commitComment, monitor.fork());
-
- if (newPackageUnits.length != 0)
- {
- writePackageUnits(newPackageUnits, monitor.fork(newPackageUnits.length));
- }
-
- if (getStore().getRepository().getIDGenerationLocation() == IDGenerationLocation.STORE)
- {
- addIDMappings(context, monitor.fork());
- }
-
- applyIDMappings(context, monitor);
-
- if (detachedObjects.length != 0)
- {
- detachObjects(detachedObjects, branch, timeStamp, monitor.fork(detachedObjects.length));
- }
-
- if (newObjects.length != 0)
- {
- writeRevisions(newObjects, branch, monitor.fork(newObjects.length));
- }
-
- if (dirtyCount != 0)
- {
- if (deltas)
- {
- writeRevisionDeltas(context.getDirtyObjectDeltas(), branch, timeStamp, monitor.fork(dirtyCount));
- }
- else
- {
- writeRevisions(context.getDirtyObjects(), branch, monitor.fork(dirtyCount));
- }
- }
-
- ExtendedDataInputStream in = context.getLobs();
- if (in != null)
- {
- try
- {
- int count = in.readInt();
- for (int i = 0; i < count; i++)
- {
- byte[] id = in.readByteArray();
- long size = in.readLong();
- if (size > 0)
- {
- writeBlob(id, size, new LimitedInputStream(in, size));
- }
- else
- {
- writeClob(id, -size, new InputStreamReader(new LimitedInputStream(in, -size)));
- }
- }
- }
- catch (IOException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
- }
- finally
- {
- monitor.done();
- }
- }
-
- /**
- * @since 3.0
- */
- protected void applyIDMappings(InternalCommitContext context, OMMonitor monitor)
- {
- context.applyIDMappings(monitor.fork());
- }
-
- /**
- * @since 4.0
- */
- protected abstract void writeCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID,
- String comment, OMMonitor monitor);
-
- /**
- * @since 3.0
- */
- protected abstract void writeRevisions(InternalCDORevision[] revisions, CDOBranch branch, OMMonitor monitor);
-
- /**
- * @since 3.0
- */
- protected abstract void writeRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas, CDOBranch branch,
- long created, OMMonitor monitor);
-
- /**
- * @since 3.0
- */
- protected abstract void detachObjects(CDOID[] detachedObjects, CDOBranch branch, long timeStamp, OMMonitor monitor);
-
- /**
- * @since 4.0
- */
- protected abstract void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException;
-
- /**
- * @since 4.0
- */
- protected abstract void writeClob(byte[] id, long size, Reader reader) throws IOException;
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 201266 + * Simon McDuff - bug 213402 + */ +package org.eclipse.emf.cdo.spi.server; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.ITransaction; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; + +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.LimitedInputStream; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class StoreAccessor extends StoreAccessorBase +{ + protected StoreAccessor(Store store, ISession session) + { + super(store, session); + } + + protected StoreAccessor(Store store, ITransaction transaction) + { + super(store, transaction); + } + + /** + * @since 4.0 + */ + @Override + protected void doWrite(InternalCommitContext context, OMMonitor monitor) + { + CDOBranch branch = context.getBranchPoint().getBranch(); + long timeStamp = context.getBranchPoint().getTimeStamp(); + long previousTimeStamp = context.getPreviousTimeStamp(); + String userID = context.getUserID(); + String commitComment = context.getCommitComment(); + + boolean deltas = getStore().getSupportedChangeFormats().contains(IStore.ChangeFormat.DELTA); + + InternalCDOPackageUnit[] newPackageUnits = context.getNewPackageUnits(); + InternalCDORevision[] newObjects = context.getNewObjects(); + CDOID[] detachedObjects = context.getDetachedObjects(); + int dirtyCount = deltas ? context.getDirtyObjectDeltas().length : context.getDirtyObjects().length; + + try + { + monitor.begin(1 + newPackageUnits.length + 2 + newObjects.length + detachedObjects.length + dirtyCount); + writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, commitComment, monitor.fork()); + + if (newPackageUnits.length != 0) + { + writePackageUnits(newPackageUnits, monitor.fork(newPackageUnits.length)); + } + + if (getStore().getRepository().getIDGenerationLocation() == IDGenerationLocation.STORE) + { + addIDMappings(context, monitor.fork()); + } + + applyIDMappings(context, monitor); + + if (detachedObjects.length != 0) + { + detachObjects(detachedObjects, branch, timeStamp, monitor.fork(detachedObjects.length)); + } + + if (newObjects.length != 0) + { + writeRevisions(newObjects, branch, monitor.fork(newObjects.length)); + } + + if (dirtyCount != 0) + { + if (deltas) + { + writeRevisionDeltas(context.getDirtyObjectDeltas(), branch, timeStamp, monitor.fork(dirtyCount)); + } + else + { + writeRevisions(context.getDirtyObjects(), branch, monitor.fork(dirtyCount)); + } + } + + ExtendedDataInputStream in = context.getLobs(); + if (in != null) + { + try + { + int count = in.readInt(); + for (int i = 0; i < count; i++) + { + byte[] id = in.readByteArray(); + long size = in.readLong(); + if (size > 0) + { + writeBlob(id, size, new LimitedInputStream(in, size)); + } + else + { + writeClob(id, -size, new InputStreamReader(new LimitedInputStream(in, -size))); + } + } + } + catch (IOException ex) + { + throw WrappedException.wrap(ex); + } + } + } + finally + { + monitor.done(); + } + } + + /** + * @since 3.0 + */ + protected void applyIDMappings(InternalCommitContext context, OMMonitor monitor) + { + context.applyIDMappings(monitor.fork()); + } + + /** + * @since 4.0 + */ + protected abstract void writeCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, + String comment, OMMonitor monitor); + + /** + * @since 3.0 + */ + protected abstract void writeRevisions(InternalCDORevision[] revisions, CDOBranch branch, OMMonitor monitor); + + /** + * @since 3.0 + */ + protected abstract void writeRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas, CDOBranch branch, + long created, OMMonitor monitor); + + /** + * @since 3.0 + */ + protected abstract void detachObjects(CDOID[] detachedObjects, CDOBranch branch, long timeStamp, OMMonitor monitor); + + /** + * @since 4.0 + */ + protected abstract void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException; + + /** + * @since 4.0 + */ + protected abstract void writeClob(byte[] id, long size, Reader reader) throws IOException; +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorBase.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorBase.java index f934bbd9ac..fbb00881bd 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorBase.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorBase.java @@ -1,508 +1,508 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 201266
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.spi.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDTemp;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDOList;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
-import org.eclipse.emf.cdo.internal.common.commit.CDOCommitDataImpl;
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureDeltaVisitorImpl;
-import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
-
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public abstract class StoreAccessorBase extends Lifecycle implements IStoreAccessor
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, StoreAccessorBase.class);
-
- private Store store;
-
- private Object context;
-
- private boolean reader;
-
- private List<CommitContext> commitContexts = new ArrayList<CommitContext>();
-
- private StoreAccessorBase(Store store, Object context, boolean reader)
- {
- this.store = store;
- this.context = context;
- this.reader = reader;
- }
-
- protected StoreAccessorBase(Store store, ISession session)
- {
- this(store, session, true);
- }
-
- protected StoreAccessorBase(Store store, ITransaction transaction)
- {
- this(store, transaction, false);
- }
-
- void setContext(Object context)
- {
- this.context = context;
- }
-
- public Store getStore()
- {
- return store;
- }
-
- public boolean isReader()
- {
- return reader;
- }
-
- /**
- * @since 3.0
- */
- public InternalSession getSession()
- {
- if (context instanceof ITransaction)
- {
- return (InternalSession)((ITransaction)context).getSession();
- }
-
- return (InternalSession)context;
- }
-
- public ITransaction getTransaction()
- {
- if (context instanceof ITransaction)
- {
- return (ITransaction)context;
- }
-
- return null;
- }
-
- public void release()
- {
- store.releaseAccessor(this);
- commitContexts.clear();
- }
-
- /**
- * @since 3.0
- */
- public final void write(InternalCommitContext context, OMMonitor monitor)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Writing transaction: {0}", getTransaction()); //$NON-NLS-1$
- }
-
- commitContexts.add(context);
- doWrite(context, monitor);
- }
-
- protected abstract void doWrite(InternalCommitContext context, OMMonitor monitor);
-
- /**
- * @since 3.0
- */
- public final void commit(OMMonitor monitor)
- {
- doCommit(monitor);
-
- long latest = CDORevision.UNSPECIFIED_DATE;
- long latestNonLocal = CDORevision.UNSPECIFIED_DATE;
- for (CommitContext commitContext : commitContexts)
- {
- CDOBranchPoint branchPoint = commitContext.getBranchPoint();
- long timeStamp = branchPoint.getTimeStamp();
- if (timeStamp > latest)
- {
- latest = timeStamp;
- }
-
- CDOBranch branch = branchPoint.getBranch();
- if (!branch.isLocal())
- {
- if (timeStamp > latestNonLocal)
- {
- latestNonLocal = timeStamp;
- }
- }
- }
-
- getStore().setLastCommitTime(latest);
- getStore().setLastNonLocalCommitTime(latestNonLocal);
- }
-
- /**
- * @since 3.0
- */
- protected abstract void doCommit(OMMonitor monitor);
-
- public final void rollback()
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Rolling back transaction: {0}", getTransaction()); //$NON-NLS-1$
- }
-
- for (CommitContext commitContext : commitContexts)
- {
- doRollback(commitContext);
- }
- }
-
- protected abstract void doRollback(CommitContext commitContext);
-
- /**
- * @since 3.0
- */
- public CDOID readResourceID(CDOID folderID, String name, CDOBranchPoint branchPoint)
- {
- QueryResourcesContext.ExactMatch context = Store.createExactMatchContext(folderID, name, branchPoint);
- queryResources(context);
- return context.getResourceID();
- }
-
- /**
- * @since 3.0
- */
- public CDOCommitData loadCommitData(long timeStamp)
- {
- CommitDataRevisionHandler handler = new CommitDataRevisionHandler(this, timeStamp);
- return handler.getCommitData();
- }
-
- /**
- * Add ID mappings for all new objects of a transaction to the commit context. The implementor must, for each new
- * object of the commit context, determine a permanent CDOID and make it known to the context by calling
- * {@link InternalCommitContext#addIDMapping(CDOID, CDOID)}.
- *
- * @since 3.0
- */
- public void addIDMappings(InternalCommitContext commitContext, OMMonitor monitor)
- {
- try
- {
- CDORevision[] newObjects = commitContext.getNewObjects();
- monitor.begin(newObjects.length);
- for (CDORevision revision : newObjects)
- {
- CDOID id = revision.getID();
- if (id instanceof CDOIDTemp)
- {
- CDOIDTemp oldID = (CDOIDTemp)id;
- CDOID newID = getNextCDOID(revision);
- if (CDOIDUtil.isNull(newID) || newID.isTemporary())
- {
- throw new IllegalStateException("newID=" + newID); //$NON-NLS-1$
- }
-
- commitContext.addIDMapping(oldID, newID);
- }
-
- monitor.worked();
- }
- }
- finally
- {
- monitor.done();
- }
- }
-
- protected abstract CDOID getNextCDOID(CDORevision revision);
-
- protected void doPassivate() throws Exception
- {
- }
-
- protected void doUnpassivate() throws Exception
- {
- }
-
- /**
- * @author Eike Stepper
- * @since 3.0
- */
- public static class CommitDataRevisionHandler implements CDORevisionHandler
- {
- private IStoreAccessor storeAccessor;
-
- private long timeStamp;
-
- private InternalCDORevisionManager revisionManager;
-
- private List<CDOPackageUnit> newPackageUnits = new ArrayList<CDOPackageUnit>();
-
- private List<CDOIDAndVersion> newObjects = new ArrayList<CDOIDAndVersion>();
-
- private List<CDORevisionKey> changedObjects = new ArrayList<CDORevisionKey>();
-
- private DetachCounter detachCounter = new DetachCounter();
-
- public CommitDataRevisionHandler(IStoreAccessor storeAccessor, long timeStamp)
- {
- this.storeAccessor = storeAccessor;
- this.timeStamp = timeStamp;
-
- InternalStore store = (InternalStore)storeAccessor.getStore();
- InternalRepository repository = store.getRepository();
- revisionManager = repository.getRevisionManager();
-
- InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false);
- InternalCDOPackageUnit[] packageUnits = packageRegistry.getPackageUnits(timeStamp, timeStamp);
- for (InternalCDOPackageUnit packageUnit : packageUnits)
- {
- if (!packageUnit.isSystem())
- {
- newPackageUnits.add(packageUnit);
- }
- }
- }
-
- public CDOCommitData getCommitData()
- {
- storeAccessor.handleRevisions(null, null, timeStamp, true, new CDORevisionHandler.Filtered.Undetached(this));
-
- List<CDOIDAndVersion> detachedObjects = detachCounter.getDetachedObjects();
- return new CDOCommitDataImpl(newPackageUnits, newObjects, changedObjects, detachedObjects);
- }
-
- /**
- * @since 4.0
- */
- public boolean handleRevision(CDORevision rev)
- {
- if (rev.getTimeStamp() != timeStamp)
- {
- throw new IllegalArgumentException("Invalid revision time stamp: "
- + CDOCommonUtil.formatTimeStamp(rev.getTimeStamp()));
- }
-
- if (rev instanceof DetachedCDORevision)
- {
- // Do nothing. Detached objects are handled by detachCounter.
- }
- else
- {
- InternalCDORevision revision = (InternalCDORevision)rev;
- CDOID id = revision.getID();
- CDOBranch branch = revision.getBranch();
- int version = revision.getVersion();
- if (version > CDOBranchVersion.FIRST_VERSION)
- {
- CDOBranchVersion oldVersion = branch.getVersion(version - 1);
- InternalCDORevision oldRevision = revisionManager.getRevisionByVersion(id, oldVersion, CDORevision.UNCHUNKED,
- true);
- InternalCDORevisionDelta delta = revision.compare(oldRevision);
- changedObjects.add(delta);
-
- detachCounter.update(oldRevision, delta);
- }
- else
- {
- InternalCDORevision oldRevision = getRevisionFromBase(id, branch);
- if (oldRevision != null)
- {
- InternalCDORevisionDelta delta = revision.compare(oldRevision);
- changedObjects.add(delta);
- }
- else
- {
- InternalCDORevision newRevision = revision.copy();
- newRevision.setRevised(CDOBranchPoint.UNSPECIFIED_DATE);
- newObjects.add(newRevision);
- }
- }
- }
-
- return true;
- }
-
- private InternalCDORevision getRevisionFromBase(CDOID id, CDOBranch branch)
- {
- if (branch.isMainBranch())
- {
- return null;
- }
-
- CDOBranchPoint base = branch.getBase();
- InternalCDORevision revision = revisionManager.getRevision(id, base, CDORevision.UNCHUNKED,
- CDORevision.DEPTH_NONE, true);
- if (revision == null)
- {
- revision = getRevisionFromBase(id, base.getBranch());
- }
-
- return revision;
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class DetachCounter extends CDOFeatureDeltaVisitorImpl
- {
- private Map<CDOID, AtomicInteger> counters = new HashMap<CDOID, AtomicInteger>();
-
- private InternalCDORevision oldRevision;
-
- public DetachCounter()
- {
- }
-
- public void update(InternalCDORevision oldRevision, InternalCDORevisionDelta delta)
- {
- try
- {
- this.oldRevision = oldRevision;
- delta.accept(this);
- }
- finally
- {
- this.oldRevision = null;
- }
- }
-
- public List<CDOIDAndVersion> getDetachedObjects()
- {
- List<CDOIDAndVersion> result = new ArrayList<CDOIDAndVersion>();
- for (Entry<CDOID, AtomicInteger> entry : counters.entrySet())
- {
- int value = entry.getValue().get();
- if (value == -1)
- {
- CDOID id = entry.getKey();
- result.add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION));
- }
- }
-
- return result;
- }
-
- @Override
- public void visit(CDOAddFeatureDelta delta)
- {
- if (isContainment(delta.getFeature()))
- {
- handleContainment(delta.getValue(), 1);
- }
- }
-
- @Override
- public void visit(CDORemoveFeatureDelta delta)
- {
- if (isContainment(delta.getFeature()))
- {
- handleContainment(delta.getValue(), -1);
- }
- }
-
- @Override
- public void visit(CDOSetFeatureDelta delta)
- {
- if (isContainment(delta.getFeature()))
- {
- handleContainment(delta.getValue(), 1);
- }
- }
-
- @Override
- public void visit(CDOUnsetFeatureDelta delta)
- {
- EStructuralFeature feature = delta.getFeature();
- if (isContainment(feature))
- {
- Object value = oldRevision.getValue(feature);
- handleContainment(value, -1);
- }
- }
-
- @Override
- public void visit(CDOClearFeatureDelta delta)
- {
- EStructuralFeature feature = delta.getFeature();
- if (isContainment(feature))
- {
- CDOList list = oldRevision.getList(feature);
- for (Object value : list)
- {
- handleContainment(value, -1);
- }
- }
- }
-
- private void handleContainment(Object value, int delta)
- {
- CDOID id = (CDOID)value;
- AtomicInteger counter = counters.get(id);
- if (counter == null)
- {
- counter = new AtomicInteger();
- counters.put(id, counter);
- }
-
- counter.addAndGet(delta);
- }
-
- private static boolean isContainment(EStructuralFeature feature)
- {
- if (feature instanceof EReference)
- {
- EReference reference = (EReference)feature;
- return reference.isContainment();
- }
-
- return false;
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 201266 + * Simon McDuff - bug 213402 + */ +package org.eclipse.emf.cdo.spi.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.branch.CDOBranchVersion; +import org.eclipse.emf.cdo.common.commit.CDOCommitData; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDTemp; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDOList; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta; +import org.eclipse.emf.cdo.common.util.CDOCommonUtil; +import org.eclipse.emf.cdo.internal.common.commit.CDOCommitDataImpl; +import org.eclipse.emf.cdo.internal.server.bundle.OM; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.ITransaction; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; +import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureDeltaVisitorImpl; +import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; + +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public abstract class StoreAccessorBase extends Lifecycle implements IStoreAccessor +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, StoreAccessorBase.class); + + private Store store; + + private Object context; + + private boolean reader; + + private List<CommitContext> commitContexts = new ArrayList<CommitContext>(); + + private StoreAccessorBase(Store store, Object context, boolean reader) + { + this.store = store; + this.context = context; + this.reader = reader; + } + + protected StoreAccessorBase(Store store, ISession session) + { + this(store, session, true); + } + + protected StoreAccessorBase(Store store, ITransaction transaction) + { + this(store, transaction, false); + } + + void setContext(Object context) + { + this.context = context; + } + + public Store getStore() + { + return store; + } + + public boolean isReader() + { + return reader; + } + + /** + * @since 3.0 + */ + public InternalSession getSession() + { + if (context instanceof ITransaction) + { + return (InternalSession)((ITransaction)context).getSession(); + } + + return (InternalSession)context; + } + + public ITransaction getTransaction() + { + if (context instanceof ITransaction) + { + return (ITransaction)context; + } + + return null; + } + + public void release() + { + store.releaseAccessor(this); + commitContexts.clear(); + } + + /** + * @since 3.0 + */ + public final void write(InternalCommitContext context, OMMonitor monitor) + { + if (TRACER.isEnabled()) + { + TRACER.format("Writing transaction: {0}", getTransaction()); //$NON-NLS-1$ + } + + commitContexts.add(context); + doWrite(context, monitor); + } + + protected abstract void doWrite(InternalCommitContext context, OMMonitor monitor); + + /** + * @since 3.0 + */ + public final void commit(OMMonitor monitor) + { + doCommit(monitor); + + long latest = CDORevision.UNSPECIFIED_DATE; + long latestNonLocal = CDORevision.UNSPECIFIED_DATE; + for (CommitContext commitContext : commitContexts) + { + CDOBranchPoint branchPoint = commitContext.getBranchPoint(); + long timeStamp = branchPoint.getTimeStamp(); + if (timeStamp > latest) + { + latest = timeStamp; + } + + CDOBranch branch = branchPoint.getBranch(); + if (!branch.isLocal()) + { + if (timeStamp > latestNonLocal) + { + latestNonLocal = timeStamp; + } + } + } + + getStore().setLastCommitTime(latest); + getStore().setLastNonLocalCommitTime(latestNonLocal); + } + + /** + * @since 3.0 + */ + protected abstract void doCommit(OMMonitor monitor); + + public final void rollback() + { + if (TRACER.isEnabled()) + { + TRACER.format("Rolling back transaction: {0}", getTransaction()); //$NON-NLS-1$ + } + + for (CommitContext commitContext : commitContexts) + { + doRollback(commitContext); + } + } + + protected abstract void doRollback(CommitContext commitContext); + + /** + * @since 3.0 + */ + public CDOID readResourceID(CDOID folderID, String name, CDOBranchPoint branchPoint) + { + QueryResourcesContext.ExactMatch context = Store.createExactMatchContext(folderID, name, branchPoint); + queryResources(context); + return context.getResourceID(); + } + + /** + * @since 3.0 + */ + public CDOCommitData loadCommitData(long timeStamp) + { + CommitDataRevisionHandler handler = new CommitDataRevisionHandler(this, timeStamp); + return handler.getCommitData(); + } + + /** + * Add ID mappings for all new objects of a transaction to the commit context. The implementor must, for each new + * object of the commit context, determine a permanent CDOID and make it known to the context by calling + * {@link InternalCommitContext#addIDMapping(CDOID, CDOID)}. + * + * @since 3.0 + */ + public void addIDMappings(InternalCommitContext commitContext, OMMonitor monitor) + { + try + { + CDORevision[] newObjects = commitContext.getNewObjects(); + monitor.begin(newObjects.length); + for (CDORevision revision : newObjects) + { + CDOID id = revision.getID(); + if (id instanceof CDOIDTemp) + { + CDOIDTemp oldID = (CDOIDTemp)id; + CDOID newID = getNextCDOID(revision); + if (CDOIDUtil.isNull(newID) || newID.isTemporary()) + { + throw new IllegalStateException("newID=" + newID); //$NON-NLS-1$ + } + + commitContext.addIDMapping(oldID, newID); + } + + monitor.worked(); + } + } + finally + { + monitor.done(); + } + } + + protected abstract CDOID getNextCDOID(CDORevision revision); + + protected void doPassivate() throws Exception + { + } + + protected void doUnpassivate() throws Exception + { + } + + /** + * @author Eike Stepper + * @since 3.0 + */ + public static class CommitDataRevisionHandler implements CDORevisionHandler + { + private IStoreAccessor storeAccessor; + + private long timeStamp; + + private InternalCDORevisionManager revisionManager; + + private List<CDOPackageUnit> newPackageUnits = new ArrayList<CDOPackageUnit>(); + + private List<CDOIDAndVersion> newObjects = new ArrayList<CDOIDAndVersion>(); + + private List<CDORevisionKey> changedObjects = new ArrayList<CDORevisionKey>(); + + private DetachCounter detachCounter = new DetachCounter(); + + public CommitDataRevisionHandler(IStoreAccessor storeAccessor, long timeStamp) + { + this.storeAccessor = storeAccessor; + this.timeStamp = timeStamp; + + InternalStore store = (InternalStore)storeAccessor.getStore(); + InternalRepository repository = store.getRepository(); + revisionManager = repository.getRevisionManager(); + + InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false); + InternalCDOPackageUnit[] packageUnits = packageRegistry.getPackageUnits(timeStamp, timeStamp); + for (InternalCDOPackageUnit packageUnit : packageUnits) + { + if (!packageUnit.isSystem()) + { + newPackageUnits.add(packageUnit); + } + } + } + + public CDOCommitData getCommitData() + { + storeAccessor.handleRevisions(null, null, timeStamp, true, new CDORevisionHandler.Filtered.Undetached(this)); + + List<CDOIDAndVersion> detachedObjects = detachCounter.getDetachedObjects(); + return new CDOCommitDataImpl(newPackageUnits, newObjects, changedObjects, detachedObjects); + } + + /** + * @since 4.0 + */ + public boolean handleRevision(CDORevision rev) + { + if (rev.getTimeStamp() != timeStamp) + { + throw new IllegalArgumentException("Invalid revision time stamp: " + + CDOCommonUtil.formatTimeStamp(rev.getTimeStamp())); + } + + if (rev instanceof DetachedCDORevision) + { + // Do nothing. Detached objects are handled by detachCounter. + } + else + { + InternalCDORevision revision = (InternalCDORevision)rev; + CDOID id = revision.getID(); + CDOBranch branch = revision.getBranch(); + int version = revision.getVersion(); + if (version > CDOBranchVersion.FIRST_VERSION) + { + CDOBranchVersion oldVersion = branch.getVersion(version - 1); + InternalCDORevision oldRevision = revisionManager.getRevisionByVersion(id, oldVersion, CDORevision.UNCHUNKED, + true); + InternalCDORevisionDelta delta = revision.compare(oldRevision); + changedObjects.add(delta); + + detachCounter.update(oldRevision, delta); + } + else + { + InternalCDORevision oldRevision = getRevisionFromBase(id, branch); + if (oldRevision != null) + { + InternalCDORevisionDelta delta = revision.compare(oldRevision); + changedObjects.add(delta); + } + else + { + InternalCDORevision newRevision = revision.copy(); + newRevision.setRevised(CDOBranchPoint.UNSPECIFIED_DATE); + newObjects.add(newRevision); + } + } + } + + return true; + } + + private InternalCDORevision getRevisionFromBase(CDOID id, CDOBranch branch) + { + if (branch.isMainBranch()) + { + return null; + } + + CDOBranchPoint base = branch.getBase(); + InternalCDORevision revision = revisionManager.getRevision(id, base, CDORevision.UNCHUNKED, + CDORevision.DEPTH_NONE, true); + if (revision == null) + { + revision = getRevisionFromBase(id, base.getBranch()); + } + + return revision; + } + + /** + * @author Eike Stepper + */ + private static final class DetachCounter extends CDOFeatureDeltaVisitorImpl + { + private Map<CDOID, AtomicInteger> counters = new HashMap<CDOID, AtomicInteger>(); + + private InternalCDORevision oldRevision; + + public DetachCounter() + { + } + + public void update(InternalCDORevision oldRevision, InternalCDORevisionDelta delta) + { + try + { + this.oldRevision = oldRevision; + delta.accept(this); + } + finally + { + this.oldRevision = null; + } + } + + public List<CDOIDAndVersion> getDetachedObjects() + { + List<CDOIDAndVersion> result = new ArrayList<CDOIDAndVersion>(); + for (Entry<CDOID, AtomicInteger> entry : counters.entrySet()) + { + int value = entry.getValue().get(); + if (value == -1) + { + CDOID id = entry.getKey(); + result.add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION)); + } + } + + return result; + } + + @Override + public void visit(CDOAddFeatureDelta delta) + { + if (isContainment(delta.getFeature())) + { + handleContainment(delta.getValue(), 1); + } + } + + @Override + public void visit(CDORemoveFeatureDelta delta) + { + if (isContainment(delta.getFeature())) + { + handleContainment(delta.getValue(), -1); + } + } + + @Override + public void visit(CDOSetFeatureDelta delta) + { + if (isContainment(delta.getFeature())) + { + handleContainment(delta.getValue(), 1); + } + } + + @Override + public void visit(CDOUnsetFeatureDelta delta) + { + EStructuralFeature feature = delta.getFeature(); + if (isContainment(feature)) + { + Object value = oldRevision.getValue(feature); + handleContainment(value, -1); + } + } + + @Override + public void visit(CDOClearFeatureDelta delta) + { + EStructuralFeature feature = delta.getFeature(); + if (isContainment(feature)) + { + CDOList list = oldRevision.getList(feature); + for (Object value : list) + { + handleContainment(value, -1); + } + } + } + + private void handleContainment(Object value, int delta) + { + CDOID id = (CDOID)value; + AtomicInteger counter = counters.get(id); + if (counter == null) + { + counter = new AtomicInteger(); + counters.put(id, counter); + } + + counter.addAndGet(delta); + } + + private static boolean isContainment(EStructuralFeature feature) + { + if (feature instanceof EReference) + { + EReference reference = (EReference)feature; + return reference.isContainment(); + } + + return false; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorPool.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorPool.java index 914e306226..01edd1ebf1 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorPool.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreAccessorPool.java @@ -1,121 +1,121 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.ISession;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IView;
-
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class StoreAccessorPool
-{
- /**
- * The {@link IStore store} instance that manages this pool.
- */
- private IStore store;
-
- /**
- * The pooling context of this pool. An instance of either {@link ISession} or {@link IView}, or <code>null</code> if
- * this pool is not contextual.
- */
- private Object context;
-
- private ConcurrentLinkedQueue<StoreAccessorBase> accessors = new ConcurrentLinkedQueue<StoreAccessorBase>();
-
- public StoreAccessorPool(IStore store, Object context)
- {
- this.store = store;
- this.context = context;
- }
-
- public IStore getStore()
- {
- return store;
- }
-
- public Object getContext()
- {
- return context;
- }
-
- /**
- * Passivates the given {@link StoreAccessor store accessor} and adds it to this pool.
- *
- * @since 4.0
- */
- public void addStoreAccessor(StoreAccessorBase storeAccessor)
- {
- try
- {
- storeAccessor.doPassivate();
- accessors.add(storeAccessor);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
-
- /**
- * Returns a {@link StoreAccessor store accessor} from this pool if one is available, or <code>null</code> otherwise.
- * If a store accessor is available it is removed from this pool and its unpassivate method is called.
- *
- * @since 4.0
- */
- public StoreAccessorBase removeStoreAccessor(Object context)
- {
- StoreAccessorBase accessor = accessors.poll();
- if (accessor != null)
- {
- try
- {
- accessor.doUnpassivate();
- accessor.setContext(context);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- return null;
- }
- }
-
- return accessor;
- }
-
- /**
- * Deactivates all contained {@link StoreAccessor store accessors} and clears this pool.
- */
- public void dispose()
- {
- for (;;)
- {
- StoreAccessorBase accessor = accessors.poll();
- if (accessor == null)
- {
- break;
- }
-
- LifecycleUtil.deactivate(accessor, OMLogger.Level.WARN);
- }
-
- context = null;
- store = null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.internal.server.bundle.OM; +import org.eclipse.emf.cdo.server.ISession; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IView; + +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.log.OMLogger; + +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public class StoreAccessorPool +{ + /** + * The {@link IStore store} instance that manages this pool. + */ + private IStore store; + + /** + * The pooling context of this pool. An instance of either {@link ISession} or {@link IView}, or <code>null</code> if + * this pool is not contextual. + */ + private Object context; + + private ConcurrentLinkedQueue<StoreAccessorBase> accessors = new ConcurrentLinkedQueue<StoreAccessorBase>(); + + public StoreAccessorPool(IStore store, Object context) + { + this.store = store; + this.context = context; + } + + public IStore getStore() + { + return store; + } + + public Object getContext() + { + return context; + } + + /** + * Passivates the given {@link StoreAccessor store accessor} and adds it to this pool. + * + * @since 4.0 + */ + public void addStoreAccessor(StoreAccessorBase storeAccessor) + { + try + { + storeAccessor.doPassivate(); + accessors.add(storeAccessor); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + + /** + * Returns a {@link StoreAccessor store accessor} from this pool if one is available, or <code>null</code> otherwise. + * If a store accessor is available it is removed from this pool and its unpassivate method is called. + * + * @since 4.0 + */ + public StoreAccessorBase removeStoreAccessor(Object context) + { + StoreAccessorBase accessor = accessors.poll(); + if (accessor != null) + { + try + { + accessor.doUnpassivate(); + accessor.setContext(context); + } + catch (Exception ex) + { + OM.LOG.error(ex); + return null; + } + } + + return accessor; + } + + /** + * Deactivates all contained {@link StoreAccessor store accessors} and clears this pool. + */ + public void dispose() + { + for (;;) + { + StoreAccessorBase accessor = accessors.poll(); + if (accessor == null) + { + break; + } + + LifecycleUtil.deactivate(accessor, OMLogger.Level.WARN); + } + + context = null; + store = null; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreChunkReader.java index d60f957d60..e9e0554a62 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/StoreChunkReader.java @@ -1,72 +1,72 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreChunkReader;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class StoreChunkReader implements IStoreChunkReader
-{
- private IStoreAccessor accessor;
-
- private CDORevision revision;
-
- private EStructuralFeature feature;
-
- private List<Chunk> chunks = new ArrayList<Chunk>(0);
-
- public StoreChunkReader(IStoreAccessor accessor, CDORevision revision, EStructuralFeature feature)
- {
- this.accessor = accessor;
- this.revision = revision;
- this.feature = feature;
- }
-
- public IStoreAccessor getAccessor()
- {
- return accessor;
- }
-
- public CDORevision getRevision()
- {
- return revision;
- }
-
- public EStructuralFeature getFeature()
- {
- return feature;
- }
-
- public List<Chunk> getChunks()
- {
- return chunks;
- }
-
- public void addSimpleChunk(int index)
- {
- chunks.add(new Chunk(index));
- }
-
- public void addRangedChunk(int fromIndex, int toIndex)
- {
- chunks.add(new Chunk(fromIndex, toIndex - fromIndex));
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.IStoreAccessor; +import org.eclipse.emf.cdo.server.IStoreChunkReader; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class StoreChunkReader implements IStoreChunkReader +{ + private IStoreAccessor accessor; + + private CDORevision revision; + + private EStructuralFeature feature; + + private List<Chunk> chunks = new ArrayList<Chunk>(0); + + public StoreChunkReader(IStoreAccessor accessor, CDORevision revision, EStructuralFeature feature) + { + this.accessor = accessor; + this.revision = revision; + this.feature = feature; + } + + public IStoreAccessor getAccessor() + { + return accessor; + } + + public CDORevision getRevision() + { + return revision; + } + + public EStructuralFeature getFeature() + { + return feature; + } + + public List<Chunk> getChunks() + { + return chunks; + } + + public void addSimpleChunk(int index) + { + chunks.add(new Chunk(index)); + } + + public void addRangedChunk(int fromIndex, int toIndex) + { + chunks.add(new Chunk(fromIndex, toIndex - fromIndex)); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/SyncingUtil.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/SyncingUtil.java index 9ab7ce6c0e..0e51b0edaa 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/SyncingUtil.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/SyncingUtil.java @@ -1,60 +1,60 @@ -/*
- * Copyright (c) 2004 - 2012 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.spi.server;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea;
-import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockAreaNotFoundException;
-
-import org.eclipse.net4j.util.CheckUtil;
-
-/**
- * Static methods that may help with classes related to repository synchronization.
- *
- * @author Eike Stepper
- * @since 4.1
- */
-public final class SyncingUtil
-{
- private SyncingUtil()
- {
- }
-
- public static InternalView openViewWithLockArea(InternalSession session, InternalLockManager lockManager,
- CDOBranch viewedBranch, String lockAreaID)
- {
- LockArea lockArea;
- InternalView view;
-
- try
- {
- lockArea = lockManager.getLockArea(lockAreaID);
-
- // If we get here, the lockArea already exists.
- view = (InternalView)lockManager.openView(session, InternalSession.TEMP_VIEW_ID, true, lockAreaID);
- }
- catch (LockAreaNotFoundException e)
- {
- // If we get here, the lockArea does not yet exist, so we open
- // a view without a lockArea first, then create a lockArea with the given ID,
- // and associate it with the view.
- view = session.openView(InternalSession.TEMP_VIEW_ID, viewedBranch.getHead());
- lockArea = lockManager.createLockArea(view, lockAreaID);
- view.setDurableLockingID(lockAreaID);
- }
-
- CheckUtil.checkNull(lockAreaID, "lockAreaID");
- CheckUtil.checkNull(lockArea, "lockArea");
- CheckUtil.checkState(lockAreaID.equals(lockArea.getDurableLockingID()), "lockAreaID has incorrect value");
-
- return view;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.spi.server; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea; +import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockAreaNotFoundException; + +import org.eclipse.net4j.util.CheckUtil; + +/** + * Static methods that may help with classes related to repository synchronization. + * + * @author Eike Stepper + * @since 4.1 + */ +public final class SyncingUtil +{ + private SyncingUtil() + { + } + + public static InternalView openViewWithLockArea(InternalSession session, InternalLockManager lockManager, + CDOBranch viewedBranch, String lockAreaID) + { + LockArea lockArea; + InternalView view; + + try + { + lockArea = lockManager.getLockArea(lockAreaID); + + // If we get here, the lockArea already exists. + view = (InternalView)lockManager.openView(session, InternalSession.TEMP_VIEW_ID, true, lockAreaID); + } + catch (LockAreaNotFoundException e) + { + // If we get here, the lockArea does not yet exist, so we open + // a view without a lockArea first, then create a lockArea with the given ID, + // and associate it with the view. + view = session.openView(InternalSession.TEMP_VIEW_ID, viewedBranch.getHead()); + lockArea = lockManager.createLockArea(view, lockAreaID); + view.setDurableLockingID(lockAreaID); + } + + CheckUtil.checkNull(lockAreaID, "lockAreaID"); + CheckUtil.checkNull(lockArea, "lockArea"); + CheckUtil.checkState(lockAreaID.equals(lockArea.getDurableLockingID()), "lockAreaID has incorrect value"); + + return view; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/package-info.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/package-info.java index ef06bddc57..9a9051326d 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/package-info.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/package-info.java @@ -1,18 +1,18 @@ -/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Server service provider interfaces and useful base implementations.
- *
- * @apiviz.exclude .*
- */
-package org.eclipse.emf.cdo.spi.server;
-
+/* + * Copyright (c) 2004 - 2012 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 + */ + +/** + * Server service provider interfaces and useful base implementations. + * + * @apiviz.exclude .* + */ +package org.eclipse.emf.cdo.spi.server; + |