Package org.odmg

Examples of org.odmg.Transaction


    }

    protected void setUp() throws Exception
    {
        super.setUp();
        Transaction tx = odmg.newTransaction();
        tx.begin();
        testProductGroup = new ProductGroup();
        testProductGroup.setGroupName("NamedRootsTest_" + System.currentTimeMillis());
        database.makePersistent(testProductGroup);
        tx.commit();
    }
View Full Code Here


        String bindingName = "testDoubleBindInOneTx_" + System.currentTimeMillis();

        Article article = createArticle();
        Article foundArticle = null;

        Transaction tx = odmg.newTransaction();
        tx.begin();
        database.bind(article, bindingName);

        foundArticle = (Article) database.lookup(bindingName);
        assertNotNull(foundArticle);

        foundArticle = null;
        database.unbind(bindingName);
        try
        {
            foundArticle = (Article) database.lookup(bindingName);
            fail("Found unbound DList");
        }
        catch (ObjectNameNotFoundException ex)
        {
            // expected exception
            assertTrue(true);
        }

        database.bind(article, bindingName);
        foundArticle = (Article) database.lookup(bindingName);

        foundArticle = null;
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        foundArticle = (Article) database.lookup(bindingName);
        assertNotNull(foundArticle);
        database.unbind(bindingName);
        tx.commit();
    }
View Full Code Here

    public void testUnBind() throws Exception
    {
        String name = "testUnBind_" + System.currentTimeMillis();

        Transaction tx = odmg.newTransaction();
        //bind object to name
        tx.begin();
        Article example = createArticle();
        database.makePersistent(example);
        tx.commit();

        // 1. perform binding
        tx.begin();
        try
        {
            database.bind(example, name);
            tx.commit();
        }
        catch (ObjectNameNotUniqueException ex)
        {
            tx.abort();
            fail(ex.getMessage());
        }

        // 2. perform unbind
        tx = odmg.newTransaction();
        tx.begin();
        try
        {
            database.unbind(name);
            tx.commit();
        }
        catch (ObjectNameNotFoundException ex)
        {
            tx.abort();
            fail("name " + name + "should be known");
        }

        // 3. check if name is really unknown now
        tx = odmg.newTransaction();
        tx.begin();
        try
        {
            Article value = (Article) database.lookup(name);
            assertNotNull("Should not find unbind name '" + name+"'", value);
            fail("name " + name + " should not be known after unbind");
        }
        catch (ObjectNameNotFoundException ex)
        {
            // OK, expected
            assertTrue(true);
        }
        tx.abort();
    }
View Full Code Here

    }

    protected void setUp() throws Exception
    {
        super.setUp();
        Transaction tx = odmg.newTransaction();
        tx.begin();
        productGroup = new ProductGroup();
        productGroup.setName("DMapTest_" + System.currentTimeMillis() + "_");
        database.makePersistent(productGroup);
        tx.commit();
    }
View Full Code Here

    {
        // create a unique name:
        final String name = "testReadAndStore_" + System.currentTimeMillis();

        // create test objects
        Transaction tx = odmg.newTransaction();
        tx.begin();
        // add objects to list
        for (int i = 0; i < 5; i++)
        {
            tx.lock(createObject(name), Transaction.WRITE);
        }
        tx.commit();

        tx.begin();
        // query test objects
        OQLQuery q = odmg.newOQLQuery();
        q.create("select all from "+DObject.class.getName()+" where name=$1");
        q.bind(name);
        Collection ret = (Collection) q.execute();
        // check result list size
        assertEquals(5, ret.size());
        // do read lock
        for (Iterator it = ret.iterator(); it.hasNext(); )
        {
            tx.lock(it.next(), Transaction.READ);
        }
        // create new list for results
        ArrayList result = new ArrayList();
        result.addAll(ret);
        tx.commit();
    }
