Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.Article


        GUID guid = new GUID();

        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker1.beginTransaction();

        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
        String originalName = a1.getArticleName();
        a1.setArticleName(guid.toString());

// start a second transaction
        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker2.beginTransaction();

        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));

        assertEquals(guid.toString(), a1.getArticleName());
        assertEquals(originalName, a2.getArticleName());
        assertNotSame(a1, a2);


        broker1.commitTransaction();
        broker1.close();
View Full Code Here


        ProductGroup group = new ProductGroup();
        group.setGroupName(name);
        tx.lock(group, Transaction.WRITE);
        for (int i = 0; i < COUNT; i++)
        {
            Article article = createArticle(name);
            group.add(article);
        }
        tx.commit();
        /**
         * 2. query on the article to make sure it is everything we set it up to be.
View Full Code Here

        // if(ojbSkipKnownIssueProblem()) return;
        String name = "testUpdateWithProxy_" + System.currentTimeMillis();

        ProductGroup pg1 = new ProductGroup(null, name + "_1", "a group");
        ProductGroup pg2 = new ProductGroup(null, name + "_2", "a group");
        Article a1 = createArticle(name);
        a1.setProductGroup(pg1);
        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        database.makePersistent(a1);
        database.makePersistent(pg1);
        database.makePersistent(pg2);
        tx.commit();

        tx.begin();
        tx.getBroker().clearCache();
        /**
         * 1. get all articles from groups and add a new article
         */
        OQLQuery query = odmg.newOQLQuery();
        query.create("select productGroup from " + ProductGroup.class.getName() + " where groupName like $1");
        query.bind(name + "%");
        Collection results = (Collection) query.execute();
        assertEquals(2, results.size());
        Iterator it = results.iterator();
        InterfaceProductGroup temp = null;
        /**
         * to each productgroup add an article with a pre-determined name.
         */
        while (it.hasNext())
        {
            Article article = createArticle(name);
            temp = (InterfaceProductGroup) it.next();
            tx.lock(temp, Transaction.WRITE);
            temp.add(article);
            article.setProductGroup(temp);
        }
        tx.commit();

        /**
         * 2. requery and find the articles we added.
View Full Code Here

    /**
     * Create an article with 4 product groups related to it in a 1-N relationship
     */
    protected Article createArticle(String name)
    {
        Article a = Article.createInstance();
        a.setArticleName(name);
        a.setIsSelloutArticle(true);
        a.setMinimumStock(100);
        a.setOrderedUnits(17);
        a.setPrice(0.45);
        //a.setProductGroupId(1);
        a.setStock(234);
        a.setSupplierId(4);
        a.setUnit("bottle");
        return a;
    }
View Full Code Here

        tx.begin();
        ProductGroup pg = new ProductGroup();
        pg.setId(new Integer(77777));
        pg.setName("1");
        _conn.makePersistent(pg);
        Article article = Article.createInstance();
        article.setArticleId(new Integer(77777));
        article.setStock(333);
        pg.add(article);
        article.setProductGroup(pg);
        _conn.makePersistent(article);
        Identity pgOid = _conn.getIdentity(pg);
        tx.commit();

        tx = _kit.getTransaction(_conn);
View Full Code Here

        if (b2 != null)
        {
            _conn.deletePersistent(b2);
        }

        Article article = Article.createInstance();
        article.setArticleId(new Integer(77777));
        ProductGroup pg = new ProductGroup();
        pg.setId(new Integer(77777));
        Identity oidArt = _conn.getIdentity(article);
        Identity oidPG = _conn.getIdentity(pg);
        article = (Article) _conn.getObjectByIdentity(oidArt);
View Full Code Here

     * @throws Throwable
     */
    public void testJustAttachConnections() throws Throwable
    {
        Transaction tx = null;
        Article example;

        OTMConnection conn1 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
        OTMConnection conn2 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
        try
        {
            tx = _kit.getTransaction(conn1);
            tx.begin();

            tx.registerConnection(conn2);

            example = (Article) conn1.getObjectByIdentity(
                    new Identity(Article.class, Article.class,
                                 new Object[]{new Integer(77779)}));
            if (example == null)
            {
                example = Article.createInstance();
                example.setArticleId(new Integer(77779));
            }
            example.setProductGroupId(new Integer(7));
            example.setStock(333);
            example.setArticleName("333");
            conn1.makePersistent(example);

            EnhancedOQLQuery query = conn2.newOQLQuery();
            query.create("select obj from " + Article.class.getName()
                         + " where " + "articleId = " + example.getArticleId());
            Article same = (Article) conn2.getIteratorByOQLQuery(query).next();
            Assert.assertNotNull("Didn't find object in context of transaction", same);

            tx.commit();

        }
View Full Code Here

        GUID guid = new GUID();

        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker1.beginTransaction();

        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
        String originalName = a1.getArticleName();
        a1.setArticleName(guid.toString());

// start a second transaction
        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker2.beginTransaction();

        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));

        assertEquals(guid.toString(), a1.getArticleName());
        assertEquals(originalName, a2.getArticleName());
        assertNotSame(a1, a2);


        broker1.commitTransaction();
        broker1.close();
View Full Code Here

        tx.begin();
        ProductGroup pg = new ProductGroup();
        pg.setId(new Integer(77777));
        pg.setName("1");
        _conn.makePersistent(pg);
        Article article = Article.createInstance();
        article.setArticleId(new Integer(77777));
        article.setStock(333);
        pg.add(article);
        article.setProductGroup(pg);
        _conn.makePersistent(article);
        Identity pgOid = _conn.getIdentity(pg);
        tx.commit();

        tx = _kit.getTransaction(_conn);
View Full Code Here

        if (b2 != null)
        {
            _conn.deletePersistent(b2);
        }

        Article article = Article.createInstance();
        article.setArticleId(new Integer(77777));
        ProductGroup pg = new ProductGroup();
        pg.setId(new Integer(77777));
        Identity oidArt = _conn.getIdentity(article);
        Identity oidPG = _conn.getIdentity(pg);
        article = (Article) _conn.getObjectByIdentity(oidArt);
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.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.