Package org.conserve.objects

Examples of org.conserve.objects.ComplexObject


    // drop all tables in both
    persistOne.dropTable(Object.class);
    persistTwo.dropTable(Object.class);
    // create some objects in the first database
    ComplexObject co = new ComplexObject();
    co.setData(new double[] { 1, 2, 3 });
    co.setSimplestObject(new SimplestObject(5.0));
    persistOne.saveObject(co);
    LessSimpleObject lso = new LessSimpleObject();
    lso.setAge(50L);
    lso.setName("name");
    lso.setValue(6);
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

  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();
View Full Code Here

  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

  public void testInnerMatching() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    SimplestObject so = new SimplestObject();
    so.setFoo(1.0);
    ComplexObject co = new ComplexObject();
    co.setObject(so);
    persist.saveObject(co);
    // close the persistence object
    persist.close();

    // re-open the persistence object
    persist = new PersistenceManager(driver, database, login, password);
    // create a SimplestObject so that no results will match
    so = new SimplestObject();
    so.setFoo(2.0);
    // make sure this matches no results
    ComplexObject search = new ComplexObject();
    search.setObject(so);
    List<ComplexObject> none = persist.getObjectsMatching(search);
    assertEquals(0, none.size());
    // change the search so that one object is returned
    so.setFoo(1.0);
    List<ComplexObject> one = persist.getObjectsMatching(search);
View Full Code Here

  public void testArrayMatching() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a complex object with an Integer array as object
    Integer[] intArray = new Integer[] { 4, 5, 6 };
    ComplexObject co = new ComplexObject();
    co.setObject(intArray);
    persist.saveObject(co);
    // close the persistence object
    persist.close();

    // re-open the persistence object
    persist = new PersistenceManager(driver, database, login, password);
    // create an integer array where all entries but one is null
    Integer[] searchArray = new Integer[3];
    searchArray[2] = 7;
    // make sure this matches no results
    ComplexObject search = new ComplexObject();
    search.setObject(searchArray);
    List<ComplexObject> none = persist.getObjectsMatching(search);
    assertEquals(0, none.size());
    // change the search so that one object is returned
    searchArray[1] = 5;
    searchArray[2] = 6;
View Full Code Here

        new SimplestObject() };
    for (int x = 0; x < array.length; x++)
    {
      array[x].setFoo((double) (x + 1));
    }
    ComplexObject co = new ComplexObject();
    co.setObject(array);
    persist.saveObject(co);
    // close the persistence object
    persist.close();

    // re-open the persistence object
    persist = new PersistenceManager(driver, database, login, password);
    // create an integer array where all entries but one is null
    SimplestObject[] searchArray = new SimplestObject[3];
    searchArray[2] = new SimplestObject();
    searchArray[2].setFoo(2.0);
    // make sure this matches no results
    ComplexObject search = new ComplexObject();
    search.setObject(searchArray);
    List<ComplexObject> none = persist.getObjectsMatching(search);
    assertEquals(0, none.size());
    // change the search so that one object is returned
    searchArray[1] = new SimplestObject();
    searchArray[1].setFoo(2.0);
View Full Code Here

        { new SimplestObject(), new SimplestObject(), new SimplestObject() }, {} };
    for (int x = 0; x < array[1].length; x++)
    {
      array[1][x].setFoo((double) (x + 1));
    }
    ComplexObject co = new ComplexObject();
    co.setObject(array);
    persist.saveObject(co);
    // close the persistence object
    persist.close();

    // re-open the persistence object
    persist = new PersistenceManager(driver, database, login, password);
    // create an integer array where all entries but one is null
    SimplestObject[][] searchArray = new SimplestObject[3][3];
    searchArray[1][2] = new SimplestObject();
    searchArray[1][2].setFoo(2.0);
    // make sure this matches no results
    ComplexObject search = new ComplexObject();
    search.setObject(searchArray);
    List<ComplexObject> none = persist.getObjectsMatching(search);
    assertEquals(0, none.size());
    // change the search so that one object is returned
    searchArray[1][1] = new SimplestObject();
    searchArray[1][1].setFoo(2.0);
View Full Code Here

  @Test
  public void testUpdateComplex() throws Exception
  {
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    // create a complex object
    ComplexObject object = new ComplexObject();
    Integer[] ages = new Integer[] { 1, 2, 3 };
    object.setObject(ages);

    // save it
    persist.saveObject(object);
    // make sure only one object exists
    List<ComplexObject> allObjects = persist.getObjectsMatching(new ComplexObject());
    assertEquals(1, allObjects.size());
    // change the object
    ages[1] = 20;
    // save the object again
    persist.saveObject(object);
    // make sure there's still only one object
    allObjects = persist.getObjectsMatching(new ComplexObject());
    assertEquals(1, allObjects.size());
    // re-open the database connection
    persist.close();
    persist = new PersistenceManager(driver, database, login, password);
    // make sure the object has been changed
    allObjects = persist.getObjectsMatching(new ComplexObject());
    assertEquals(1, allObjects.size());
    ComplexObject first = allObjects.get(0);
    Integer[] databaseAges = (Integer[]) first.getObject();
    assertEquals(1, (int) databaseAges[0]);
    assertEquals(20, (int) databaseAges[1]);
    assertEquals(3, (int) databaseAges[2]);
    assertTrue(databaseAges.length == 3);

    // add another object
    ComplexObject nuObject = new ComplexObject();
    Integer[] nuAges = new Integer[] { 5, 6, 7 };
    nuObject.setObject(nuAges);
    persist.saveObject(nuObject);

    // update the new object
    nuAges[1] = 60;

    // make sure only one object has been modified
    allObjects = persist.getObjectsMatching(new ComplexObject());
    assertEquals(2, allObjects.size());
    first = allObjects.get(0);
    ComplexObject second = allObjects.get(1);
    Integer[] a = (Integer[]) first.getObject();
    Integer[] b = (Integer[]) second.getObject();

    assertTrue((a[0] == 1 && b[0] == 5) || (b[0] == 1 && a[0] == 5));
    assertTrue((a[1] == 20 && b[1] == 60) || (b[1] == 20 && a[1] == 60));
    assertTrue((a[2] == 3 && b[2] == 7) || (b[2] == 3 && a[2] == 7));
View Full Code Here

TOP

Related Classes of org.conserve.objects.ComplexObject

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.