Class CompositeKeyComponentGenerator
- All Implemented Interfaces:
DataGenerator<Integer>, IndexedDataGenerator
public class CompositeKeyComponentGenerator
extends AbstractDataGenerator<Integer>
implements IndexedDataGenerator
Generates one component (dimension) of a row-ordered cartesian product, which
is what is needed to populate composite primary/foreign keys densely and
without collisions.
For the n-th row (0-based) the value is
start + ((n / repeat) % cycle), where:
cycleis the size of this dimension, andrepeatis how many consecutive rows share a value — i.e. the product of the sizes of all dimensions nested inside this one.
Example — a composite key over warehouses (W) × items (I), filled in
row-major order with warehouse outermost: configure the warehouse component
with repeat=I, cycle=W and the item component with
repeat=1, cycle=I. Filling exactly W * I rows then yields every
(w, i) pair exactly once.
The produced values do not depend on the random source; counter state is
held by the generator instance and advances on every generate().
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class AbstractDataGenerator
random, randomUtils -
Method Summary
Modifier and TypeMethodDescriptiongenerate()Generates a random value of type T.Retrieves a value from a ResultSet column.voidseek(long rowIndex) Positions this generator so the nextDataGenerator.generate()returns the value for the given absolute (0-based) row index.voidset(Connection connection, PreparedStatement statement, int parameterIndex, Integer value) Sets a specific value on a PreparedStatement parameter.Methods inherited from class AbstractDataGenerator
generateAndSet, generateAsString, reseed
-
Method Details
-
generate
Description copied from interface:DataGeneratorGenerates a random value of type T.- Specified by:
generatein interfaceDataGenerator<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 nextDataGenerator.generate()returns the value for the given absolute (0-based) row index.The value is a closed form of the row index (
start + ((rowIndex / repeat) % cycle)), so seeking is O(1): the counter is simply set torowIndex.- Specified by:
seekin interfaceIndexedDataGenerator- 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:DataGeneratorSets a specific value on a PreparedStatement parameter.- Specified by:
setin interfaceDataGenerator<Integer>- Overrides:
setin classAbstractDataGenerator<Integer>- 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
Description copied from interface:DataGeneratorRetrieves a value from a ResultSet column.- Specified by:
getin interfaceDataGenerator<Integer>- 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
-