Search in sources :

Example 16 with Node

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

the class AutoFixCorruptNode method testAutoFix.

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"));
}
Also used : NodeIterator(javax.jcr.NodeIterator) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) UUID(java.util.UUID) File(java.io.File) Session(javax.jcr.Session)

Example 17 with Node

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

the class FulltextQueryTest method testContainsPropScopeXPath.

public void testContainsPropScopeXPath() throws RepositoryException {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "tEst text" });
    n.setProperty("mytext", new String[] { "The quick brown Fox jumps over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "The quick brown Fox jumps over the lazy dog." });
    n.setProperty("mytext", new String[] { "text text" });
    testRootNode.save();
    String sql = "/jcr:root" + testRoot + "/element(*, nt:unstructured)" + "[jcr:contains(@title, 'quick fox')]";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.XPATH);
    checkResult(q.execute(), 1);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 18 with Node

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

the class FulltextSQL2QueryTest method testFulltextSimpleSQL.

public void testFulltextSimpleSQL() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM [nt:unstructured]" + " WHERE ISCHILDNODE([" + testRoot + "])" + " AND CONTAINS(mytext, 'fox')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 19 with Node

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

the class JoinTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    node = testRootNode.addNode("jointest", "nt:unstructured");
    Node n1a = node.addNode("n1a", "nt:unstructured");
    n1a.addMixin(NodeType.MIX_REFERENCEABLE);
    n1a.setProperty("type", "parent");
    Node n1b = node.addNode("n1b", "nt:unstructured");
    n1b.addMixin(NodeType.MIX_REFERENCEABLE);
    n1b.setProperty("type", "parent");
    n1b.setProperty("testJoinWithOR4", "testJoinWithOR4");
    Node n1c = node.addNode("n1c", "nt:unstructured");
    n1c.addMixin(NodeType.MIX_REFERENCEABLE);
    n1c.setProperty("type", "parent");
    Node n3 = node.addNode("node3", "nt:unstructured");
    n3.addMixin(NodeType.MIX_REFERENCEABLE);
    n3.setProperty("testref", new String[] { n1a.getIdentifier() }, PropertyType.REFERENCE);
    n3.setProperty("type", "child");
    n3.setProperty("testJoinWithOR4", "testJoinWithOR4");
    Node n4 = node.addNode("node4", "nt:unstructured");
    n4.addMixin(NodeType.MIX_REFERENCEABLE);
    n4.setProperty("testref", new String[] { n1b.getIdentifier() }, PropertyType.REFERENCE);
    n4.setProperty("type", "child");
    Node n5 = node.addNode("node5", "nt:unstructured");
    n5.addMixin(NodeType.MIX_REFERENCEABLE);
    n5.setProperty("testref", new String[] { n1c.getIdentifier() }, PropertyType.REFERENCE);
    n5.setProperty("type", "child");
    Node parent2 = testRootNode.addNode("jointest_other", "nt:unstructured");
    parent2.setProperty("p", "abc");
    Node p2n1 = parent2.addNode("p2n1", "nt:unstructured");
    p2n1.setProperty("p", "abc");
    Node p2n2 = parent2.addNode("p2n2", "nt:unstructured");
    p2n2.setProperty("p", "xyz");
    testRootNode.getSession().save();
}
Also used : Node(javax.jcr.Node)

Example 20 with Node

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

the class ChildAxisQueryTest method testNotIsDescendantNodeQuery.

/**
     * JCR-3337
     */
public void testNotIsDescendantNodeQuery() throws Exception {
    Node foo = testRootNode.addNode("foo");
    testRootNode.getSession().save();
    String sql = "SELECT a.* FROM [nt:base] as a WHERE isdescendantnode(a,'" + testRootNode.getPath() + "') and not isdescendantnode(a,'" + foo.getPath() + "')";
    executeSQL2Query(sql, new Node[] { foo });
}
Also used : Node(javax.jcr.Node)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81