db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg LocalTxManager.java TransactionTable.java
Date Mon, 06 Dec 2004 12:28:38 GMT
arminw      2004/12/06 04:28:38

  Modified:    src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        LocalTxManager.java
  Removed:     src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        TransactionTable.java
  Log:
  make TransactionTable inner class
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.5.2.1   +96 -27    db-ojb/src/java/org/apache/ojb/odmg/LocalTxManager.java
  
  Index: LocalTxManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/LocalTxManager.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- LocalTxManager.java	4 Apr 2004 23:53:38 -0000	1.5
  +++ LocalTxManager.java	6 Dec 2004 12:28:38 -0000	1.5.2.1
  @@ -1,10 +1,5 @@
   package org.apache.ojb.odmg;
   
  -import org.apache.ojb.broker.util.configuration.Configuration;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.odmg.TransactionNotInProgressException;
  -
   /* Copyright 2002-2004 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
  @@ -19,10 +14,23 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
  +import java.util.Hashtable;
  +
  +import org.apache.ojb.broker.util.configuration.Configuration;
  +import org.odmg.Transaction;
  +import org.odmg.TransactionNotInProgressException;
  +
  +/**
  + * In a non-appserver environment, without a transaction manager, we can
  + * safely associate the current ODMG transaction with the calling thread.
  + *
  + * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  + * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  + * @version $Id$
  + */
   public class LocalTxManager implements OJBTxManager
   {
  -    private static Logger log = LoggerFactory.getLogger(LocalTxManager.class);
  -
       /**
        * Internal table which provides mapping between threads and transactions.
        * This is required because a Thread can join a Transaction already in
  @@ -40,15 +48,16 @@
   
       /**
        * Returns the current transaction for the calling thread.
  -     * @throws org.odmg.TransactionNotInProgressException {@link org.odmg.TransactionNotInProgressException}
if no transaction was found.
  +     *
  +     * @throws org.odmg.TransactionNotInProgressException
  +     *          {@link org.odmg.TransactionNotInProgressException} if no transaction was
found.
        */
       public TransactionImpl getCurrentTransaction()
       {
           TransactionImpl tx = (TransactionImpl) tx_table.get(Thread.currentThread());
  -        if (tx == null)
  +        if(tx == null)
           {
  -            throw new TransactionNotInProgressException(
  -                    "Calling method needed transaction, but no transaction found for current
thread :-(");
  +            throw new TransactionNotInProgressException("Calling method needed transaction,
but no transaction found for current thread :-(");
           }
           return tx;
       }
  @@ -62,35 +71,95 @@
           return (TransactionImpl) tx_table.get(Thread.currentThread());
       }
   
  -	/**
  -	 * add the current transaction to the map key'd by the calling thread.
  -	 */
  +    /**
  +     * add the current transaction to the map key'd by the calling thread.
  +     */
       public void registerTx(TransactionImpl tx)
       {
           tx_table.put(Thread.currentThread(), tx);
       }
   
  -	/**
  -	 * remove the current transaction from the map key'd by the calling thread.
  -	 */
  +    /**
  +     * remove the current transaction from the map key'd by the calling thread.
  +     */
       public void deregisterTx(Object token)
       {
           tx_table.remove(Thread.currentThread());
       }
  -    
  -	/**
  -	 * included to keep interface contract consistent.
  -	 */
  +
  +    /**
  +     * included to keep interface contract consistent.
  +     */
       public void abortExternalTx(TransactionImpl odmgTrans)
       {
  -    	/**
  -    	 * no op
  -    	 */
  +        /**
  +         * no op
  +         */
       }
  -    
  +
       public void configure(Configuration config)
       {
  -    	
  +
  +    }
  +
  +
  +    //=======================================================
  +    // inner class
  +    //=======================================================
  +    /**
  +     * TransactionTable provides a mapping between the calling
  +     * thread and the Transaction it is currently using.
  +     * One thread can be joined with one transaction at
  +     * a certain point in time. But a thread can join with
  +     * different transactions subsequently.
  +     * This mapping from threads to Transactions is based on ODMG.
  +     *
  +     * @author Thomas Mahler & David Dixon-Peugh
  +     */
  +    static final class TransactionTable
  +    {
  +        /**
  +         * the internal Hashtable mapping Transactions to threads
  +         */
  +        private Hashtable m_table = new Hashtable();
  +
  +        /**
  +         * Creates new TransactionTable
  +         */
  +        public TransactionTable()
  +        {
  +        }
  +
  +        /**
  +         * Retreive a Transaction associated with a thread.
  +         *
  +         * @param key_thread The thread to lookup.
  +         * @return The transaction associated with the thread.
  +         */
  +        public Transaction get(Thread key_thread)
  +        {
  +            return (Transaction) m_table.get(key_thread);
  +        }
  +
  +        /**
  +         * Store the Thread/Transaction pair in the TransactionTable
  +         *
  +         * @param key_thread Thread that the transaction will be associated to
  +         * @param value_tx   Transaction to be associated with the thread
  +         */
  +        public void put(Thread key_thread, Transaction value_tx)
  +        {
  +            m_table.put(key_thread, value_tx);
  +        }
  +
  +        /**
  +         * Remove the entry for the thread
  +         *
  +         * @param key_thread Thread to be removed.
  +         */
  +        public void remove(Thread key_thread)
  +        {
  +            m_table.remove(key_thread);
  +        }
       }
  -    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message