Package org.apache.ojb.odmg.shared

Examples of org.apache.ojb.odmg.shared.Person


        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;
        String lastname = "testStoreThreePersons_2_" + postfix;

        Person father = createPerson(firstnameFather, lastname, null, null);
        Person child_1 = createPerson(firstnameChild_1, lastname, null, null);
        Person child_2 = createPerson(firstnameChild_2, lastname, null, null);

        Person[] children = new Person[]{child_1, child_2};
        father.setChildren(children);
        child_1.setFather(father);
        child_2.setFather(father);

        /*
         lock father then all childs
         */
        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        tx.lock(father, Transaction.WRITE);
        tx.lock(child_2, Transaction.WRITE);
        tx.lock(child_1, Transaction.WRITE);

        tx.commit();
        assertEquals(2, father.getChildren().length);

        tx.begin();
        // make sure all objects are retrieved freshly in subsequent transactions
        ((TransactionImpl) tx).getBroker().clearCache();
        OQLQuery qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        Collection result = (Collection) qry.execute();

        assertEquals("Exactly one element in result set", 1, result.size());
        Person returnedFather = (Person) result.iterator().next();
        // should retrieve new instance
        assertTrue("not same", returnedFather != father);
        Person[] returnedChildren = returnedFather.getChildren();
        assertNotNull(returnedChildren);
        // check original instance again
        assertEquals(2, father.getChildren().length);
        assertEquals(2, returnedChildren.length);
        Person child = returnedChildren[0];
        Person lookupFather = child.getFather();
        assertNotNull(lookupFather);
        assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
        // unfortunately, PersonImpl does not have a suitable equals method.
        assertEquals(
                "children's names are equal",
                Arrays.asList(getFirstNames(returnedChildren)),
                Arrays.asList(getFirstNames(children)));
View Full Code Here


        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;
        String lastname = "testStoreThreePersons_3" + postfix;

        Person father = createPerson(firstnameFather, lastname, null, null);
        Person child_1 = createPerson(firstnameChild_1, lastname, null, null);
        Person child_2 = createPerson(firstnameChild_2, lastname, null, null);

        Person[] children = new Person[]{child_1, child_2};
        father.setChildren(children);
        child_1.setFather(father);
        child_2.setFather(father);

        /*
         lock childs first, then lock father
         TODO: Does not pass - why? A defined lock
         order necessary?
         if this doesn't make sense remove the test
         */
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(child_1, Transaction.WRITE);
        tx.lock(child_2, Transaction.WRITE);
        tx.lock(father, Transaction.WRITE);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        // make sure all objects are retrieved freshly in subsequent transactions
        ((TransactionImpl) tx).getBroker().clearCache();

        OQLQuery qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where lastname=$1");
        qry.bind(lastname);
        Collection result = (Collection) qry.execute();
        assertEquals(3, new ArrayList(result).size());


        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        result = (Collection) qry.execute();
        tx.commit();
        assertEquals("Exactly one element in result set", 1, result.size());

        tx.begin();
        Person returnedFather = (Person) result.iterator().next();
        // should retrieve new instance, cause we clear the cache
        assertTrue("not same instance expected", returnedFather != father);
        Person[] returnedChildren = returnedFather.getChildren();
        assertNotNull(returnedChildren);
        assertEquals(2, returnedChildren.length);
        Person child = returnedChildren[0];
        Person lookupFather = child.getFather();
        assertNotNull(lookupFather);
        assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
        // unfortunately, PersonImpl does not have a suitable equals method.
// comment out, because of child object order problem (it's not a bug, it's bad test writing)
//        assertEquals(
//                "children's names are equal",
//                Arrays.asList(getFirstNames(returnedChildren)),
View Full Code Here

        assertEquals("Exactly one element in result set", 0, result.size());
    }

    private Person createPerson(String firstname, String lastname, Person father, Person mother)
    {
        Person p = new PersonImpl();
        p.setFirstname(firstname);
        p.setLastname(lastname);
        p.setFather(father);
        p.setMother(mother);
        // p.setChildren(null);
        return p;
    }
View Full Code Here

    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        for(int i = 1; i <= CONTROL_SIZE; i++)
        {
            Person aPerson = new PersonImpl();
            aPerson.setFirstname("firstname" + i);
            aPerson.setLastname("lastname" + i);
            database.makePersistent(aPerson);
        }
        tx.commit();
    }
View Full Code Here

    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < COUNT; i++)
        {
            Person aPerson = new PersonImpl();
            aPerson.setFirstname("firstname" + id +"_" + i);
            aPerson.setLastname("lastname" + id +"_" + i);
            database.makePersistent(aPerson);
        }
        tx.commit();
    }
View Full Code Here

     * store an object and then retrieve it by id.
     */
    public void testStoreRetrieveSameTxn() throws Exception
    {
        String name = "testStoreRetrieveSameTxn_" + System.currentTimeMillis();
        Person mum = new PersonImpl();
        mum.setFirstname(name);

        TransactionExt txn = (TransactionExt) odmg.newTransaction();
        txn.begin();
        txn.lock(mum, Transaction.WRITE);
        // System.out.println("locked for write: " + mum);
        txn.commit();

        txn.begin();
        txn.getBroker().clearCache();
        Identity mumId = txn.getBroker().serviceIdentity().buildIdentity(mum);
        Person mum2 = (Person) txn.getBroker().getObjectByIdentity(mumId);
        // System.out.println("retrieved: " + mum2);
        txn.commit();
        assertNotNull(mum2);
        assertEquals(name, mum2.getFirstname());
    }
View Full Code Here

  {
    Transaction tx = odmg.newTransaction();
    tx.begin();
    for (int i = 0; i < COUNT; i++)
    {
      Person aPerson = new PersonImpl();
      aPerson.setFirstname("firstname" + i);
      aPerson.setLastname("lastname" + i);
      database.makePersistent(aPerson);
    }
    tx.commit();
  }
View Full Code Here

        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over " + id_filter);
        }
        tx.commit();
  }
View Full Code Here

        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==5)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 5");
        }
        tx.commit();

        // now we try to reuse OQLQuery
        tx.begin();

        query.bind(new Integer(8));
        query.bind(new Integer(id_filter));
        allPersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        it = allPersons.iterator();
        while (it.hasNext())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==8)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 8");
        }

        // reuse OQLQuery within same tx
        query.bind(new Integer(9));
        query.bind(new Integer(id_filter));
        allPersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        it = allPersons.iterator();
        while (it.hasNext())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==9)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 9");
        }
        tx.commit();
    }
View Full Code Here

          catch (ODMGException ex)
          {
            fail("ODMGException: " + ex.getMessage());
          }
          String name = "testStoreRetrieveSameTxn_" + System.currentTimeMillis();
          Person mum = new PersonImpl();
          mum.setFirstname(name);

          TransactionExt txn = (TransactionExt)odmg.newTransaction();
          txn.begin();
          txn.lock(mum, Transaction.WRITE);
          // System.out.println("locked for write: " + mum);
          txn.commit();

          txn.begin();
          txn.getBroker().clearCache();
          Identity mumId = txn.getBroker().serviceIdentity().buildIdentity(mum);
          Person mum2 = (Person)txn.getBroker().getObjectByIdentity(mumId);
          // System.out.println("retrieved: " + mum2);
          txn.commit();
          db.close();
          assertNotNull(mum2);
          assertEquals(name, mum2.getFirstname());
      }
View Full Code Here

TOP

Related Classes of org.apache.ojb.odmg.shared.Person

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.