Package org.conserve

Examples of org.conserve.PersistenceManager


  {
    String name = "foo";
    int value = 1;
    Object otherObject = new SimpleObject();
    Object redundantObject = new SimplestObject();
    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);

    // create original objects
    OriginalObject oo = new OriginalObject();
    oo.setName(name);
    oo.setValue(value);
    oo.setOtherObject(otherObject);
    oo.setRedundantObject(redundantObject);
    oo.setArray(new long[]{8,9,10,11});
    pm.saveObject(oo);
    pm.close();

    // change array to long
    pm = new PersistenceManager(driver, database, login, password);
    pm.changeName(OriginalObject.class, ArrayToLong.class);
    pm.close();
    pm = new PersistenceManager(driver, database, login, password);
    pm.updateSchema(ArrayToLong.class);
    pm.close();
    //check that array no longer exist
    pm = new PersistenceManager(driver, database, login, password);
    List<ArrayToLong>res1 = pm.getObjects(ArrayToLong.class, new All());
    assertEquals(1,res1.size());
    ArrayToLong obj1 = res1.get(0);
    assertEquals(0,obj1.getArray());
    //save a long
    obj1.setArray(1);
    pm.saveObject(obj1);
    pm.close();

    //change long to array
    pm = new PersistenceManager(driver, database, login, password);
    pm.changeName(ArrayToLong.class, OriginalObject.class);
    pm.close();
    pm = new PersistenceManager(driver, database, login, password);
    pm.updateSchema(OriginalObject.class);
    pm.close();
    //make sure the array is null
    pm = new PersistenceManager(driver, database, login, password);
    List<OriginalObject>res2 = pm.getObjects(OriginalObject.class, new All());
    assertEquals(1,res2.size());
    OriginalObject obj2  = res2.get(0);
    assertNull(obj2.getArray());
    pm.close();
  }
View Full Code Here


   */
  @Test
  public void testChangeSubclassing() throws Exception
  {

    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);
    // create two OriginalObject, store them.
    pm.saveObject(new OriginalObject());
    pm.saveObject(new OriginalObject());
    // create two NotSubClass, store them
    NotSubClass ns = new NotSubClass();
    ns.setName("foo");
    pm.saveObject(ns);
    ns = new NotSubClass();
    ns.setName("bar");
    pm.saveObject(ns);

    pm.close();
    pm = new PersistenceManager(driver, database, login, password);
    // rename NotSubClass to SubClass
    pm.changeName(NotSubClass.class, SubClass.class);

    pm.close();
    pm = new PersistenceManager(driver, database, login, password);
    // change the database schema
    pm.updateSchema(SubClass.class);

    // search all SubClass, make sure both objects are returned
    List<SubClass> res2 = pm.getObjects(SubClass.class, new All());
    assertEquals(2, res2.size());

    // search all OriginalObject, make sure all objects are returned.
    List<OriginalObject> res3 = pm.getObjects(OriginalObject.class, new All());
    assertEquals(4, res3.size());

    // search all OriginalObject with name "foo", make sure SubClass
    // objects are returned.
    OriginalObject searchObject = new OriginalObject();
    searchObject.setName("foo");
    res3 = pm.getObjects(OriginalObject.class, new Equal(searchObject));
    assertEquals(1, res3.size());
    for (OriginalObject oo : res3)
    {
      assertTrue(oo instanceof SubClass);
    }

    // rename SubClass to to NotSubClass
    pm.changeName(SubClass.class, NotSubClass.class);
    // change the database schema
    pm.updateSchema(NotSubClass.class);

    // search all OriginalObject, make sure both objects are returned.
    res3 = pm.getObjects(OriginalObject.class, new All());
    assertEquals(2, res3.size());
    // search all NotSubClass, make sure both objects are returned
    List<NotSubClass> res1 = pm.getObjects(NotSubClass.class, new All());
    assertEquals(2, res1.size());
    // search NotSubClass, make sure only matchign object is returned
    NotSubClass searchObject2 = new NotSubClass();
    searchObject2.setName("foo");
    res1 = pm.getObjects(NotSubClass.class, new Equal(searchObject2));
    assertEquals(1, res1.size());

    pm.close();

    // TODO: Test changing inheritance of an object that is a property of
    // another object

  }
