Settings

Note
the configuration in JdbcTableFacet takes precedence over the global setting.

Java package: guru.mikelue.foxglove.setting

  • A setting controls the fallback behavior of data generation.

Setting on table facet

Setting on DataGenerator

Use DataSetting on DataGenerator
var dataSetting = new DataSetting()
    // Wont' generate value for NULLABLE column automatically
    .notAutoGenerateFor(Property.NULLABLE);

var dataGenerator = new JdbcDataGenerator(getDataSource());
dataGenerator
    .withSetting(dataSetting);

Global setting

Change setting globally
DataSetting.defaults()
    // Generates text with 128 characters for types of TEXT, LONGVARCHAR, etc.
    .largeTextLength(128)
    // Generates null values with 10% odds for all nullable columns
    .generateNull(10);

Configurations

Suppliers by rules

Note
see DatabaseMetaData.getColumns(…​) for detail of metadata.
By JDBCType
var dataSetting = new DataSetting()
    // Sets up fixed text for all VARCHAR columns
    .givenType(JDBCType.VARCHAR)
        .useSupplier(() -> "fixed-text");
By type name
var dataSetting = new DataSetting()
    // Sets up fixed text for columns with type name of "VARYING CHARACTERS"
    .givenType("VARYING CHARACTERS")
        .useSupplier(() -> "varying-text");
By column matcher
var dataSetting = new DataSetting()
    // Sets up supplier if the name of column contains "address"
    .columnMatcher(meta -> meta.name().contains("address"))
        .useSupplier(addressGen);

Auto-generating behavior

By column’s properties
var dataSetting = new DataSetting()
    // Generates value even if the column is AUTO_INCREMENT
    .autoGenerateFor(Property.AUTO_INCREMENT)
    // Won't generate value for NULLABLE columns
    .notAutoGenerateFor(Property.NULLABLE);
By condition of exclusion
var dataSetting = new DataSetting()
    // Excludes the column with name ending with "_computed"
    .excludeWhen(meta -> meta.name().endsWith("_computed"));

Generating null values

The control the generation of null values on NULLABLE COLUMNS.

Default dicing for nullable value
var dataSetting = new DataSetting()
    .givenType(JDBCType.VARCHAR)
        .useSupplier(() -> "not-null-value")
    // Generates null value(1/6 odds) for any nullable column
    .generateNull(true);
Customize odds for nullable value
var dataSetting = new DataSetting()
    .givenType(JDBCType.VARCHAR)
        .useSupplier(() -> "not-null-value")
    // Generates null value(10% odds) for any nullable column
    .generateNull(10);

Misc

Sets the length for large text
var dataSetting = new DataSetting()
    // Generates 256 characters for types of TEXT, LONGVARCHAR, etc.
    .largeTextLength(256);

References