Author: rhauch
Date: 2009-11-30 14:40:58 -0500 (Mon, 30 Nov 2009)
New Revision: 1370
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/Changes.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java
Log:
DNA-548 Changed JcrWorkspace, JcrSession, and WorkspaceLockManager so that they use
ExecutionContext more consistently. JcrWorkspace and JcrSession both share the exact same
ExecutionContext instance, while WorkspaceLockManager was changed to expect the JcrSession
in most of its methods so the lock manager can use the JcrSession's ExecutionContext
in its operations. (The latter also has the advantage of recording which sessions were
performing the lock operations, since now the session's context is used for all lock
operations.)
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/Changes.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/Changes.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/Changes.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -127,7 +127,7 @@
* @return the context identifier; never null
*/
public String getContextId() {
- return processId;
+ return contextId;
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-11-30 17:06:05
UTC (rev 1369)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-11-30 19:40:58
UTC (rev 1370)
@@ -1336,7 +1336,7 @@
* @see javax.jcr.Node#holdsLock()
*/
public final boolean holdsLock() /*throws RepositoryException*/{
- WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lockFor(this.location);
+ WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lockFor(session(), this.location);
return lock != null &&
cache.session().lockTokens().contains(lock.getLockToken());
}
@@ -1368,9 +1368,9 @@
while (!nodesToVisit.isEmpty()) {
Node<JcrNodePayload, JcrPropertyPayload> node =
nodesToVisit.remove(nodesToVisit.size() - 1);
- if (session().workspace().lockManager().lockFor(node.getLocation()) !=
null) throw new LockException(
-
JcrI18n.parentAlreadyLocked.text(this.location,
-
node.getLocation()));
+ if (session().workspace().lockManager().lockFor(session(),
node.getLocation()) != null) throw new LockException(
+
JcrI18n.parentAlreadyLocked.text(this.location,
+
node.getLocation()));
for (Node<JcrNodePayload, JcrPropertyPayload> child :
node.getChildren()) {
nodesToVisit.add(child);
@@ -1378,9 +1378,8 @@
}
}
- WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lock(cache,
+ WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lock(session(),
this.location,
-
session().getUserID(),
isDeep,
isSessionScoped);
@@ -1394,7 +1393,7 @@
* @see javax.jcr.Node#unlock()
*/
public final void unlock() throws LockException, RepositoryException {
- WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lockFor(this.location);
+ WorkspaceLockManager.DnaLock lock =
session().workspace().lockManager().lockFor(session(), this.location);
if (lock == null) {
throw new LockException(JcrI18n.notLocked.text(this.location));
@@ -1404,7 +1403,7 @@
throw new LockException(JcrI18n.lockTokenNotHeld.text(this.location));
}
- session().workspace().lockManager().unlock(lock);
+ session().workspace().lockManager().unlock(session(), lock);
session().removeLockToken(lock.getLockToken());
}
@@ -1413,14 +1412,14 @@
if (session() == null || session().workspace() == null) return null;
WorkspaceLockManager lockManager = session().workspace().lockManager();
- WorkspaceLockManager.DnaLock lock = lockManager.lockFor(this.location);
+ WorkspaceLockManager.DnaLock lock = lockManager.lockFor(session(),
this.location);
if (lock != null) return lock;
AbstractJcrNode parent = this;
while (!parent.isRoot()) {
parent = parent.getParent();
- WorkspaceLockManager.DnaLock parentLock =
lockManager.lockFor(parent.location);
+ WorkspaceLockManager.DnaLock parentLock = lockManager.lockFor(session(),
parent.location);
if (parentLock != null && parentLock.isLive()) {
return parentLock.isDeep() ? parentLock : null;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-11-30 17:06:05
UTC (rev 1369)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-11-30 19:40:58
UTC (rev 1370)
@@ -410,7 +410,7 @@
this.federatedSource.initialize(new
FederatedRepositoryContext(this.connectionFactory));
this.lockManagers = new ConcurrentHashMap<String, WorkspaceLockManager>();
- this.locksPath = pathFactory.create(pathFactory.createRootPath(),
JcrLexicon.SYSTEM, DnaLexicon.LOCKS);
+ this.locksPath = pathFactory.create(pathFactory.createRootPath(),
JcrLexicon.SYSTEM, DnaLexicon.LOCKS);
}
protected void initializeSystemContent( Graph systemGraph ) {
@@ -430,12 +430,12 @@
return graph;
}
- Graph createSystemGraph() {
+ Graph createSystemGraph( ExecutionContext sessionContext ) {
assert this.systemSourceName != null;
assert this.connectionFactory != null;
- assert this.executionContext != null;
+ assert sessionContext != null;
// The default workspace should be the system workspace ...
- Graph result = Graph.create(this.systemSourceName, this.connectionFactory,
this.executionContext);
+ Graph result = Graph.create(this.systemSourceName, this.connectionFactory,
sessionContext);
if (this.systemWorkspaceName != null) {
result.useWorkspace(systemWorkspaceName);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-11-30 17:06:05 UTC
(rev 1369)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-11-30 19:40:58 UTC
(rev 1370)
@@ -65,7 +65,6 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.ValueFactories;
-import org.jboss.dna.graph.property.basic.LocalNamespaceRegistry;
import org.jboss.dna.graph.session.GraphSession;
import org.jboss.dna.jcr.JcrContentHandler.EnclosingSAXException;
import org.jboss.dna.jcr.JcrContentHandler.SaveMode;
@@ -143,21 +142,21 @@
JcrSession( JcrRepository repository,
JcrWorkspace workspace,
- ExecutionContext workspaceContext,
+ ExecutionContext sessionContext,
+ NamespaceRegistry globalNamespaceRegistry,
Map<String, Object> sessionAttributes ) {
assert repository != null;
assert workspace != null;
assert sessionAttributes != null;
- assert workspaceContext != null;
+ assert sessionContext != null;
this.repository = repository;
this.sessionAttributes = sessionAttributes;
this.workspace = workspace;
// Create an execution context for this session, which should use the local
namespace registry ...
- NamespaceRegistry workspaceRegistry = workspaceContext.getNamespaceRegistry();
- NamespaceRegistry local = new LocalNamespaceRegistry(workspaceRegistry);
- this.executionContext = workspaceContext.with(local);
- this.sessionRegistry = new JcrNamespaceRegistry(Behavior.JSR170_SESSION, local,
workspaceRegistry, this);
+ this.executionContext = sessionContext;
+ NamespaceRegistry local = sessionContext.getNamespaceRegistry();
+ this.sessionRegistry = new JcrNamespaceRegistry(Behavior.JSR170_SESSION, local,
globalNamespaceRegistry, this);
this.rootPath =
this.executionContext.getValueFactories().getPathFactory().createRootPath();
// Set up the graph to use for this session (which uses the session's
namespace registry and context) ...
@@ -311,11 +310,11 @@
return;
}
- if (workspace().lockManager().isHeldBySession(lt)) {
+ if (workspace().lockManager().isHeldBySession(this, lt)) {
throw new LockException(JcrI18n.lockTokenAlreadyHeld.text(lt));
}
- workspace().lockManager().setHeldBySession(lt, true);
+ workspace().lockManager().setHeldBySession(this, lt, true);
lockTokens.add(lt);
}
@@ -776,7 +775,7 @@
return;
}
- this.workspace().lockManager().cleanLocks(lockTokens);
+ this.workspace().lockManager().cleanLocks(this);
this.executionContext.getSecurityContext().logout();
isLive = false;
}
@@ -858,7 +857,7 @@
throw new IllegalStateException(JcrI18n.cannotRemoveLockToken.text(lt));
}
- workspace().lockManager().setHeldBySession(lt, false);
+ workspace().lockManager().setHeldBySession(this, lt, false);
lockTokens.remove(lt);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-11-30 17:06:05
UTC (rev 1369)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-11-30 19:40:58
UTC (rev 1370)
@@ -34,7 +34,6 @@
import javax.jcr.InvalidSerializedDataException;
import javax.jcr.ItemExistsException;
import javax.jcr.ItemNotFoundException;
-import javax.jcr.NamespaceRegistry;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -61,10 +60,12 @@
import org.jboss.dna.graph.connector.RepositorySourceException;
import org.jboss.dna.graph.connector.UuidAlreadyExistsException;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.ValueFormatException;
+import org.jboss.dna.graph.property.basic.LocalNamespaceRegistry;
import org.jboss.dna.graph.request.InvalidWorkspaceException;
import org.jboss.dna.graph.request.ReadBranchRequest;
import org.jboss.dna.graph.session.GraphSession;
@@ -132,7 +133,7 @@
private final JcrQueryManager queryManager;
private final WorkspaceLockManager lockManager;
-
+
/**
* The {@link Session} instance that this corresponds with this workspace.
*/
@@ -151,34 +152,16 @@
this.repository = repository;
this.lockManager = repository.getLockManager(workspaceName);
- // // Set up the execution context for this workspace, which should use the
namespace registry that persists
- // // the namespaces in the graph ...
- // Graph namespaceGraph =
Graph.create(this.repository.getRepositorySourceName(),
- // this.repository.getConnectionFactory(),
- // context);
- // namespaceGraph.useWorkspace(workspaceName);
- //
- // // Make sure the "/jcr:system" node exists ...
- // PathFactory pathFactory = context.getValueFactories().getPathFactory();
- // Path root = pathFactory.createRootPath();
- // Path systemPath = pathFactory.create(root, JcrLexicon.SYSTEM);
- // Property systemPrimaryType =
context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.SYSTEM);
- // namespaceGraph.create(systemPath, systemPrimaryType).ifAbsent().and();
- //
- // Name uriProperty = DnaLexicon.NAMESPACE_URI;
- // Path namespacesPath = pathFactory.create(systemPath, DnaLexicon.NAMESPACES);
- // PropertyFactory propertyFactory = context.getPropertyFactory();
- // Property namespaceType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.NAMESPACE);
- // org.jboss.dna.graph.property.NamespaceRegistry persistentRegistry = new
GraphNamespaceRegistry(namespaceGraph,
- // namespacesPath,
- // uriProperty, namespaceType);
- this.context = context;
+ // Create an execution context for this session, which should use the local
namespace registry ...
+ NamespaceRegistry globalRegistry = context.getNamespaceRegistry();
+ NamespaceRegistry local = new LocalNamespaceRegistry(globalRegistry);
+ this.context = context.with(local);
// Now create a graph for the session ...
this.graph = this.repository.createWorkspaceGraph(workspaceName);
// Set up the session for this workspace ...
- this.session = new JcrSession(this.repository, this, this.context,
sessionAttributes);
+ this.session = new JcrSession(this.repository, this, this.context,
globalRegistry, sessionAttributes);
// This must be initialized after the session
this.nodeTypeManager = new JcrNodeTypeManager(session,
this.repository.getRepositoryTypeManager());
@@ -213,7 +196,7 @@
final WorkspaceLockManager lockManager() {
return this.lockManager;
}
-
+
/**
* {@inheritDoc}
*/
@@ -233,7 +216,7 @@
*
* @see javax.jcr.Workspace#getNamespaceRegistry()
*/
- public final NamespaceRegistry getNamespaceRegistry() {
+ public final javax.jcr.NamespaceRegistry getNamespaceRegistry() {
return workspaceRegistry;
}
@@ -325,7 +308,6 @@
// This also performs the check permission for reading the parent ...
Name newNodeName = destPath.getLastSegment().getName();
SessionCache cache = this.session.cache();
-
/*
* Find the UUID for the source node. Have to go directly against the
graph.
@@ -336,7 +318,7 @@
if (uuidProp != null) {
UUID sourceUuid =
this.context.getValueFactories().getUuidFactory().create(uuidProp.getFirstValue());
- DnaLock sourceLock = lockManager().lockFor(Location.create(sourceUuid));
+ DnaLock sourceLock = lockManager().lockFor(session,
Location.create(sourceUuid));
if (sourceLock != null && sourceLock.getLockToken() == null) {
throw new LockException(JcrI18n.lockTokenNotHeld.text(srcAbsPath));
}
@@ -350,7 +332,7 @@
throw new LockException(destAbsPath);
}
}
-
+
Node<JcrNodePayload, JcrPropertyPayload> parent = cache.findNode(null,
destPath.getParent());
cache.findBestNodeDefinition(parent, newNodeName,
parent.getPayload().getPrimaryTypeName());
@@ -481,7 +463,6 @@
// This also performs the check permission for reading the parent ...
Name newNodeName = destPath.getLastSegment().getName();
SessionCache cache = this.session.cache();
-
/*
* Find the UUID for the source node. Have to go directly against the
graph.
@@ -492,7 +473,7 @@
if (uuidProp != null) {
UUID sourceUuid =
this.context.getValueFactories().getUuidFactory().create(uuidProp.getFirstValue());
- DnaLock sourceLock = lockManager().lockFor(Location.create(sourceUuid));
+ DnaLock sourceLock = lockManager().lockFor(session,
Location.create(sourceUuid));
if (sourceLock != null && sourceLock.getLockToken() == null) {
throw new LockException(srcAbsPath);
}
@@ -506,7 +487,7 @@
throw new LockException(destAbsPath);
}
}
-
+
Node<JcrNodePayload, JcrPropertyPayload> parent = cache.findNode(null,
destPath.getParent());
cache.findBestNodeDefinition(parent, newNodeName,
parent.getPayload().getPrimaryTypeName());
@@ -633,7 +614,7 @@
if (newParentLock != null && newParentLock.getLockToken() ==
null) {
throw new LockException(destAbsPath);
}
- }
+ }
// Now perform the clone, using the direct (non-session) method ...
cache.graphSession().immediateMove(srcPath, destPath);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -31,7 +31,6 @@
@ThreadSafe
class WorkspaceLockManager {
- private final ExecutionContext context;
private final Path locksPath;
private final JcrRepository repository;
private final String workspaceName;
@@ -41,7 +40,6 @@
JcrRepository repository,
String workspaceName,
Path locksPath ) {
- this.context = context;
this.repository = repository;
this.workspaceName = workspaceName;
this.locksPath = locksPath;
@@ -49,7 +47,7 @@
this.workspaceLocksByNodeUuid = new ConcurrentHashMap<UUID, DnaLock>();
Property locksPrimaryType =
context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.LOCKS);
- repository.createSystemGraph().create(locksPath,
locksPrimaryType).ifAbsent().and();
+ repository.createSystemGraph(context).create(locksPath,
locksPrimaryType).ifAbsent().and();
}
/**
@@ -60,34 +58,34 @@
* The location given in {@code nodeLocation} must have a UUID.
* </p>
*
- * @param cache the session cache from which the node was loaded
+ * @param session the session in which the node is being locked and that loaded the
node
* @param nodeLocation the location for the node; may not be null and must have a
UUID
- * @param lockOwner the owner of the new lock
* @param isDeep whether the node's descendants in the content graph should also
be locked
* @param isSessionScoped whether the lock should outlive the session in which it was
created
* @return an object representing the newly created lock
* @throws RepositoryException if an error occurs updating the graph state
*/
- DnaLock lock( SessionCache cache,
+ DnaLock lock( JcrSession session,
Location nodeLocation,
- String lockOwner,
boolean isDeep,
boolean isSessionScoped ) throws RepositoryException {
assert nodeLocation != null;
UUID lockUuid = UUID.randomUUID();
- UUID nodeUuid = uuidFor(nodeLocation);
+ UUID nodeUuid = uuidFor(session, nodeLocation);
if (nodeUuid == null) {
throw new
RepositoryException(JcrI18n.uuidRequiredForLock.text(nodeLocation));
}
+ ExecutionContext sessionContext = session.getExecutionContext();
+ String lockOwner = sessionContext.getSecurityContext().getUserName();
DnaLock lock = createLock(lockOwner, lockUuid, nodeUuid, isDeep,
isSessionScoped);
- Graph.Batch batch = repository.createSystemGraph().batch();
+ Graph.Batch batch = repository.createSystemGraph(sessionContext).batch();
- PropertyFactory propFactory = context.getPropertyFactory();
- PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ PropertyFactory propFactory = sessionContext.getPropertyFactory();
+ PathFactory pathFactory = sessionContext.getValueFactories().getPathFactory();
Property lockOwnerProp = propFactory.create(JcrLexicon.LOCK_OWNER, lockOwner);
Property lockIsDeepProp = propFactory.create(JcrLexicon.LOCK_IS_DEEP, isDeep);
@@ -102,6 +100,7 @@
lockIsDeepProp).ifAbsent().and();
batch.execute();
+ SessionCache cache = session.cache();
AbstractJcrNode lockedNode = cache.findJcrNode(Location.create(nodeUuid));
NodeEditor editor = cache.getEditorFor(lockedNode.nodeInfo());
@@ -111,7 +110,7 @@
false);
editor.setProperty(JcrLexicon.LOCK_IS_DEEP,
(JcrValue)cache.session().getValueFactory().createValue(isDeep), false);
- lockNodeInRepository(nodeUuid, lockOwnerProp, lockIsDeepProp, lock, isDeep);
+ lockNodeInRepository(session, nodeUuid, lockOwnerProp, lockIsDeepProp, lock,
isDeep);
workspaceLocksByNodeUuid.put(nodeUuid, lock);
return lock;
@@ -133,13 +132,14 @@
* <p>
* This method will also attempt to {@link Graph#lock(Location) lock the node in the
underlying repository}. If the underlying
* repository supports locks and {@link LockFailedException the lock attempt fails},
this method will cancel the lock attempt
- * by calling {@link #unlock(DnaLock)} and will throw a {@code RepositoryException}.
+ * by calling {@link #unlock(JcrSession,DnaLock)} and will throw a {@code
RepositoryException}.
* </p>
* <p>
* This method does not modify the system graph. In other words, it will not create
the record for the lock in the {@code
* /jcr:system/dna:locks} subgraph.
* </p>
*
+ * @param session the session in which the node is being locked and that loaded the
node
* @param nodeUuid the UUID of the node to lock
* @param lockOwnerProp an existing property with name {@link JcrLexicon#LOCK_OWNER}
and the value being the name of the lock
* owner
@@ -153,7 +153,8 @@
* @throws RepositoryException if the repository in which the node represented by
{@code nodeUuid} supports locking but
* signals that the lock for the node cannot be acquired
*/
- void lockNodeInRepository( UUID nodeUuid,
+ void lockNodeInRepository( JcrSession session,
+ UUID nodeUuid,
Property lockOwnerProp,
Property lockIsDeepProp,
DnaLock lock,
@@ -170,7 +171,7 @@
workspaceBatch.execute();
} catch (LockFailedException lfe) {
// Attempt to lock node at the repo level failed - cancel lock
- unlock(lock);
+ unlock(session, lock);
throw new RepositoryException(lfe);
}
@@ -179,13 +180,16 @@
/**
* Removes the provided lock, effectively unlocking the node to which the lock is
associated.
*
+ * @param session the session in which the node is being unlocked
* @param lock the lock to be removed
*/
- void unlock( DnaLock lock ) {
+ void unlock( JcrSession session,
+ DnaLock lock ) {
try {
+ ExecutionContext context = session.getExecutionContext();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
- Graph.Batch batch = repository.createSystemGraph().batch();
+ Graph.Batch batch = repository.createSystemGraph(context).batch();
batch.delete(pathFactory.create(locksPath,
pathFactory.createSegment(lock.getUuid().toString())));
batch.remove(JcrLexicon.LOCK_OWNER,
JcrLexicon.LOCK_IS_DEEP).on(lock.nodeUuid);
@@ -232,17 +236,21 @@
* Checks whether the given lock token is currently held by any session by querying
the lock record in the underlying
* repository.
*
+ * @param session the session on behalf of which the lock query is being performed
* @param lockToken the lock token to check; may not be null
* @return true if a session currently holds the lock token, false otherwise
*/
- boolean isHeldBySession( String lockToken ) {
+ boolean isHeldBySession( JcrSession session,
+ String lockToken ) {
assert lockToken != null;
+ ExecutionContext context = session.getExecutionContext();
ValueFactory<Boolean> booleanFactory =
context.getValueFactories().getBooleanFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
- org.jboss.dna.graph.Node lockNode =
repository.createSystemGraph().getNodeAt(pathFactory.create(locksPath,
-
pathFactory.createSegment(lockToken)));
+ org.jboss.dna.graph.Node lockNode = repository.createSystemGraph(context)
+
.getNodeAt(pathFactory.create(locksPath,
+
pathFactory.createSegment(lockToken)));
return
booleanFactory.create(lockNode.getProperty(DnaLexicon.IS_HELD_BY_SESSION).getFirstValue());
@@ -253,18 +261,22 @@
* lock as being held (or not held) by some {@link Session}. Note that this method
does not identify <i>which</i> (if any)
* session holds the token for the lock, just that <i>some</i> session
holds the token for the lock.
*
+ * @param session the session on behalf of which the lock operation is being
performed
* @param lockToken the lock token for which the "held" status should be
modified; may not be null
* @param value the new value
*/
- void setHeldBySession( String lockToken,
+ void setHeldBySession( JcrSession session,
+ String lockToken,
boolean value ) {
assert lockToken != null;
+ ExecutionContext context = session.getExecutionContext();
PropertyFactory propFactory = context.getPropertyFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
-
repository.createSystemGraph().set(propFactory.create(DnaLexicon.IS_HELD_BY_SESSION,
value)).on(pathFactory.create(locksPath,
-
pathFactory.createSegment(lockToken)));
+ repository.createSystemGraph(context)
+ .set(propFactory.create(DnaLexicon.IS_HELD_BY_SESSION, value))
+ .on(pathFactory.create(locksPath,
pathFactory.createSegment(lockToken)));
}
/**
@@ -288,11 +300,13 @@
/**
* Returns the lock that corresponds to the given UUID
*
+ * @param session the session on behalf of which the lock operation is being
performed
* @param nodeLocation the node UUID
* @return the corresponding lock, possibly null if there is no such lock
*/
- DnaLock lockFor( Location nodeLocation ) {
- UUID nodeUuid = uuidFor(nodeLocation);
+ DnaLock lockFor( JcrSession session,
+ Location nodeLocation ) {
+ UUID nodeUuid = uuidFor(session, nodeLocation);
if (nodeUuid == null) return null;
return workspaceLocksByNodeUuid.get(nodeUuid);
}
@@ -302,10 +316,12 @@
* returns the {@link Location#getUuid() default UUID} if it exists. If it does not,
the method returns the value of the
* {@link JcrLexicon#UUID} property as a UUID. If the location does not contain that
property, the method returns null.
*
+ * @param session the session on behalf of which the lock operation is being
performed
* @param location the location for which the UUID should be returned
* @return the UUID that identifies the given location or {@code null} if the
location does not have a UUID.
*/
- UUID uuidFor( Location location ) {
+ UUID uuidFor( JcrSession session,
+ Location location ) {
assert location != null;
if (location.getUuid() != null) return location.getUuid();
@@ -313,26 +329,28 @@
org.jboss.dna.graph.property.Property uuidProp =
location.getIdProperty(JcrLexicon.UUID);
if (uuidProp == null) return null;
+ ExecutionContext context = session.getExecutionContext();
return
context.getValueFactories().getUuidFactory().create(uuidProp.getFirstValue());
}
/**
* Unlocks all locks corresponding to the tokens in the {@code lockTokens} collection
that are session scoped.
*
- * @param lockTokens the collection of lock tokens
+ * @param session the session on behalf of which the lock operation is being
performed
*/
- void cleanLocks( Collection<String> lockTokens ) {
+ void cleanLocks( JcrSession session ) {
+ Collection<String> lockTokens = session.lockTokens();
for (String lockToken : lockTokens) {
DnaLock lock = lockFor(lockToken);
if (lock != null && lock.isSessionScoped()) {
- unlock(lock);
+ unlock(session, lock);
}
}
}
/**
* Internal representation of a locked node. This class should only be created
through calls to
- * {@link WorkspaceLockManager#lock(SessionCache, Location, String, boolean,
boolean)}.
+ * {@link WorkspaceLockManager#lock(JcrSession, Location, boolean, boolean)}.
*/
@ThreadSafe
public class DnaLock {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -142,7 +142,7 @@
return graph;
}
});
- stub(repository.createSystemGraph()).toAnswer(new Answer<Graph>() {
+ stub(repository.createSystemGraph(context)).toAnswer(new Answer<Graph>() {
public Graph answer( InvocationOnMock invocation ) throws Throwable {
return graph;
}
@@ -164,7 +164,7 @@
// Set up the session attributes ...
sessionAttributes = new HashMap<String, Object>();
sessionAttributes.put("attribute1", "value1");
-
+
// Now create the workspace ...
SecurityContext mockSecurityContext = new MockSecurityContext(null,
Collections.singleton(JcrSession.DNA_WRITE_PERMISSION));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -119,7 +119,7 @@
sourceGraph = Graph.create(source, context);
// Set up the graph that goes directly to the system source ...
- systemGraph = repository.createSystemGraph();
+ systemGraph = repository.createSystemGraph(context);
}
@After
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-11-30 17:06:05
UTC (rev 1369)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-11-30 19:40:58
UTC (rev 1370)
@@ -56,7 +56,9 @@
import javax.jcr.nodetype.NodeType;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
+import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JaasSecurityContext;
+import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.junit.After;
import org.junit.Before;
@@ -203,8 +205,9 @@
Subject subject = new Subject(false, Collections.singleton(principal),
Collections.EMPTY_SET, Collections.EMPTY_SET);
LoginContext loginContext = mock(LoginContext.class);
stub(loginContext.getSubject()).toReturn(subject);
- Session session = new JcrSession(repository, workspace, context.with(new
JaasSecurityContext(loginContext)),
- sessionAttributes);
+ NamespaceRegistry globalRegistry = context.getNamespaceRegistry();
+ ExecutionContext sessionContext = context.with(new
JaasSecurityContext(loginContext));
+ Session session = new JcrSession(repository, workspace, sessionContext,
globalRegistry, sessionAttributes);
try {
assertThat(session.getUserID(), is("name"));
} finally {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -117,6 +117,11 @@
}
@Test
+ public void shouldHaveSameContextIdAsSession() {
+ assertThat(workspace.context().getId(),
is(session.getExecutionContext().getId()));
+ }
+
+ @Test
public void shouldProvideNamespaceRegistry() throws Exception {
NamespaceRegistry registry = workspace.getNamespaceRegistry();
assertThat(registry, is(notNullValue()));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java 2009-11-30
17:06:05 UTC (rev 1369)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java 2009-11-30
19:40:58 UTC (rev 1370)
@@ -4,6 +4,7 @@
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.util.LinkedList;
import java.util.UUID;
@@ -75,7 +76,7 @@
return graph;
}
});
- stub(repository.createSystemGraph()).toAnswer(new Answer<Graph>() {
+ stub(repository.createSystemGraph(context)).toAnswer(new Answer<Graph>() {
public Graph answer( InvocationOnMock invocation ) throws Throwable {
return graph;
}
@@ -139,7 +140,9 @@
Property lockOwnerProp = propFactory.create(JcrLexicon.LOCK_OWNER, lockOwner);
Property lockIsDeepProp = propFactory.create(JcrLexicon.LOCK_IS_DEEP, isDeep);
- workspaceLockManager.lockNodeInRepository(validUuid, lockOwnerProp,
lockIsDeepProp, lock, isDeep);
+ JcrSession session = mock(JcrSession.class);
+ stub(session.getExecutionContext()).toReturn(context);
+ workspaceLockManager.lockNodeInRepository(session, validUuid, lockOwnerProp,
lockIsDeepProp, lock, isDeep);
assertNextRequestIsLock(validLocation, LockScope.SELF_ONLY, 0);
}