View Full Code Here

   * Test changing inheritance model.
   */
  @Test
  public void testChangeInheritance() throws Exception
  {
    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);
    // create two OriginalObject, store them.
    pm.saveObject(new OriginalObject());
    pm.saveObject(new OriginalObject());
    // rename OriginalObject to ChangedInheritance
    pm.changeName(OriginalObject.class, ChangedInheritance.class);

    // change the database schema, adding interface Serialized.
    pm.updateSchema(ChangedInheritance.class);

    // search all Serializable, make sure both objects are returned
    List<Serializable> res1 = pm.getObjects(Serializable.class, new All());
    assertEquals(2, res1.size());
    // search all ChangedInheritance, make sure both objects are returned
    List<ChangedInheritance> res2 = pm.getObjects(ChangedInheritance.class, new All());
    assertEquals(2, res2.size());

    // search all OriginalObject, make sure no objects are returned.
    List<OriginalObject> res3 = pm.getObjects(OriginalObject.class, new All());
    assertEquals(0, res3.size());

    // rename ChangedInheritance to OriginalObject, thus removing the
    // interface
    pm.changeName(ChangedInheritance.class, OriginalObject.class);
    // change the database schema
    pm.updateSchema(OriginalObject.class);

    // search all Serializable, make sure no objects are returned
    res1 = pm.getObjects(Serializable.class, new All());
    assertEquals(0, res1.size());
    // search all ChangedInheritance, make sure no objects are returned.
    res2 = pm.getObjects(ChangedInheritance.class, new All());
    assertEquals(0, res2.size());
    // search all OriginalObject, make sure both objects are returned.
    res3 = pm.getObjects(OriginalObject.class, new All());
    assertEquals(2, res3.size());

    pm.close();
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testCopyDown() throws Exception
  {
    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);
    // add two Bottom objects.
    OriginalBottom b1 = new OriginalBottom();
    b1.setFoo(1);
    OriginalBottom b2 = new OriginalBottom();
    b2.setFoo(2);
    pm.saveObject(b1);
    pm.saveObject(b2);

    pm.changeName(OriginalTop.class, ModifiedTop.class);
    pm.changeName(OriginalMiddle.class, ModifiedMiddle.class);
    pm.changeName(OriginalBottom.class, ModifiedBottom.class);

    pm.updateSchema(ModifiedBottom.class);
    pm.close();

    // get all ModifiedBottom with foo==1
    pm = new PersistenceManager(driver, database, login, password);
    ModifiedBottom ot = new ModifiedBottom();
    ot.setFoo(1);
    List<ModifiedBottom> res = pm.getObjectsMatching(ot);
    assertEquals(1, res.size());
    pm.close();
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testCopyUp() throws Exception
  {
    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);
    // add two Bottom objects.
    ModifiedBottom b1 = new ModifiedBottom();
    b1.setFoo(1);
    ModifiedBottom b2 = new ModifiedBottom();
    b2.setFoo(2);
    pm.saveObject(b1);
    pm.saveObject(b2);

    pm.changeName(ModifiedTop.class, OriginalTop.class);
    pm.changeName(ModifiedMiddle.class, OriginalMiddle.class);
    pm.changeName(ModifiedBottom.class, OriginalBottom.class);

    pm.updateSchema(OriginalBottom.class);
    pm.close();

    // get all OriginalTop with foo==1
    pm = new PersistenceManager(driver, database, login, password);
    OriginalTop ot = new OriginalTop();
    ot.setFoo(1);
    List<OriginalTop> res = pm.getObjectsMatching(ot);
    assertEquals(1, res.size());
    pm.close();
  }
View Full Code Here

  }

  @Test
  public void testListObjects() throws Exception
  {
    PersistenceManager pm = new PersistenceManager(driver, database, login, password);
    // drop all tables
    pm.dropTable(Object.class);

    ListContainingObject a = new ListContainingObject();
    a.addStr("1");
    a.addStr("2");
    a.addStr("3");
    a.addStr("4");
    pm.saveObject(a);
    ListContainingObject b = new ListContainingObject();
    b.addStr("5");
    b.addStr("6");
    b.addStr("7");
    b.addStr("8");
    pm.saveObject(b);
    pm.close();

    pm = new PersistenceManager(driver, database, login, password);

    // search
    List<ListContainingObject> res = pm.getObjects(ListContainingObject.class, new All());
    assertEquals(2, res.size());
    for (ListContainingObject r : res)
    {
      assertNotNull(r.getList());
      assertTrue(3 < r.getList().size());
View Full Code Here

TOP

Related Classes of org.conserve.PersistenceManager

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.