Package org.apache.jackrabbit.ocm.query

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


    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 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);
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 testGetObjectsOrForSingleFilter() {

        try {

            // Build the Query Object
            QueryManager queryManager = this.getQueryManager();
            Filter filter1 = queryManager.createFilter(Paragraph.class);
            filter1.addOrFilter("text", new String[]{"Para 1","Para 2"});
            filter1.setScope("/test/");

            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 testGetObjectsOrWithAndForSingleFilter() {

        try {

            // Build the Query Object
            QueryManager queryManager = this.getQueryManager();
            Filter filter1 = queryManager.createFilter(Paragraph.class);
            filter1.addOrFilter("text", new String[]{"Para 1","Another Para "}).addLike("text", "Para%");
            filter1.setScope("/test/");

            Query query = queryManager.createQuery(filter1);

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

        public void testGetObjectOrderByWithUpdatableJCRExpression() {

            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");

                String strQueryBuilderStringWithDescending = ((QueryImpl)query).getOrderByExpression();
               
                ObjectContentManager ocm = this.getObjectContentManager();
                Collection result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());

                //Text is Descending
                Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
                Iterator iterator = result.iterator();
                Paragraph para = (Paragraph)iterator.next();
                assertEquals("Para 3",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 2",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 1",para.getText());

                //Text is Ascending
                query = queryManager.createQuery(filter);
                query.addOrderByAscending("text");

                ocm = this.getObjectContentManager();
                result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());
                iterator = result.iterator();
                para = (Paragraph)iterator.next();
                assertEquals("Para 1",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 2",para.getText());
                para = (Paragraph)iterator.next();
                assertEquals("Para 3",para.getText());

                //Text is Descending
                query = queryManager.createQuery(filter);
                ((QueryImpl)query).addJCRExpression(strQueryBuilderStringWithDescending);
                ocm = this.getObjectContentManager();
                result = ocm.getObjects(query);
                assertEquals("Invalid number of objects - should be = 3", 3, result.size());
                iterator = result.iterator();
View Full Code Here

    {

      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);
      log.info("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);
      log.info("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, Calendar.DECEMBER, 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, Calendar.DECEMBER, 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.