protected String getNextStructId ( final IPerson person , final String prefix ) { final int userId = person . getID ( ) ; return nextStructTransactionOperations . execute ( status -> jdbcOperations . execute ( new ConnectionCallback < String > ( ) { @ Override public String doInConnection ( Connection con ) throws SQLException , DataAccessException { try ( Statement stmt = con . createStatement ( ) ) { String sQuery = "SELECT NEXT_STRUCT_ID FROM UP_USER WHERE USER_ID=" + userId ; logger . debug ( "getNextStructId(): {}" , sQuery ) ; int currentStructId ; try ( ResultSet rs = stmt . executeQuery ( sQuery ) ) { if ( rs . next ( ) ) { currentStructId = rs . getInt ( 1 ) ; } else { throw new SQLException ( "no rows returned for query [" + sQuery + "]" ) ; } } int nextStructId = currentStructId + 1 ; String sUpdate = "UPDATE UP_USER SET NEXT_STRUCT_ID=" + nextStructId + " WHERE USER_ID=" + userId + " AND NEXT_STRUCT_ID=" + currentStructId ; logger . debug ( "getNextStructId(): {}" , sUpdate ) ; stmt . executeUpdate ( sUpdate ) ; return prefix + nextStructId ; } } } ) ) ; }
Return the next available structure id for a user