private void onConnect ( Connection con , String [ ] sqlCommands ) throws SQLException { final boolean trace = TraceComponent . isAnyTracingEnabled ( ) ; TransactionManager tm = connectorSvc . getTransactionManager ( ) ; Transaction suspendedTx = null ; String currentSQL = null ; Throwable failure = null ; try { UOWCoordinator coord = tm == null ? null : ( ( UOWCurrent ) tm ) . getUOWCoord ( ) ; if ( coord != null && coord . isGlobal ( ) ) suspendedTx = tm . suspend ( ) ; Statement stmt = con . createStatement ( ) ; for ( String sql : sqlCommands ) { currentSQL = sql ; if ( trace && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "execute onConnect SQL" , sql ) ; stmt . execute ( sql ) ; } stmt . close ( ) ; } catch ( Throwable x ) { failure = x ; } if ( suspendedTx != null ) { try { tm . resume ( suspendedTx ) ; } catch ( Throwable x ) { failure = x ; } } if ( failure != null ) { if ( trace && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "failed" , AdapterUtil . stackTraceToString ( failure ) ) ; throw new SQLNonTransientConnectionException ( AdapterUtil . getNLSMessage ( "DSRA4004.onconnect.sql" , currentSQL , dsConfig . get ( ) . id ) , "08000" , 0 , failure ) ; } }
Execute the onConnect SQL commands . The connection won t be enlisted in a WAS transaction yet but it s necessary to suspend and WAS global transaction in order to avoid confusing the DB2 type 2 JDBC driver .