Package org.apache.jackrabbit.core

Examples of org.apache.jackrabbit.core.TransientRepository


    }

    @Override
    protected Context createJndiContext() throws Exception {
        Context context = super.createJndiContext();
        repository = new TransientRepository("target/repository.xml", "target/repository");
        context.bind("repository", repository);
        return context;
    }
View Full Code Here


    }

    public void testAutoFix() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);
        Node root = s.getRootNode();

        // add nodes /test and /test/missing
        Node test = root.addNode("test");
        Node missing = test.addNode("missing");
        missing.addMixin("mix:referenceable");
        UUID id = UUID.fromString(missing.getIdentifier());
        s.save();
        s.logout();

        // remove the bundle for /test/missing directly in the database
        Connection conn = DriverManager.getConnection(
                "jdbc:derby:"+TEST_DIR+"/workspaces/default/db");
        PreparedStatement prep = conn.prepareStatement(
                "delete from DEFAULT_BUNDLE  where NODE_ID_HI=? and NODE_ID_LO=?");
        prep.setLong(1, id.getMostSignificantBits());
        prep.setLong(2, id.getLeastSignificantBits());
        prep.executeUpdate();
        conn.close();

        // login and try the operation
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");

        // try to add a node with the same name
        try {
            test.addNode("missing");
            s.save();
        } catch (RepositoryException e) {
            // expected
        }

        s.logout();

        s = openSession(rep, true);
        test = s.getRootNode().getNode("test");
        // iterate over all child nodes fixes the corruption
        NodeIterator it = test.getNodes();
        while (it.hasNext()) {
            it.nextNode();
        }

        // try to add a node with the same name
        test.addNode("missing");
        s.save();

        // try to delete the parent node
        test.remove();
        s.save();

        s.logout();
        rep.shutdown();

        FileUtils.deleteDirectory(new File("repository"));

    }
View Full Code Here

    public Session getRepositorySession() throws JcrStorageException {
        if (session != null)
            return session;
        try {
            Repository repository = new TransientRepository();
            session = repository.login(new SimpleCredentials("xmpp-admin", "adminpassword".toCharArray()));
            return session;
        } catch (Exception e) {
            throw new JcrStorageException(e);
        }
    }
View Full Code Here

     * href="https://issues.apache.org/jira/browse/JCR-3069">JCR-3069</a>
     */
    public void testAutoFixWithConsistencyCheck() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);
        Node root = s.getRootNode();

        // add nodes /test and /test/missing
        Node test = root.addNode("test");
        Node missing = test.addNode("missing");
        missing.addMixin("mix:referenceable");
        UUID id = UUID.fromString(missing.getIdentifier());
        s.save();
        s.logout();

        destroyBundle(id, "workspaces/default");

        s = openSession(rep, false);
        try {
            ConsistencyReport r = TestHelper.checkConsistency(s, false);
            assertNotNull(r);
            assertNotNull(r.getItems());
            assertEquals(1, r.getItems().size());
            assertEquals(test.getIdentifier(), r.getItems().iterator().next()
                    .getNodeId());
        } finally {
            s.logout();
            rep.shutdown();
            FileUtils.deleteDirectory(new File("repository"));
        }
    }
View Full Code Here

    }

    public void testMissingVHR() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);

        String oldVersionRecoveryProp = System
                .getProperty("org.apache.jackrabbit.version.recovery");
View Full Code Here

    }

    public void testMissingRootVersion() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);

        String oldVersionRecoveryProp = System
                .getProperty("org.apache.jackrabbit.version.recovery");
View Full Code Here

    // similar to above, but disconnects version history before damaging the repository
    public void testMissingRootVersion2() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);

        String oldVersionRecoveryProp = System
                .getProperty("org.apache.jackrabbit.version.recovery");
View Full Code Here

    }

    public void testAutoFix() throws Exception {

        // new repository
        TransientRepository rep = new TransientRepository(new File(TEST_DIR));
        Session s = openSession(rep, false);
        Node root = s.getRootNode();

        // add nodes /test and /test/missing
        Node test = root.addNode("test");
        Node missing = test.addNode("missing");
        missing.addMixin("mix:referenceable");
        UUID id = UUID.fromString(missing.getIdentifier());
        s.save();
        s.logout();

        destroyBundle(id, "workspaces/default");

        // login and try the operation
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");

        // try to add a node with the same name
        try {
            test.addNode("missing");
            s.save();
        } catch (RepositoryException e) {
            // expected
        }

        s.logout();

        s = openSession(rep, true);
        test = s.getRootNode().getNode("test");
        // iterate over all child nodes fixes the corruption
        NodeIterator it = test.getNodes();
        while (it.hasNext()) {
            it.nextNode();
        }

        // try to add a node with the same name
        test.addNode("missing");
        s.save();

        // try to delete the parent node
        test.remove();
        s.save();

        s.logout();
        rep.shutdown();

        FileUtils.deleteDirectory(new File("repository"));
    }
View Full Code Here

     * @see org.drools.repository.RepositoryConfigurator#getJCRRepository()
     */
    public Repository getJCRRepository(String repoRootDir) {
        try {
            if (repoRootDir == null) {
                return new TransientRepository();
            } else {
                return new TransientRepository(repoRootDir + "/repository.xml", repoRootDir);
            }
        } catch ( IOException e ) {
            throw new RulesRepositoryException("Unable to create a Repository instance.", e);
        }
    }
View Full Code Here

     * @see org.drools.repository.RepositoryConfigurator#getJCRRepository()
     */
    public Repository getJCRRepository(String repoRootDir) {

            if (repoRootDir == null) {
                return new TransientRepository();
            } else {
                return new TransientRepository(repoRootDir + "/repository.xml", repoRootDir);
            }

    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.TransientRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.