private void create ( Connection conn ) throws SQLException { logger . debug ( "enter - create()" ) ; try { PreparedStatement stmt = null ; ResultSet rs = null ; try { stmt = conn . prepareStatement ( CREATE_SEQ ) ; stmt . setString ( INS_NAME , getName ( ) ) ; stmt . setLong ( INS_NEXT_KEY , nextKey ) ; stmt . setLong ( INS_INTERVAL , interval ) ; stmt . setLong ( INS_UPDATE , System . currentTimeMillis ( ) ) ; if ( stmt . executeUpdate ( ) != 1 ) { logger . warn ( "Unable to create sequence " + getName ( ) + "." ) ; sequence = - 1L ; } } finally { if ( rs != null ) { try { rs . close ( ) ; } catch ( SQLException ignore ) { /* ignore */ } } if ( stmt != null ) { try { stmt . close ( ) ; } catch ( SQLException ignore ) { /* ignore */ } } } } finally { logger . debug ( "exit - create()" ) ; } }
Creates a new entry in the database for this sequence . This method will throw an error if two threads are simultaneously trying to create a sequence . This state should never occur if you go ahead and create the sequence in the database before deploying the application . It could be avoided by checking SQL exceptions for the proper XOPEN SQLState for duplicate keys . Unfortunately that approach is error prone due to the lack of consistency in proper XOPEN SQLState reporting in JDBC drivers .