Package org.apache.ojb.odmg.shared

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


        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();
        try
        {
            database.bind(example, bindingName);
            tx.commit();
        }
        catch (ObjectNameNotUniqueException ex)
        {
            tx.abort();
            fail(ex.getMessage());
        }

        // TestThreadsNLocks look up
        Article lookedUp1 = null;
        tx = (TransactionImpl) odmg.newTransaction();
        tx.begin();
        try
        {
            // lookup by name binding
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

        pg1.setName("BatchModeTest ProductGroup #1");
        database.makePersistent(pg1);

        tx.checkpoint();

        Article a1 = Article.createInstance();
        a1.setArticleName("BatchModeTest Article #1");
        a1.setProductGroup(pg1);
        pg1.addArticle(a1);
        database.makePersistent(a1);

        ProductGroup pg2 = new ProductGroup();
        pg2.setName("BatchModeTest ProductGroup #2");
        database.makePersistent(pg2);

        Article a2 = Article.createInstance();
        a2.setArticleName("BatchModeTest Article #2");
        a2.setProductGroup(pg2);
        pg2.addArticle(a2);

        tx.checkpoint();

        database.deletePersistent(a1);
View Full Code Here

            query.create("select all from " + Article.class.getName());
            // 4. perform the query and store the result in a persistent Collection
            Collection allArticles = (Collection) query.execute();
            // 5. now iterate over the result to print each product
            java.util.Iterator iter = allArticles.iterator();
            Article a = null;
            while (iter.hasNext())
            {
                a = (Article) iter.next();

                if (tx.tryLock(a, Transaction.WRITE))
                {

                    //db.makePersistent(a);
                    //System.out.println(super.getName() + " ---- Lock erhalten & warten"+ a);
                    Thread.sleep(1000);
                    a.setArticleName(super.getName() + a.getArticleId());
                }
                else
                {
                    //System.out.println(super.getName() + " ---- Konnte lock nicht bekommen" + a);
                }
View Full Code Here

    }

    protected Article createArticle(Implementation odmg) throws Exception
    {

        Article a = new Article();
        PersistenceBroker broker = ((HasBroker) odmg.currentTransaction()).getBroker();
        FieldDescriptor fld = broker.getClassDescriptor(Article.class).getFieldDescriptorByName("articleId");
        Integer val = (Integer) broker.serviceSequenceManager().getUniqueValue(fld);

        a.setArticleId(val.intValue());
        a.setArticleName("New Funny Article " + a.getArticleId());
        a.setStock(234);
        a.setProductGroupId(7);

        return a;
    }
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.