use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryFactoryImpl method getOrCreateRepository.
/**
* Either returns a cached repository or creates a repository instance and
* puts it into the {@link #REPOSITORIES} cache.
*
* @param home path to the repository home.
* @return the repository instance.
* @throws RepositoryException if an error occurs while creating the
* repository instance.
*/
private static synchronized TransientRepository getOrCreateRepository(String home, Map<?, ?> parameters) throws RepositoryException {
// Prepare the repository properties
Properties properties = new Properties(System.getProperties());
for (Map.Entry<?, ?> entry : parameters.entrySet()) {
Object key = entry.getKey();
if (key != null) {
Object value = entry.getValue();
if (value != null) {
properties.setProperty(key.toString(), value.toString());
} else {
properties.remove(key.toString());
}
}
}
if (home != null) {
properties.put(REPOSITORY_HOME_VARIABLE, home);
}
TransientRepository repository = REPOSITORIES.get(properties);
if (repository == null) {
try {
TransientRepository tr;
if (home == null) {
tr = new TransientRepository(properties);
// also remember this instance as the default repository
REPOSITORIES.put(null, tr);
} else {
tr = new TransientRepository(properties);
}
REPOSITORIES.put(properties, tr);
repository = tr;
} catch (IOException e) {
throw new RepositoryException("Failed to install repository configuration", e);
}
}
return repository;
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryImpl method createPersistenceManager.
/**
* Creates a workspace persistence manager based on the given
* configuration. The persistence manager is instantiated using
* information in the given persistence manager configuration and
* initialized with a persistence manager context containing the other
* arguments.
*
* @return the created workspace persistence manager
* @throws RepositoryException if the persistence manager could
* not be instantiated/initialized
*/
private PersistenceManager createPersistenceManager(File homeDir, FileSystem fs, PersistenceManagerConfig pmConfig) throws RepositoryException {
try {
PersistenceManager pm = pmConfig.newInstance(PersistenceManager.class);
PMContext pmContext = new PMContext(homeDir, fs, context.getRootNodeId(), context.getNamespaceRegistry(), context.getNodeTypeRegistry(), context.getDataStore(), context.getRepositoryStatistics());
pm.init(pmContext);
return pm;
} catch (Exception e) {
String msg = "Cannot instantiate persistence manager " + pmConfig.getClassName();
throw new RepositoryException(msg, e);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryImpl method createDataStoreGarbageCollector.
/**
* Creates a data store garbage collector for this repository.
* <p>
* Note that you should use the {@link RepositoryManager} interface
* to access this functionality. This RepositoryImpl method may be
* removed in future Jackrabbit versions.
*/
public GarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
ArrayList<PersistenceManager> pmList = new ArrayList<PersistenceManager>();
InternalVersionManagerImpl vm = context.getInternalVersionManager();
PersistenceManager pm = vm.getPersistenceManager();
pmList.add(pm);
String[] wspNames = getWorkspaceNames();
SessionImpl[] sessions = new SessionImpl[wspNames.length];
for (int i = 0; i < wspNames.length; i++) {
String wspName = wspNames[i];
WorkspaceInfo wspInfo = getWorkspaceInfo(wspName);
// this will initialize the workspace if required
SessionImpl systemSession = SystemSession.create(context, wspInfo.getConfig());
// mark the workspace as 'active' so it does not get disposed by
// the workspace-janitor until the garbage collector is done
wspInfo.setActive(true);
// the workspace could be disposed, so re-initialize if required
// afterwards it will not be disposed because it was marked active
wspInfo.initialize();
sessions[i] = systemSession;
pm = wspInfo.getPersistenceManager();
pmList.add(pm);
}
IterablePersistenceManager[] ipmList = new IterablePersistenceManager[pmList.size()];
for (int i = 0; i < pmList.size(); i++) {
pm = pmList.get(i);
if (!(pm instanceof IterablePersistenceManager)) {
ipmList = null;
break;
}
ipmList[i] = (IterablePersistenceManager) pm;
}
GarbageCollector gc = new GarbageCollector(context, context.getDataStore(), ipmList, sessions);
synchronized (this) {
if (context.isGcRunning()) {
throw new RepositoryException("Cannot create GC. GC already running");
}
context.setGcRunning(true);
}
return gc;
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryImpl method getCustomRepositoryDescriptors.
/**
* Returns a <code>Properties</code> object containing custom repository
* descriptors or <code>null</code> if none exist.
* <p>
* Overridable to allow subclasses to add custom descriptors or to
* override standard descriptor values.
* <p>
* Note that the properties entries will be set as single-valued <code>STRING</code>
* descriptor values.
* <p>
* This method tries to load the <code>Properties</code> from the
* <code>org/apache/jackrabbit/core/repository.properties</code> resource
* found in the class path.
*
* @throws RepositoryException if the properties can not be loaded
*/
protected Properties getCustomRepositoryDescriptors() throws RepositoryException {
InputStream in = RepositoryImpl.class.getResourceAsStream(PROPERTIES_RESOURCE);
if (in != null) {
try {
Properties props = new Properties();
props.load(in);
return props;
} catch (IOException e) {
String msg = "Failed to load customized repository properties: " + e.toString();
log.error(msg);
throw new RepositoryException(msg, e);
} finally {
IOUtils.closeQuietly(in);
}
} else {
return null;
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryImpl method createWorkspaceInternal.
/**
* Creates a workspace with the given name and given workspace configuration
* template.
*
* The difference between this method and {@link #createWorkspace(String, InputSource)}
* is that the later notifies the other cluster node that workspace has been created
* whereas this method only creates the workspace.
*
* @param workspaceName name of the new workspace
* @param configTemplate the workspace configuration template of the new
* workspace
* @throws RepositoryException if a workspace with the given name already
* exists or if another error occurs
* @see WorkspaceImpl#createWorkspace(String,InputSource)
*/
private void createWorkspaceInternal(String workspaceName, InputSource configTemplate) throws RepositoryException {
synchronized (wspInfos) {
if (wspInfos.containsKey(workspaceName)) {
throw new RepositoryException("workspace '" + workspaceName + "' already exists.");
}
// create the workspace configuration
WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName, configTemplate);
WorkspaceInfo info = createWorkspaceInfo(config);
wspInfos.put(workspaceName, info);
}
}
Aggregations