Package org.apache.ojb.odmg.shared

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


        String postfix = "_" + System.currentTimeMillis();
        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;

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

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

        /*
         * lock only the father, let OJB do the rest
         */
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(father, Transaction.WRITE);
        tx.commit();

        // without running tx, should not take effect
        father.setChildren(null);
        father.setFirstname(null);

        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);
        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 postfix = "_" + System.currentTimeMillis();
        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;

        Person father = createPerson(firstnameFather, "testStoreThreePersons_2", null, null);
        Person child_1 = createPerson(firstnameChild_1, "testStoreThreePersons_2", null, null);
        Person child_2 = createPerson(firstnameChild_2, "testStoreThreePersons_2", 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
         */
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(father, Transaction.WRITE);
        tx.lock(child_2, Transaction.WRITE);
        tx.lock(child_1, Transaction.WRITE);
        tx.commit();

        // without running tx, should not take effect
        father.setChildren(null);
        father.setFirstname(null);

        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);
        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 postfix = "_" + System.currentTimeMillis();
        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;

        Person father = createPerson(firstnameFather, "testStoreThreePersons_3", null, null);
        Person child_1 = createPerson(firstnameChild_1, "testStoreThreePersons_3", null, null);
        Person child_2 = createPerson(firstnameChild_2, "testStoreThreePersons_3", 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();

        // without running tx, should not take effect
        father.setChildren(null);
        father.setFirstname(null);

        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, cause we clear the cache
        assertTrue("not same", 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.
        assertEquals(
                "children's names are equal",
                Arrays.asList(getFirstNames(returnedChildren)),
                Arrays.asList(getFirstNames(children)));
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

          catch (ODMGException ex)
          {
            fail("ODMGException: " + ex.getMessage());
          }

          Person mum = new PersonImpl();
          TransactionImpl txn = (TransactionImpl)odmg.newTransaction();
          txn.begin();
          txn.lock(mum, Transaction.WRITE);
          System.out.println("locked for write: " + mum);
          Identity mumId = new Identity(mum, txn.getBroker());
          txn.commit();
          txn.begin();

          Person mum2 = (Person)txn.getObjectByIdentity(mumId);
          System.out.println("retrieved: " + mum2);
          txn.commit();
          db.close();
        }
        catch (Exception exc)
View Full Code Here

  {
    Transaction tx = odmg.newTransaction();
    tx.begin();
    for (int i = 0; i < COUNT; i++)
    {
      Person aPerson = new PersonImpl();
      aPerson.setId(i);
      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

    /**TestThreadsNLocks state transition of modification states*/
    public void testLoading()
    {
        try
        {
            Person mum = new PersonImpl();
            mum.setFirstname("Macy");
            mum.setLastname("Gray");

            Person dad = new PersonImpl();
            dad.setFirstname("Paul");
            dad.setLastname("Gray");

            Person kevin = new PersonImpl();
            kevin.setFirstname("Kevin");
            kevin.setLastname("Gray");
            kevin.setMother(mum);
            kevin.setFather(dad);

            Transaction tx = odmg.newTransaction();
            tx.begin();
            tx.lock(kevin, Transaction.WRITE);
            tx.commit();

            tx = odmg.newTransaction();
            tx.begin();
            ((HasBroker) tx).getBroker().clearCache();
            OQLQuery qry = odmg.newOQLQuery();
            qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
            qry.bind("Kevin");

            DList result = (DList) qry.execute();
            Person boy = (Person) result.get(0);
            assertEquals(boy.getFirstname(), kevin.getFirstname());
            assertEquals(boy.getFather().getFirstname(), dad.getFirstname());
            assertEquals(boy.getMother().getFirstname(), mum.getFirstname());

            tx.commit();
        }
        catch (Throwable t)
        {
View Full Code Here

        String firstnameFather = "Father" + postfix;
        String firstnameChild_1 = "Child_One" + postfix;
        String firstnameChild_2 = "Child_Two" + postfix;
        String lastname = "testStoreThreePersons_1_" + 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 only the father, let OJB do the rest
         */
        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        tx.lock(father, Transaction.WRITE);
        tx.commit();

        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);
        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

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.