Package org.apache.ojb.otm.core

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


    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

   public void testSwizzle4() throws TransactionException, LockingException, PBFactoryException, PersistenceBrokerException
    {
        clearTestData();
        TestClassA a = generateTestData();
    TestClassB b = a.getB();
        Transaction tx = _kit.getTransaction(_conn);

        tx.begin();
        _conn.makePersistent(b);
        _conn.makePersistent(a);
        b.setA(a);
        tx.commit();
        /**
        * clear to start test
        */
        _conn.invalidateAll();
        tx = _kit.getTransaction(_conn);
        tx.begin();
        /**
     * load B
     */
    Identity oidb = _conn.getIdentity(b);
        TestClassB b1 = (TestClassB) _conn.getObjectByIdentity(oidb);
    /**
     * load A
      */
    Identity oida = _conn.getIdentity(a);
    TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oida);
    assertTrue(a1 != null);
    assertTrue(a1.getB().equals(b1));
    assertTrue(b1.getA().equals(a1));
        /**
     * update B
     */
        a.setValue1("a");
        _conn.makePersistent(a);

    /**
     * B, as navigated from A, should be the same as B gotten directly.
     */
    assertTrue(a1.getValue1().equals(a.getValue1()));
        tx.commit();

    /**
     * clear
     */
        clearTestData();
View Full Code Here

     * Cache data must be independent of any objects available to used,
     * otherwise modification of user objects outside transaction will
     * damage cache data
     */
    public void testCacheIndependence() throws Throwable {
        Transaction tx = null;
        Collection addresses = this.getAddresses();
        deleteAddresses(addresses);
        Identity oid;
        Address address = new Address("oldCountry", "oldCity", "oldStreet");

        try {
            tx = _kit.getTransaction(_conn);
            tx.begin();
            _conn.makePersistent(address);
            oid = _conn.getIdentity(address);
            tx.commit();

            address.setStreet("newStreet");

            tx = _kit.getTransaction(_conn);
            tx.begin();
            address = (Address) _conn.getObjectByIdentity(oid);
            assertEquals("Cache was damaged.", "oldStreet", address.getStreet());
            tx.commit();

            address.setStreet("newStreet");

            tx = _kit.getTransaction(_conn);
            tx.begin();
            address = (Address) _conn.getObjectByIdentity(oid, LockType.WRITE_LOCK);
            assertEquals("Cache was damaged.", "oldStreet", address.getStreet());
            tx.commit();

            address.setStreet("newStreet");

            tx = _kit.getTransaction(_conn);
            tx.begin();
            address = (Address) _conn.getObjectByIdentity(oid);
            assertEquals("Cache was damaged.", "oldStreet", address.getStreet());
            tx.commit();
        } catch (Throwable e) {
            if (tx != null) {
                try {
                    tx.rollback();
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
            throw e;
View Full Code Here

                                                address.getStreet());
        }
    }

    private Collection getAddresses() throws Throwable {
        Transaction tx = null;
        Collection addresses;
        try {
            tx = _kit.getTransaction(_conn);
            tx.begin();
            _conn.invalidateAll();
            Query q = QueryFactory.newQuery(Address.class, (Criteria)null);
            addresses = _conn.getCollectionByQuery(q);
            tx.commit();
        } catch (Throwable e) {
            if (tx != null) {
                try {
                    tx.rollback();
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
            throw e;
View Full Code Here

        return addresses;
    }

    private Collection updateAddresses(Collection newAddresses)
            throws Throwable {
        Transaction tx = null;
        Collection oldAddresses;
        try {
            tx = _kit.getTransaction(_conn);
            tx.begin();

            Query q = QueryFactory.newQuery(Address.class, (Criteria)null);
            oldAddresses = _conn.getCollectionByQuery(q);

            Iterator oldAddressesIterator = oldAddresses.iterator();
            while (oldAddressesIterator.hasNext()) {
                Address oldAddress = (Address)oldAddressesIterator.next();
                if (!newAddresses.contains(oldAddress)) {
                    _conn.deletePersistent(oldAddress);
                }
            }

            Iterator newAddressesIterator = newAddresses.iterator();
            while (newAddressesIterator.hasNext()) {
                Address newAddress = (Address)newAddressesIterator.next();
                _conn.makePersistent(newAddress);
            }
            tx.commit();
        } catch (Throwable e) {
            if (tx != null) {
                try {
                    tx.rollback();
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
            throw e;
View Full Code Here

        return newAddresses;
    }

    private Collection deleteAddresses(Collection oldAddresses)
            throws Throwable {
        Transaction tx = null;
        try {
            tx = _kit.getTransaction(_conn);
            tx.begin();

            Iterator oldAddressesIterator = oldAddresses.iterator();
            while (oldAddressesIterator.hasNext()) {
                Address oldAddress = (Address)oldAddressesIterator.next();
                _conn.deletePersistent(oldAddress);
                oldAddressesIterator.remove();
            }
            tx.commit();
        } catch (Throwable e) {
            if (tx != null) {
                try {
                    tx.rollback();
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
            throw e;
View Full Code Here

    private void clearTestData() throws LockingException
    {
        TestClassA a = generateTestData();
        TestClassB b2 = generateAnotherB();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        Identity oid = _conn.getIdentity(a);
        Identity oidb = _conn.getIdentity(a.getB());
        Identity oidb2 = _conn.getIdentity(b2);
        TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
        if (a1 != null)
        {
            _conn.deletePersistent(a1);
        }
        TestClassB b1 = (TestClassB) _conn.getObjectByIdentity(oidb);
        if (b1 != null)
        {
            _conn.deletePersistent(b1);
        }
        b2 = (TestClassB) _conn.getObjectByIdentity(oidb2);
        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);
        if (article != null)
        {
            _conn.deletePersistent(article);
        }
        pg = (ProductGroup) _conn.getObjectByIdentity(oidPG);
        if (pg != null)
        {
            _conn.deletePersistent(pg);
        }
        tx.commit();
    }
View Full Code Here

    List qualifiers = new Vector();
    qualifiers.add(qual1);
    qualifiers.add(qual2);
    paper.setQualifiers(qualifiers);
    Transaction trans = _kit.getTransaction(_conn);
    trans.begin();
    _conn.makePersistent(qual1);
    _conn.makePersistent(qual2);
    _conn.makePersistent(paper);
    Identity paperId = _conn.getIdentity(paper);
    trans.commit();

    // sanity check
    trans = _kit.getTransaction(_conn);
    trans.begin();
    Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
    qualifiers = retPaper.getQualifiers();

    assertEquals(2, qualifiers.size());
    trans.commit();

    return retPaper;
  }
View Full Code Here

      paper.setAuthor("Jonny Myers");
      paper.setDate(now);
      Qualifier qual = new Topic();
      qual.setName("qual " + now);
      paper.setQualifiers(Arrays.asList(new Qualifier[]{qual}));
      Transaction trans = _kit.getTransaction(_conn);
      trans.begin();
      _conn.makePersistent(paper);        // store Paper and intermediary table only
      Identity paperId = _conn.getIdentity(paper);
      trans.commit();

    //  broker.clearCache();
      trans = _kit.getTransaction(_conn);
      trans.begin();
      Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
      assertEquals(0, retPaper.getQualifiers().size());
      trans.commit();
      ;
    }
    finally
    {
      cod.setCascadeStore(autoUpdate);
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.