Search in sources :

Example 56 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class RegistryHelper method registerRepository.

/**
     * Binds a configured repository to the given JNDI context.
     * This method creates a {@link BindableRepository BindableRepository}
     * instance using the given configuration information, and binds
     * it to the given JNDI context.
     *
     * @param ctx            context where the repository should be registered (i.e. bound)
     * @param name           the name to register the repository with
     * @param configFilePath path to the configuration file of the repository
     * @param repHomeDir     repository home directory
     * @param overwrite      if <code>true</code>, any existing binding with the given
     *                       name will be overwritten; otherwise a <code>NamingException</code> will
     *                       be thrown if the name is already bound
     * @throws RepositoryException if the repository cannot be created
     * @throws NamingException if the repository cannot be registered in JNDI
     */
public static void registerRepository(Context ctx, String name, String configFilePath, String repHomeDir, boolean overwrite) throws NamingException, RepositoryException {
    Reference reference = new Reference(Repository.class.getName(), BindableRepositoryFactory.class.getName(), // no classpath defined
    null);
    reference.add(new StringRefAddr(BindableRepository.CONFIGFILEPATH_ADDRTYPE, configFilePath));
    reference.add(new StringRefAddr(BindableRepository.REPHOMEDIR_ADDRTYPE, repHomeDir));
    // always create instance by using BindableRepositoryFactory
    // which maintains an instance cache;
    // see http://issues.apache.org/jira/browse/JCR-411 for details
    Object obj = new BindableRepositoryFactory().getObjectInstance(reference, null, null, null);
    if (overwrite) {
        ctx.rebind(name, obj);
    } else {
        ctx.bind(name, obj);
    }
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Example 57 with Repository

use of javax.jcr.Repository 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)

Example 58 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class ConnectionFactoryTest method testTransactionSupport.

/**
     * Test if the session supports transactions
     */
public void testTransactionSupport() throws Exception {
    // Create the connection factory
    Object cf = mcf.createConnectionFactory();
    assertTrue(cf instanceof JCARepositoryHandle);
    Repository repository = (Repository) cf;
    // Open a session
    Session session = repository.login(JCR_SUPERUSER);
    assertTrue(session instanceof XAResource);
    session.logout();
}
Also used : Repository(javax.jcr.Repository) XAResource(javax.transaction.xa.XAResource) JCARepositoryHandle(org.apache.jackrabbit.jca.JCARepositoryHandle) Session(javax.jcr.Session)

Example 59 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class ConnectionFactoryTest method testAllocation.

/**
     * Test the connection factory allocation.
     */
public void testAllocation() throws Exception {
    // Create the connection factory
    Object cf = mcf.createConnectionFactory();
    assertTrue(cf instanceof JCARepositoryHandle);
    Repository repository = (Repository) cf;
    // Open a new session
    Session session = repository.login(JCR_SUPERUSER);
    assertTrue(session != null);
    assertTrue(session instanceof JCASessionHandle);
    // Logout session
    session.logout();
}
Also used : Repository(javax.jcr.Repository) JCARepositoryHandle(org.apache.jackrabbit.jca.JCARepositoryHandle) JCASessionHandle(org.apache.jackrabbit.jca.JCASessionHandle) Session(javax.jcr.Session)

Example 60 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class RepositoryFactoryImplTest method testGetSpi2jcrRepository.

public void testGetSpi2jcrRepository() throws RepositoryException {
    Repository coreRepo = factory.getRepository(null);
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("org.apache.jackrabbit.spi.RepositoryServiceFactory", "org.apache.jackrabbit.spi2jcr.Spi2jcrRepositoryServiceFactory");
    parameters.put("org.apache.jackrabbit.spi2jcr.Repository", coreRepo);
    Repository jcr2spiRepo = factory.getRepository(parameters);
    assertNotNull(jcr2spiRepo);
    assertEquals("Jackrabbit", jcr2spiRepo.getDescriptor(Repository.REP_NAME_DESC));
}
Also used : Repository(javax.jcr.Repository) HashMap(java.util.HashMap)

Aggregations

Repository (javax.jcr.Repository)111 Session (javax.jcr.Session)33 RepositoryException (javax.jcr.RepositoryException)28 SimpleCredentials (javax.jcr.SimpleCredentials)15 Node (javax.jcr.Node)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4