Package org.apache.ojb.otm.core

Examples of org.apache.ojb.otm.core.Transaction


        Query q;
        Iterator iter;
        /**
        * delete effectiveness first
        */
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        q = QueryFactory.newQuery(Effectiveness.class, crit);
        iter = _conn.getIteratorByQuery(q);
        while (iter.hasNext())
        {
            _conn.deletePersistent(iter.next());
        }
        tx.commit();
        /**
        * then version
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        q = QueryFactory.newQuery(Version.class, crit);
        iter = _conn.getIteratorByQuery(q);
        while (iter.hasNext())
        {
            _conn.deletePersistent(iter.next());
        }
        tx.commit();
        /**
        * the contract
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        q = QueryFactory.newQuery(Contract.class, crit);
        iter = _conn.getIteratorByQuery(q);
        while (iter.hasNext())
        {
            _conn.deletePersistent(iter.next());
        }
        tx.commit();
    }
View Full Code Here


    public void testSwizzle2() throws TransactionException, LockingException, PBFactoryException, PersistenceBrokerException
    {
        clearTestData();
        TestClassA a = generateTestData();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        _conn.makePersistent(a.getB());
        _conn.makePersistent(a);
        tx.commit();
        /**
        * clear to start test
        */
        _conn.invalidateAll();
        /**
        * get A to make it and the related B in cache
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        Identity oid = _conn.getIdentity(a);
        TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
        assertTrue(a1.getB() != null);
        assertTrue(a1.getB().getValue1().equals("hi there"));
        /**
        * everything is good, update b
        */
        tx.commit();

        /**
        * now get B and update it, do NOT get it by traversing A
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        Identity boid = _conn.getIdentity(a.getB());
        TestClassB b1 = (TestClassB) _conn.getObjectByIdentity(boid);
        assertTrue(b1 != null);
        assertTrue(b1.getValue1().equals("hi there"));
        /**
        * everything is good, update b
        */
        _conn.lockForWrite(b1);
        b1.setValue1("goodbye there");
        tx.commit();
        /**
        * make sure b was updated
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        boid = _conn.getIdentity(a.getB());
        b1 = (TestClassB) _conn.getObjectByIdentity(boid);
        assertTrue(b1 != null);
        assertTrue(b1.getValue1().equals("goodbye there"));
        tx.commit();

        /**
        * now get A again and make sure the related B is updated to reflect
        * the new value.
        */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        TestClassA a2 = (TestClassA) _conn.getObjectByIdentity(oid);
        assertTrue(a2.getB() != null);
        assertTrue(a2.getB().getValue1().equals("goodbye there"));
        tx.commit();
        clearTestData();
    }
View Full Code Here

    public void testSwizzleNto1() throws Exception
    {
        clearTestData();
        TestClassA a = generateTestData();
        TestClassB b2 = generateAnotherB();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        _conn.makePersistent(a.getB());
        _conn.makePersistent(a);
        tx.commit();
        /**
         * change B
         */
        tx = _kit.getTransaction(_conn);
        tx.begin();
        Identity oid = _conn.getIdentity(a);
        TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
        _conn.makePersistent(b2);
        a1.setB(b2);
        tx.commit();

        tx = _kit.getTransaction(_conn);
        tx.begin();
        a = (TestClassA) _conn.getObjectByIdentity(oid);
        assertTrue(a.getB() != null);
        assertTrue(a.getB().getValue1().equals("value2"));
        a.setB(null);
        tx.commit();

        tx = _kit.getTransaction(_conn);
        tx.begin();
        a = (TestClassA) _conn.getObjectByIdentity(oid);
        assertTrue(a.getB() == null);
        tx.commit();
    }
View Full Code Here

        if (ojbSkipKnownIssueProblem("OTM-layer has caching issues"))
        {
            return;
        }
        clearTestData();
        Transaction tx = _kit.getTransaction(_conn);
        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);
        tx.begin();
        pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
        pg.getAllArticlesInGroup().clear();
        tx.commit();

        tx = _kit.getTransaction(_conn);
        tx.begin();
        pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
        assertEquals("should be equal", 0, pg.getAllArticlesInGroup().size());
        tx.commit();

        tx = _kit.getTransaction(_conn);
        tx.begin();
        pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
        pg.getAllArticlesInGroup().add(article);
        tx.commit();

        tx = _kit.getTransaction(_conn);
        tx.begin();
        pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
        assertEquals("should be equal", 1, pg.getAllArticlesInGroup().size());
        tx.commit();
        clearTestData();
    }
View Full Code Here

     * deletes all PerformanceArticle created by <code>insertNewArticles</code>.
     */
    protected void deleteArticles() throws Exception
    {
        long start = System.currentTimeMillis();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        for(int i = 0; i < articleCount; i++)
        {
            _conn.deletePersistent(arr[i]);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("deleting " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

     * The number of objects to create is defined by <code>articleCount</code>.
     */
    protected void insertNewArticles() throws Exception
    {
        long start = System.currentTimeMillis();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        for(int i = 0; i < articleCount; i++)
        {
            _conn.makePersistent(arr[i]);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("inserting " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

     * The lookup is done one by one, that is: a primary key based lookup is used.
     */
    protected void readArticles() throws Exception
    {
        long start = System.currentTimeMillis();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        for(int i = 0; i < articleCount; i++)
        {
            Object[] pks = {new Integer(offsetId + i)};
            Identity oid = new Identity(PerformanceArticle.class, PerformanceArticle.class, pks);
            _conn.getObjectByIdentity(oid, LockType.NO_LOCK);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

    protected void readArticlesByCursor() throws Exception
    {
        // clear the cache
        _conn.invalidateAll();

        Transaction tx = _kit.getTransaction(_conn);
        Criteria c = new Criteria();
        c.addBetween("articleId", new Integer(offsetId), new Integer(offsetId + articleCount));
        Query q = new QueryByCriteria(PerformanceArticle.class, c);
        long start = System.currentTimeMillis();
        tx.begin();
        Iterator iter = _conn.getIteratorByQuery(q, LockType.NO_LOCK);
        int fetchCount = 0;
        while(iter.hasNext())
        {
            fetchCount++;
            iter.next();
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

     * All objects are modified and changes are written to the RDBMS with an UPDATE.
     */
    protected void updateExistingArticles() throws Exception
    {
        long start = System.currentTimeMillis();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        // update all objects
        for(int i = 0; i < articleCount; i++)
        {
            _conn.lockForWrite(arr[i]);
            arr[i].setPrice(arr[i].getPrice() * 1.95583);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("updating " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

    {
      return m_baoa;
    }
    else
    {
      Transaction tx = _kit.getTransaction(_conn);
      tx.begin();
      BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
      a.setPk("abc123");
      Identity oid = _conn.getIdentity(a);
      a = (BidirectionalAssociationObjectA) _conn.getObjectByIdentity(oid);
      if (a == null)
      {
        a = new BidirectionalAssociationObjectA();
        a.setPk("abc123");
        _conn.makePersistent(a);
        BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
        b.setPk("xyz987");
        _conn.makePersistent(b);
        a.setRelatedB(b);
        b.setRelatedA(a);
      }
      tx.commit();
      m_baoa = a;
      return m_baoa;
    }
  }
View Full Code Here

TOP

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