Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Firebird Open Source J2ee connector - jdbc driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
 
 package org.firebirdsql.jca;
 
 
The class FBLocalTransaction implements LocalTransaction both in the cci and spi meanings. A flag is used to distinguish the current functionality. This class works by delegating the operations to the internal implementations of the XAResource functionality in FBManagedConnection.

Author(s):
David Jencks
Version:
1.0
 
 public class FBLocalTransaction implements FirebirdLocalTransaction,
         javax.resource.cci.LocalTransaction {
 
     protected final FBManagedConnection mc;
 
     protected Xid xid = null;
 
     // used to determine if local transaction events notify
     // ConnectionEventListeners see jca spec section 6.8. Basically
     // not null means this is cci LocalTransaction, null means
     // spi.LocalTransaction.
     protected final ConnectionEvent beginEvent;
 
     protected final ConnectionEvent commitEvent;
 
     protected final ConnectionEvent rollbackEvent;
 
     // should be package!!! perhaps reorganize and eliminate jdbc!!!
         this. = mc;
         if (c == null) {
              = null;
              = null;
              = null;
         } else {
              = new ConnectionEvent(mc,
                     .null);
             .setConnectionHandle(c);
 
              = new ConnectionEvent(mc,
                     .null);
             .setConnectionHandle(c);
 
              = new ConnectionEvent(mc,
                     .null);
             .setConnectionHandle(c);
         }
     }

    
Get the associated Xid.

Returns:
instance of javax.transaction.xa.Xid representing a transaction ID that is managed by this local transaction.
 
     public Xid getXid() {
         return ;
     }

    
Check whether a started transaction is associated with the current database connection.
 
     public boolean inTransaction() throws ResourceException {
         try {
             return .getGDSHelper().inTransaction();
         } catch (GDSException ex) {
             throw new FBResourceException(ex);
         }
     }

    
Begin a local transaction.

Throws:
javax.resource.ResourceException generic exception if operation fails
javax.resource.spi.LocalTransactionException error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException error condition internal to resource adapter
javax.resource.spi.EISSystemException EIS instance specific error condition
    public void begin() throws ResourceException {
        internalBegin();
    }

    
Perform the internal operations to begin a local transaction.

Throws:
javax.resource.ResourceException generic exception if operation fails
javax.resource.spi.LocalTransactionException error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException error condition internal to resource adapter
javax.resource.spi.EISSystemException EIS instance specific error condition
    public void internalBegin() throws ResourceException {
        if ( != null) {
            // throw exception only if xid is known to the managed connection
            if (.isXidActive())
                throw new FBResourceTransactionException(
                        "Local transaction active: can't begin another",
                        .);
        }
         = new FBLocalXid();
        try {
            .internalStart(.);
        } catch (XAException ex) {
             = null;
            throw new FBResourceException(ex);
        } catch (GDSException ex) {
             = null;
            throw new FBResourceException(ex);
        }
        if ( != null)
                );
    }

    
Commit a local transaction.

Throws:
javax.resource.ResourceException generic exception if operation fails
javax.resource.spi.LocalTransactionException error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException error condition internal to resource adapter
javax.resource.spi.EISSystemException EIS instance specific error condition
    public void commit() throws ResourceException {
        internalCommit();
    }

    
Perform the internal processing to commit a local transaction.

Throws:
javax.resource.ResourceException generic exception if operation fails
javax.resource.spi.LocalTransactionException error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException error condition internal to resource adapter
javax.resource.spi.EISSystemException EIS instance specific error condition
    public void internalCommit() throws ResourceException {
        // if there is no xid assigned, but we are still here,
        // that means that automatic commit was called in managed
        // scenario when managed connection was enlisted in global
        // transaction
        if ( == nullreturn;
        synchronized () {
            try {
                .internalEnd(.);
                .internalCommit(true);
            } catch (XAException ex) {
                throw new FBResourceTransactionException(ex.getMessage(), ex);
            } catch (GDSException ex) {
                throw new FBResourceException(ex);
            } finally {
                 = null;
            }
            if ( != null) {
                .notify(
                    .,
                    );
            }
        }
    }

    
Rollback a local transaction.

Throws:
javax.resource.ResourceException - generic exception if operation fails
javax.resource.spi.LocalTransactionException - error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException - error condition internal to resource adapter
javax.resource.spi.EISSystemException - EIS instance specific error condition
    public void rollback() throws ResourceException {
        internalRollback();
    }

    
Perform the internal processing to rollback a local transaction.

Throws:
javax.resource.ResourceException - generic exception if operation fails
javax.resource.spi.LocalTransactionException - error condition related to local transaction management
javax.resource.spi.ResourceAdapterInternalException - error condition internal to resource adapter
javax.resource.spi.EISSystemException - EIS instance specific error condition
    public void internalRollback() throws ResourceException {
        // if there is no xid assigned, but we are still here,
        // that means that automatic commit was called in managed
        // scenario when managed connection was enlisted in global
        // transaction
        if ( == nullreturn;
        synchronized () {
            try {
                .internalEnd(.); // ??? on flags
                                                            // --FBManagedConnection
                                                            // is its own
                                                            // XAResource
                .internalRollback();
            } catch (XAException ex) {
                throw new FBResourceTransactionException(ex.getMessage());
            } catch (GDSException ex) {
                throw new FBResourceTransactionException(ex.getMessage(), ex);
            } finally {
                 = null;
            }
            if ( != null) {
                .notify(
                    .,
                    );
            }
        }
    }
    // This is an intentionally non-implemented xid, so if prepare is called
    // with it, it won't work.
    // Only object identity works for equals!
    public static class FBLocalXid implements Xid {
        private static final int formatId = 0x0102;// ????????????
        private String strValue;
        public FBLocalXid() {
             = "Xid[" + hashCode() + "]";
        }

        
Return the global transaction id of this transaction.
        public byte[] getGlobalTransactionId() {
            return null;
        }

        
Return the branch qualifier of this transaction.
        public byte[] getBranchQualifier() {
            return null;
        }

        
Return the format identifier of this transaction. The format identifier augments the global id and specifies how the global id and branch qualifier should be interpreted.
        public int getFormatId() {
            return ;
        }
        public String toString() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X