001package io.ebean.config.dbplatform;
002
003import io.ebean.BackgroundExecutor;
004
005import javax.sql.DataSource;
006import java.sql.ResultSet;
007import java.sql.SQLException;
008import java.util.ArrayList;
009import java.util.List;
010
011/**
012 * Database sequence based IdGenerator using Sequence Step (e.g. step 50).
013 */
014public abstract class SequenceStepIdGenerator extends SequenceIdGenerator {
015
016  /**
017   * Construct with stepSize (typically 50).
018   */
019  protected SequenceStepIdGenerator(BackgroundExecutor be, DataSource ds, String seqName, int stepSize) {
020    super(be, ds, seqName, stepSize);
021  }
022
023  /**
024   * Add the next set of Ids as the next value plus all the following numbers up to the step size.
025   */
026  @Override
027  protected List<Long> readIds(ResultSet resultSet, int ignoreRequestSize) throws SQLException {
028
029    List<Long> newIds = new ArrayList<>(allocationSize);
030    if (resultSet.next()) {
031      long start = resultSet.getLong(1);
032      for (int i = 0; i < allocationSize; i++) {
033        newIds.add(start + i);
034      }
035    }
036    return newIds;
037  }
038
039}