Package guru.mikelue.foxglove.setting
Class DataSetting
java.lang.Object
guru.mikelue.foxglove.setting.DataSetting
- All Implemented Interfaces:
DataSettingInfo
Defines the data generation setting.
Overview
This object can used by multi-layered mechanism(sorted by priority):JdbcTableFacetDataGenerator- globally
Global setting
defaults() could be used to configure the global default setting.
DataSetting.defaults()
.givenType(JDBCType.VARCHAR)
.useSpec(Instancio.gen().string().alphaNumeric().length(16))
Use setting locally
Some types implementSettingAware.withSetting(DataSettingInfo),
so you could provide a customized DataSetting to them.
Example of JdbcTableFacet.Builder
var settingOfATable = new DataSetting();
.givenType(JDBCType.VARCHAR)
.useSpec(Instancio.gen().string().alphaNumeric().length(16))
tableFacetBuilder.withDataSetting(settingOfATable);
Example of DataGenerator
var settingForGenerator = new DataSetting();
.givenType(JDBCType.VARCHAR)
.useSpec(Instancio.gen().string().alphaNumeric().length(16))
dataGenerator.withDataSetting(settingForGenerator);
Features
Column spec
There are ways to define the supplier for matched columns:- Using a
SupplierbyColumnConfig.useSupplier(Supplier) - Using a
SupplierofValueSpecbyColumnConfig.useSpec(Supplier) - Using a
SupplierDeciderbyColumnConfig.decideSupplier(SupplierDecider)
Auto-generating by properties
- Use
autoGenerateFor(Property...)to set properties for auto-generating - Use
notAutoGenerateFor(Property...)to unset properties for not to auto-generating
Miscellaneous
- Use
generateNull(boolean),generateNull(int)to supply possiblenullvalue for nullable columns - Use
largeTextLength(int, int)to alter length for large text. e.g.:JDBCType.CLOB
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionautoGenerateFor(ColumnMeta.Property... properties) Sets whether or not to generate value automatically by the given properties of a column.<T> ColumnConfig<T, DataSetting> columnMatcher(ColumnMatcher matcher) Starts to configureSupplierfor columns matched by givenColumnMatcher.static final DataSettingdefaults()Gives the data setting can be changed for applying anySettingAwareglobally.excludeWhen(ColumnMatcher matcher) Excludes columns matched by givenColumnMatcherfrom auto-generating.generateNull(boolean enabled) Sets to generate possiblenullfor nullable columns.generateNull(int diceSides) Enables null value generating and sets the dice sides to generate possiblenullfor nullable columns, by ratio of1/diceSides.intGets the default number of rows for generated data.<T> ColumnConfig<T, DataSetting> Starts to configureSupplierfor columns matched by given type name.<T> ColumnConfig<T, DataSetting> booleanisAutoGenerating(ColumnMeta column) Gets whether or not to generate value automatically by the given properties of a column.largeTextLength(int length) Sets the length for types ofCLOB,LONGVARCHAR, etc.largeTextLength(int minLength, int maxLength) Sets the length range for types ofCLOB,LONGVARCHAR, etc.notAutoGenerateFor(ColumnMeta.Property... properties) Sets to not to generate value automatically by the given properties of a column.resolveSupplier(ColumnMeta columnMeta) Resolves theSupplierfor the given column metadata.setDefaultNumberOfRows(int numberOfRows) Sets the default number of rows for generated data.
-
Constructor Details
-
DataSetting
public DataSetting()Constructs an empty data setting.following settings are copied from
defaults():- Default number of rows
- Auto-generating properties
- Null generating setting
- Large text length setting
-
-
Method Details
-
defaults
Gives the data setting can be changed for applying anySettingAwareglobally.- Returns:
- The default data setting.
- See Also:
-
givenType
- Type Parameters:
T- The type of values supplied- Parameters:
jdbcType- The JDBC type to match columns- Returns:
- The next step to configure value generator for matched
JDBCType
-
givenType
Starts to configureSupplierfor columns matched by given type name.- Type Parameters:
T- The type of values supplied- Parameters:
typeName- The type name to match columns- Returns:
- The next step to configure value generator for matched type name
-
columnMatcher
Starts to configureSupplierfor columns matched by givenColumnMatcher.The priority of multiple matchers is not determined You have to provide a valid
Supplierin your decider for matched column.- Type Parameters:
T- The type of values supplied- Parameters:
matcher- The matcher to match columns- Returns:
- The next step to configure value generator for matched columns
-
getDefaultNumberOfRows
public int getDefaultNumberOfRows()Gets the default number of rows for generated data.This number of rows is used when:
- No specific number of rows is defined by
TableFacet
- Specified by:
getDefaultNumberOfRowsin interfaceDataSettingInfo- Returns:
- The default number of rows for generated data
- No specific number of rows is defined by
-
setDefaultNumberOfRows
Sets the default number of rows for generated data.This number of rows is used when:
- No specific number of rows is defined by
TableFacet
- Parameters:
numberOfRows- of rows The default number of rows for generated data- Returns:
- The data setting itself
- See Also:
- No specific number of rows is defined by
-
autoGenerateFor
Sets whether or not to generate value automatically by the given properties of a column.Other properties not given will be set to not generate value automatically for first time call this method.
- Parameters:
properties- The properties of columns- Returns:
- The data setting itself
- See Also:
-
notAutoGenerateFor
Sets to not to generate value automatically by the given properties of a column. Other properties not given will be set to generate value automatically for first time call this method.- Parameters:
properties- The properties of columns- Returns:
- The data setting itself
- See Also:
-
generateNull
Sets to generate possiblenullfor nullable columns.Default is not to generate
null.- Parameters:
enabled- Whether or not to generate possiblenull- Returns:
- The data setting itself
- See Also:
-
generateNull
Enables null value generating and sets the dice sides to generate possiblenullfor nullable columns, by ratio of1/diceSides.Default sides of dice is 6.
- Parameters:
diceSides- The sides of dice to generate possiblenull- Returns:
- The data setting itself
- See Also:
-
excludeWhen
Excludes columns matched by givenColumnMatcherfrom auto-generating. This exclusion has highest priority than auto-generating by other settings.- Parameters:
matcher- The matcher to match columns- Returns:
- The data setting itself
- See Also:
-
largeTextLength
Sets the length for types ofCLOB,LONGVARCHAR, etc.- Parameters:
length- The fixed length of large text- Returns:
- The data setting itself
- See Also:
-
largeTextLength
Sets the length range for types ofCLOB,LONGVARCHAR, etc.- Parameters:
minLength- The minimum length of large textmaxLength- The maximum length of large text- Returns:
- The data setting itself
- See Also:
-
resolveSupplier
Resolves theSupplierfor the given column metadata. The priority of resolution is:- Column matcher configured by
columnMatcher(ColumnMatcher) - Type name configured by
givenType(String) - JDBC type configured by
givenType(JDBCType)
- Specified by:
resolveSupplierin interfaceDataSettingInfo- Type Parameters:
T- The type of value supplied by the resolvedSupplier- Parameters:
columnMeta- The metadata of column used to resolveSupplier- Returns:
- The resolved
Supplieror empty
- Column matcher configured by
-
isAutoGenerating
Gets whether or not to generate value automatically by the given properties of a column. Additionally, theexcludeWhen(ColumnMatcher)also affects this behavior.The default properties to generate value automatically:
The conditions used by this method will gives
truefor a column:- Not-excluded by
excludeWhen(ColumnMatcher) - Matches any customized matching by
columnMatcher(ColumnMatcher) - Not-excluded by
ColumnMeta.properties() - Matches type by
givenType(String) - Matches type by
givenType(JDBCType) - Not-excluded by not supported
JDBCTypes
- Specified by:
isAutoGeneratingin interfaceDataSettingInfo- Parameters:
column- The metadata of a column- Returns:
- Whether or not to generate value automatically
- Not-excluded by
-