Package org.odmg

Examples of org.odmg.Transaction


    public void doTestStoreComplex() throws Exception
    {
        String postfix = "doTestStoreComplex_" + System.currentTimeMillis();
        Movie movie = buildMovieWithActorsAndBackReferences(postfix);

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

        OQLQuery queryMovie = movieQuery(postfix);
        Collection resultMovie = (Collection) queryMovie.execute();
        assertEquals(3, resultMovie.size());
        Iterator it = resultMovie.iterator();
View Full Code Here


    public void doTestStoreComplex_2() throws Exception
    {
        String postfix = "doTestStoreComplex_2_" + System.currentTimeMillis();
        Movie movie = buildMovieWithActorsAndBackReferences(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(3, resultMovie.size());
        it = resultMovie.iterator();
View Full Code Here

        }

        public void runTestCase() throws Throwable
        {
            threadNumber = newThreadKey();
            Transaction tx = odmg.newTransaction();
            for (int i = 0; i < objectUpdates; i++)
            {
                tx.begin();
                updateObject(tx, obj);
                tx.commit();
            }
        }
View Full Code Here

     * Store the objects and return the result of the query
     * "select gourmets from " + ODMGGourmet.class.getName() + " where gourmetId=$1"
     */
    private int store(Implementation odmg, Database db, ODMGGourmet gourmet) throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        db.makePersistent(gourmet);
        tx.commit();

        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        query = odmg.newOQLQuery();
        query.create("select gourmets from " + ODMGGourmet.class.getName() +
                " where gourmetId=$1");
        query.bind(new Integer(gourmet.getGourmetId()));
        List gourmets = (List) query.execute();
        tx.commit();
        return gourmets.size();
    }
View Full Code Here

        /*
        we expect 2 created 'fish'
        */
        assertEquals(2, fishs.size());

        Transaction tx = odmg.newTransaction();
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select gourmets from " + ODMGGourmet.class.getName() +
                " where name=$1");
        query.bind(doris.getName());
        List result = (List) query.execute();
        assertEquals("We should found a gourmet", 1, result.size());
        ODMGGourmet gourmet = (ODMGGourmet)result.get(0);

        /*
        now we lock main object and add a new reference object
        */
        tx.lock(gourmet, Transaction.WRITE);
        gourmet.addFavoriteFood(goldfish);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select fishs from " + Fish.class.getName() +
                " where (name=$1 or name=$2 or name=$3)");
        query.bind(tuna.getName());
        query.bind(trout.getName());
        query.bind(goldfish.getName());

        tx = odmg.newTransaction();
        tx.begin();
        fishs = (List) query.execute();
        tx.commit();
        assertEquals("seems referenced object was not added (if found <3) ",3, fishs.size());
    }
View Full Code Here

        /*
        we expect 3 created 'fish'
        */
        assertEquals(3, fishs.size());

        Transaction tx = odmg.newTransaction();
        tx.begin();
        query = odmg.newOQLQuery();
        query.create("select gourmets from " + ODMGGourmet.class.getName() +
                " where name=$1");
        query.bind(doris.getName());
        List result = (List) query.execute();
        assertEquals("We should found a gourmet_doris", 1, result.size());
        ODMGGourmet gourmet_doris = (ODMGGourmet)result.get(0);
        assertEquals(3, gourmet_doris.getFavoriteFood().size());

        /*
        now we lock main object and add remove a reference object
        */
        tx.lock(gourmet_doris, Transaction.WRITE);
        List foodList = gourmet_doris.getFavoriteFood();
        foodList.remove(0);
        //gourmet_doris.setFavoriteFood(foodList);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select gourmets from " + ODMGGourmet.class.getName() +
                " where name=$1");
        query.bind(doris.getName());

        tx = odmg.newTransaction();
        tx.begin();
        result = (List) query.execute();
        assertEquals("We should found a gourmet_doris", 1, result.size());
        gourmet_doris = (ODMGGourmet)result.get(0);
        tx.commit();
        assertEquals(
          "We removed one fish, so doris should only have two entries left",
          2, gourmet_doris.getFavoriteFood().size());
    }
View Full Code Here

        return lo;
    }

    private void storeObject(Object obj) throws Exception
    {
        Transaction tx = odmg.newTransaction();

        tx.begin();
        tx.lock(obj, Transaction.WRITE);
        tx.commit();
    }
View Full Code Here

        //System.out.println("TEST: Database closed");
    }

    private void newSite(Implementation odmg, String name, int year, int semester) throws Exception
    {
        Transaction tx = null;
        tx = odmg.newTransaction();
        Site site = null;
        tx.begin();

        site = new Site();
        site.setName(name);
        site.setYear(new Integer(year));
        site.setSemester(new Integer(semester));

        tx.lock(site, Transaction.WRITE);
        tx.commit();
    }
View Full Code Here

        String name = "testSimpleQueryDelete - " + System.currentTimeMillis();

        db.open(databaseName, Database.OPEN_READ_WRITE);
        Site site = new Site();
        site.setName(name);
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(site, Transaction.WRITE);
        tx.commit();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result = (List) query.execute();
        if (result.size() == 0)
        {
            fail("Stored object not found");
        }
        tx.commit();

        tx.begin();
        db.deletePersistent(site);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result2 = (List) query.execute();
        if (result2.size() > 0)
        {
            fail("We should not found deleted objects");
        }
        tx.commit();
    }
View Full Code Here

            /* Create an object */
            Site site = new Site();
            site.setName(name);

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

            /* Retrieve from the object created, and set the year*/
            OQLQuery query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);

            tx.begin();
            List result = (List) query.execute();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNull(site.getYear());
            tx.lock(site, Transaction.UPGRADE);
            site.setYear(new Integer(2003));

            tx.commit();

            /* Flush the cache, and retrieve the object again */
            query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);
            tx.begin();
            ((HasBroker) tx).getBroker().clearCache();
            result = (List) query.execute();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNotNull("year should not be null", site.getYear());
            tx.commit();

            db.close();
        }
        finally
        {
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.