Package org.apache.jackrabbit.ocm.manager

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


  private void importData(Date date)
  {
    try
    {

      ObjectContentManager ocm = getObjectContentManager();

      for (int i = 1; i <= 10; i++)
      {
        Atomic a = new Atomic();
        a.setPath("/test" + i);
        a.setBooleanObject(new Boolean(i % 2 == 0));
        a.setBooleanPrimitive(true);
        a.setIntegerObject(new Integer(100 * i));
        a.setIntPrimitive(200 + i);
        a.setString("Test String " + i);
        a.setDate(date);
        Calendar calendar = Calendar.getInstance();
        calendar.set(1976, 4, 20, 15, 40);
        a.setCalendar(calendar);
        a.setDoubleObject(new Double(2.12 + i));
        a.setDoublePrimitive(1.23 + i);
        long now = System.currentTimeMillis();
        a.setTimestamp(new Timestamp(now));
        if ((i % 2) == 0)
        {
          a.setByteArray("This is small object stored in a JCR repository".getBytes());
          a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
        }
        else
        {
          a.setByteArray("This is small object stored in the repository".getBytes());
          a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
        }
        ocm.insert(a);

      }
      ocm.save();

    }
    catch (Exception e)
    {
      e.printStackTrace();
View Full Code Here


   
    public void testCrossReferences()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();
            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            a.setA1("a1");
            a.setA2("a2");
           
            ocm.insert(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
           
            B b = new B();
            b.setB1("b1");
            b.setB2("b2");
            // Add crossreference between b and a
            a.setB(b);
            b.setA(a);

            B b1 = new B();
            b1.setB1("b1.1");
            b1.setB2("b1.2");           
            b1.setA(a);
            a.addB(b1);

            B b2 = new B();
            b2.setB1("b2.1");
            b2.setB2("b2.2");           
            b2.setA(a);
            a.addB(b2);

            ocm.update(a);
            ocm.save();
           

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertTrue("Duplicate instance a", a == a.getB().getA());
           
            Collection collection = a.getCollection();
            assertTrue("Invalid number of items in the collection", collection.size() == 2);
View Full Code Here

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


            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            a.setA1("a1");
            a.setA2("a2");
            B b = new B();
            b.setB1("b1");
            b.setB2("b2");
            a.setB(b);
           
            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 is null", a);
            assertTrue("Incorrect a1", a.getA1().equals("a1"));
            assertNotNull("a.b is null", a.getB());
            assertTrue("Incorrect a.b.b1", a.getB().getB1().equals("b1"));
            assertNotNull("a.collection is null", a.getCollection());
            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            a.setA1("new value");
            B newB = new B();
            newB.setB1("new B1");
            newB.setB2("new B2");
            a.setB(newB);
           
           
            ocm.update(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject("/test");
            assertNotNull("a is null", a);
            assertTrue("Incorrect a1", a.getA1().equals("new value"));
            assertNotNull("a.b is null", a.getB());
            assertTrue("Incorrect a.b.b1", a.getB().getB1().equals("new B1"));
           
View Full Code Here

     */
    public void testDiscriminatorAndNodeType()
    {
       try
         {
           ObjectContentManager ocm = getObjectContentManager();


             // --------------------------------------------------------------------------------          
             // Create and store the object in the repository
            // --------------------------------------------------------------------------------
           Discriminator discriminatorObject = new Discriminator();
           discriminatorObject.setPath("/test");
           discriminatorObject.setContent("This is my content");
             ocm.insert(discriminatorObject);            
             ocm.save();
            

             // --------------------------------------------------------------------------------
             // Get the object
             // --------------------------------------------------------------------------------          
             discriminatorObject = (Discriminator) ocm.getObject( "/test");
             assertNotNull("discriminator object  is null", discriminatorObject );
             assertTrue("Incorrect content", discriminatorObject.getContent().equals("This is my content"));
            
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
             discriminatorObject.setContent("new content");            
            
             ocm.update(discriminatorObject);
             ocm.save();

             // --------------------------------------------------------------------------------
             // Get the object
             // --------------------------------------------------------------------------------          
             discriminatorObject = (Discriminator) ocm.getObject( "/test");
             assertNotNull("discriminator object  is null", discriminatorObject );
             assertTrue("Incorrect content", discriminatorObject.getContent().equals("new content"));
            

            
View Full Code Here

        
    }
   
    public void testIsPersistent()
    {   
      ObjectContentManager ocm = getObjectContentManager();
      assertTrue("Class A is not persistent ", ocm.isPersistent(A.class));
      assertFalse("Class String is  persistent - hum ? ", ocm.isPersistent(String.class));
    }
View Full Code Here

   
    public void testAtomicFields()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();
          Date date = new Date();
          Calendar calendar = Calendar.getInstance();
            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            Atomic a = new Atomic();
            a.setPath("/test");
            a.setBooleanObject(new Boolean(true));
            a.setBooleanPrimitive(true);
            a.setIntegerObject(new Integer(100));
            a.setIntPrimitive(200);
            a.setString("Test String");
            a.setDate(date);
            a.setInt2boolean(true);
           
            byte[] content = "Test Byte".getBytes();
            a.setByteArray(content);
            a.setCalendar(calendar);
            a.setDoubleObject(new Double(2.12));
            a.setDoublePrimitive(1.23);
            long now = System.currentTimeMillis();
            a.setTimestamp(new Timestamp(now));
           
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes());
            a.setInputStream(byteArrayInputStream);
            a.setNamedProperty("ocm:test");
            a.setPathProperty("/node1/node2");
            a.setUndefinedProperty("aStringData");
           
            ocm.insert(a);
            ocm.save();

            
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------
            a = null;
            a = (Atomic) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertNotNull("Boolean object is null", a.getBooleanObject());
            assertTrue("Incorrect boolean object", a.getBooleanObject().booleanValue());
            assertTrue("Incorrect boolean primitive", a.isBooleanPrimitive());
            assertNotNull("Integer Object is null", a.getIntegerObject());
            assertTrue("Incorrect Integer object", a.getIntegerObject().intValue() == 100);
            assertTrue("Incorrect int primitive", a.getIntPrimitive() == 200);
            assertNotNull("String object is null", a.getString());
            assertTrue("Incorrect boolean object", a.getString().equals("Test String"));
            assertNotNull("Byte array object is null", a.getByteArray());
            assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test Byte"));
           
            assertNotNull("date object is null", a.getDate());
            assertTrue("Invalid date", a.getDate().equals(date));           
            assertNotNull("calendar object is null", a.getCalendar());
           
            log.debug("Calendar : " + a.getCalendar().get(Calendar.YEAR) + "-" + a.getCalendar().get(Calendar.MONTH) + "-" + a.getCalendar().get(Calendar.DAY_OF_MONTH));
            assertTrue("Invalid calendar object", a.getCalendar().equals(calendar));
           
            assertNotNull("Double object is null", a.getDoubleObject());
            assertTrue("Incorrect double object", a.getDoubleObject().doubleValue() == 2.12);
            assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23);
           
            assertNotNull("Incorrect input stream primitive", a.getInputStream());
            assertNotNull("Incorrect timestamp", a.getTimestamp());
            assertTrue("Invalid timestamp value ", a.getTimestamp().getTime() == now);           
            assertTrue("Invalid int2boolean value ", a.isInt2boolean());
           
            assertTrue("Invalid namedProperty value ", a.getNamedProperty().equals("ocm:test"));
            assertTrue("Invalid pathProperty value ", a.getPathProperty().equals("/node1/node2"));
            assertTrue("Invalid undefinedProperty value ", ((String) a.getUndefinedProperty()).equals("aStringData"));
            // --------------------------------------------------------------------------------
            // Update the property "namedProperty" with an invalid value
            // --------------------------------------------------------------------------------           
            try
            {
               // update with an incorrect namespace - Should throws an exception
               a.setNamedProperty("unknown:test");              
               ocm.update(a);
               fail("Exception was not triggered with an invalid namespace");
               ocm.save();
            }
            catch (Exception e)
            {
              
               
            }
           
            // --------------------------------------------------------------------------------
            // Update the property "pathProperty" with an invalid value
            // --------------------------------------------------------------------------------           
            try
            {
               // update with an incorrect namespace - Should throws an exception
               a.setPathProperty("//node1");              
               ocm.update(a);
               fail("Exception was not triggered with an invalid path");
               ocm.save();
            }
            catch (Exception e)
            {
              
               
            }
           
            // --------------------------------------------------------------------------------
            // Update the property "undefinedProperty" with an invalid value
            // --------------------------------------------------------------------------------           
            a = null;
            a = (Atomic) ocm.getObject( "/test");

            a.setUndefinedProperty(new Double(1.2));
            ocm.update(a);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------
            a = null;
            a = (Atomic) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            assertTrue("Invalid undefinedProperty value ", ((Double) a.getUndefinedProperty()).doubleValue() == 1.2);
           
        }
        catch (Exception e)
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 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 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

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.