@Override
  public NumbersRecord readItem() throws Exception {
    int i = readerIndex;

    // Throw an exception when forcedFailCount is reached
    if (forcedFailCount != 0 && readerIndex >= forcedFailCount) {
      forcedFailCount = 0;
      failindex = readerIndex;
      testState = STATE_RETRY;
      Reporter.log("Fail on purpose NumbersRecord.readItem<p>");
      throw new MyParentException("Fail on purpose in NumbersRecord.readItem()");
    }

    if (testState == STATE_RETRY) {
      if (stepCtx.getProperties().getProperty("retry.read.exception.invoked") != "true") {
        Reporter.log("onRetryReadException not invoked<p>");
        throw new Exception("onRetryReadException not invoked");
      }

      if (stepCtx.getProperties().getProperty("retry.read.exception.match") != "true") {
        Reporter.log("retryable exception does not match");
        throw new Exception("retryable exception does not match");
      }

      testState = STATE_NORMAL;
    }

    if (readerIndex > 5) {
      return null;
    }

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rs = null;

    try {
      connection = RetryConnectionHelper.getConnection(dataSource);

      statement = connection.prepareStatement(RetryConnectionHelper.SELECT_NUMBERS);
      statement.setInt(1, readerIndex);
      rs = statement.executeQuery();

      int quantity = -1;
      while (rs.next()) {
        quantity = rs.getInt("quantity");
      }

      readerIndex++;

      return new NumbersRecord(i, quantity);
    } catch (SQLException e) {
      throw e;
    } finally {
      RetryConnectionHelper.cleanupConnection(connection, rs, statement);
    }
  }
 @Override
 public Serializable checkpointInfo() throws Exception {
   NumbersCheckpointData _chkptData = new NumbersCheckpointData();
   _chkptData.setCount(readerIndex);
   stepCtx.getProperties().setProperty("checkpoint.index", Integer.toString(readerIndex));
   return _chkptData;
 }
Example #3
0
  public void open(Serializable cpd) throws NamingException {

    InventoryCheckpointData checkpointData = (InventoryCheckpointData) cpd;

    InitialContext ctx = new InitialContext();
    dataSource = (DataSource) ctx.lookup(ConnectionHelper.jndiName);

    if (cpd != null) {
      this.readerIndex = checkpointData.getInventoryCount();

      stepCtx.getProperties().setProperty("init.checkpoint", this.readerIndex + "");
    }
  }
  public void open(Serializable cpd) throws NamingException {

    NumbersCheckpointData numbersCheckpointData = (NumbersCheckpointData) cpd;

    forcedFailCount = Integer.parseInt(forcedFailCountProp);

    InitialContext ctx = new InitialContext();
    dataSource = (DataSource) ctx.lookup(RetryConnectionHelper.jndiName);

    if (cpd != null) {
      forcedFailCount = 0;
      this.readerIndex = numbersCheckpointData.getCount();
      stepCtx.getProperties().setProperty("init.checkpoint", this.readerIndex + "");
    }
  }