Package org.apache.jackrabbit.ocm.query

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


  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


        try {

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

            Query query = queryManager.createQuery(filter);
            Paragraph paragraph = (Paragraph) ocm.getObject(query);
            assertNotNull("Object is null", paragraph);
            assertTrue("Invalid paragraph found", paragraph.getText().equals("Para 1"));

        } catch (Exception e) {
View Full Code Here

        try {

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

            Query query = queryManager.createQuery(filter);

            Collection result = ocm.getObjects(query);
            assertEquals("Invalid number of objects - should be = 1", 1, result.size());
            Paragraph paragraph = (Paragraph) result.iterator().next();
            assertTrue("Invalid paragraph found", paragraph.getText().equals("Para 1"));
View Full Code Here

    {

      ObjectContentManager ocm = getObjectContentManager();

      // Test Boolean value
      QueryManager queryManager = ocm.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

  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 Folders found on the root level
    //---------------------------------------------------------------------------------------------------------
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(FolderImpl.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(DocumentImpl.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
    //---------------------------------------------------------------------------------------------------------
    FolderImpl folder2 = (FolderImpl) 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));


    CmsObjectImpl cmsObject = (CmsObjectImpl) 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));

    //---------------------------------------------------------------------------------------------------------
    // Retrieve Contents (ancestor of Documents)
    //---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(ContentImpl.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(CmsObjectImpl.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(CmsObjectImpl.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

  public void testQueryAtomicFieldsWithConverter()
  {
    ObjectContentManager ocm = getObjectContentManager();

    // Test Boolean value
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(Atomic.class);
    filter.addEqualTo("int2boolean", new Boolean(true));
    Query query = queryManager.createQuery(filter);

    long start = System.currentTimeMillis();
    Collection result = ocm.getObjects(query);
    log.info("getObjects  : " + (System.currentTimeMillis() - start));
View Full Code Here

        // get persistent bean extent by root path
        try
        {
            // construct query filter
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(beanClass);
            filter.setScope(beanClassNodeRootPaths.get(beanClass)+"//");
            Query query = queryManager.createQuery(filter);
           
            // invoke query
            Collection<? extends IBean> beansExtentList = ocm.getObjects(query);
            if ((beansExtentList != null) && !beansExtentList.isEmpty())
            {
View Full Code Here

        // get persistent beans by root path and filter
        try
        {
            // construct query filter
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(beanClass);
            filter.setScope(beanClassNodeRootPaths.get(beanClass)+"//");
            if (name != null)
            {
                String mappedName = IMPLEMENTATION_FIELD_MAP.get(name);
                name = ((mappedName != null) ? mappedName : name);
                if (value instanceof IUuidBean)
                {
                    value = ((IUuidBean)value).getUuid();
                }
                filter = ((value != null) ? filter.addEqualTo(name, value) : filter.addIsNull(name));
            }           
            Query query = queryManager.createQuery(filter);
            if (orderBy != null)
            {
                String mappedOrderBy = IMPLEMENTATION_FIELD_MAP.get(orderBy);
                orderBy = ((mappedOrderBy != null) ? mappedOrderBy : orderBy);
                if (ascending)
View Full Code Here

        // get persistent beans by root path and filter
        try
        {
            // construct query filter
            QueryManager queryManager = ocm.getQueryManager();
            Filter filter = queryManager.createFilter(beanClass);
            filter.setScope(beanClassNodeRootPaths.get(beanClass)+"//");
            if ((values != null) && !values.isEmpty())
            {
                for (Map.Entry<String,Object> value : values.entrySet())
                {
                    String valueName = value.getKey();
                    String mappedValueName = IMPLEMENTATION_FIELD_MAP.get(valueName);
                    valueName = ((mappedValueName != null) ? mappedValueName : valueName);
                    Object valueValue = value.getValue();
                    if (valueValue instanceof IUuidBean)
                    {
                        valueValue = ((IUuidBean)valueValue).getUuid();
                    }
                    filter = ((valueValue != null) ? filter.addEqualTo(valueName, valueValue) : filter.addIsNull(valueName));
                }
            }
            Query query = queryManager.createQuery(filter);
            if (orderBy != null)
            {
                String mappedOrderBy = IMPLEMENTATION_FIELD_MAP.get(orderBy);
                orderBy = ((mappedOrderBy != null) ? mappedOrderBy : orderBy);
                if (ascending)
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.