Package org.apache.jackrabbit.ocm.manager

Examples of org.apache.jackrabbit.ocm.manager.ObjectContentManager


            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"));
           
        }
        catch (Exception e)
View Full Code Here


            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();
            assertTrue("Invalid paragraph found" , paragraph.getText().equals("Para 1"));
           
        }
View Full Code Here

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

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
            assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 1"));
            assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
View Full Code Here

           
              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());
           
            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
            assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 1"));
            assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
View Full Code Here

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

            Paragraph[] paragraphs = (Paragraph[]) result.toArray(new Paragraph[result.size()]);
            assertTrue("Invalid paragraph found", paragraphs[0].getText().equals("Para 3"));
            assertTrue("Invalid paragraph found", paragraphs[1].getText().equals("Para 2"));
View Full Code Here

       
    }
   
    private void importData() throws JcrMappingException
    {
      ObjectContentManager ocm = getObjectContentManager();

        Page page = new Page();
        page.setPath("/test");
        page.setTitle("Page Title");
       
        ArrayList paragraphs = new ArrayList();
       
        paragraphs.add(new Paragraph("Para 1"));
        paragraphs.add(new Paragraph("Para 2"));
        paragraphs.add(new Paragraph("Para 3"));
        paragraphs.add(new Paragraph("Another Para "));
        page.setParagraphs(paragraphs);
       
        ocm.insert(page)
        ocm.save();
               

    }
View Full Code Here

    public void testMultiValue()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------

            MultiValue multiValue = new MultiValue();
            multiValue.setPath("/test");
           
            ArrayList values = new ArrayList();
            values.add("Value1");
            values.add("Value2");
            values.add("Value3");
            values.add("Value4");
            multiValue.setMultiValues(values);
           
            ocm.insert(multiValue);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            multiValue = (MultiValue) ocm.getObject( "/test");
            assertNotNull("Object is null", multiValue);
            assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
            assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 4);           
            assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            values = new ArrayList();
            values.add("Value1");
            values.add("Value2");
            values.add("Value3");
            values.add("Value4");
            values.add("Value5");
            multiValue.setMultiValues(values);
           
            ocm.update(multiValue);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          

            multiValue = (MultiValue) ocm.getObject( "/test");
            assertNotNull("Object is null", multiValue);
            assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues());
            assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 5);           
            assertTrue("Incorrect collection element", ((String) multiValue.getMultiValues().iterator().next()).equals("Value1"));
           
