Package org.conserve

Examples of org.conserve.PersistenceManager


    // deleteAll();
  }

  protected void deleteAll() throws SQLException
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    persist.deleteObjects(new Object());// clear everything
    persist.close();
  }
View Full Code Here


   * {@link org.conserve.PersistenceManager#saveObject(java.lang.Object)}.
   */
  @Test
  public void testAddSimplestObject() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a test object
    SimplestObject so = new SimplestObject();
    so.setFoo(0.67);
    persist.saveObject(so);
    persist.close();
  }
View Full Code Here

   * {@link org.conserve.PersistenceManager#saveObject(java.lang.Object)}.
   */
  @Test
  public void testAddObject() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a test object
    SimpleObject so = new SimpleObject();
    so.setAge(1000L);
    so.setCount(3);
    so.setName("foo bar");
    so.setScale(0.67);
    persist.saveObject(so);
    LessSimpleObject lso = new LessSimpleObject();
    lso.setAge(1000000L);
    lso.setCount(123456);
    lso.setKey((short) 99);
    lso.setName("j random");
    lso.setScale(-9.0);
    persist.saveObject(lso);
    // insert the same object again
    persist.saveObject(lso);
    // new less-simple object
    persist.close();
  }
View Full Code Here

   *
   */
  @Test
  public void testGetObjectFromInterface() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a test object
    SimpleObject so = new SimpleObject();
    so.setAge(1000L);
    so.setCount(3);
    so.setName("foo bar");
    so.setScale(0.67);
    persist.saveObject(so);
    LessSimpleObject lso = new LessSimpleObject();
    lso.setAge(1000000L);
    lso.setCount(123456);
    lso.setKey((short) 99);
    lso.setName("j random");
    lso.setScale(-9.0);
    persist.saveObject(lso);
    // insert the same object again
    persist.saveObject(lso);
    persist.close();

    persist = new PersistenceManager(driver, database, login, password);
    // try getting all the objects
    List<BaseInterface> obs = persist.getObjects(BaseInterface.class, new All());
    assertEquals(1, obs.size());
    persist.close();
  }
View Full Code Here

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

    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a test object
    SimpleObject so = new SimpleObject();
    so.setAge(1000L);
    so.setCount(3);
    so.setName("foo bar");
    so.setScale(0.67);
    persist.saveObject(so);
    LessSimpleObject lso = new LessSimpleObject();
    lso.setAge(1000000L);
    lso.setCount(123456);
    lso.setKey((short) 99);
    lso.setName("j random");
    lso.setScale(-9.0);
    persist.saveObject(lso);
    // insert the same object again
    persist.saveObject(lso);
    persist.close();

    persist = new PersistenceManager(driver, database, login, password);
    // try getting all the objects
    SimpleObject pattern = new SimpleObject();
    pattern.setCount(3);
    List<SimpleObject> obs = persist.getObjects(SimpleObject.class, new GreaterOrEqual(pattern));
    assertEquals(2, obs.size());
    pattern.setCount(4);
    obs = persist.getObjects(SimpleObject.class, new GreaterOrEqual(pattern));
    assertEquals(1, obs.size());
    pattern.setCount(3);
    List<LessSimpleObject> obs2 = persist.getObjects(LessSimpleObject.class, new GreaterOrEqual(pattern));
    assertEquals(1, obs2.size());

    // assert that two objects are equal if they are the result of the same
    // search
    List<LessSimpleObject> obs3 = persist.getObjects(LessSimpleObject.class, new GreaterOrEqual(pattern));
    assertEquals(obs2.get(0), obs3.get(0));

    persist.close();
  }
View Full Code Here

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

    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a test object
    SimpleObject so = new SimpleObject();
    so.setAge(1000L);
    so.setCount(3);
    so.setName("foo bar");
    so.setScale(0.67);
    persist.saveObject(so);
    LessSimpleObject lso = new LessSimpleObject();
    lso.setAge(1000000L);
    lso.setCount(123456);
    lso.setKey((short) 99);
    lso.setName("j random");
    lso.setScale(-9.0);
    persist.saveObject(lso);
    // insert the same object again
    persist.saveObject(lso);
    persist.close();

    persist = new PersistenceManager(driver, database, login, password);
    // try deleting one object
    List<Object> allObjects = persist.getObjectsMatching(new Object());
    assertEquals(2, allObjects.size());
    // delete one LessSimpleObject
    SimpleObject pattern = new LessSimpleObject();
    persist.deleteObjects(LessSimpleObject.class, new GreaterOrEqual(pattern));
    allObjects = persist.getObjectsMatching(new Object());
    assertEquals(1, allObjects.size());
    // delete all objects
    persist.deleteObjects(new Object());
    allObjects = persist.getObjectsMatching(new Object());
    assertTrue(allObjects.isEmpty());
    persist.close();
  }
