Package org.apache.jackrabbit.ocm.manager

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


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

          // --------------------------------------------------------------------------------
            // Manually create a node
          // we need this test as SimpleFieldsHelper.storeSimpleField sets the
          // property value if the field is not set but a jcrDefaultValue
          // is set. But we want to test, that SimpleFieldsHelper.retrieveSimpleField
          // sets the default value from the jcrDefaultValue
            // --------------------------------------------------------------------------------
          Node nodeA = ocm.getSession().getRootNode().addNode("testDefault", "ocm:DefTestPrimary");
          nodeA.setProperty("ocm:p1", "p1Value");
          ocm.getSession().save();
         
            
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------
            Default a = (Default) ocm.getObject( "/testDefault" );
            assertNotNull("a is null", a);
           
            assertEquals("p1Value", a.getP1());
            assertNull(a.getP2());
            assertEquals("p3DescriptorDefaultValue", a.getP3());
View Full Code Here


       
          // No scope         
            QueryManager queryManager = this.getQueryManager();
            Filter filter = queryManager.createFilter(Page.class);               
            Query query = queryManager.createQuery(filter);           
            ObjectContentManager ocm = this.getObjectContentManager();
           
            long  start = System.currentTimeMillis();
            Iterator iterator = ocm.getObjectIterator(query);
            System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
                       
            start = System.currentTimeMillis();
            Collection result = ocm.getObjects(query);
            System.out.println("getObject takes : " + (System.currentTimeMillis() - start));  
           
            start = System.currentTimeMillis();
            iterator = ocm.getObjectIterator(query);
            System.out.println("getObject takes : " + (System.currentTimeMillis() - start));              

           
        }
        catch (Exception e)