View Full Code Here


  public void testBeanProxy() {

    try {
      ObjectContentManager ocm = this.getObjectContentManager();

      Detail detail = new Detail();
      detail.setField("FieldValue");     
     
      Detail proxyDetail = new Detail();
      proxyDetail.setField("ProxyFieldValue");
     
      Main main = new Main();
      main.setPath("/test");
      main.setDetail(detail);
      main.setProxyDetail(proxyDetail);
             
            ocm.insert(main);
      ocm.save();
     
     
      //---------------------------------------------------------------------------------------------------------
      // Retrieve the main object
      //---------------------------------------------------------------------------------------------------------           
      main = (Main) ocm.getObject( "/test");
      assertNotNull("detail is null", main.getDetail());
      assertTrue("Invalid detail bean", main.getDetail().getField().equals("FieldValue"));

      assertNotNull("proxydetail is null", main.getProxyDetail());
      Object proxyObject = main.getProxyDetail();
      assertTrue("Invalid class specify for the proxy bean", proxyObject  instanceof Detail);
      assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("ProxyFieldValue"));
     
      Detail nullDetail = main.getNullDetail();
      assertNull("nulldetail is not  null",nullDetail );

     
      //---------------------------------------------------------------------------------------------------------
      // Update 
      //---------------------------------------------------------------------------------------------------------           
       detail = new Detail();
      detail.setField("AnotherFieldValue");     
     
      proxyDetail = new Detail();
      proxyDetail.setField("AnotherProxyFieldValue");
     
      main.setDetail(detail);
      main.setProxyDetail(proxyDetail);
     
      ocm.update(main);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve the main object
      //---------------------------------------------------------------------------------------------------------           
      main = (Main) ocm.getObject( "/test");
      assertNotNull("detail is null", main.getDetail());
      assertTrue("Invalid detail bean", main.getDetail().getField().equals("AnotherFieldValue"));

      assertNotNull("proxydetail is null", main.getProxyDetail());
      proxyObject = main.getProxyDetail();
      assertTrue("Invalid class specify for the proxy bean", proxyObject  instanceof Detail);
      assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("AnotherProxyFieldValue"));
           
      assertNull("nulldetail is not  null",main.getNullDetail());
       
      //---------------------------------------------------------------------------------------------------------
      // Delete the main object
      //---------------------------------------------------------------------------------------------------------           
      ocm.remove("/test");
      ocm.save();
 
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
View Full Code Here

          
    public void testHashMap()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();
         
            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository with null hashmap
            // --------------------------------------------------------------------------------

            Main main = new Main();
            main.setPath("/test");
            main.setText("Main text");
                       
            ocm.insert(main);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            main = (Main) ocm.getObject( "/test");           
            assertTrue("Incorrect text", main.getText().equals("Main text"));          
            assertNull("HashMap is not null", main.getHashMap());
           
            // --------------------------------------------------------------------------------
            // Update an object graph in the repository
            // --------------------------------------------------------------------------------

            main = new Main();
            main.setPath("/test");
            main.setText("Main text");
           
            HashMapElement hashMapElement = new HashMapElement();
            Element e1 = new Element();
            e1.setId("e1");
            e1.setText("Element 1");
            hashMapElement.addObject(e1);
           
            Element e2 = new Element();
            e2.setId("e2");
            e2.setText("Element 2");
            hashMapElement.addObject(e2);
           
            main.setHashMap(hashMapElement);
           
            ocm.update(main);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            main = (Main) ocm.getObject( "/test");
            assertNotNull("main.getHashMap() is null", main.getHashMap());
            assertTrue("Incorrect text", main.getText().equals("Main text"));          
            assertTrue("Incorrect para element", ((Element) main.getHashMap().get("e1")).getText().equals("Element 1"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            hashMapElement = new HashMapElement();
            e1 = new Element();
            e1.setId("e1");
            e1.setText("Element 1");
            hashMapElement.addObject(e1);
           
            e2 = new Element();
            e2.setId("e3");
            e2.setText("Element 3");
            hashMapElement.addObject(e2);

            Element e3 = new Element();
            e3.setId("e4");
            e3.setText("Element 4");
            hashMapElement.addObject(e3);
            main.setHashMap(hashMapElement);
           
            ocm.update(main);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            assertNotNull("main.getElements() is null", main.getHashMap());
View Full Code Here

  }
 
  public void testDefaultCollectionConverterWithProxy() {

    try {
      ObjectContentManager ocm = this.getObjectContentManager();

      ArrayList  details= new ArrayList();
      for(int i=1; i<=100;i++)
      {
        Detail detail = new Detail();
        detail.setField("field" + i);       
        details.add(detail);
      }
     
      Main main = new Main();
      main.setProxyCollection(details);
      main.setPath("/test");             
            ocm.insert(main);
      ocm.save();
     
     
      //---------------------------------------------------------------------------------------------------------
      // Retrieve the main object
      //---------------------------------------------------------------------------------------------------------           
      main = (Main) ocm.getObject( "/test");
      assertNotNull("main is null", main);

            Collection result = main.getProxyCollection();
            assertEquals("Invalide size", result.size(), 100);
            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());
     
      //---------------------------------------------------------------------------------------------------------
      // Update 
      //---------------------------------------------------------------------------------------------------------
           
            Detail detail = new Detail();
      detail.setField("newFieldValue");     
      result.add(detail);
      main.setProxyCollection(result);
      ocm.update(main);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve the main object
      //---------------------------------------------------------------------------------------------------------           
      main = (Main) ocm.getObject("/test");
      assertNotNull("main  is null", main);
            assertEquals("Invalide size",main.getProxyCollection().size(), 101);
            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());

            //---------------------------------------------------------------------------------------------------------
      // Delete the main object
      //---------------------------------------------------------------------------------------------------------           
      ocm.remove("/test");
      ocm.save();           
 
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.ocm.manager.ObjectContentManager

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.