Package org.modeshape.jcr.api.query

Examples of org.modeshape.jcr.api.query.QueryManager


    }

    @FixFor( "MODE-1824" )
    @Test
    public void shouldBeAbleToExecuteQueryWithTwoColumns() throws RepositoryException {
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        QueryObjectModelFactory factory = queryManager.getQOMFactory();
        Selector car1Selector = factory.selector("car:Car", "car1");
        Selector car2Selector = factory.selector("car:Car", "car2");
        Join join = factory.join(car1Selector, car2Selector, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER,
                                 factory.equiJoinCondition("car1", "car:maker", "car2", "car:maker"));
        Column[] columns = new Column[] {factory.column("car1", "car:maker", "maker"),
View Full Code Here


    }

    @FixFor( "MODE-1825" )
    @Test
    public void shouldBeAbleToExecuteQueryForAllColumns() throws RepositoryException {
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        QueryObjectModelFactory factory = queryManager.getQOMFactory();
        Selector car1Selector = factory.selector("car:Car", "car1");
        Selector car2Selector = factory.selector("car:Car", "car2");
        Join join = factory.join(car1Selector, car2Selector, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER,
                                 factory.equiJoinCondition("car1", "car:maker", "car2", "car:maker"));
        Column[] columns = new Column[] {factory.column("car1", null, null)};
View Full Code Here

    }

    @FixFor( "MODE-1833" )
    @Test
    public void shouldBeAbleToQueryAllColumnsOnSimpleType() throws RepositoryException {
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        QueryObjectModelFactory factory = queryManager.getQOMFactory();
        Query query = factory.createQuery(factory.selector("modetest:simpleType", "type1"), null, null,
                                          new Column[] {factory.column("type1", null, null)});
        QueryResult result = query.execute();
        validateQuery().rowCount(0).validate(query, result);
    }
View Full Code Here

    }

    @Test
    public void shouldFindBuiltInNodeTypes() throws Exception {
        String queryString = "select [jcr:path] from [nt:base] where ischildnode('/jcr:system/jcr:nodeTypes')";
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
        QueryResult result = query.execute();
        long numNodetypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes().getSize();
        validateQuery().rowCount(numNodetypes).validate(query, result);
    }
View Full Code Here

            printMessage("-------------------- MyQueryTest---------------------");

            String descOrder = "SELECT [nt:file].[jcr:created] FROM [nt:file] INNER JOIN [nt:base] AS content ON ISCHILDNODE(content,[nt:file]) WHERE ([nt:file].[jcr:mixinTypes] = 'mix:simpleVersionable' AND NAME([nt:file]) LIKE 'f%') ORDER BY content.[jcr:lastModified] DESC";
            String ascOrder = "SELECT [nt:file].[jcr:created] FROM [nt:file] INNER JOIN [nt:base] AS content ON ISCHILDNODE(content,[nt:file]) WHERE ([nt:file].[jcr:mixinTypes] = 'mix:simpleVersionable' AND NAME([nt:file]) LIKE 'f%') ORDER BY content.[jcr:lastModified] ASC";

            QueryManager queryManager = session.getWorkspace().getQueryManager();
            Query query = queryManager.createQuery(descOrder, Query.JCR_SQL2);
            QueryResult result = query.execute();

            // checking first query
            RowIterator it = result.getRows();
            assertEquals(2, it.getSize());

            Node n1 = it.nextRow().getNode();
            Node n2 = it.nextRow().getNode();

            assertEquals("f2", n1.getName());
            assertEquals("f1", n2.getName());

            // the same request with other order
            query = queryManager.createQuery(ascOrder, Query.JCR_SQL2);
            result = query.execute();

            // checking second query
            it = result.getRows();
            assertEquals(2, it.getSize());

            n1 = it.nextRow().getNode();
            n2 = it.nextRow().getNode();

            assertEquals("f1", n1.getName());
            assertEquals("f2", n2.getName());

            // Try the XPath query ...
            String descOrderX = "/jcr:root//element(*,nt:file)[(@jcr:mixinTypes = 'mix:simpleVersionable')] order by jcr:content/@jcr:lastModified descending";
            String ascOrderX = "/jcr:root//element(*,nt:file)[(@jcr:mixinTypes = 'mix:simpleVersionable')] order by jcr:content/@jcr:lastModified ascending";
            query = queryManager.createQuery(descOrderX, Query.XPATH);
            result = query.execute();
            // checking first query
            it = result.getRows();
            assertEquals(2, it.getSize());

            n1 = it.nextRow().getNode();
            n2 = it.nextRow().getNode();

            assertEquals("f2", n1.getName());
            assertEquals("f1", n2.getName());

            // the same request with other order
            query = queryManager.createQuery(ascOrderX, Query.XPATH);
            result = query.execute();

            // checking second query
            it = result.getRows();
            assertEquals(2, it.getSize());
