Interface DataGenerator<T>

Type Parameters:
T - the Java type of values generated by this generator
All Known Implementing Classes:
AbstractDataGenerator, BigDecimalGenerator, BitGenerator, BitStringGenerator, BooleanGenerator, ByteGenerator, CharacterGenerator, ChildCountGenerator, ChildKeyComponentGenerator, CidrGenerator, CompositeKeyComponentGenerator, CreditGenerator, CurrentSqlTimestampGenerator, CustomerLastNameGenerator, DataColumnGenerator, DatafakerStringGenerator, DateGenerator, DoubleGenerator, FloatGenerator, GroupedPermutationGenerator, GroupedPrefixGenerator, InetGenerator, InstantGenerator, IntegerArrayGenerator, IntegerGenerator, IntervalGenerator, JsonbGenerator, LongGenerator, MacAddressGenerator, NormalDoubleGenerator, NormalIntegerGenerator, OrderLineDeliveryDateGenerator, RowProjectionGenerator, ScaledBigDecimalGenerator, SequentialIntegerGenerator, ShortGenerator, SimpleStringGenerator, SkewedTimestampGenerator, SqlBlobGenerator, SqlClobGenerator, SqlDateGenerator, SqlStructGenerator, SqlTimeGenerator, SqlTimestampGenerator, StaticBigDecimalGenerator, StaticDoubleGenerator, StaticFloatGenerator, StaticIntegerGenerator, StaticStringGenerator, StringArrayGenerator, UUIDGenerator, VariableStringGenerator, WeightedCategoricalGenerator, XmlGenerator, ZipCodeGenerator, ZipfianIntegerGenerator

public interface DataGenerator<T>
Core interface for generating test data for database columns.

DataGenerator implementations provide the ability to generate realistic test data for specific data types, with support for both random generation and seeded generation for reproducible results. Each generator handles the complexities of working with JDBC PreparedStatements and ResultSets.

Generators are created by DatabaseSupport implementations based on column metadata, ensuring that generated values respect database constraints such as size limits, nullable settings, and type-specific requirements.

The interface supports both in-memory generation (via generate()) and direct JDBC operations (via generateAndSet(Connection, PreparedStatement, int) and set(Connection, PreparedStatement, int, T)).

Author:
Tim Veil
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates a random value of type T.
    void
    generateAndSet(Connection connection, PreparedStatement statement, int parameterIndex)
    Generates a value and sets it on a PreparedStatement parameter.
    Generates a value and returns its string representation.
    get(ResultSet resultSet, int columnIndex)
    Retrieves a value from a ResultSet column.
    void
    reseed(long seed)
    Resets this generator's random source to the given seed for reproducible foreign-key wraparound.
    void
    set(Connection connection, PreparedStatement statement, int parameterIndex, T value)
    Sets a specific value on a PreparedStatement parameter.
  • Method Details

    • generate

      T generate()
      Generates a random value of type T.
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • generateAsString

      String generateAsString()
      Generates a value and returns its string representation.
      Returns:
      the string representation of a generated value
    • reseed

      void reseed(long seed)
      Resets this generator's random source to the given seed for reproducible foreign-key wraparound. Implementations must replace the underlying RandomGenerator with a freshly seeded one (there is no in-place setSeed on RandomGenerator) while preserving any counter or sequence state the generator maintains, so that only random draws replay.
      Parameters:
      seed - the random seed value
    • generateAndSet

      void generateAndSet(Connection connection, PreparedStatement statement, int parameterIndex) throws SQLException
      Generates a value and sets it on a PreparedStatement parameter.
      Parameters:
      connection - the database connection
      statement - the prepared statement to set the parameter on
      parameterIndex - the 1-based parameter index
      Throws:
      SQLException - if the database operation fails
    • set

      void set(Connection connection, PreparedStatement statement, int parameterIndex, T value) throws SQLException
      Sets a specific value on a PreparedStatement parameter.
      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

      T get(ResultSet resultSet, int columnIndex) throws SQLException
      Retrieves a value from a ResultSet column.
      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