Package org.apache.jackrabbit.ocm.query

Examples of org.apache.jackrabbit.ocm.query.QueryManager


      {
       
                     
            ObjectContentManager ocm = this.getObjectContentManager();
            // Search on subtree (test/node1)
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Paragraph.class);   
            filter.setScope("/test/node1//");
            Query query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            Collection result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 8", result.size() == 8);
           
           
            queryManager = this.getQueryManager();
            filter = queryManager.createFilter(Paragraph.class);   
            filter.setScope("/test//");
            query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 16", result.size() == 16);
           
            // Test on children
            queryManager = this.getQueryManager();
            filter = queryManager.createFilter(Paragraph.class);   
            filter.setScope("/test/");
            query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
           
              // Search on scope and properties
            queryManager = this.getQueryManager();
            filter = queryManager.createFilter(Paragraph.class);   
            filter.setScope("/test//");
            filter.addEqualTo("text", "Para 1");
            query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 3", result.size() == 3);

           
            queryManager = this.getQueryManager();
            filter = queryManager.createFilter(Paragraph.class);   
            filter.setScope("/test//");
            filter.addContains("text", "another");
            query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 4", result.size() == 4);
           
            queryManager = this.getQueryManager();
            filter = queryManager.createFilter(Page.class);   
            filter.setScope("/test/node1/");           
            query = queryManager.createQuery(filter);           
            ocm = this.getObjectContentManager();
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 2", result.size() == 2);
            assertTrue ("Invalid object in the collection" , this.contains(result, "/test/node1/page1", Page.class));
            assertTrue ("Invalid object in the collection" , this.contains(result, "/test/node1/page2", Page.class));
View Full Code Here


        try {

            ObjectContentManager ocm = this.getObjectContentManager();
            // Build the Query Object
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(Paragraph.class);
            filter.addLike("text", "Para%");
            filter.setScope("/test/");

            Query query = queryManager.createQuery(filter);

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 3", 3, result.size());

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
View Full Code Here

    ocm.save();

    //---------------------------------------------------------------------------------------------------------
    // Retrieve Folders found on the root level
    //---------------------------------------------------------------------------------------------------------
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(FolderImpl.class);
    Query query = queryManager.createQuery(filter);
    filter.setScope("/");
    Collection result = ocm.getObjects(query);
    assertEquals("Invalid number of folders found", result.size(), 2);
    assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/folder2", FolderImpl.class));


    //---------------------------------------------------------------------------------------------------------
    // Retrieve Documents
    //---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(DocumentImpl.class);

    filter.addLike("name", "document name%");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid number of documents  found", result.size(),2);
    assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));


    //---------------------------------------------------------------------------------------------------------
    // Retrieve folder2
    //---------------------------------------------------------------------------------------------------------
    FolderImpl folder2 = (FolderImpl) ocm.getObject( "/folder2");
    assertNotNull("folder 2 is null", folder2);
    assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,2);
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));


    CmsObjectImpl cmsObject = (CmsObjectImpl) ocm.getObject( "/folder2");
    assertNotNull("folder 2 is null", cmsObject);
    assertTrue("Invalid instance for folder 2",  cmsObject instanceof FolderImpl);
    assertEquals("Invalid number of documents  found in folder2 children",  folder2.getChildren().size(),2);
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));

    //---------------------------------------------------------------------------------------------------------
    // Retrieve Contents (ancestor of Documents)
    //---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(ContentImpl.class);
    filter.addLike("name", "document name%");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid number of documents  found", result.size(),2);
    assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));


    //---------------------------------------------------------------------------------------------------------
    // Retrieve all cmsobjects found on the root level
    //---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(CmsObjectImpl.class);
    filter.setScope("/");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid ancestor object found", result.size(),5);
    assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));


    //---------------------------------------------------------------------------------------------------------
    // Retrieve all cmsobjects found anywhere
    //---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(CmsObjectImpl.class);
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid ancestor object found", result.size(),7);
    assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
