public Connection getConnection ( ) throws FetchException { try { if ( mOpenConnections == null ) { throw new FetchException ( "Repository is closed" ) ; } JDBCTransaction txn = localTransactionScope ( ) . getTxn ( ) ; if ( txn != null ) { // Return the connection used by the current transaction. return txn . getConnection ( ) ; } // Get connection outside lock section since it may block. Connection con = mDataSource . getConnection ( ) ; con . setAutoCommit ( true ) ; mOpenConnectionsLock . lock ( ) ; try { if ( mOpenConnections == null ) { con . close ( ) ; throw new FetchException ( "Repository is closed" ) ; } mOpenConnections . put ( con , null ) ; } finally { mOpenConnectionsLock . unlock ( ) ; } return con ; } catch ( Exception e ) { throw toFetchException ( e ) ; } }
Any connection returned by this method must be closed by calling yieldConnection on this repository .