Package org.odmg

Examples of org.odmg.Transaction


         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)));
        // System.out.println(Arrays.asList(getFirstNames(returnedChildren)));
        tx.commit();

        /*
         delete father then children
         fk-constraints?
         */
        tx.begin();
        database.deletePersistent(returnedFather.getChildren()[0]);
        database.deletePersistent(returnedFather.getChildren()[1]);
        database.deletePersistent(returnedFather);
        tx.commit();

        qry = odmg.newOQLQuery();
        qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
        qry.bind(firstnameFather);
        result = (Collection) qry.execute();
View Full Code Here


        if(ojbSkipKnownIssueProblem()) return;

        int odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsBefore = getDBObjectCountWithNewPB(Project.class);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        //store
        persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransaction", 5));
        persistentStoreObjects(database, getNewProjects("testResultsAfterTransaction", 3));
        //store more
        storeObjects(tx, getNewODMGZoos("testResultsAfterTransaction", 5));
        storeObjects(tx, getNewProjects("testResultsAfterTransaction", 2));
        tx.commit();

        int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsAfter = getDBObjectCountWithNewPB(Project.class);
        int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);

        assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfter);
        assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfter);
        assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfterOQL);
        assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfterOQL);


        //we do twice
        odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsBefore = getDBObjectCountWithNewPB(Project.class);

        //tx should be reusable
        tx.begin();
        //store
        persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransaction", 5));
        persistentStoreObjects(database, getNewProjects("testResultsAfterTransaction", 3));
        //store more
        storeObjects(tx, getNewODMGZoos("testResultsAfterTransaction", 5));
        storeObjects(tx, getNewProjects("testResultsAfterTransaction", 2));
        tx.commit();

        odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsAfter = getDBObjectCountWithNewPB(Project.class);
        odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);
View Full Code Here

    public void testResultsAfterTransactionWithClearedCache() throws Exception
    {
        int odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsBefore = getDBObjectCountWithNewPB(Project.class);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        //store
        persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
        persistentStoreObjects(database, getNewProjects("testResultsAfterTransactionWithClearedCache", 3));
        //store more
        storeObjects(tx, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
        storeObjects(tx, getNewProjects("testResultsAfterTransactionWithClearedCache", 2));
        tx.commit();

        //###### hack we clear cache of PB ########
        PersistenceBroker tmp = PersistenceBrokerFactory.defaultPersistenceBroker();
        tmp.clearCache();
        tmp.close();

        int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsAfter = getDBObjectCountWithNewPB(Project.class);
        int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);

        assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfter);
        assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfter);
        assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfterOQL);
        assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfterOQL);


        //we do twice
        odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsBefore = getDBObjectCountWithNewPB(Project.class);

        //tx should be reusable
        tx.begin();
        //store
        persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
        persistentStoreObjects(database, getNewProjects("testResultsAfterTransactionWithClearedCache", 3));
        //store more
        storeObjects(tx, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
        storeObjects(tx, getNewProjects("testResultsAfterTransactionWithClearedCache", 2));
        tx.commit();

        //###### hack we clear cache of PB ########
        tmp = PersistenceBrokerFactory.defaultPersistenceBroker();
        tmp.clearCache();
        tmp.close();
View Full Code Here

    public void testUserRollback() throws Exception
    {
        int odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsBefore = getDBObjectCountWithNewPB(Project.class);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        storeObjects(tx, getNewODMGZoos("testUserRollback", 10));
        storeObjects(tx, getNewProjects("testUserRollback", 10));
        //we abort tx
        tx.abort();

        int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsAfter = getDBObjectCountWithNewPB(Project.class);
        int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);

        assertEquals("Wrong number of odmgZoos found", odmgZoosBefore, odmgZoosAfter);
        assertEquals("Wrong number of projects found", projectsBefore, projectsAfter);
        assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore), odmgZoosAfterOQL);
        assertEquals("Wrong number of projects found", (projectsBefore), projectsAfterOQL);

        //We do this twice
        odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsBefore = getDBObjectCountWithNewPB(Project.class);

        tx.begin();
        storeObjects(tx, getNewODMGZoos("testUserRollback", 10));
        storeObjects(tx, getNewProjects("testUserRollback", 10));
        //we abort tx
        tx.abort();

        odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsAfter = getDBObjectCountWithNewPB(Project.class);
        odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);
