Examples of ODMGZoo


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

    {
        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        tx.begin();
        PersistenceBroker broker = tx.getBroker();
        ODMGZoo obj = new ODMGZoo();
        tx.lock(obj, Transaction.WRITE);
        obj.setName("testTransactionFlush");

        tx.flush();

        Criteria crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        Iterator it = broker.getIteratorByQuery(query);
        assertTrue(it.hasNext());
        assertSame(obj, it.next());
View Full Code Here

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

        return list;
    }

    protected ODMGZoo newODMGZoo(String name)
    {
        ODMGZoo odmgZoo = new ODMGZoo();
        ++counter;
        if(name == null)
        {
            odmgZoo.setName("animal_" + counter);
        }
        else
        {
            odmgZoo.setName(name + "_" + counter);
        }
        return odmgZoo;
    }
View Full Code Here

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

        return list;
    }

    protected ODMGZoo newODMGZoo()
    {
        ODMGZoo odmgZoo = new ODMGZoo();
        ++counter;
        odmgZoo.setName("animal " + counter);
        return odmgZoo;
    }
View Full Code Here

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

     * implementing a common interface) are treated correctly
     */
    public void testPolymorphOneToMany()
    {

        ODMGZoo myZoo = new ODMGZoo("London");
        Mammal elephant = new Mammal(37, "Jumbo", 4);
        Mammal cat = new Mammal(11, "Silvester", 4);
        Reptile snake = new Reptile(3, "Kaa", "green");

        myZoo.addAnimal(snake);
        myZoo.addAnimal(elephant);
        myZoo.addAnimal(cat);

        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            database.makePersistent(myZoo);
            tx.commit();

            int id = myZoo.getZooId();

            tx = odmg.newTransaction();
            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select zoos from " + ODMGZoo.class.getName() +
                    " where zooId=$1");
            query.bind(new Integer(id));
            List zoos = (List) query.execute();
            assertEquals(1, zoos.size());
            ODMGZoo zoo = (ODMGZoo) zoos.get(0);
            tx.commit();
            assertEquals(3, zoo.getAnimals().size());


        }
        catch (ODMGException e)
        {
View Full Code Here

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

        String name = "testTransactionFlush_" + System.currentTimeMillis();
        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        tx.begin();
        PersistenceBroker broker = tx.getBroker();
        ODMGZoo obj = new ODMGZoo();
        tx.lock(obj, Transaction.WRITE);
        obj.setName(name);

        tx.flush();

        Criteria crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should find object in DB/cache
        Iterator it = broker.getIteratorByQuery(query);
        assertTrue(it.hasNext());
        ODMGZoo other = (ODMGZoo) it.next();
        assertNotNull(other);
        assertEquals(obj.getZooId(), other.getZooId());
        assertEquals(obj.getName(), other.getName());
        assertFalse(it.hasNext());
        // now we abort tx, so all flushed objects shouldn't be found
        // in further queries
        tx.abort();
View Full Code Here

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

        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        tx.begin();
        PersistenceBroker broker = tx.getBroker();

        ODMGZoo obj = new ODMGZoo();
        obj.setName(name);
        tx.lock(obj, Transaction.WRITE);
        tx.flush();
        // System.err.println("First flush call, insert new object");

        // PB to query
        Criteria crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        Iterator it = broker.getIteratorByQuery(query);
        assertTrue(it.hasNext());
        ODMGZoo other = (ODMGZoo) it.next();
        assertNotNull(other);
        assertEquals(obj.getZooId(), other.getZooId());
        assertEquals(obj.getName(), other.getName());
        assertFalse(it.hasNext());

        /*** Charles : Start ***/
        // Let's flush, change the name and flush again
        tx.flush();
        // System.err.println("Second flush call, nothing to do");
        obj.setName("updated_" + name);
        tx.flush();
        // System.err.println("Third flush call, update");
        OQLQuery q = odmg.newOQLQuery();
        q.create("select zoos from " + ODMGZoo.class.getName() + " where name like $1");
        q.bind("updated_" + name);

        //Redo the query - we should find the object again
        it = ((Collection) q.execute()).iterator();
        assertTrue(it.hasNext());
        other = (ODMGZoo) it.next();
        assertNotNull(other);
        assertEquals(obj.getZooId(), other.getZooId());
        assertEquals(obj.getName(), other.getName());
        assertFalse(it.hasNext());
        /*** Charles : End ***/

        // now we abort tx, so all flushed objects shouldn't be found
        // in further queries
View Full Code Here

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

        return list;
    }

    protected ODMGZoo newODMGZoo(String name)
    {
        ODMGZoo odmgZoo = new ODMGZoo();
        ++counter;
        if(name == null)
        {
            odmgZoo.setName("animal_" + counter);
        }
        else
        {
            odmgZoo.setName(name + "_" + counter);
        }
        return odmgZoo;
    }
View Full Code Here

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

     * implementing a common interface) are treated correctly
     */
    public void testPolymorphOneToMany()
    {

        ODMGZoo myZoo = new ODMGZoo("London");
        Mammal elephant = new Mammal(37, "Jumbo", 4);
        Mammal cat = new Mammal(11, "Silvester", 4);
        Reptile snake = new Reptile(3, "Kaa", "green");

        myZoo.addAnimal(snake);
        myZoo.addAnimal(elephant);
        myZoo.addAnimal(cat);

        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            database.makePersistent(myZoo);
            tx.commit();

            int id = myZoo.getZooId();

            tx = odmg.newTransaction();
            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select zoos from " + ODMGZoo.class.getName() +
                    " where zooId=$1");
            query.bind(new Integer(id));
            List zoos = (List) query.execute();
            assertEquals(1, zoos.size());
            ODMGZoo zoo = (ODMGZoo) zoos.get(0);
            tx.commit();
            assertEquals(3, zoo.getAnimals().size());


        }
        catch (ODMGException e)
        {
View Full Code Here

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

    {
        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        tx.begin();
        PersistenceBroker broker = tx.getBroker();
        ODMGZoo obj = new ODMGZoo();
        tx.lock(obj, Transaction.WRITE);
        obj.setName("testTransactionFlush");

        tx.flush();

        Criteria crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        Iterator it = broker.getIteratorByQuery(query);
        assertTrue(it.hasNext());
        assertSame(obj, it.next());
View Full Code Here

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

        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        tx.begin();
        PersistenceBroker broker = tx.getBroker();

        ODMGZoo obj = new ODMGZoo();
        tx.lock(obj, Transaction.WRITE);
        obj.setName("testTransactionFlush");

        tx.flush();

        Criteria crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        Iterator it = broker.getIteratorByQuery(query);
        assertTrue(it.hasNext());
        assertSame(obj, it.next());
        assertFalse(it.hasNext());

        /*** Charles : Start ***/
        // Let's flush, change the name and flush again
        tx.flush();
        obj.setName("testTransactionFlushCHANGED");
        tx.flush();
        //Redo the query - we should find the object again
        crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        it = broker.getIteratorByQuery(query);
        assertTrue("Should find object",it.hasNext());
        assertSame(obj, it.next());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.