Search in sources :

Example 1 with PersistenceManager

use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.

the class RepositoryImpl method createVersionManager.

/**
     * Creates the version manager.
     *
     * @param vConfig the versioning config
     * @return the newly created version manager
     * @throws RepositoryException if an error occurs
     */
protected InternalVersionManagerImpl createVersionManager(VersioningConfig vConfig, DelegatingObservationDispatcher delegatingDispatcher) throws RepositoryException {
    FileSystem fs = vConfig.getFileSystem();
    PersistenceManager pm = createPersistenceManager(vConfig.getHomeDir(), fs, vConfig.getPersistenceManagerConfig());
    ISMLocking ismLocking = vConfig.getISMLocking();
    return new InternalVersionManagerImpl(pm, fs, context.getNodeTypeRegistry(), delegatingDispatcher, SYSTEM_ROOT_NODE_ID, VERSION_STORAGE_NODE_ID, ACTIVITIES_NODE_ID, context.getItemStateCacheFactory(), ismLocking, context.getNodeIdFactory());
}
Also used : ISMLocking(org.apache.jackrabbit.core.state.ISMLocking) PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) InternalVersionManagerImpl(org.apache.jackrabbit.core.version.InternalVersionManagerImpl)

Example 2 with PersistenceManager

use of org.apache.jackrabbit.core.persistence.PersistenceManager 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 3 with PersistenceManager

use of org.apache.jackrabbit.core.persistence.PersistenceManager 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 4 with PersistenceManager

use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit-oak by apache.

the class JackrabbitNodeState method createRootNodeState.

public static JackrabbitNodeState createRootNodeState(RepositoryContext context, String workspaceName, NodeState root, Map<String, String> uriToPrefix, boolean copyBinariesByReference, boolean skipOnError) throws RepositoryException {
    final Map<NodeId, JackrabbitNodeState> emptyMountPoints = ImmutableMap.of();
    final PersistenceManager versionPM = context.getInternalVersionManager().getPersistenceManager();
    final JackrabbitNodeState versionStorage = new JackrabbitNodeState(versionPM, root, uriToPrefix, VERSION_STORAGE_NODE_ID, "/jcr:system/jcr:versionStorage", null, emptyMountPoints, copyBinariesByReference, skipOnError);
    final JackrabbitNodeState activities = new JackrabbitNodeState(versionPM, root, uriToPrefix, ACTIVITIES_NODE_ID, "/jcr:system/jcr:activities", null, emptyMountPoints, copyBinariesByReference, skipOnError);
    PersistenceManager pm = context.getWorkspaceInfo(workspaceName).getPersistenceManager();
    final Map<NodeId, JackrabbitNodeState> mountPoints = ImmutableMap.of(VERSION_STORAGE_NODE_ID, versionStorage, ACTIVITIES_NODE_ID, activities);
    return new JackrabbitNodeState(pm, root, uriToPrefix, ROOT_NODE_ID, "/", workspaceName, mountPoints, copyBinariesByReference, skipOnError);
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 5 with PersistenceManager

use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.

the class PersistenceManagerIteratorTest method testGetAllNodeIds.

public void testGetAllNodeIds() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    Repository rep = session.getRepository();
    if (!(rep instanceof RepositoryImpl)) {
        log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
        return;
    }
    RepositoryImpl r = (RepositoryImpl) rep;
    RepositoryConfig conf = r.getConfig();
    Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
    String[] names = new String[coll.size()];
    Iterator<WorkspaceConfig> wspIt = coll.iterator();
    for (int i = 0; wspIt.hasNext(); i++) {
        WorkspaceConfig wsc = wspIt.next();
        names[i] = wsc.getName();
    }
    for (int i = 0; i < names.length && i < 1; i++) {
        Session s = getHelper().getSuperuserSession(names[i]);
        try {
            Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
            m.setAccessible(true);
            Object info = m.invoke(r, names[i]);
            m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
            m.setAccessible(true);
            PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
            if (!(pm instanceof AbstractBundlePersistenceManager)) {
                log("PM skipped: " + pm.getClass());
                continue;
            }
            AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
            log("PM: " + pm.getClass().getName());
            log("All nodes in one step");
            NodeId after = null;
            NodeId first = null;
            for (NodeId id : apm.getAllNodeIds(null, 0)) {
                log("  " + id);
                if (first == null) {
                    // initialize first node id
                    first = id;
                }
                if (after != null) {
                    assertFalse(id.compareTo(after) == 0);
                }
                after = id;
            }
            // start with first
            after = first;
            log("All nodes using batches");
            while (true) {
                log(" bigger than: " + after);
                Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
                if (!it.hasNext()) {
                    break;
                }
                while (it.hasNext()) {
                    NodeId id = it.next();
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
            log("Random access");
            for (int j = 0; j < 50; j++) {
                after = NodeId.randomId();
                log(" bigger than: " + after);
                for (NodeId id : apm.getAllNodeIds(after, 2)) {
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
        } finally {
            s.logout();
        }
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Node(javax.jcr.Node) Method(java.lang.reflect.Method) Repository(javax.jcr.Repository) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Session(javax.jcr.Session)

Aggregations

PersistenceManager (org.apache.jackrabbit.core.persistence.PersistenceManager)7 Repository (javax.jcr.Repository)3 IterablePersistenceManager (org.apache.jackrabbit.core.persistence.IterablePersistenceManager)3 RepositoryException (javax.jcr.RepositoryException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 ConsistencyChecker (org.apache.jackrabbit.core.persistence.check.ConsistencyChecker)2 InternalVersionManagerImpl (org.apache.jackrabbit.core.version.InternalVersionManagerImpl)2 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 LoginException (javax.jcr.LoginException)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 RepositoryImpl (org.apache.jackrabbit.core.RepositoryImpl)1 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)1 RepositoryConfig (org.apache.jackrabbit.core.config.RepositoryConfig)1 WorkspaceConfig (org.apache.jackrabbit.core.config.WorkspaceConfig)1