private static void checkTableSequences(Properties ctx,SvrProcess sp){
  String trxName=null;
  if (sp != null)   trxName=sp.get_TrxName();
  String sql="SELECT TableName " + "FROM AD_Table t " + "WHERE IsActive='Y' AND IsView='N'"+ " AND NOT EXISTS (SELECT * FROM AD_Sequence s "+ "WHERE UPPER(s.Name)=UPPER(t.TableName) AND s.IsTableID='Y')";
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,trxName);
    rs=pstmt.executeQuery();
    while (rs.next()) {
      String tableName=rs.getString(1);
      if (MSequence.createTableSequence(ctx,tableName,trxName)) {
        if (sp != null)         sp.addLog(0,null,null,tableName);
 else         s_log.fine(tableName);
      }
 else {
        rs.close();
        throw new Exception("Error creating Table Sequence for " + tableName);
      }
    }
  }
 catch (  Exception e) {
    s_log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  sql="UPDATE AD_Sequence s " + "SET Name = (SELECT TableName FROM AD_Table t " + "WHERE t.IsView='N' AND UPPER(s.Name)=UPPER(t.TableName)) "+ "WHERE s.IsTableID='Y'"+ " AND EXISTS (SELECT * FROM AD_Table t "+ "WHERE t.IsActive='Y' AND t.IsView='N'"+ " AND UPPER(s.Name)=UPPER(t.TableName) AND s.Name<>t.TableName)";
  int no=DB.executeUpdate(sql,trxName);
  if (no > 0) {
    if (sp != null)     sp.addLog(0,null,null,"SyncName #" + no);
 else     s_log.fine("Sync #" + no);
  }
  if (no >= 0)   return;
  sql="SELECT TableName, s.Name " + "FROM AD_Table t, AD_Sequence s " + "WHERE t.IsActive='Y' AND t.IsView='N'"+ " AND UPPER(s.Name)=UPPER(t.TableName) AND s.Name<>t.TableName";
  try {
    pstmt=DB.prepareStatement(sql,null);
    rs=pstmt.executeQuery();
    while (rs.next()) {
      String TableName=rs.getString(1);
      String SeqName=rs.getString(2);
      sp.addLog(0,null,null,"ERROR: TableName=" + TableName + " - Sequence="+ SeqName);
    }
  }
 catch (  Exception e) {
    s_log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
}

private static void checkTableSequences ( Properties ctx , SvrProcess sp ) { String trxName = null ; if ( sp != null ) trxName = sp . get_TrxName ( ) ; String sql = "SELECT TableName " + "FROM AD_Table t " + "WHERE IsActive='Y' AND IsView='N'" + " AND NOT EXISTS (SELECT * FROM AD_Sequence s " + "WHERE UPPER(s.Name)=UPPER(t.TableName) AND s.IsTableID='Y')" ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , trxName ) ; rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) ) { String tableName = rs . getString ( 1 ) ; if ( MSequence . createTableSequence ( ctx , tableName , trxName ) ) { if ( sp != null ) sp . addLog ( 0 , null , null , tableName ) ; else s_log . fine ( tableName ) ; } else { rs . close ( ) ; throw new Exception ( "Error creating Table Sequence for " + tableName ) ; } } } catch ( Exception e ) { s_log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } sql = "UPDATE AD_Sequence s " + "SET Name = (SELECT TableName FROM AD_Table t " + "WHERE t.IsView='N' AND UPPER(s.Name)=UPPER(t.TableName)) " + "WHERE s.IsTableID='Y'" + " AND EXISTS (SELECT * FROM AD_Table t " + "WHERE t.IsActive='Y' AND t.IsView='N'" + " AND UPPER(s.Name)=UPPER(t.TableName) AND s.Name<>t.TableName)" ; int no = DB . executeUpdate ( sql , trxName ) ; if ( no > 0 ) { if ( sp != null ) sp . addLog ( 0 , null , null , "SyncName #" + no ) ; else s_log . fine ( "Sync #" + no ) ; } if ( no >= 0 ) return ; sql = "SELECT TableName, s.Name " + "FROM AD_Table t, AD_Sequence s " + "WHERE t.IsActive='Y' AND t.IsView='N'" + " AND UPPER(s.Name)=UPPER(t.TableName) AND s.Name<>t.TableName" ; try { pstmt = DB . prepareStatement ( sql , null ) ; rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) ) { String TableName = rs . getString ( 1 ) ; String SeqName = rs . getString ( 2 ) ; sp . addLog ( 0 , null , null , "ERROR: TableName=" + TableName + " - Sequence=" + SeqName ) ; } } catch ( Exception e ) { s_log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } }
check existence of table sequences .
