Package org.apache.ojb.odmg.shared

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


    /**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");

            List result = (List) 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

        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.
        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

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.