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 TypeMethodDescriptiongenerate()Generates a random value of type T.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.Retrieves a value from a ResultSet column.voidreseed(long seed) Resets this generator's random source to the given seed for reproducible foreign-key wraparound.voidset(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 underlyingRandomGeneratorwith a freshly seeded one (there is no in-placesetSeedonRandomGenerator) 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 connectionstatement- the prepared statement to set the parameter onparameterIndex- 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 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
-
get
Retrieves a value from a ResultSet column.- Parameters:
resultSet- the result set to read fromcolumnIndex- the 1-based column index- Returns:
- the value from the result set, properly cast to type T
- Throws:
SQLException- if the database operation fails
-