Package org.apache.ojb.otm.core

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


     * bound to.
     */
    public Transaction getTransaction(OTMConnection conn)
    {
        TransactionFactory txFactory = getTransactionFactory();
        Transaction tx = txFactory.getTransactionForConnection(conn);
        tx.setKit(this);
        return tx;
    }
View Full Code Here


      else
        msg.append(" null. Make sure you pass a non-null OTMConnection to this method. An OTMConnection can be acquired by calling acquireConnection (PBKey pbKey)");
            throw new TransactionFactoryException(msg.toString());
        }

        Transaction tx = (Transaction) _transactionMap.get(connection);
        if (tx == null)
        {
            tx = new Transaction();
            _transactionMap.put(connection, tx);
        }
        // ensure that this connection is registered into this transaction
        tx.registerConnection(connection);
        return tx;
    }
View Full Code Here

        if (jtaTx == null)
        {
            throw new TransactionFactoryException("Unable to get the JTA Transaction");
        }

        Transaction tx = (Transaction) _transactionMap.get(jtaTx);
        if (tx == null)
        {
            tx = new Transaction();
            _transactionMap.put(jtaTx, tx);
        }

        // ensure that this connection is registered into this transaction
        tx.registerConnection(baseConnection);
        return tx;
  }
View Full Code Here

     * @see org.apache.ojb.otm.lock.TransactionIsolation#readLock(Transaction, ObjectLocks)
     */
    public void readLock(Transaction tx, ObjectLock lock)
        throws LockingException
    {
        Transaction writer = lock.getWriter();
        if (writer == null)
        {
            lock.readLock(tx);
            if (lock.getWriter() != null)
            {
View Full Code Here

                readLock(tx, lock);
            }
        }
        else
        {
            Transaction reader = (Transaction) readers.iterator().next();

            if (reader != tx) {
                lock.waitForTx(reader);
            }
        }
View Full Code Here

            readLock(tx, lock);
            writeLock(tx, lock);
        }
        else
        {
            Transaction reader = (Transaction) readers.iterator().next();
            if (reader == tx)
            {
                lock.writeLock(tx);
            }
            else
View Full Code Here

     * @see org.apache.ojb.otm.lock.isolation.TransactionIsolation#readLock(Transaction, ObjectLock)
     */
    public void readLock(Transaction tx, ObjectLock lock)
        throws LockingException
    {
        Transaction writer = lock.getWriter();
        if (writer == null)
        {
            lock.readLock(tx);
            if (lock.getWriter() != null)
            {
View Full Code Here

       
        if (!readers.isEmpty())
        {
            for (Iterator it = readers.iterator(); it.hasNext(); )
            {
                Transaction reader = (Transaction) it.next();

                if (reader != tx)
                {
                    lock.waitForTx(reader);
                    writeLock(tx, lock);
View Full Code Here

        createTestData();
        /**
        * first get the contract object.
        */
        PersistenceBrokerFactory.defaultPersistenceBroker().clearCache();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        Criteria crit = new Criteria();
        crit.addEqualTo("pk", "C" + TIME);
        Query q = QueryFactory.newQuery(Contract.class, crit);
        Iterator it = _conn.getIteratorByQuery(q, LockType.WRITE_LOCK);
        Object retval = null;
        RelatedToContract r2c = new RelatedToContract();
        r2c.setPk("R2C" + TIME);
        r2c.setRelatedValue1("matt");
        r2c.setRelatedValue2(34);
        r2c.setRelatedValue3(new Timestamp(TIME));
        _conn.makePersistent(r2c);
        while (it.hasNext())
        {
            retval = it.next();
            ((Contract) retval).setRelatedToContract(r2c);
        }
        tx.commit();
        r2c = null;
        tx = _kit.getTransaction(_conn);
        tx.begin();
        crit = new Criteria();
        crit.addEqualTo("pk", "E" + TIME);
        q = QueryFactory.newQuery(Effectiveness.class, crit);
        it = _conn.getIteratorByQuery(q);
        retval = null;
        while (it.hasNext())
        {
            retval = it.next();
        }
        tx.commit();
        assertTrue("contract object should have a RelatedToContract instance attached", ((Effectiveness) retval).getVersion().getContract().getRelatedToContract() != null);
    }
View Full Code Here

   public void testSwizzle3() throws TransactionException, LockingException, PBFactoryException, PersistenceBrokerException
    {
        clearTestData();
        TestClassA a = generateTestData();
        Transaction tx = _kit.getTransaction(_conn);
        tx.begin();
        _conn.makePersistent(a.getB());
        _conn.makePersistent(a);
    TestClassB b = a.getB();
        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);
        assertTrue(b1 != null);
    /**
     * load A
      */
    Identity oida = _conn.getIdentity(a);
    TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oida);

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

    /**
     * clear
     */
        clearTestData();
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.