private boolean checkForKey() throws Exception {
  String query=m_query;
  query=query.replaceAll(" +"," ");
  if (!query.startsWith("SELECT *")) {
    return false;
  }
  m_orderBy.clear();
  if (!m_DataBaseConnection.isConnected()) {
    m_DataBaseConnection.connectToDatabase();
  }
  DatabaseMetaData dmd=m_DataBaseConnection.getMetaData();
  String table=endOfQuery(true);
  ResultSet rs=dmd.getPrimaryKeys(null,null,table);
  while (rs.next()) {
    m_orderBy.add(rs.getString(4));
  }
  rs.close();
  if (m_orderBy.size() != 0) {
    return true;
  }
  rs=dmd.getBestRowIdentifier(null,null,table,DatabaseMetaData.bestRowSession,false);
  ResultSetMetaData rmd=rs.getMetaData();
  int help=0;
  while (rs.next()) {
    m_orderBy.add(rs.getString(2));
    help++;
  }
  rs.close();
  if (help == rmd.getColumnCount()) {
    m_orderBy.clear();
  }
  if (m_orderBy.size() != 0) {
    return true;
  }
  return false;
}

private boolean checkForKey ( ) throws Exception { String query = m_query ; query = query . replaceAll ( " +" , " " ) ; if ( ! query . startsWith ( "SELECT *" ) ) { return false ; } m_orderBy . clear ( ) ; if ( ! m_DataBaseConnection . isConnected ( ) ) { m_DataBaseConnection . connectToDatabase ( ) ; } DatabaseMetaData dmd = m_DataBaseConnection . getMetaData ( ) ; String table = endOfQuery ( true ) ; ResultSet rs = dmd . getPrimaryKeys ( null , null , table ) ; while ( rs . next ( ) ) { m_orderBy . add ( rs . getString ( 4 ) ) ; } rs . close ( ) ; if ( m_orderBy . size ( ) != 0 ) { return true ; } rs = dmd . getBestRowIdentifier ( null , null , table , DatabaseMetaData . bestRowSession , false ) ; ResultSetMetaData rmd = rs . getMetaData ( ) ; int help = 0 ; while ( rs . next ( ) ) { m_orderBy . add ( rs . getString ( 2 ) ) ; help ++ ; } rs . close ( ) ; if ( help == rmd . getColumnCount ( ) ) { m_orderBy . clear ( ) ; } if ( m_orderBy . size ( ) != 0 ) { return true ; } return false ; }
checks for a unique key using the jdbc driver ' s method : getprimarykey ( ) , getbestrowidentifier ( ) . depending on their implementation a key can be detected . the key is needed to order the instances uniquely for an inremental loading . if an existing key cannot be detected , use - p option .
