Class ChildCountGenerator

java.lang.Object
io.bloviate.gen.AbstractDataGenerator<Integer>
io.bloviate.gen.ChildCountGenerator
All Implemented Interfaces:
DataGenerator<Integer>, IndexedDataGenerator

public class ChildCountGenerator extends AbstractDataGenerator<Integer> implements IndexedDataGenerator
Emits a parent table's "number of children" column under variable parent-child cardinality: for the k-th row (0-based) it returns cardinality.count(k) (for example TPC-C's o_ol_cnt). Sharing the same ChildCardinality instance with the child table's ChildKeyComponentGenerators guarantees that each parent's declared child count equals the number of child rows generated for it.

The produced values do not depend on the random source; counter state is held by the generator instance and advances on every generate().

  • Method Details

    • generate

      public Integer generate()
      Description copied from interface: DataGenerator
      Generates a random value of type T.
      Specified by:
      generate in interface DataGenerator<Integer>
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • seek

      public void seek(long rowIndex)
      Positions this generator so the next DataGenerator.generate() returns the value for the given absolute (0-based) row index.

      The value is cardinality.count(rowIndex), a pure function of the row index, so seeking is O(1): the counter is set to rowIndex.

      Specified by:
      seek in interface IndexedDataGenerator
      Parameters:
      rowIndex - the absolute, 0-based row index to seek to; must be >= 0
    • set

      public void set(Connection connection, PreparedStatement statement, int parameterIndex, Integer value) throws SQLException
      Description copied from interface: DataGenerator
      Sets a specific value on a PreparedStatement parameter.
      Specified by:
      set in interface DataGenerator<Integer>
      Overrides:
      set in class AbstractDataGenerator<Integer>
      Parameters:
      connection - the database connection
      statement - the prepared statement to set the parameter on
      parameterIndex - the 1-based parameter index
      value - the value to set
      Throws:
      SQLException - if the database operation fails
    • get

      public Integer get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      Retrieves a value from a ResultSet column.
      Specified by:
      get in interface DataGenerator<Integer>
      Parameters:
      resultSet - the result set to read from
      columnIndex - the 1-based column index
      Returns:
      the value from the result set, properly cast to type T
      Throws:
      SQLException - if the database operation fails