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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected RandomGeneratorThe random source backing all value generation; swapped out byreseed(long).protected SeededRandomUtilsA reusableSeededRandomUtilsview overrandom, created once per generator so subclasses don't allocate a fresh wrapper on everygenerate()call. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDataGenerator(RandomGenerator random) Initializes the generator with the given random source and aSeededRandomUtilsview over it. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidgenerateAndSet(Connection connection, PreparedStatement statement, int parameterIndex) Generates a value and sets it on a PreparedStatement parameter.Generates a value and returns its string representation.voidreseed(long seed) Resets only the random source, replacingrandom(and itsrandomUtilsview) with a freshly seededRandomGenerator.voidset(Connection connection, PreparedStatement statement, int parameterIndex, T value) Sets a specific value on a PreparedStatement parameter.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataGenerator
generate, get
-
Field Details
-
random
The random source backing all value generation; swapped out byreseed(long). -
randomUtils
A reusableSeededRandomUtilsview overrandom, created once per generator so subclasses don't allocate a fresh wrapper on everygenerate()call. It is rebuilt byreseed(long)so it always wraps the currentrandom.
-
-
Constructor Details
-
AbstractDataGenerator
Initializes the generator with the given random source and aSeededRandomUtilsview over it.- Parameters:
random- the random source backing all value generation
-
-
Method Details
-
reseed
public void reseed(long seed) Resets only the random source, replacingrandom(and itsrandomUtilsview) with a freshly seededRandomGenerator. Any counter or sequence state held by a subclass is intentionally left untouched, mirroring the legacyRandom.setSeedbehavior the engine relied on for foreign-key wraparound — only the random draws replay, not the generator's own progression.- Specified by:
reseedin interfaceDataGenerator<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:DataGeneratorGenerates a value and sets it on a PreparedStatement parameter.- Specified by:
generateAndSetin interfaceDataGenerator<T>- Parameters:
connection- the database connectionstatement- the prepared statement to set the parameter onparameterIndex- 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:DataGeneratorSets a specific value on a PreparedStatement parameter.- Specified by:
setin interfaceDataGenerator<T>- Parameters:
connection- the database connectionstatement- the prepared statement to set the parameter onparameterIndex- the 1-based parameter indexvalue- the value to set- Throws:
SQLException- if the database operation fails
-
generateAsString
Description copied from interface:DataGeneratorGenerates a value and returns its string representation.- Specified by:
generateAsStringin interfaceDataGenerator<T>- Returns:
- the string representation of a generated value
-