View Full Code Here

        try {
            Node relationship = nodeA.addNode("relationship", "test:relationship");
            relationship.setProperty("test:target", new JcrValue[] {nodeBRef, nodeCRef});

            session.save();
            QueryManager queryManager = session.getWorkspace().getQueryManager();

            // Find the reference in the node ...
            String queryString = "SELECT relationship.[test:target] FROM [test:relationship] AS relationship";
            Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            validateQuery().rowCount(1).validate(query, query.execute());

            // Find the UUIDs of the 'test:node' (which are all 'mix:referenceable') ...
            queryString = "SELECT [jcr:uuid], [jcr:path] FROM [test:node]";
            query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            validateQuery().rowCount(3).onEachRow(new Predicate() {
                @Override
                public void validate( int rowNumber,
                                      Row row ) throws RepositoryException {
                    assertNotNull(row.getValue("jcr:uuid"));
                }
            }).validate(query, query.execute());

            queryString = "SELECT relationship.[test:target], target.[jcr:path] "
                          + "   FROM [test:relationship] AS relationship "
                          + "   JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] ";
            query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            validateQuery().rowCount(2).validate(query, query.execute());

            queryString = "SELECT node.[jcr:path], relationship.[test:target], target.[jcr:path] FROM [test:node] AS node "
                          + "   JOIN [test:relationship] AS relationship ON ISCHILDNODE(relationship, node) "
                          + "   JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] "
                          + "   WHERE node.[test:name] = 'A'";
            query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            validateQuery().rowCount(2).validate(query, query.execute());

            queryString = "SELECT DISTINCT target.* FROM [test:node] AS node "
                          + "   JOIN [test:relationship] AS relationship ON ISCHILDNODE(relationship, node) "
                          + "   JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] "
                          + "   WHERE node.[test:name] = 'A'";
            query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            validateQuery().rowCount(2).validate(query, query.execute());
        } finally {
            nodeA.remove();
            nodeB.remove();
            nodeC.remove();
View Full Code Here

        session.save();

        try {
            String queryString = "SELECT * from [nt:unstructured] where REFERENCE() IN " + idList(nodeA, nodeB);
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            QueryResult result = query.execute();
            final List<String> resultIds = new ArrayList<String>();
            validateQuery().rowCount(2).onEachRow(new Predicate() {
                @Override
                public void validate( int rowNumber,
View Full Code Here

        session.save();

        try {
            String queryString = "SELECT * from [nt:unstructured] where REFERENCE() IN " + idList(nodeA, nodeB);
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            QueryResult result = query.execute();
            final List<String> resultIds = new ArrayList<String>();
            validateQuery().rowCount(2).onEachRow(new Predicate() {
                @Override
                public void validate( int rowNumber,
View Full Code Here

        Collections.sort(referrerIds);

        session.save();
        try {
            String queryString = "SELECT * from [nt:unstructured] where REFERENCE() IN " + idList(nodeA, nodeB);
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            QueryResult result = query.execute();

            final List<String> resultIds = new ArrayList<String>();
            validateQuery().rowCount(2).onEachRow(new Predicate() {
                @Override
View Full Code Here

        session.save();

        try {
            String queryString = "SELECT * from [nt:unstructured] where REFERENCE() IN " + idList(nodeA, nodeB);
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
            QueryResult result = query.execute();

            final List<String> resultIds = new ArrayList<String>();
            validateQuery().rowCount(3).onEachRow(new Predicate() {
                @Override
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.api.query.QueryManager

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.