Search in sources :

Example 6 with RepositoryException

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;
}
Also used : RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with RepositoryException

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);
    }
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) RepositoryException(javax.jcr.RepositoryException) PMContext(org.apache.jackrabbit.core.persistence.PMContext) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) AccessDeniedException(javax.jcr.AccessDeniedException) IOException(java.io.IOException) LoginException(javax.jcr.LoginException) TransactionException(org.apache.jackrabbit.data.core.TransactionException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 with RepositoryException

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;
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) InternalVersionManagerImpl(org.apache.jackrabbit.core.version.InternalVersionManagerImpl) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 9 with RepositoryException

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;
    }
}
Also used : InputStream(java.io.InputStream) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 10 with RepositoryException

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);
    }
}
Also used : WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50