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
      {
       
          // No scope         
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Page.class);               
            Query query = queryManager.createQuery(filter);           
            ObjectContentManager ocm = this.getObjectContentManager();
           
            long  start = System.currentTimeMillis();
            Iterator iterator = ocm.getObjectIterator(query);
            System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
View Full Code Here

  ocm.save();

  //--------------------------------------------------------------------------------------------------------- 
  // Retrieve Folders found on the root level
  //---------------------------------------------------------------------------------------------------------     
  QueryManager queryManager = ocm.getQueryManager();
  Filter filter = queryManager.createFilter(Folder.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(Document.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
  //--------------------------------------------------------------------------------------------------------- 
  Folder folder2 = (Folder) 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));
 
 
  CmsObject cmsObject = (CmsObject) 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));
 
  Folder childFolder = (Folder) ocm.getObject( "/folder2/subfolder");
  Folder parenFolder  = childFolder.getParentFolder();
  assertNotNull("parent folder  is null", parenFolder);
  assertTrue("Invalid instance for parent folder",  parenFolder instanceof FolderImpl);
  assertEquals("Invalid number of documents  found in folder2 children",  parenFolder.getChildren().size(),2);
  assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/document4", DocumentImpl.class));
  assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/subfolder", FolderImpl.class));
 
  //--------------------------------------------------------------------------------------------------------- 
  // Retrieve Contents (ancestor of Documents)
  //---------------------------------------------------------------------------------------------------------     
  queryManager = ocm.getQueryManager();
  filter = queryManager.createFilter(Content.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(CmsObject.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(CmsObject.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

    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

  ocm.save();

  //--------------------------------------------------------------------------------------------------------- 
  // Retrieve Folders found on the root level
  //---------------------------------------------------------------------------------------------------------     
  QueryManager queryManager = ocm.getQueryManager();
  Filter filter = queryManager.createFilter(Folder.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(Document.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
  //--------------------------------------------------------------------------------------------------------- 
  Folder folder2 = (Folder) 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));
 
 
  CmsObject cmsObject = (CmsObject) 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));
 
  Folder childFolder = (Folder) ocm.getObject( "/folder2/subfolder");
  Folder parenFolder  = childFolder.getParentFolder();
  assertNotNull("parent folder  is null", parenFolder);
  assertTrue("Invalid instance for parent folder",  parenFolder instanceof FolderImpl);
  assertEquals("Invalid number of documents  found in folder2 children",  parenFolder.getChildren().size(),2);
  assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/document4", DocumentImpl.class));
  assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/subfolder", FolderImpl.class));
 
  //--------------------------------------------------------------------------------------------------------- 
  // Retrieve Contents (ancestor of Documents)
  //---------------------------------------------------------------------------------------------------------     
  queryManager = ocm.getQueryManager();
  filter = queryManager.createFilter(Content.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(CmsObject.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(CmsObject.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

    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

      try
      {
       
          // No scope         
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Page.class);               
            Query query = queryManager.createQuery(filter);           
            ObjectContentManager ocm = this.getObjectContentManager();
           
            long  start = System.currentTimeMillis();
            Iterator iterator = ocm.getObjectIterator(query);
            System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
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

    public void testBuildExpression1()
    {
      try
      {
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(C.class);
            filter.addEqualTo("name", "a test value")
                    .addEqualTo("id", new Integer(1));
            filter.setScope("/test//");
           
            Query query = queryManager.createQuery(filter);
            String jcrExpression = queryManager.buildJCRExpression(query);
            assertNotNull("jcrExpression is null", jcrExpression);
            assertTrue("Invalid JcrExpression", jcrExpression.equals("/jcr:root/test//element(*, ocm:C) [@ocm:name = 'a test value' and @ocm:id = 1]"));
        }
        catch (Exception e)
        {
View Full Code Here

    public void testBuildExpression2()
    {

      try
      {
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(C.class);
            filter.addEqualTo("name", "a test value")
                  .addEqualTo("id", new Integer(1));
           
            Query query = queryManager.createQuery(filter);
            String jcrExpression = queryManager.buildJCRExpression(query);
            assertNotNull("jcrExpression is null", jcrExpression);
            assertTrue("Invalid JcrExpression", jcrExpression.equals("//element(*, ocm:C) [@ocm:name = 'a test value' and @ocm:id = 1]"));
        }
        catch (Exception e)
        {
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.