Package org.apache.ojb.odmg.shared

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


        //bind object to name
        tx.begin();

        // get new DList instance
        DList dlist = odmg.newDList();
        Article a1 = createArticle();
        Article a2 = createArticle();
        Article a3 = createArticle();
        dlist.add(a1);
        dlist.add(a2);
        dlist.add(a3);
        database.bind(dlist, bindingName);
        // lookup the named object - DList
        List value = (List) database.lookup(bindingName);
        assertNotNull("Could not lookup object for binding name: "+bindingName, value);
        tx.commit();

        try
        {
            tx.begin();
            database.bind(dlist, bindingName);
            tx.commit();
            fail("We expected a ObjectNameNotUniqueException, but was not thrown");
        }
        catch (ObjectNameNotUniqueException ex)
        {
            // we wait for this exception
            assertTrue(true);
            tx.abort();
        }

        try
        {
            tx.begin();
            tx.getBroker().clearCache();
            database.bind(dlist, bindingName);
            tx.commit();
            fail("We expected a ObjectNameNotUniqueException, but was not thrown");
        }
        catch (ObjectNameNotUniqueException ex)
        {
            // we wait for this exception
            assertTrue(true);
            tx.abort();
        }

        tx.begin();
        List result = (List) database.lookup(bindingName);
        assertNotNull(result);
        assertEquals(3, result.size());
        Article newA1 = (Article) result.get(0);
        assertNotNull(newA1);
        assertEquals(a1.getArticleName(), newA1.getArticleName());
        tx.commit();

        tx.begin();
        // we want to completely remove the named object
        // the persisted DList with all DList entries,
View Full Code Here


    {
        String bindingName = "testBindPersistentCapableObject_" + System.currentTimeMillis();
        TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
        //bind object to name
        tx.begin();
        Article example = createArticle();
        database.bind(example, bindingName);
        Article value = (Article) database.lookup(bindingName);
        assertTrue("Could not lookup object for binding name: "+bindingName, value != null);
        tx.commit();

        try
        {
View Full Code Here

    public void testDoubleBindInOneTx() throws Exception
    {
        String bindingName = "testDoubleBindInOneTx_" + System.currentTimeMillis();

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

        Transaction tx = odmg.newTransaction();
        tx.begin();
        database.bind(article, bindingName);
View Full Code Here

        String bindingName = "testLookup_" + System.currentTimeMillis();
        // clear named roots.
        TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
        //bind object to name
        tx.begin();
        Article example = createArticle();
        database.makePersistent(example);
        tx.commit();

        tx.begin();
        database.bind(example, bindingName);
        tx.commit();

        // TestThreadsNLocks look up
        Article lookedUp1 = null;
        tx = (TransactionImpl) odmg.newTransaction();
        tx.begin();
        // lookup by name binding
        lookedUp1 = (Article) database.lookup(bindingName);
        tx.commit();
View Full Code Here

        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)
        {
View Full Code Here

        {
            tx.begin();

            ProductGroup pg = new ProductGroup();
            pg.setName("PG A");
            Article example = new Article();
            example.setProductGroup(pg);
            pg.addArticle(example);
            db.makePersistent(pg);

            // modify Object after persist call is allowed
            example.setStock(333);
            example.addToStock(47);
            example.addToStock(7);
            example.addToStock(4);

            //System.out.println("now commit all changes...");
            tx.commit();
        }
        catch (Exception ex)
View Full Code Here

            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = 60");
            List results = (List) query.execute();

            Article a = (Article) results.get(0);

            // cross check with PersistenceBroker lookup
            // 1. get OID
            Article example = new Article();
            example.setArticleId(60);
            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());
            // 2. lookup object by OID
            PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
            broker.clearCache();
            Article b = (Article) broker.getObjectByIdentity(oid);

            assertEquals("should be same object", a, b);

            //System.out.println("now commit all changes...");
            tx.commit();
View Full Code Here

            // look it up again
            List newResults = (List) db.lookup(name);

            assertEquals(originalSize, newResults.size());
            Article art = (Article) newResults.get(0);
            assertNotNull(art);
//            OJB.getLogger().info(results);

            tx.commit();
View Full Code Here

            query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
            query.bind(new Integer(30));

            List results = (List) query.execute();

            Article a = (Article) results.get(0);

            //crosscheck with PersistenceBroker lookup
            // 1. get OID
            Article example = new Article();
            example.setArticleId(30);
            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());

            // 2. lookup object by OID
            PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
            broker.clearCache();
            Article b = (Article) broker.getObjectByIdentity(oid);

            assertEquals("should be same object", a, b);

            //System.out.println("now commit all changes...");
            tx.commit();
View Full Code Here

            // retrieve an Article
            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
            query.bind(new Integer(30));
            List results = (List) query.execute();
            Article a = (Article) results.get(0);

            // manipulate metadata
            broker = ((TransactionImpl) tx).getBroker();
            cld = broker.getClassDescriptor(Article.class);
            tablename = cld.getFullTableName();
            cld.setTableName("ELVIS");
            broker.getDescriptorRepository().setClassDescriptor(cld);

            //broker will crash as metadata is corrupt
            a.addToStock(5);
            tx.commit();
            fail("Can commit tx with corrupt metadata");
        }
        catch (Throwable t)
        {
View Full Code Here

TOP

Related Classes of org.apache.ojb.odmg.shared.Article

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.