View Full Code Here

        // create a unique name:
        final String name = "testAdding_" + System.currentTimeMillis();

        // get DList and fill with objects
        DList list = odmg.newDList();
        Transaction tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < 5; i++)
        {
            DObject a = createObject(name);
            list.add(a);
        }
        // bind the new list
        database.bind(list, name);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        Object obj = database.lookup(name);
        tx.commit();
        assertNotNull("binded DList not found", obj);

        // iterate list
        Iterator iter = list.iterator();
        while (iter.hasNext())
        {
            DObject a = (DObject) iter.next();
            assertNotNull(a);
        }
        assertEquals(5, list.size());

        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
        DList lookedUp = (DList) database.lookup(name);
        tx.commit();
        assertNotNull("binded DList not found", lookedUp);

        //System.out.println("sequence of items in lookedup list:");
        iter = lookedUp.iterator();
        Iterator iter1 = list.iterator();
View Full Code Here

    public void testRemoving() throws Exception
    {
        // create a unique name:
        String name = "testRemoving_" + System.currentTimeMillis();

        Transaction tx = odmg.newTransaction();
        tx.begin();
        DList list = odmg.newDList();
        // bind the list to the name:
        database.bind(list, name);

        for (int i = 0; i < 5; i++)
        {
            DObject a = createObject(name);
            list.add(a);
        }
        assertEquals(5, list.size());
        tx.commit();

        // delete two items
        tx = odmg.newTransaction();
        tx.begin();
        ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
        DList lookedUp = (DList) database.lookup(name);
        assertNotNull("database lookup does not find the named DList", lookedUp);
        assertEquals("Wrong number of list entries", 5, lookedUp.size());
        lookedUp.remove(2);
        lookedUp.remove(1);
        tx.commit();

        // check if deletion was successful
        tx = odmg.newTransaction();
        tx.begin();
        ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
        lookedUp = (DList) database.lookup(name);
        tx.commit();

        assertEquals(3, lookedUp.size());
    }
View Full Code Here

    public void testAddingWithIndex() throws Exception
    {
        // create a unique name:
        String name = "testAddingWithIndex_" + System.currentTimeMillis();

        Transaction tx = odmg.newTransaction();
        tx.begin();
        DList list = odmg.newDList();
        database.bind(list, name);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < 5; i++)
        {
            DObject a = createObject(name);
            list.add(a);
        }

        list.add(2, createObject(name+"_pos2"));
        list.add(0, createObject(name+"_pos0"));
        list.add(7, createObject(name+"_pos7"));
        tx.commit();

        tx.begin();
        ((TransactionImpl) tx).getBroker().clearCache();
        // System.out.println("list: " + list);
        // System.out.println("lookup list: " + db.lookup(name));
        tx.commit();

        //System.out.println("sequence of items in list:");
        Iterator iter = list.iterator();
        DObject a;
        while (iter.hasNext())
        {
            a = (DObject) iter.next();
            assertNotNull(a);
            //System.out.print(a.getArticleId() + ", ");
        }


        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionImpl) tx).getBroker().clearCache();
        DList lookedUp = (DList) database.lookup(name);
        // System.out.println("lookup list: " + lookedUp);
        assertNotNull("database lookup does not find DList", lookedUp);
        assertEquals(8, lookedUp.size());
        iter = lookedUp.iterator();
        while (iter.hasNext())
        {
            a = (DObject) iter.next();
        }
        tx.commit();
    }
View Full Code Here

    public void testDBag() throws Exception
    {
        String name = "testDBag_" + System.currentTimeMillis();

        Transaction tx = odmg.newTransaction();
        tx.begin();
        DBag bag1 = odmg.newDBag();
        DBag bag2 = odmg.newDBag();
        DObject a, b, c, d, e;
        a = createObject(name);
        b = createObject(name);
        c = createObject(name);
        d = createObject(name);
        e = createObject(name);
        bag1.add(a);
        bag1.add(b);
        bag1.add(c);
        bag2.add(b);
        bag2.add(c);
        bag2.add(d);
        bag2.add(e);
        DBag bag3 = bag1.difference(bag2);
        assertEquals("should contain only 1 element", 1, bag3.size());

        bag3 = bag1.intersection(bag2);
        assertEquals("should contain two elements", 2, bag3.size());

        tx.commit();
    }
View Full Code Here

        newProduct.setStock(Integer.parseInt(in));

        // now perform persistence operations

        // 3. open transaction
        Transaction tx = odmg.newTransaction();

        tx.begin();

        // 4. acquire write lock on new object
        tx.lock(newProduct, Transaction.WRITE);

        // 5. commit transaction
        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.