Package org.apache.jackrabbit.ocm.query

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


    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

     
      this.importData(date);
      ObjectContentManager ocm = this.getObjectContentManager();
     
      // Test Boolean value
      QueryManager queryManager = this.getQueryManager();
      Filter filter = queryManager.createFilter(Atomic.class);
      filter.addEqualTo("booleanObject", new Boolean(true));
      Query query = queryManager.createQuery(filter);
     
      long start = System.currentTimeMillis();
      Collection result = ocm.getObjects(query);
      System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
     
      assertTrue("Invalid number of objects - should be = 50", result.size() == 50);
     
      filter = queryManager.createFilter(Atomic.class);
      filter.addEqualTo("booleanPrimitive", new Boolean(false));
      query = queryManager.createQuery(filter);

      start = System.currentTimeMillis();
      result = ocm.getObjects(query);
      System.out.println("getObjects 2 : " + (System.currentTimeMillis() - start));
      assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
     
     
      // Test int value
      filter = queryManager.createFilter(Atomic.class);
      filter.addBetween("integerObject", new Integer(0), new Integer(500));
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 5", result.size() == 5);
     
      filter = queryManager.createFilter(Atomic.class);
      filter.addLessOrEqualThan("intPrimitive", new Integer(236));
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 36", result.size() == 36);

     
      //Test Date & Calendar
      filter = queryManager.createFilter(Atomic.class);
      Calendar calendar = Calendar.getInstance();
      calendar.set(2012, 12, 01);
      filter.addLessThan("calendar", calendar);
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);

      filter = queryManager.createFilter(Atomic.class);
      calendar = Calendar.getInstance();
      calendar.set(1975, 12, 01);
      filter.addLessThan("calendar", calendar);
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
     
      filter = queryManager.createFilter(Atomic.class);     
      filter.addEqualTo("date", date);
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);

      filter = queryManager.createFilter(Atomic.class);     
      filter.addBetween("date", date, new Date());
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);

      filter = queryManager.createFilter(Atomic.class);     
      filter.addGreaterThan("date", date);
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);

      // Test contains method
      filter = queryManager.createFilter(Atomic.class);     
      filter.addContains(".", "JCR");
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
     
      filter = queryManager.createFilter(Atomic.class);     
      filter.addContains("string", "JCR");
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
     
      filter = queryManager.createFilter(Atomic.class);     
      filter.addContains("string", "ocm");
      query = queryManager.createQuery(filter);
     
      result = ocm.getObjects(query);     
      assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);

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 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

    public void testGetObjectEqualsTo() {

        try {

            // Build the Query Object
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Paragraph.class);
            filter.addEqualTo("text", "Para 1");

            Query query = queryManager.createQuery(filter);

            ObjectContentManager ocm = this.getObjectContentManager();
            Paragraph paragraph = (Paragraph) ocm.getObject(query);
            assertNotNull("Object is null", paragraph);
            assertTrue("Invalid paragraph found", paragraph.getText().equals("Para 1"));
View Full Code Here

    public void testGetObjectsEqualsTo() {

        try {

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

            Query query = queryManager.createQuery(filter);

            ObjectContentManager ocm = this.getObjectContentManager();
            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 1", 1, result.size());
            Paragraph paragraph = (Paragraph) result.iterator().next();
View Full Code Here

    public void testGetObjectsLike() {

        try {

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

            Query query = queryManager.createQuery(filter);

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

    public void testGetObjectsOr() {

        try {

            // Build the Query Object
            QueryManager queryManager = this.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);

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

    public void testGetObjectOrderBy() {

        try {

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

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

            ObjectContentManager ocm = this.getObjectContentManager();
            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 3", 3, result.size());
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.