Search in sources :

Example 26 with Session

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

the class QueryTest method propertyIndexWithDeclaringNodeTypeAndRelativQuery.

@Test
public void propertyIndexWithDeclaringNodeTypeAndRelativQuery() throws RepositoryException {
    Session session = getAdminSession();
    RowIterator rit;
    QueryResult r;
    String query;
    query = "//element(*, rep:Authorizable)[@rep:principalName = 'admin']";
    r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
    rit = r.getRows();
    assertEquals("[rep:Authorizable] as [a] /* property principalName = admin " + "where [a].[rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
    query = "//element(*, rep:Authorizable)[admin/@rep:principalName = 'admin']";
    r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
    rit = r.getRows();
    assertEquals("[rep:Authorizable] as [a] /* nodeType " + "Filter(query=explain select [jcr:path], [jcr:score], * " + "from [rep:Authorizable] as a " + "where [admin/rep:principalName] = 'admin' " + "/* xpath: //element(*, rep:Authorizable)[" + "admin/@rep:principalName = 'admin'] */, path=*, " + "property=[admin/rep:principalName=[admin]]) " + "where [a].[admin/rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 27 with Session

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

the class QueryPlanTest method uuidIndex.

@Test
public void uuidIndex() throws Exception {
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node testRootNode = session.getRootNode().addNode("testroot");
    Node n = testRootNode.addNode("node");
    n.addMixin("mix:referenceable");
    session.save();
    // this matches just one node (exact path),
    // so it should use the TraversintIndex
    String xpath = "/jcr:root/testroot/node[@jcr:uuid]";
    Query q;
    QueryResult result;
    RowIterator it;
    q = qm.createQuery("explain " + xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String plan = it.nextRow().getValue("plan").getString();
    assertEquals("[nt:base] as [a] /* traverse \"/testroot/node\" where " + "([a].[jcr:uuid] is not null) " + "and (issamenode([a], [/testroot/node])) */", plan);
    // verify the result
    q = qm.createQuery(xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String path = it.nextRow().getPath();
    assertEquals("/testroot/node", path);
    assertFalse(it.hasNext());
    // this potentially matches many nodes,
    // so it should use the index on the UUID property
    xpath = "/jcr:root/testroot/*[@jcr:uuid]";
    q = qm.createQuery("explain " + xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    plan = it.nextRow().getValue("plan").getString();
    assertEquals("[nt:base] as [a] /* property uuid IS NOT NULL " + "where ([a].[jcr:uuid] is not null) " + "and (ischildnode([a], [/testroot])) */", plan);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 28 with Session

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

the class QueryPlanTest method nodeType.

@Test
public void nodeType() throws Exception {
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node nodetype = session.getRootNode().getNode("oak:index").getNode("nodetype");
    nodetype.setProperty("entryCount", 10000000);
    Node testRootNode = session.getRootNode().addNode("testroot");
    Node n1 = testRootNode.addNode("node1");
    Node n2 = n1.addNode("node2");
    n2.addNode("node3");
    session.save();
    String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where [node2/node3/jcr:primaryType] is not null " + "and isdescendantnode('/testroot')";
    Query q;
    QueryResult result;
    RowIterator it;
    q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String plan = it.nextRow().getValue("plan").getString();
    // should not use the index on "jcr:primaryType"
    assertEquals("[nt:base] as [nt:base] /* traverse \"/testroot//*\" " + "where ([nt:base].[node2/node3/jcr:primaryType] is not null) " + "and (isdescendantnode([nt:base], [/testroot])) " + "*/", plan);
    // verify the result
    q = qm.createQuery(sql2, Query.JCR_SQL2);
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String path = it.nextRow().getValue("path").getString();
    assertEquals("/testroot/node1", path);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 29 with Session

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

the class QueryTest method encodedPath.

@SuppressWarnings("deprecation")
@Test
public void encodedPath() throws RepositoryException {
    Session session = getAdminSession();
    session.getRootNode().addNode("hello").addNode("world");
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Query q;
    q = qm.createQuery("/jcr:root/hel_x006c_o/*", Query.XPATH);
    assertEquals("/hello/world", getPaths(q));
    q = qm.createQuery("//hel_x006c_o", Query.XPATH);
    assertEquals("/hello", getPaths(q));
    q = qm.createQuery("//element(hel_x006c_o, nt:base)", Query.XPATH);
    assertEquals("/hello", getPaths(q));
}
Also used : Query(javax.jcr.query.Query) 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)

Example 30 with Session

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

the class UserManagerTest method testNewUserCanLogin.

@Test
public void testNewUserCanLogin() throws RepositoryException, NotExecutableException {
    String uid = createUserId();
    User u = null;
    Session s = null;
    try {
        u = userMgr.createUser(uid, "pw");
        superuser.save();
        Credentials creds = new SimpleCredentials(uid, "pw".toCharArray());
        s = superuser.getRepository().login(creds);
    } finally {
        if (u != null) {
            u.remove();
            superuser.save();
        }
        if (s != null) {
            s.logout();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session) Test(org.junit.Test)

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