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 DatabaseImpl.java ImplementationImpl.java ImplementationJTAImpl.java NarrowTransaction.java
Date Sat, 14 Aug 2004 23:42:38 GMT
arminw      2004/08/14 16:42:38

  Modified:    src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        DatabaseImpl.java ImplementationImpl.java
                        ImplementationJTAImpl.java NarrowTransaction.java
  Log:
  bug fix, in managed environments a Database#open(...) call should not
  expect a running JTA-tx.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.26.2.1  +21 -20    db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/DatabaseImpl.java,v
  retrieving revision 1.26
  retrieving revision 1.26.2.1
  diff -u -r1.26 -r1.26.2.1
  --- DatabaseImpl.java	20 May 2004 11:13:10 -0000	1.26
  +++ DatabaseImpl.java	14 Aug 2004 23:42:37 -0000	1.26.2.1
  @@ -47,7 +47,7 @@
   
       private PBKey pbKey;
       private boolean isOpen;
  -    private ImplementationImpl ojb;
  +    private ImplementationImpl odmg;
       /**
        * the broker instance for persistence operations
        * the named roots map;
  @@ -58,12 +58,20 @@
       {
           nrm = NamedRootsMap.getInstance();
           isOpen = false;
  -        this.ojb = ojb;
  +        this.odmg = ojb;
       }
   
       private TransactionImpl getTransaction()
       {
  -        return TxManagerFactory.instance().getTransaction();
  +        Object result = odmg.currentTransaction();
  +        // TODO: remove this workaround
  +        // In managed environments only wrapped tx are returned, so
  +        // we have to extract the real tx first
  +        if(result instanceof NarrowTransaction)
  +        {
  +            return ((NarrowTransaction) result).getRealTransaction();
  +        }
  +        return (TransactionImpl) result;
       }
   
       /**
  @@ -79,11 +87,6 @@
           return pbKey;
       }
   
  -    public ImplementationImpl getAssociatedImplementation()
  -    {
  -        return ojb;
  -    }
  -
       public boolean isOpen()
       {
           return this.isOpen;
  @@ -124,7 +127,7 @@
               pbKey = broker.getPBKey();
               isOpen = true;
               //register opened database
  -            ojb.registerOpenDatabase(this);
  +            odmg.registerOpenDatabase(this);
               if (log.isDebugEnabled()) log.debug("Open database using PBKey " + pbKey);
           }
           catch (PBFactoryException ex)
  @@ -164,25 +167,23 @@
            * is the associated Tx open? ODMG 3.0 says we can't close the database with an
open Tx pending.
            * check if a tx was found, the tx was associated with database
            */
  -        if ((getTransaction() != null) &&
  -                getTransaction().isOpen() &&
  +        if (odmg.hasOpenTransaction() &&
                   getTransaction().getAssociatedDatabase().equals(this))
           {
  -            String txStatus = TxUtil.getStatusString(getTransaction().getStatus());
  -            TransactionInProgressException ex = new TransactionInProgressException(
  -                    "Database cannot be closed, associated Tx is still open." +
  -                    " Transaction status is '" + txStatus + "'." +
  -                    " Used PBKey was "+getTransaction().getBroker().getPBKey());
  -            log.error(ex);
  +            String msg = "Database cannot be closed, associated Tx is still open." +
  +                    " Transaction status is '" + TxUtil.getStatusString(getTransaction().getStatus())
+ "'." +
  +                    " Used PBKey was "+getTransaction().getBroker().getPBKey();
  +            log.error(msg);
  +            TransactionInProgressException ex = new TransactionInProgressException(msg);
               throw ex;
           }
           isOpen = false;
           // remove the current PBKey
           pbKey = null;
           // if we close current database, we have to notify implementation instance
  -        if (this == ojb.getCurrentDatabase())
  +        if (this == odmg.getCurrentDatabase())
           {
  -            ojb.setCurrentDatabase(null);
  +            odmg.setCurrentDatabase(null);
           }
       }
   
  
  
  
  1.1.2.1   +7 -1      db-ojb/src/java/org/apache/ojb/odmg/ImplementationImpl.java
  
  Index: ImplementationImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ImplementationImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- ImplementationImpl.java	20 May 2004 11:13:10 -0000	1.1
  +++ ImplementationImpl.java	14 Aug 2004 23:42:37 -0000	1.1.2.1
  @@ -143,6 +143,12 @@
           return ojbTxManager.getTransaction();
       }
   
  +    public boolean hasOpenTransaction()
  +    {
  +        TransactionImpl tx = ojbTxManager.getTransaction();
  +        return tx != null ? tx.isOpen() : false;
  +    }
  +
       /**
        * Create a new <code>Database</code> object.
        * @return The new <code>Database</code> object.
  
  
  
  1.2.2.1   +2 -8      db-ojb/src/java/org/apache/ojb/odmg/ImplementationJTAImpl.java
  
  Index: ImplementationJTAImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ImplementationJTAImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- ImplementationJTAImpl.java	20 May 2004 11:13:10 -0000	1.2
  +++ ImplementationJTAImpl.java	14 Aug 2004 23:42:37 -0000	1.2.2.1
  @@ -44,12 +44,6 @@
           super();
       }
   
  -    protected synchronized void registerOpenDatabase(DatabaseImpl newDB)
  -    {
  -        super.registerOpenDatabase(newDB);
  -        beginInternTransaction();
  -    }
  -
       public Database getDatabase(Object obj)
       {
           beginInternTransaction();
  @@ -64,7 +58,7 @@
           since we use proprietary extensions for Transaction interface
           do cast to enhanced interface
           */
  -        return new NarrowTransaction((TransactionExt) super.currentTransaction());
  +        return new NarrowTransaction((TransactionImpl) super.currentTransaction());
       }
   
       public EnhancedOQLQuery newOQLQuery()
  
  
  
  1.10.2.1  +13 -2     db-ojb/src/java/org/apache/ojb/odmg/NarrowTransaction.java
  
  Index: NarrowTransaction.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/NarrowTransaction.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- NarrowTransaction.java	19 Jun 2004 09:21:38 -0000	1.10
  +++ NarrowTransaction.java	14 Aug 2004 23:42:37 -0000	1.10.2.1
  @@ -19,13 +19,24 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
  +/**
  + * Wraps {@link org.odmg.Transaction} in managed environments.
  + *
  + * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  + */
   public class NarrowTransaction implements TransactionExt
   {
  -    private TransactionExt tx;
  +    private TransactionImpl tx;
   
  -    public NarrowTransaction(TransactionExt tx)
  +    public NarrowTransaction(TransactionImpl tx)
       {
           this.tx = tx;
  +    }
  +
  +    public TransactionImpl getRealTransaction()
  +    {
  +        return tx;
       }
   
       public void markDelete(Object anObject)
  
  
  

---------------------------------------------------------------------
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