org.modeshape.graph.connector.base
Class Repository<NodeType extends Node,WorkspaceType extends Workspace>

java.lang.Object
  extended by org.modeshape.graph.connector.base.Repository<NodeType,WorkspaceType>
Type Parameters:
NodeType - the node type
WorkspaceType - the workspace type
Direct Known Subclasses:
FileSystemRepository, InfinispanRepository, InMemoryRepository, JBossCacheRepository, JdbcMetadataRepository, SvnRepository

@ThreadSafe
public abstract class Repository<NodeType extends Node,WorkspaceType extends Workspace>
extends Object

A representation of a repository as a set of named workspaces. Workspaces can be created or destroyed, though the exact type of Workspace is dictated by the Transaction. All workspaces contain a root node with the same UUID.

Note that this class is thread-safe, since a BaseRepositorySource will contain a single instance of a concrete subclass of this class. Often, the Workspace objects are used to hold onto the workspace-related content, but access to the content is always done through a transaction.


Field Summary
protected  ExecutionContext context
           
protected  UUID rootNodeUuid
           
protected  BaseRepositorySource source
           
 
Constructor Summary
protected Repository(BaseRepositorySource source)
          Creates a MapRepository with the given repository source name, root node UUID, and a default workspace with the given name.
 
Method Summary
 RequestProcessor createRequestProcessor(Transaction<NodeType,WorkspaceType> txn)
          Create a RequestProcessor instance that should be used to process a set of requests within the supplied transaction.
 WorkspaceType createWorkspace(Transaction<NodeType,WorkspaceType> txn, String name, CreateWorkspaceRequest.CreateConflictBehavior existingWorkspaceBehavior, String nameOfWorkspaceToClone)
          Attempts to create a workspace with the given name with name-collision behavior determined by the behavior parameter.
 boolean destroyWorkspace(String name)
          Removes the named workspace from the #workspaces workspaces map.
 ExecutionContext getContext()
           
protected  String getDefaultWorkspaceName()
           
 UUID getRootNodeUuid()
          Returns the UUID used by the root nodes in each workspace.
 String getSourceName()
          Returns the logical name (as opposed to the class name) of the repository source that defined this instance of the repository for use in error, informational, and other contextual messages.
 WorkspaceType getWorkspace(Transaction<NodeType,WorkspaceType> txn, String name)
          Returns the workspace with the given name.
 Set<String> getWorkspaceNames()
          Get the names of the available workspaces that have been loaded.
protected  void initialize()
          Initializes the repository by creating the default workspace.
abstract  Transaction<NodeType,WorkspaceType> startTransaction(ExecutionContext context, boolean readonly)
          Begin a transaction, hinting whether the transaction will be used only to read the content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected final BaseRepositorySource source

rootNodeUuid

protected final UUID rootNodeUuid

context

protected final ExecutionContext context
Constructor Detail

Repository

protected Repository(BaseRepositorySource source)
Creates a MapRepository with the given repository source name, root node UUID, and a default workspace with the given name.

Parameters:
source - the repository source to which this repository belongs
Throws:
IllegalArgumentException - if the repository source is null, if the source's BaseRepositorySource.getRepositoryContext() is null, or if the source name is null or empty
Method Detail

initialize

protected void initialize()
Initializes the repository by creating the default workspace.

Due to the ordering restrictions on constructor chaining, this method cannot be called until the repository is fully initialized. This method MUST be called at the end of the constructor by any class that implements MapRepository .


getContext

public ExecutionContext getContext()

getDefaultWorkspaceName

protected String getDefaultWorkspaceName()

getRootNodeUuid

public final UUID getRootNodeUuid()
Returns the UUID used by the root nodes in each workspace.

Note that the root nodes themselves are distinct objects in each workspace and a change to the root node of one workspace does not imply a change to the root nodes of any other workspaces. However, the JCR specification mandates that all referenceable root nodes in a repository use a common UUID (in support of node correspondence); therefore this must be supported by ModeShape.

Returns:
the root node UUID

getSourceName

public String getSourceName()
Returns the logical name (as opposed to the class name) of the repository source that defined this instance of the repository for use in error, informational, and other contextual messages.

Returns:
sourceName the logical name for the repository source name

getWorkspaceNames

public Set<String> getWorkspaceNames()
Get the names of the available workspaces that have been loaded.

Returns:
the immutable names of the workspaces.

getWorkspace

public WorkspaceType getWorkspace(Transaction<NodeType,WorkspaceType> txn,
                                  String name)
Returns the workspace with the given name.

Parameters:
txn - the transaction attempting to get the workspace, and which may be used to create the workspace object if needed; may not be null
name - the name of the workspace to return
Returns:
the workspace with the given name; may be null if no workspace with the given name exists

createWorkspace

public WorkspaceType createWorkspace(Transaction<NodeType,WorkspaceType> txn,
                                     String name,
                                     CreateWorkspaceRequest.CreateConflictBehavior existingWorkspaceBehavior,
                                     String nameOfWorkspaceToClone)
                                                throws InvalidWorkspaceException
Attempts to create a workspace with the given name with name-collision behavior determined by the behavior parameter.

This method will first check to see if a workspace already exists with the given name. If no such workspace exists, the method will create a new workspace with the given name, add it to the #workspaces workspaces map, and return it. If a workspace with the requested name already exists and the behavior is CreateWorkspaceRequest.CreateConflictBehavior.DO_NOT_CREATE , this method will return null without modifying the state of the repository. If a workspace with the requested name already exists and the behavior is CreateWorkspaceRequest.CreateConflictBehavior.CREATE_WITH_ADJUSTED_NAME, this method will generate a unique new name for the workspace, create a new workspace with the given name, added it to the #workspaces workspaces map, and return it.

If nameOfWorkspaceToClone is given, this method will clone the content in this original workspace into the new workspace. However, if no workspace with the name nameOfWorkspaceToClone exists, the method will create an empty workspace.

Parameters:
txn - the transaction creating the workspace; may not be null
name - the requested name of the workspace. The name of the workspace that is returned from this method may not be the same as the requested name; may not be null
existingWorkspaceBehavior - the behavior to use in case a workspace with the requested name already exists in the repository
nameOfWorkspaceToClone - the name of the workspace from which the content should be cloned; be null if the new workspace is to be empty (other than the root node)
Returns:
the newly created workspace with an exact copy of the contents from the workspace named nameOfWorkspaceToClone or null if a workspace with the requested name already exists in the repository and behavior == CreateConflictBehavior#DO_NOT_CREATE.
Throws:
InvalidWorkspaceException - if the workspace could not be created

destroyWorkspace

public boolean destroyWorkspace(String name)
Removes the named workspace from the #workspaces workspaces map.

Parameters:
name - the name of the workspace to remove
Returns:
true if a workspace with that name previously existed in the map

createRequestProcessor

public RequestProcessor createRequestProcessor(Transaction<NodeType,WorkspaceType> txn)
Create a RequestProcessor instance that should be used to process a set of requests within the supplied transaction.

Parameters:
txn - the transaction; may not be null
Returns:
the request processor

startTransaction

public abstract Transaction<NodeType,WorkspaceType> startTransaction(ExecutionContext context,
                                                                     boolean readonly)
Begin a transaction, hinting whether the transaction will be used only to read the content. If this is called, then the transaction must be either committed or rolled back.

Parameters:
context - the context in which the transaction is to be performed; may not be null
readonly - true if the transaction will not modify any content, or false if changes are to be made
Returns:
the transaction; never null
See Also:
Transaction.commit(), Transaction.rollback()


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.