private synchronized void open ( Execution event , String dsn ) throws SQLException , PersistenceException { try { Connection conn ; if ( connection != null ) { return ; } state = "OPENING" ; try { InitialContext ctx = new InitialContext ( ) ; DataSource ds ; if ( dsn == null ) { dsn = event . getDataSource ( ) ; } if ( dsn == null ) { throw new PersistenceException ( "No data source name" ) ; } state = "LOOKING UP" ; ds = dsCache . get ( dsn ) ; if ( ds == null ) { ds = ( DataSource ) ctx . lookup ( dsn ) ; if ( ds != null ) { dsCache . put ( dsn , ds ) ; } } if ( ds == null ) { throw new PersistenceException ( "Could not find data source: " + dsn ) ; } conn = ds . getConnection ( ) ; openTime = System . currentTimeMillis ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "DPTRANSID-" + transactionId + " connection.get - dsn='" + dsn + ' ' ) ; } state = "CONNECTED" ; } catch ( NamingException e ) { logger . error ( "Problem with datasource: " + e . getMessage ( ) ) ; throw new PersistenceException ( e . getMessage ( ) ) ; } conn . setAutoCommit ( false ) ; conn . setReadOnly ( readOnly ) ; connection = conn ; if ( tracking ) { connections . incrementAndGet ( ) ; transactions . put ( new Integer ( transactionId ) , this ) ; } } finally { } }
Opens a connection for the specified execution .