View Full Code Here

    private void importData() throws JcrMappingException
    {
       
      try
    {
        ObjectContentManager ocm = getObjectContentManager();
       
          if (ocm.objectExists("/test"))
            {
                ocm.remove("/test");
            }
         
      ObjectContentManagerImpl ocmImpl = (ObjectContentManagerImpl) ocm;
     
      Session session = ocmImpl.getSession();
      Node root = session.getRootNode();
      root.addNode("test");
      root.addNode("test/node1");
      root.addNode("test/node2");
     
      root.save();
     
      Page page = new Page();
      page.setPath("/test/node1/page1");
      page.setTitle("Page 1 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);
           
     
      page = new Page();
      page.setPath("/test/node1/page2");
      page.setTitle("Page 2 Title");
     
      paragraphs = new ArrayList();
     
      paragraphs.add(new Paragraph("Para 1"));
      paragraphs.add(new Paragraph("Para 2"));
      paragraphs.add(new Paragraph("Para 5"));
      paragraphs.add(new Paragraph("Another Para"));
      page.setParagraphs(paragraphs);
     
      ocm.insert(page);
     
      page = new Page();
      page.setPath("/test/node2/page1");
      page.setTitle("Page 3 Title");
     
      paragraphs = new ArrayList();
     
      paragraphs.add(new Paragraph("Para 1"));
      paragraphs.add(new Paragraph("Para 4"));
      paragraphs.add(new Paragraph("Para 5"));
      paragraphs.add(new Paragraph("Another Para"));
      page.setParagraphs(paragraphs);
     
      ocm.insert(page);

      page = new Page();
      page.setPath("/test/node2/page2");
      page.setTitle("Page 4 Title");
     
      paragraphs = new ArrayList();
     
      paragraphs.add(new Paragraph("Para 6"));
      paragraphs.add(new Paragraph("Para 7"));
      paragraphs.add(new Paragraph("Para 8"));
      paragraphs.add(new Paragraph("Another Para"));
      page.setParagraphs(paragraphs);
     
      ocm.insert(page);
     
      ocm.save();
     

     
    }
    catch (RepositoryException e)
View Full Code Here

   
    public void testParentBeanConverter() throws Exception
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

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

            Page page = new Page();
            page.setPath("/test");
            page.setTitle("Page Title");
           
            Collection paragraphs = new ArrayList();
           
            paragraphs.add(new Paragraph("Para 1"));
            paragraphs.add(new Paragraph("Para 2"));
            paragraphs.add(new Paragraph("Para 3"));
            page.setParagraphs(paragraphs);
           
            ocm.insert(page);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            page = (Page) ocm.getObject("/test");
            paragraphs = page.getParagraphs();
            for (Iterator iter = paragraphs.iterator(); iter.hasNext();) {
        Paragraph paragraph = (Paragraph) iter.next();
        System.out.println("Paragraph path : " + paragraph.getPath());       
      }           
            Paragraph p1 = (Paragraph) ocm.getObject("/test/collection-element[2]");
            Page paraPage = p1.getPage();
            assertNotNull("Parent page is null", paraPage);
            assertTrue("Invalid parent page", paraPage.getPath().equals("/test"));
           
            // --------------------------------------------------------------------------------
            // Remove the object
            // --------------------------------------------------------------------------------          
            ocm.remove("/test");
            ocm.save();
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
View Full Code Here

    public void testNullValueAtomicFields()
    {
        try
        {

          ObjectContentManager ocm = getObjectContentManager();
    
            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            Atomic a = new Atomic();
            a.setPath("/test");
            a.setIntegerObject(new Integer(100));           
            a.setDate(new Date());
            byte[] content = "Test Byte".getBytes();
            a.setByteArray(content);
            a.setCalendar(Calendar.getInstance());
            a.setDoubleObject(new Double(2.12));
            a.setDoublePrimitive(1.23);
           
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
            a.setInputStream(byteArrayInputStream);
           
            ocm.insert(a);
            ocm.save();
            
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------
            a = null;
            a = (Atomic) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertNull("Boolean object is not null", a.getBooleanObject());
           
            assertFalse("Incorrect boolean primitive", a.isBooleanPrimitive());
            assertNotNull("Integer Object is null", a.getIntegerObject());
View Full Code Here

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

            // --------------------------------------------------------------------------------
            // Create and store an object with a null collection field
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");              
           
            ocm.insert(a);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNull("a.collection is not null", a.getCollection());
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            C c1 = new C();
            c1.setId("first");
            c1.setName("First Element");
            C c2 = new C();
            c2.setId("second");
            c2.setName("Second Element");
           
            C c3 = new C();
            c3.setId("third");
            c3.setName("Third Element");
           
           
            Collection collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            collection.add(c3);
           
            a.setCollection(collection);
           
            ocm.update(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject("/test");
            assertNotNull("a is null", a);
            assertNotNull("a.collection is null", a.getCollection());
            assertTrue("Incorrect collection size", a.getCollection().size() == 3);
            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            a.setCollection(null);
            ocm.update(a);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNull("a.collection is not null", a.getCollection());
           
            // --------------------------------------------------------------------------------
            // Export to check the content
            // --------------------------------------------------------------------------------          
View Full Code Here

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

            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            C c1 = new C();
            c1.setId("first");
            c1.setName("First Element");
            C c2 = new C();
            c2.setId("second");
            c2.setName("Second Element");
           
            C c3 = new C();
            c3.setId("third");
            c3.setName("Third Element");
           
           
            Collection collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            collection.add(c3);
           
            a.setCollection(collection);
           
            ocm.insert(a);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a.collection is null", a.getCollection());
            assertEquals("Incorrect a.collection size", 3, a.getCollection().size());
            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            c1 = new C();
            c1.setId("new first");
            c1.setName("First Element");
           
            c2 = new C();
            c2.setId("new second");
            c2.setName("Second Element");
           
            collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            a.setCollection(collection);
           
            ocm.update(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertNotNull("a.collection is null", a.getCollection());
            assertTrue("Incorrect collection size", a.getCollection().size() == 2);
            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("new first"));
           
View Full Code Here

         
          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 importData()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

      ObjectContentManagerImpl ocmImpl = (ObjectContentManagerImpl) ocm;
     
      Session session = ocmImpl.getSession();
      Node root = session.getRootNode();
      root.addNode("test");

            MultiValue multiValue = new MultiValue();
            multiValue.setPath("/test/m1");
            multiValue.setName("m1");
            ArrayList values = new ArrayList();
            values.add("Value1");
            values.add("Value2");
            values.add("Value3");
            values.add("Value4");
            multiValue.setMultiValues(values);
            ocm.insert(multiValue);
           
            multiValue = new MultiValue();
            multiValue.setPath("/test/m2");
            multiValue.setName("m2");
            values = new ArrayList();
            values.add("Value1");
            values.add("Value5");
            values.add("Value6");
            values.add("Value7");           
            multiValue.setMultiValues(values);
            ocm.insert(multiValue);
           
            multiValue = new MultiValue();
            multiValue.setPath("/test/m3");
            multiValue.setName("m3");
            values = new ArrayList();
            values.add("Value1");
            values.add("Value2");
            values.add("Value8");
            values.add("Value9");
           
            multiValue.setMultiValues(values);
            ocm.insert(multiValue);
                                  
            ocm.save();
           
        }
        catch(Exception e)
        {
          e.printStackTrace();
View Full Code Here

    public void testAddElement()
    {
        try
        {

          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            C c1 = new C();
            c1.setId("first");
            c1.setName("First Element");
            C c2 = new C();
            c2.setId("second");
            c2.setName("Second Element");
           
            C c3 = new C();
            c3.setId("third");
            c3.setName("Third Element");
           
           
            Collection collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            collection.add(c3);
           
            a.setCollection(collection);
           
            ocm.insert(a);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a.collection is null", a.getCollection());
            assertEquals("Incorrect a.collection size", 3, a.getCollection().size());
            assertEquals("Incorrect a.collection", "first", ((C) a.getCollection().iterator().next()).getId());
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            C c4 = new C();
            c4.setId("Fourth");
            c4.setName("Fourth Element");
               
            collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            collection.add(c3);
            collection.add(c4);
            a.setCollection(collection);
           
            ocm.update(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertNotNull("a.collection is null", a.getCollection());
            assertEquals("Incorrect collection size", 4, a.getCollection().size());
            assertEquals("Incorrect a.collection", "first", ((C) a.getCollection().iterator().next()).getId());
           
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.