private void initialize(String schema) {
    hbTable = new Table(schema, TABLE_NAME);
    hbId = new Column("id", Types.BIGINT, true); // true => isNotNull
    hbSeqno = new Column("seqno", Types.BIGINT);
    hbEventId = new Column("eventid", Types.VARCHAR, 128);
    hbSourceTstamp = new Column("source_tstamp", Types.TIMESTAMP);
    hbTargetTstamp = new Column("target_tstamp", Types.TIMESTAMP);
    hbLagMillis = new Column("lag_millis", Types.BIGINT);
    hbSalt = new Column("salt", Types.BIGINT);
    hbName = new Column("name", Types.VARCHAR, 128);

    Key hbKey = new Key(Key.Primary);
    hbKey.AddColumn(hbId);

    hbTable.AddColumn(hbId);
    hbTable.AddColumn(hbSeqno);
    hbTable.AddColumn(hbEventId);
    hbTable.AddColumn(hbSourceTstamp);
    hbTable.AddColumn(hbTargetTstamp);
    hbTable.AddColumn(hbLagMillis);
    hbTable.AddColumn(hbSalt);
    hbTable.AddColumn(hbName);
    hbTable.AddKey(hbKey);

    sourceTsQuery = "SELECT source_tstamp from " + schema + "." + TABLE_NAME + " where id=" + KEY;
  }
  private void initializeStage(String schema) {
    hbStageTable = new Table(schema, STAGE_TABLE_NAME);
    hbTOpcode = new Column("tungsten_opcode", Types.VARCHAR, 2);
    hbTSeqno = new Column("tungsten_seqno", Types.BIGINT, true);
    hbTRowId = new Column("tungsten_row_id", Types.BIGINT, true);
    hbTCommitTstamp = new Column("tungsten_commit_timestamp", Types.TIMESTAMP);

    Key hbKey = new Key(Key.Primary);

    hbKey.AddColumn(hbTOpcode);
    hbKey.AddColumn(hbTSeqno);
    hbKey.AddColumn(hbTRowId);

    hbStageTable.AddColumn(hbTOpcode);
    hbStageTable.AddColumn(hbTSeqno);
    hbStageTable.AddColumn(hbTRowId);
    hbStageTable.AddColumn(hbTCommitTstamp);
    hbStageTable.AddColumn(hbId);
    hbStageTable.AddColumn(hbSeqno);
    hbStageTable.AddColumn(hbEventId);
    hbStageTable.AddColumn(hbSourceTstamp);
    hbStageTable.AddColumn(hbTargetTstamp);
    hbStageTable.AddColumn(hbLagMillis);
    hbStageTable.AddColumn(hbSalt);
    hbStageTable.AddColumn(hbName);
    hbStageTable.AddKey(hbKey);
  }
  private void generateChunkingPreparedStatement(Table table, long blockSize) throws SQLException {
    String fqnTable =
        connection.getDatabaseObjectName(table.getSchema())
            + '.'
            + connection.getDatabaseObjectName(table.getName());

    StringBuffer sqlBuffer = new StringBuffer("SELECT ");
    StringBuffer colBuf = new StringBuffer();
    whereClause = new String();

    if (table.getPrimaryKey() != null) {
      // TODO
      // No dedicated chunking algorithm for this type of pk (either
      // composite or datatype not handled)
    } else {
      if (logger.isDebugEnabled()) logger.debug("Handling table " + table.toExtendedString());
      // This is a unique key that can be used
      Key key = table.getPKFromUniqueIndex();

      if (key == null) {
        logger.info("getPKFromUniqueIndex returned null key");
      }
      ArrayList<Column> colsList = key.getColumns();

      if (logger.isDebugEnabled()) logger.debug("colsList = " + colsList);

      Column[] columns = new Column[colsList.size()];
      int i = 0;
      for (Column column : colsList) {
        columns[i] = column;
        i++;
      }

      whereClause = buildWhereClause(columns, 0);

      for (int j = 0; j < columns.length; j++) {
        if (j > 0) {
          colBuf.append(", ");
        }
        colBuf.append(columns[j].getName());
      }
      sqlBuffer.append(colBuf);
    }

    sqlBuffer.append(" FROM ");
    sqlBuffer.append(fqnTable);
    if (eventId != null) {
      sqlBuffer.append(" AS OF SCN ");
      sqlBuffer.append(eventId);
    }

    sqlBuffer.append(" ORDER BY ");
    sqlBuffer.append(colBuf);

    String sql = sqlBuffer.toString();
    if (logger.isDebugEnabled()) logger.debug("Generated statement :" + sql);
    pStmt = connection.prepareStatement(sql);

    // TODO : have a setting ?
    pStmt.setFetchSize(100);
  }