Package org.odmg

Examples of org.odmg.Transaction


    public void testDoubleAbortTxCall() throws Exception
    {
        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            tx.abort();
            tx.abort();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw e;
View Full Code Here


        }
    }

    public void testInternalCausedRollback() throws Exception
    {
        Transaction tx = odmg.newTransaction();
        String name = "testCheckCacheAfterRollback_"+System.currentTimeMillis();
        try
        {
            tx.begin();

            RollbackObjectOne ro = new RollbackObjectOne();
            ro.setName(name);
            tx.lock(ro, Transaction.WRITE);
            // this should fail
            tx.lock(new Exception(), Transaction.WRITE);

            tx.commit();
            fail("A exception was expected");
        }
        catch(Exception e)
        {
            if(tx != null && tx.isOpen()) tx.abort();
        }
    }
View Full Code Here

    protected void tearDown() throws Exception
    {
        super.tearDown();
        try
        {
            Transaction currentTx = odmg.currentTransaction();
            if(currentTx != null && currentTx.isOpen())
            {
                currentTx.abort();
            }
        }
        catch(Exception e)
        {
        }
View Full Code Here

  }

    private void deleteData(Class target)
      throws Exception
  {
    Transaction tx = odmg.newTransaction();
    tx.begin();
    OQLQuery query = odmg.newOQLQuery();
    query.create("select allStuff from " + target.getName());
    Collection allTargets = (Collection) query.execute();
    Iterator it = allTargets.iterator();
    while (it.hasNext())
    {
      database.deletePersistent(it.next());
    }
    tx.commit();
  }
View Full Code Here

    joe.setFather(father);
    joe.setFirstname("joe");
    joe.setId(joeID);

    Transaction tx = odmg.newTransaction();
    tx.begin();
    database.makePersistent(father);
    database.makePersistent(mother);
    database.makePersistent(jimmy);
    database.makePersistent(joe);
    tx.commit();

        // read using id
    tx = odmg.newTransaction();
    tx.begin();
    query = odmg.newOQLQuery();
    query.create("select person from " + PersonImpl.class.getName() +
           " where (mother.id=$1 or father.id=$2)");
    query.bind(new Integer(motherID));
    query.bind(new Integer(fatherID));
    persons = (List) query.execute();
        assertEquals(2, persons.size());
    tx.commit();

        // read using firstname
        tx = odmg.newTransaction();
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select person from " + PersonImpl.class.getName() +
                     " where (mother.firstname=$1 or father.firstname=$2)");
        query.bind("mom");
        query.bind("dad");
        persons = (List) query.execute();
        assertEquals(2, persons.size());
        tx.commit();
  }
View Full Code Here

    TestClassB b1 = new TestClassB();
    TestClassB b2 = new TestClassB();
    a1.setB(b1);
    a2.setB(b2);

    Transaction tx = odmg.newTransaction();
    tx.begin();
    database.makePersistent(a1);
    database.makePersistent(a2);
    database.makePersistent(b1);
    database.makePersistent(b2);
    tx.commit();
    tx = odmg.newTransaction();
    tx.begin();
    // get the right values
    OQLQuery query = odmg.newOQLQuery();
    query.create("select a from " + TestClassA.class.getName());
    List As = (List) query.execute();
    Iterator asIterator = As.iterator();
    TestClassA temp = null;

    temp = (TestClassA) asIterator.next();
    String bID1 = temp.getB().getOid();
    temp = (TestClassA) asIterator.next();
    String bID2 = temp.getB().getOid();

    query = odmg.newOQLQuery();
    query.create("select a from " + TestClassA.class.getName() +
           " where (b.oid=$1 or b.oid=$2)");
    query.bind(bID1);
    query.bind(bID2);
    As = (List) query.execute();
    assertTrue(As.size() == 2);
    tx.commit();
  }
View Full Code Here

        CollectibleA coll_2 = new CollectibleA(name);

        coll_1.setGatherer(gat_1);
        coll_2.setGatherer(gat_2);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        db.makePersistent(coll_1);
        db.makePersistent(coll_2);
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        OQLQuery query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        Collection result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
            CollectibleA collectible = (CollectibleA) iterator.next();
            Gatherer gat = collectible.getGatherer();
            assertNotNull(gat);
            assertEquals("Gatherer_"+name, gat.getName());
            tx.lock(collectible, Transaction.WRITE);
            collectible.getGatherer().setName("New_"+name);
        }
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
            CollectibleA collectible = (CollectibleA) iterator.next();
            Gatherer gat = collectible.getGatherer();
            assertNotNull(gat);
            assertEquals("New_"+name, gat.getName());
            tx.lock(collectible, Transaction.WRITE);
            collectible.setGatherer(null);
        }
        tx.commit();

        tx.begin();
        ((TransactionExt)tx).getBroker().clearCache();
        query = odmg.newOQLQuery();
        query.create(queryStr);
        query.bind(name);
        result = (Collection) query.execute();
        assertNotNull(result);
        assertEquals(2, result.size());

        for (Iterator iterator = result.iterator(); iterator.hasNext();)
        {
            CollectibleA collectible = (CollectibleA) iterator.next();
            Gatherer gat = collectible.getGatherer();
            assertNull(gat);
        }
        tx.commit();
    }
View Full Code Here

            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)
        {
            t.printStackTrace();
            fail(t.getMessage());
View Full Code Here

    public void doTestStore() throws Exception
    {
        String postfix = "doTestStore_" + System.currentTimeMillis();
        Movie movie = buildMovieWithActors(postfix);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
View Full Code Here

    public void doTestStore_2() throws Exception
    {
        String postfix = "doTestStore_2_" + System.currentTimeMillis();
        Movie movie = buildMovieWithActors(postfix);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        Iterator it = movie.getActors().iterator();
        while(it.hasNext())
        {
            database.makePersistent(it.next());
        }
        database.makePersistent(movie);
        tx.commit();

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(1, resultMovie.size());
        Movie newMovie = (Movie) resultMovie.iterator().next();
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.