View Full Code Here

        try {

            ObjectContentManager ocm = this.getObjectContentManager();
            // Build the Query Object
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter1 = queryManager.createFilter(Paragraph.class);
            filter1.addEqualTo("text", "Para 1");
            filter1.setScope("/test/");

            Filter filter2 = queryManager.createFilter(Paragraph.class);
            filter2.addEqualTo("text", "Para 2");

            filter1.addOrFilter(filter2);

            Query query = queryManager.createQuery(filter1);

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 2", 2, result.size());

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
View Full Code Here

        try {

            ObjectContentManager ocm = this.getObjectContentManager();
            // Build the Query Object
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter1 = queryManager.createFilter(Paragraph.class);
            filter1.addOrFilter("text", new String[]{"Para 1","Para 2"});
            filter1.setScope("/test/");

            Query query = queryManager.createQuery(filter1);

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 2", 2, result.size());

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
View Full Code Here

        try {

            ObjectContentManager ocm = this.getObjectContentManager();
            // Build the Query Object
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter1 = queryManager.createFilter(Paragraph.class);
            filter1.addOrFilter("text", new String[]{"Para 1","Another Para "}).addLike("text", "Para%");
            filter1.setScope("/test/");

            Query query = queryManager.createQuery(filter1);

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 1", 1, result.size());

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
View Full Code Here

        try {

            ObjectContentManager ocm = this.getObjectContentManager();
            // Build the Query Object
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(Paragraph.class);
            filter.addLike("text", "Para%");
            filter.setScope("/test/");

            Query query = queryManager.createQuery(filter);
            query.addOrderByDescending("text");

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 3", 3, result.size());
View Full Code Here

            try {

                ObjectContentManager ocm = this.getObjectContentManager();
                // Build the Query Object
                QueryManager queryManager = ocm.getQueryManager();
                Filter filter = queryManager.createFilter(Paragraph.class);
                filter.addLike("text", "Para%");
                filter.setScope("/test/");

                Query query = queryManager.createQuery(filter);
                query.addOrderByDescending("text");

                String strQueryBuilderStringWithDescending = ((QueryImpl)query).getOrderByExpression();

                Collection result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());

                //Text is Descending
                Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
                Iterator iterator = result.iterator();
                Paragraph para = (Paragraph)iterator.next();
                assertEquals("Para 3",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 2",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 1",para.getText());

                //Text is Ascending
                query = queryManager.createQuery(filter);
                query.addOrderByAscending("text");

                ocm = this.getObjectContentManager();
                result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());
                iterator = result.iterator();
                para = (Paragraph)iterator.next();
                assertEquals("Para 1",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 2",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 3",para.getText());

                //Text is Descending
                query = queryManager.createQuery(filter);
                ((QueryImpl)query).addJCRExpression(strQueryBuilderStringWithDescending);
                ocm = this.getObjectContentManager();
                result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());
                iterator = result.iterator();
View Full Code Here

    ocm.save();

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve Descendant class (implements  Interface.class)
    //---------------------------------------------------------------------------------------------------------     
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(Interface.class);
    Query query = queryManager.createQuery(filter);

    Collection result = ocm.getObjects(query);
    assertEquals("Invalid number of  interface  found", result.size(),3);
    assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant3", AnotherDescendant.class));
   

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve Descendant class and its children (implements  AnotherInterface.class)
    //---------------------------------------------------------------------------------------------------------     
      queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(AnotherInterface.class);
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid number of  interface  found", result.size(),4);
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
View Full Code Here

    {
      this.importData(date);
      ObjectContentManager ocm = getObjectContentManager();
       
      // Query all objects
      QueryManager queryManager = ocm.getQueryManager();
      Filter filter = queryManager.createFilter(Atomic.class)
      filter.setScope("/");
      Query query = queryManager.createQuery(filter);
      Collection result = ocm.getObjects(query);
            assertEquals("Incorrect number of objects found", 10, result.size());

            // Get objects
            Atomic atomic = (Atomic) ocm.getObject( "/test[2]");
            assertNotNull("Object /test[2] not found", atomic);

            atomic = (Atomic) ocm.getObject( "/test[10]");
            assertNotNull("Object /test[2] not found", atomic);

            // Update the object
            atomic.setString("Modified Test String 10");
            ocm.update(atomic);
            ocm.save();

            // Query on the attribute "string"
            queryManager = ocm.getQueryManager();
      filter = queryManager.createFilter(Atomic.class)
      filter.addLike("string", "Modified%");     
      query = queryManager.createQuery(filter);
      result = ocm.getObjects(query);
      assertTrue("Incorrect number of objects found", result.size() == 1);

      atomic = (Atomic) ocm.getObject(query);
      assertNotNull("Object not found", atomic);
      assertTrue("Incorrect Object", atomic.getString().equals("Modified Test String 10"));
     
            // Delete all objects
            queryManager = ocm.getQueryManager();
      filter = queryManager.createFilter(Atomic.class)
      filter.setScope("/");
      query = queryManager.createQuery(filter) ;
            ocm.remove(query);
            ocm.save();

      result = ocm.getObjects(query);
            assertTrue("Incorrect number of objects found", result.size() == 0);
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.ocm.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.