Repository and Workspace management.
Introduction
Along with "static" repository configuration described in section
*JCR Configuration* it is possible to manage JCR Repositories and Workspaces configuration dynamically, using API methods. eXo JCR API supports such a functionality:
- Adding a repository
- Removing a repository
- Adding a workspace
- Removing a workspace
Repository management
Repository management API contains such methods:
public interface RepositoryService {
.....
/**
* Creates a new repository
* @param repositoryEntry
* @throws RepositoryConfigurationException
* @throws RepositoryException
*/
void createRepository(RepositoryEntry repositoryEntry) throws RepositoryConfigurationException,
RepositoryException;
/**
* Removes the repository with the name repositoryName
* @param repositoryName
* @throws RepositoryException
*/
void removeRepository(String repositoryName) throws RepositoryException;
/**
* Indicates if the repository with the name repositoryName can be removed
* @param repositoryName
* @throws RepositoryException
*/
boolean canRemoveRepository(String repositoryName) throws RepositoryException ;
.....
}
Create a new repository
String newDsName = "newDs";
Properties properties = new Properties();
properties.setProperty("driverClassName", "org.hsqldb.jdbcDriver");
properties.setProperty("url", "jdbc:hsqldb:file:target/temp/data/" + newDsName);
properties.setProperty("username", "sa");
properties.setProperty("password", "");
DataSource bds = BasicDataSourceFactory.createDataSource(properties);
new InitialContext().bind(newDsName, bds);
List params = new ArrayList();
params.add(new SimpleParameterEntry("source-name", newDsName);
params.add(new SimpleParameterEntry("db-type", "generic"));
params.add(new SimpleParameterEntry("multi-db", "false"));
params.add(new SimpleParameterEntry("update-storage", "true"));
params.add(new SimpleParameterEntry("max-buffer-size", "200K"));
params.add(new SimpleParameterEntry("swap-directory", "target/temp/swap/ws"));
ContainerEntry containerEntry = new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
(ArrayList) params);
// The parameters could also be set as below
// containerEntry.setParameters(params);
WorkspaceEntry workspaceEntry = new WorkspaceEntry("newWs", "nt:unstructured");
workspaceEntry.setContainer(containerEntry);
repositoryEntry.addWorkspace(workspaceEntry);
RepositoryService service = (RepositoryService) container
.getComponentInstanceOfType(RepositoryService.class);
service.createRepository(repositoryEntry);
Remove an existing repository
Repository can be removed if all sessions are closed.
RepositoryService service = (RepositoryService) container
.getComponentInstanceOfType(RepositoryService.class);
if(service.canRemoveRepository(repositoryName)){
service.removeRepository(repositoryName);
}
Workspace management
Workspace management API contains methods:
public interface ManageableRepository extends Repository {
.....
/**
* Adds a new workspace configuration
* @param wsConfig
* @throws RepositoryConfigurationException
* @throws RepositoryException
*/
public void configWorkspace(WorkspaceEntry wsConfig) throws RepositoryConfigurationException, RepositoryException;
/**
* Creates a new workspace with the name workspaceName
* @param workspaceName
* @throws RepositoryException
*/
void createWorkspace(String workspaceName) throws RepositoryException;
/**
* Removes the workspace with the name workspaceName
* @param workspaceName
* @throws RepositoryException
*/
void removeWorkspace(String workspaceName) throws RepositoryException;
/**
* Indicates if the workspace with the name workspaceName can be removed
* @param workspaceName
* @return
* @throws NoSuchWorkspaceException
*/
boolean canRemoveWorkspace(String workspaceName) throws NoSuchWorkspaceException;
.....
}
Create a new workspace
Before creating a new workspace, workspace
configuration must be added to the repository.
After that it is possible to create a new workspace with existing configuration.
List params = new ArrayList();
params.add(new SimpleParameterEntry("source-name", "jdbcjcr"));
params.add(new SimpleParameterEntry("db-type", "generic"));
params.add(new SimpleParameterEntry("multi-db", "false"));
params.add(new SimpleParameterEntry("update-storage", "true"));
params.add(new SimpleParameterEntry("max-buffer-size", "200K"));
params.add(new SimpleParameterEntry("swap-directory", "target/temp/swap/ws"));
ContainerEntry containerEntry = new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
(ArrayList) params);
// The parameters could also be set as below
// containerEntry.setParameters(params);
WorkspaceEntry workspaceEntry = new WorkspaceEntry("newws", "nt:unstructured");
workspaceEntry.setContainer(containerEntry);
RepositoryService service = (RepositoryService) container
.getComponentInstanceOfType(RepositoryService.class);
ManageableRepository defRep = service.getDefaultRepository();
defRep.configWorkspace(workspaceEntry);
defRep.createWorkspace(workspaceEntry.getName());
Removing an existing workspace
A workspace can be removed if all sessions in the workspace are closed. The system workspace can be removed only with the repository.
RepositoryService service = (RepositoryService) container
getComponentInstanceOfType(RepositoryService.class);
ManageableRepository defRep = service.getDefaultRepository();
if(defRep.canRemoveWorkspace(workspaceName){
defRep.removeWorkspace(workspaceName);
}
Node types and namespaces
During dynamic creation of a repository all namespaces stored in
*configuration* will be registered.
All node types described in
*autoCreatedInNewRepository*? section and section with the same name as the created repository will also be registered.