public static boolean checkClientSequences(Properties ctx,int AD_Client_ID,String trxName){
  String sql="SELECT TableName " + "FROM AD_Table t " + "WHERE IsActive='Y' AND IsView='N'"+ " AND AD_Table_ID IN "+ "(SELECT AD_Table_ID FROM AD_Column "+ "WHERE ColumnName = 'DocumentNo' OR ColumnName = 'Value')"+ " AND 'DocumentNo_' || TableName NOT IN "+ "(SELECT Name FROM AD_Sequence s "+ "WHERE s.AD_Client_ID=?)";
  int counter=0;
  boolean success=true;
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,trxName);
    pstmt.setInt(1,AD_Client_ID);
    rs=pstmt.executeQuery();
    while (rs.next()) {
      String tableName=rs.getString(1);
      s_log.fine("Add: " + tableName);
      MSequence seq=new MSequence(ctx,AD_Client_ID,tableName,trxName);
      if (seq.save())       counter++;
 else {
        s_log.severe("Not created - AD_Client_ID=" + AD_Client_ID + " - "+ tableName);
        success=false;
      }
    }
  }
 catch (  Exception e) {
    s_log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  s_log.info("AD_Client_ID=" + AD_Client_ID + " - created #"+ counter+ " - success="+ success);
  return success;
}

public static boolean checkClientSequences ( Properties ctx , int AD_Client_ID , String trxName ) { String sql = "SELECT TableName " + "FROM AD_Table t " + "WHERE IsActive='Y' AND IsView='N'" + " AND AD_Table_ID IN " + "(SELECT AD_Table_ID FROM AD_Column " + "WHERE ColumnName = 'DocumentNo' OR ColumnName = 'Value')" + " AND 'DocumentNo_' || TableName NOT IN " + "(SELECT Name FROM AD_Sequence s " + "WHERE s.AD_Client_ID=?)" ; int counter = 0 ; boolean success = true ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , trxName ) ; pstmt . setInt ( 1 , AD_Client_ID ) ; rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) ) { String tableName = rs . getString ( 1 ) ; s_log . fine ( "Add: " + tableName ) ; MSequence seq = new MSequence ( ctx , AD_Client_ID , tableName , trxName ) ; if ( seq . save ( ) ) counter ++ ; else { s_log . severe ( "Not created - AD_Client_ID=" + AD_Client_ID + " - " + tableName ) ; success = false ; } } } catch ( Exception e ) { s_log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } s_log . info ( "AD_Client_ID=" + AD_Client_ID + " - created #" + counter + " - success=" + success ) ; return success ; }
check / initialize client documentno / value sequences
