Package org.apache.jackrabbit.ocm.query

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


    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


    {
      this.importData(date);
      ObjectContentManager ocm = this.getObjectContentManager();
       
      // Query all objects
      QueryManager queryManager = this.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 = this.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 = this.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

      ocm.remove("/test5");
      ocm.save();

      assertFalse("Test5 has not been removed", ocm.objectExists("/test5"));

      QueryManager queryManager = this.getQueryManager();
      Filter filter = queryManager.createFilter(Atomic.class);
      filter.addEqualTo("booleanObject" , new Boolean(false));
      Query query = queryManager.createQuery(filter);
      ocm.remove(query);
      ocm.save();

      filter = queryManager.createFilter(Atomic.class);
      filter.setScope("//");
      query = queryManager.createQuery(filter);     
      Collection result = ocm.getObjects(query);
      assertEquals("Invalid number of objects", 5, result.size());

    }
    catch (Exception e)
View Full Code Here

            assertEquals("Invalid value for test", "another test", a.getTest());
           
            // --------------------------------------------------------------------------------
            // Search on the interface
            // --------------------------------------------------------------------------------
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(SimpleInterface.class);
            filter.addEqualTo("test", "another test");
            Query q = queryManager.createQuery(filter);
           
            Collection result = ocm.getObjects(q);
            assertNotNull(result);
            assertEquals("Invalid number of SimpleInterface found", 1, result.size());
           
View Full Code Here

    ocm.save();

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

    Collection result = ocm.getObjects(query);
    assertEquals("Invalid number of Descendant 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));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
   

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve AnotherDescendant class
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(AnotherDescendant.class);
    filter.addEqualTo("anotherDescendantField", "anotherDescendantValue");
    query = queryManager.createQuery(filter);

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

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve some descendants & subdescendants
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(Descendant.class);   
    filter.addEqualTo("descendantField","descendantValue2");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid ancestor object found", result.size(),2);
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
   
    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve all class
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(Ancestor.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, "/descendant1", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
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

    {
      this.importData(date);
      ObjectContentManager ocm = this.getObjectContentManager();
       
      // Query all objects
      QueryManager queryManager = this.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 = this.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 = this.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

      {
       
               
            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
      {
       
          // No scope       
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Page.class);         
            Query query = queryManager.createQuery(filter);
              // we need this to be sure about objects order in the iterator test
              query.addOrderByAscending("title");
            ObjectContentManager ocm = this.getObjectContentManager();
     
            long  start = System.currentTimeMillis();
View Full Code Here

    public void testMultiValueSearch()
    {
        try
        {
         
          QueryManager queryManager = this.getQueryManager();
        Filter filter = queryManager.createFilter(MultiValue.class);
        filter.addEqualTo("multiValues", "Value1");
        Query query = queryManager.createQuery(filter);     
        ObjectContentManager ocm = this.getObjectContentManager();
        Collection result = ocm.getObjects(query);
        assertTrue("Invalid number of objects - should be = 3", result.size() == 3);

          queryManager = this.getQueryManager();
        filter = queryManager.createFilter(MultiValue.class);
        filter.addEqualTo("multiValues", "Value9");
        query = queryManager.createQuery(filter);     
        ocm = this.getObjectContentManager();
        result = ocm.getObjects(query);
        assertTrue("Invalid number of objects - should be = 1", result.size() == 1);
        MultiValue multiValue = (MultiValue)result.iterator().next();
        assertTrue("Incorrect MultiValue found ", multiValue.getName().equals("m3"));
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.