Coverage Report - org.apache.ojb.odmg.ImplementationJTAImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ImplementationJTAImpl
N/A
N/A
1.583
 
 1  
 package org.apache.ojb.odmg;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import org.apache.ojb.broker.OJBRuntimeException;
 19  
 import org.apache.ojb.broker.util.configuration.ConfigurationException;
 20  
 import org.apache.ojb.broker.util.logging.Logger;
 21  
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 22  
 import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
 23  
 import org.odmg.DArray;
 24  
 import org.odmg.DBag;
 25  
 import org.odmg.DList;
 26  
 import org.odmg.DMap;
 27  
 import org.odmg.DSet;
 28  
 import org.odmg.Database;
 29  
 import org.odmg.Implementation;
 30  
 import org.odmg.Transaction;
 31  
 
 32  
 /**
 33  
  * Implementation of the ODMG {@link Implementation} interface for use in
 34  
  * managed enviroments.
 35  
  *
 36  
  * @version $Id: ImplementationJTAImpl.java,v 1.1 2007-08-24 22:17:37 ewestfal Exp $
 37  
  */
 38  
 public class ImplementationJTAImpl extends ImplementationImpl
 39  
 {
 40  
     private Logger log = LoggerFactory.getLogger(ImplementationJTAImpl.class);
 41  
 
 42  
     protected ImplementationJTAImpl()
 43  
     {
 44  
         super();
 45  
     }
 46  
 
 47  
     public Database getDatabase(Object obj)
 48  
     {
 49  
         beginInternTransaction();
 50  
         return this.getCurrentDatabase();
 51  
     }
 52  
 
 53  
     public Transaction currentTransaction()
 54  
     {
 55  
         beginInternTransaction();
 56  
         /*
 57  
         we wrap the intern odmg transaction to avoid unauthorised calls
 58  
         since we use proprietary extensions for Transaction interface
 59  
         do cast to enhanced interface
 60  
         */
 61  
         return new NarrowTransaction((TransactionImpl) super.currentTransaction());
 62  
     }
 63  
 
 64  
     public EnhancedOQLQuery newOQLQuery()
 65  
     {
 66  
         beginInternTransaction();
 67  
         return super.newOQLQuery();
 68  
     }
 69  
 
 70  
     public DList newDList()
 71  
     {
 72  
         beginInternTransaction();
 73  
         return super.newDList();
 74  
     }
 75  
 
 76  
     public DBag newDBag()
 77  
     {
 78  
         beginInternTransaction();
 79  
         return super.newDBag();
 80  
     }
 81  
 
 82  
     public DSet newDSet()
 83  
     {
 84  
         beginInternTransaction();
 85  
         return super.newDSet();
 86  
     }
 87  
 
 88  
     public DArray newDArray()
 89  
     {
 90  
         beginInternTransaction();
 91  
         return super.newDArray();
 92  
     }
 93  
 
 94  
     public DMap newDMap()
 95  
     {
 96  
         beginInternTransaction();
 97  
         return super.newDMap();
 98  
     }
 99  
 
 100  
     /**
 101  
      * Here we start a intern odmg-Transaction to hide transaction demarcation
 102  
      * This method could be invoked several times within a transaction, but only
 103  
      * the first call begin a intern odmg transaction
 104  
      */
 105  
     private void beginInternTransaction()
 106  
     {
 107  
         if (log.isDebugEnabled()) log.debug("beginInternTransaction was called");
 108  
         J2EETransactionImpl tx = (J2EETransactionImpl) super.currentTransaction();
 109  
         if (tx == null) tx = newInternTransaction();
 110  
         if (!tx.isOpen())
 111  
         {
 112  
             // start the transaction
 113  
             tx.begin();
 114  
             tx.setInExternTransaction(true);
 115  
         }
 116  
     }
 117  
 
 118  
     /**
 119  
      * Returns a new intern odmg-transaction for the current database.
 120  
      */
 121  
     private J2EETransactionImpl newInternTransaction()
 122  
     {
 123  
         if (log.isDebugEnabled()) log.debug("obtain new intern odmg-transaction");
 124  
         J2EETransactionImpl tx = new J2EETransactionImpl(this);
 125  
         try
 126  
         {
 127  
             getConfigurator().configure(tx);
 128  
         }
 129  
         catch (ConfigurationException e)
 130  
         {
 131  
             throw new OJBRuntimeException("Cannot create new intern odmg transaction", e);
 132  
         }
 133  
         return tx;
 134  
     }
 135  
 
 136  
     /**
 137  
      * Not supported in managed-environment.
 138  
      */
 139  
     public Transaction newTransaction()
 140  
     {
 141  
         throw new UnsupportedOperationException("Not supported in managed environment");
 142  
     }
 143  
 }