Class DatafakerStringGenerator

java.lang.Object
io.bloviate.gen.AbstractDataGenerator<String>
io.bloviate.datafaker.DatafakerStringGenerator
All Implemented Interfaces:
DataGenerator<String>

public class DatafakerStringGenerator extends AbstractDataGenerator<String>
Produces a realistic String value from a Datafaker provider — an email, a name, a phone number, an address part, and so on. The provider is supplied as a Function<Faker, String> by DatafakerGeneratorPlugin.

Reproducibility. Datafaker needs a Random; this generator seeds one from the engine's column-seeded RandomGenerator, so the same base seed yields the same realistic values on every run. reseed(long) rebuilds the Faker so the output stays deterministic under foreign-key wraparound and intra-table partitioning too. The Locale is fixed (not the JVM default) so output is identical across machines.

If the produced value is longer than the column's declared size it is truncated, so locale-specific output cannot overflow a VARCHAR(n).

Since:
2.11.0
  • Constructor Details

    • DatafakerStringGenerator

      public DatafakerStringGenerator(RandomGenerator random, Locale locale, Integer maxSize, Function<net.datafaker.Faker, String> valueFunction)
      Creates a generator that draws realistic values from the given Datafaker provider.
      Parameters:
      random - the engine-supplied, column-seeded random source
      locale - the locale for realistic values (fixed for reproducibility)
      maxSize - the column's max length, or null/0 for unbounded; longer values are truncated
      valueFunction - the Datafaker provider to draw from
  • Method Details

    • generate

      public String generate()
      Description copied from interface: DataGenerator
      Generates a random value of type T.
      Returns:
      a generated value, may be null if the generator supports nullable columns
    • reseed

      public void reseed(long seed)
      Description copied from class: AbstractDataGenerator
      Resets only the random source, replacing AbstractDataGenerator.random (and its AbstractDataGenerator.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<String>
      Overrides:
      reseed in class AbstractDataGenerator<String>
      Parameters:
      seed - the seed for the replacement generator
    • get

      public String get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      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