View Full Code Here

    public void testUserRollbackWithCheckpoint() throws Exception
    {
        int odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsBefore = getDBObjectCountWithNewPB(Project.class);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        storeObjects(tx, getNewODMGZoos("testUserRollbackWithCheckpoint", 10));
        // now we store objects to DB
        tx.checkpoint();
        storeObjects(tx, getNewProjects("testUserRollbackWithCheckpoint", 10));
        //we abort tx, all actions after the last checkpoint call should be rollback
        tx.abort();

        int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        int projectsAfter = getDBObjectCountWithNewPB(Project.class);
        int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);

        assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfter);
        assertEquals("Wrong number of projects found", projectsBefore, projectsAfter);
        assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfterOQL);
        assertEquals("Wrong number of projects found", projectsBefore, projectsAfterOQL);

        //***********************
        // do the procedure again
        odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsBefore = getDBObjectCountWithNewPB(Project.class);
        // we reuse current tx
        tx.begin();
        storeObjects(tx, getNewODMGZoos("testUserRollbackWithCheckpoint", 10));
        // now we store objects to DB
        tx.checkpoint();
        storeObjects(tx, getNewProjects("testUserRollbackWithCheckpoint", 10));
        //we abort tx, all actions after the last checkpoint call should be rollback
        tx.abort();

        odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
        projectsAfter = getDBObjectCountWithNewPB(Project.class);
        odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
        projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, Project.class);
View Full Code Here

        return count;
    }

    protected int getDBObjectCountViaOqlQueryUseNewTransaction(Implementation odmg, Class target) throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        query.create("select allProjects from " + target.getName());
        List list = (List) query.execute();
        tx.commit();
        return list.size();
    }
View Full Code Here

        return list.size();
    }

    protected void deleteAll(Implementation odmg, Class target) throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        try
        {
            OQLQuery query = odmg.newOQLQuery();
            query.create("select allObjects from " + target.getName());
            List list = (List) query.execute();
            for (int i = 0; i < list.size(); i++)
            {
                Object obj = list.get(i);
                database.deletePersistent(obj);
            }
        }
        finally
        {
            tx.commit();
        }
    }
View Full Code Here

    // user described test case
    public void testDuplicateLocking() throws Exception
    {
        RollbackObjectOne ro = null;

        Transaction tx = odmg.newTransaction();
        tx.begin();
        ro = new RollbackObjectOne();
        ro.setName("test_step_1");
        tx.lock(ro, Transaction.WRITE);
        tx.lock(ro, Transaction.WRITE);
        tx.commit();

        tx.begin();
        tx.lock(ro, Transaction.WRITE);
        tx.lock(ro, Transaction.WRITE);
        ro.setName("test_step_2");
        tx.commit();

        tx.begin();
        tx.lock(ro, Transaction.WRITE);
        ro.setName("test_step_3");
        tx.lock(ro, Transaction.WRITE);
        tx.commit();
    }
View Full Code Here

    {
        RollbackObjectOne ro = null;
        RollbackObjectOne ro_2 = null;
        String name = "testCheckCacheAfterRollback_"+System.currentTimeMillis();

        Transaction tx = odmg.newTransaction();
        tx.begin();
        ro = new RollbackObjectOne();
        ro.setName(name);
        tx.lock(ro, Transaction.WRITE);

        ro_2 = new RollbackObjectOne();
        ro_2.setName(name);
        tx.lock(ro_2, Transaction.WRITE);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        query.create("select all from " + RollbackObjectOne.class.getName() + " where name like $1");
        query.bind(name);
        List list = (List) query.execute();
        tx.commit();
        assertEquals(2,list.size());

        tx = odmg.newTransaction();
        tx.begin();
        tx.lock(ro, Transaction.WRITE);
        ro = new RollbackObjectOne();
        ro.setDescription(name);

        tx.lock(ro_2, Transaction.WRITE);
        ro_2 = new RollbackObjectOne();
        ro_2.setDescription(name);

        tx.abort();

        tx = odmg.newTransaction();
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select all from " + RollbackObjectOne.class.getName() + " where name like $1");
        query.bind(name);
        list = (List) query.execute();
        tx.commit();
        assertEquals(2,list.size());
        assertNull(((RollbackObjectOne)list.get(0)).getDescription());
        assertNull(((RollbackObjectOne)list.get(1)).getDescription());

        // after tx another tx should be able to lock these objects
View Full Code Here

     * test empty usage of methods
     */
    public void testEmpty() throws Exception
    {
        // get new tx instance each time
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.abort();

        tx = odmg.newTransaction();
        tx.begin();
        tx.checkpoint();
        tx.checkpoint();
        tx.abort();

        tx = odmg.newTransaction();
        tx.begin();
        tx.checkpoint();
        tx.checkpoint();
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        tx.commit();

        // with same tx instance
        tx = odmg.newTransaction();
        tx.begin();
        tx.abort();

        tx.begin();
        tx.checkpoint();
        tx.checkpoint();
        tx.abort();

        tx.begin();
        tx.checkpoint();
        tx.checkpoint();
        tx.commit();

        tx.begin();
        tx.commit();
    }
View Full Code Here

TOP

Related Classes of org.odmg.Transaction

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.