View Full Code Here

   *
   */
  @Test
  public void testAddComplexObject() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);

    ComplexObject co = new ComplexObject(new double[] { 1.1, 2.2, 3.3 });
    LessSimpleObject so = new LessSimpleObject();
    so.setScale(0.67);
    co.setObject(so);
    SimplestObject sto = new SimplestObject();
    sto.setFoo(9999.6);
    co.setSimplestObject(sto);
    persist.saveObject(co);
    ComplexObject co2 = new ComplexObject(co.getData());
    co2.setObject(so);
    co2.setSimplestObject(sto);
    persist.saveObject(co2);
    persist.close();
    persist = new PersistenceManager(driver, database, login, password);
    // List<Object> allList = persist.getObjects(new Object());
    // assertEquals(4, allList.size());
    List<ComplexObject> complexList = persist.getObjectsMatching(new ComplexObject());
    assertEquals(2, complexList.size());
    ComplexObject a = complexList.get(0);
    ComplexObject b = complexList.get(1);
    assertEquals(a.getData(), b.getData());
    assertTrue(a.getData() != null);
    assertEquals(3, a.getData().length);
    assertTrue(a.getData()[2] == 3.3);
    persist.close();
  }
View Full Code Here

   */
  @Test
  public void testComplexArray() throws Exception
  {
    // create the database connection
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);

    ComplexObject co1 = new ComplexObject(new double[] { 1.1, 2.2, 3.3, 4.4 });
    persist.saveObject(co1);

    // create an array of complex objects
    ComplexArrayObject cao = new ComplexArrayObject();
    ComplexObject[] coArray = new ComplexObject[3];
    for (int x = 0; x < coArray.length; x++)
    {
      ComplexObject co = new ComplexObject();
      co.setData(new double[] { x, x * 2, x * 3 });
      SimpleObject so = new SimpleObject();
      so.setAge((long) x);
      co.setObject(so);
      coArray[x] = co;
    }
    cao.setData(coArray);
    persist.saveObject(cao);
    persist.close();
    persist = new PersistenceManager(driver, database, login, password);
    List<ComplexArrayObject> res = persist.getObjectsMatching(new ComplexArrayObject());
    assertEquals(1, res.size());
    ComplexArrayObject ob1 = res.get(0);
    assertEquals(3, ob1.getData().length);
    persist.close();

  }
View Full Code Here

   */
  @Test
  public void testDeleteComplexObject() throws Exception
  {
    // create the database connection
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);

    ComplexObject co1 = new ComplexObject(new double[] { 1.1, 2.2, 3.3, 4.4 });
    // saving the object gives it an outside reference
    persist.saveObject(co1);

    // create an array of complex objects
    ComplexObject[] coArray = new ComplexObject[3];
    for (int x = 0; x < coArray.length - 1; x++)
    {
      ComplexObject co = new ComplexObject();
      co.setData(new double[] { x, x * 2, x * 3 });
      SimpleObject so = new SimpleObject();
      so.setAge((long) x);
      co.setObject(so);
      coArray[x] = co;
    }
    // one of the complex objects in the array has an outside reference
    coArray[2] = co1;

    ComplexArrayObject cao = new ComplexArrayObject();
    cao.setData(coArray);
    persist.saveObject(cao);
    persist.close();

    // check that there is one ComplexArrayObject
    persist = new PersistenceManager(driver, database, login, password);
    List<ComplexArrayObject> res = persist.getObjectsMatching(new ComplexArrayObject());
    assertEquals(1, res.size());
    ComplexArrayObject ob1 = res.get(0);
    // check that the ComplexArrayObject contains 3 ComplexObjects
    assertEquals(3, ob1.getData().length);
    persist.close();

    persist = new PersistenceManager(driver, database, login, password);
    persist.deleteObjects(new ComplexArrayObject());
    List<ComplexObject> tmp = persist.getObjectsMatching(new ComplexObject());
    assertEquals(1, tmp.size());
    persist.close();
  }
View Full Code Here

   *
   */
  @Test
  public void testArrayOfArrays() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    ComplexObject co = new ComplexObject();
    SimplestObject[][][] array = new SimplestObject[1][1][1];
    for (int x = 0; x < array.length; x++)
    {
      for (int y = 0; y < array[x].length; y++)
      {
        array[x][y][0] = new SimplestObject();
      }
    }
    co.setObject(array);
    persist.saveObject(co);
    ComplexObject co2 = new ComplexObject();
    SimplestObject[][][] array2 = new SimplestObject[1][][];
    array2[0] = array[0];
    co2.setObject(array2);
    persist.saveObject(co2);
    persist.close();
    persist = new PersistenceManager(driver, database, login, password);
    List<ComplexObject> cos = persist.getObjectsMatching(new ComplexObject());
    assertEquals(2, cos.size());
    co = cos.get(0);
    SimplestObject[][][] resArray = (SimplestObject[][][]) co.getObject();
    assertTrue(resArray != null);
    assertEquals(1, resArray.length);
    assertEquals(1, resArray[0].length);
    assertEquals(1, resArray[0][0].length);
    assertTrue(resArray[0][0][0] != null);
    co2 = cos.get(1);
    SimplestObject[][][] resArray2 = (SimplestObject[][][]) co2.getObject();
    assertTrue(resArray != resArray2);
    assertArrayEquals(resArray[0], resArray2[0]);

    persist.close();
  }
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.