Package org.apache.jackrabbit.ocm.query

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


    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


      {
       
               
            ObjectContentManager ocm = this.getObjectContentManager();
            // Search on subtree (test/node1)
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(Paragraph.class);
            filter.setScope("/test/node1//");
            Query query = queryManager.createQuery(filter);
            Collection result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 8", result.size() == 8);
     

            filter = queryManager.createFilter(Paragraph.class);
            filter.setScope("/test//");
            query = queryManager.createQuery(filter);
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 16", result.size() == 16);
     
            // Test on children
            filter = queryManager.createFilter(Paragraph.class);
            filter.setScope("/test/");
            query = queryManager.createQuery(filter);
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
     
              // Search on scope and properties
            filter = queryManager.createFilter(Paragraph.class);
            filter.setScope("/test//");
            filter.addEqualTo("text", "Para 1");
            query = queryManager.createQuery(filter);
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 3", result.size() == 3);


            filter = queryManager.createFilter(Paragraph.class);
            filter.setScope("/test//");
            filter.addContains("text", "another");
            query = queryManager.createQuery(filter);
            result = ocm.getObjects(query);
            assertTrue("Invalid number of objects - should be = 4", result.size() == 4);

            filter = queryManager.createFilter(Page.class);
            filter.setScope("/test/node1/");     
            query = queryManager.createQuery(filter);
            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 = getObjectContentManager().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

            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

    public void testBuildExpression1()
    {
      try
      {
            QueryManager queryManager = getObjectContentManager().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

    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

    public void testBuildExpression2()
    {

      try
      {
            QueryManager queryManager = getObjectContentManager().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

    public void testBuildExpression1()
    {
      try
      {
            QueryManager queryManager = getObjectContentManager().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 = getObjectContentManager().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

    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

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.