Package org.apache.jackrabbit.ocm.query

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


      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


      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

      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

      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

      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

    {
      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

      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

    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

     
      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

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.