Search in sources :

Example 21 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class QueryTest method anyChildNodeProperty.

@Test
@Ignore("OAK-1215")
public void anyChildNodeProperty() throws Exception {
    Session session = getAdminSession();
    Node content = session.getRootNode().addNode("test");
    content.addNode("one").addNode("child").setProperty("prop", "hello");
    content.addNode("two").addNode("child").setProperty("prop", "hi");
    session.save();
    String query = "//*[*/@prop = 'hello']";
    QueryResult r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
    NodeIterator it = r.getNodes();
    assertTrue(it.hasNext());
    String path = it.nextNode().getPath();
    assertEquals("/test/one", path);
    assertFalse(it.hasNext());
    query = "//*[*/*/@prop = 'hello']";
    r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
    it = r.getNodes();
    assertTrue(it.hasNext());
    path = it.nextNode().getPath();
    assertEquals("/test", path);
    assertFalse(it.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 22 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class QueryTest method testOak1354.

@Test
public void testOak1354() throws Exception {
    Session session = createAdminSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    if (!manager.hasNodeType("mymixinOak1354")) {
        StringBuilder defs = new StringBuilder();
        defs.append("[mymixinOak1354]\n");
        defs.append("  mixin");
        Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
        CndImporter.registerNodeTypes(cndReader, session);
    }
    Node p = session.getRootNode().addNode("one");
    p.addMixin("mymixinOak1354");
    session.save();
    Query q = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM [mymixinOak1354]", Query.JCR_SQL2);
    QueryResult qr = q.execute();
    NodeIterator ni = qr.getNodes();
    assertTrue(ni.hasNext());
    Node n = ni.nextNode();
    assertEquals("/one", n.getPath());
    assertFalse(ni.hasNext());
    session.logout();
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) QueryResult(javax.jcr.query.QueryResult) InputStreamReader(java.io.InputStreamReader) Query(javax.jcr.query.Query) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 23 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class QueryTest method testOak1128.

@Test
public void testOak1128() throws RepositoryException {
    Session session = createAdminSession();
    Node p = session.getRootNode().addNode("etc");
    p.addNode("p1");
    Node r = p.addNode("p2").addNode("r", "nt:unstructured");
    r.setProperty("nt:resourceType", "test");
    session.save();
    Query q = session.getWorkspace().getQueryManager().createQuery("/jcr:root/etc//*[" + "(@jcr:primaryType = 'nt:file'  or @jcr:primaryType = 'nt:folder') " + "or @nt:resourceType = 'test']", "xpath");
    QueryResult qr = q.execute();
    NodeIterator ni = qr.getNodes();
    Node n = ni.nextNode();
    assertEquals("/etc/p2/r", n.getPath());
    session.logout();
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 24 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class QueryTest method date.

@Test
public void date() throws Exception {
    Session session = getAdminSession();
    Node t1 = session.getRootNode().addNode("t1");
    t1.setProperty("x", "22.06.07");
    Node t2 = session.getRootNode().addNode("t2");
    t2.setProperty("x", "2007-06-22T01:02:03.000Z", PropertyType.DATE);
    session.save();
    String query = "//*[x='a' or x='b']";
    QueryResult r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
    NodeIterator it = r.getNodes();
    assertFalse(it.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 25 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class QueryTest method or.

@SuppressWarnings("deprecation")
@Test
public void or() throws RepositoryException {
    Session session = getAdminSession();
    Node hello = session.getRootNode().addNode("hello");
    hello.setProperty("x", 1);
    Node world = hello.addNode("world");
    world.setProperty("x", 2);
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Query q;
    q = qm.createQuery("select a.[jcr:path] from [nt:base] as a " + "inner join [nt:base] as b " + "on ischildnode(a, b) " + "where a.x = 1 or a.x = 2 or b.x = 3 or b.x = 4", Query.JCR_SQL2);
    assertEquals("/hello", getPaths(q));
    q = qm.createQuery("//hello[@x=1]/*[@x=2]", Query.XPATH);
    assertEquals("/hello/world", getPaths(q));
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

Session (javax.jcr.Session)1393 Node (javax.jcr.Node)761 Test (org.junit.Test)387 RepositoryException (javax.jcr.RepositoryException)304 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)162 Property (javax.jcr.Property)90 SimpleCredentials (javax.jcr.SimpleCredentials)88 Privilege (javax.jcr.security.Privilege)84 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Value (javax.jcr.Value)71 Query (javax.jcr.query.Query)69 NodeIterator (javax.jcr.NodeIterator)68 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)65 QueryManager (javax.jcr.query.QueryManager)63 HashMap (java.util.HashMap)57 IOException (java.io.IOException)56 ArrayList (java.util.ArrayList)55 AccessControlManager (javax.jcr.security.AccessControlManager)55 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)52 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)49