Class AbstractDataGenerator<T>

java.lang.Object
io.bloviate.gen.AbstractDataGenerator<T>
Type Parameters:
T - the Java type of values generated by this generator
All Implemented Interfaces:
DataGenerator<T>
Direct Known Subclasses:
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 abstract class AbstractDataGenerator<T> extends Object implements DataGenerator<T>
Abstract base class providing common functionality for data generators.

This class implements common DataGenerator methods and provides a foundation for specific data type generators. It handles:

  • Random seed management for reproducible data generation
  • Standard JDBC PreparedStatement parameter setting
  • String representation generation
  • Coordination between generation and JDBC operations

Concrete subclasses need only implement the DataGenerator.generate() method to provide type-specific random value generation. They may optionally override set(Connection, PreparedStatement, int, Object) (declared as set(..., T)) and for database-specific handling.

Author:
Tim Veil
See Also:
  • Field Details

  • Constructor Details

    • AbstractDataGenerator

      public AbstractDataGenerator(RandomGenerator random)
      Initializes the generator with the given random source and a SeededRandomUtils view over it.
      Parameters:
      random - the random source backing all value generation
  • Method Details

    • reseed

      public void reseed(long seed)
      Resets only the random source, replacing random (and its randomUtils view) with a freshly seeded RandomGenerator. Any counter or sequence state held by a subclass is intentionally left untouched, mirroring the legacy Random.setSeed behavior the engine relied on for foreign-key wraparound — only the random draws replay, not the generator's own progression.
      Specified by:
      reseed in interface DataGenerator<T>
      Parameters:
      seed - the seed for the replacement generator
    • generateAndSet

      public final void generateAndSet(Connection connection, PreparedStatement statement, int parameterIndex) throws SQLException
      Description copied from interface: DataGenerator
      Generates a value and sets it on a PreparedStatement parameter.
      Specified by:
      generateAndSet in interface DataGenerator<T>
      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

      public void set(Connection connection, PreparedStatement statement, int parameterIndex, T value) throws SQLException
      Description copied from interface: DataGenerator
      Sets a specific value on a PreparedStatement parameter.
      Specified by:
      set in interface DataGenerator<T>
      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
    • generateAsString

      public String generateAsString()
      Description copied from interface: DataGenerator
      Generates a value and returns its string representation.
      Specified by:
      generateAsString in interface DataGenerator<T>
      Returns:
      the string representation of a generated value