Settings
See default generators page for more details about default generators.
Packages:
guru.mikelue.foxglove.setting- The main package providing DataSetting.
Overview
The setting object is DataSetting, which controls how to decide generators for columns.
- Ways to choose generators(ordered by priority)
By ColumnMatcher, which is a Predicate<ColumnMeta>
By type name(as
String), which comes fromTYPE_NAMEofDatabaseMetaData.getColumns(…)By java.sql.JDBCType, which comes from
DATA_TYPEofDatabaseMetaData.getColumns(…)
- Ways to provide Supplier for a column
A Supplier
A SupplierDecider, which is a function to decide Supplier by ColumnMeta
new DataSetting()
// Generates 20 rows if no other row number setting on the table
.setDefaultNumberOfRows(20)
// Excludes columns with name starting with "audit_"
.excludeWhen(columnMeta -> columnMeta.name().startsWith("audit_"))
// Use column matcher
.columnMatcher(columnMeta -> columnMeta.name().endsWith("_status"))
// Choose one of the fixed domain values randomly
.useSupplier(gen().oneOf("ACTIVE", "INACTIVE", "PENDING"))
// For type name
.givenType("enum_status")
// Choose one of the fixed domain values randomly
.useSupplier(gen().oneOf("ACTIVE", "INACTIVE", "UNKNOWN"))
// For JDBCType
.givenType(JDBCType.VARCHAR)
// Fixed value for all VARCHAR columns
.useSupplier(() -> "fixed-text")
.givenType(JDBCType.INTEGER)
// Fixed range for all INTEGER columns
.useSpec(() -> gen().ints().range(1000, 1000000))
// Generates 128 characters for types of TEXT, LONGVARCHAR, etc.
.largeTextLength(128)
// Generates null values with 5% odds for all nullable columns
.generateNull(20);Global settings
You could use
DataSetting.default()to get the current global settings.
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);Apply to TableFacet
See Table Facet - Setting for applying DataSetting to TableFacet.
Apply to DataGenerator
var dataSetting = new DataSetting()
// Wont' generate value for NULLABLE column automatically
.notAutoGenerateFor(Property.NULLABLE);
var dataGenerator = new JdbcDataGenerator(getDataSource());
dataGenerator
.withSetting(dataSetting);Multi-level settings
Both of TableFacet and DataGenerator are implementing SettingAware,
which have their own settings.
The priority of settings(from high to low) are:
TableFacet setting
DataGenerator setting
DataSetting.defaults()
Note | The scalar settings(e.g. If current level have found(by |
Excluding
The DataSetting is a kind of fallback mechanism to provide generators for columns without specific generator defined.
You could use DataSetting.execludeWhen(Predicate<ColumnMeta>) to exclude some columns from applying any generator of this setting.
var dataSetting = new DataSetting()
// Excludes the column with name ending with "_computed"
.excludeWhen(meta -> meta.name().endsWith("_computed"));