Class DataSetting

java.lang.Object
guru.mikelue.foxglove.setting.DataSetting
All Implemented Interfaces:
DataSettingInfo

public class DataSetting extends Object implements DataSettingInfo
Defines the data generation setting.

Overview

This object can used by multi-layered mechanism(sorted by priority):

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 implement SettingAware.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:

Auto-generating by properties

Miscellaneous

See Also:
  • 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

      public static final DataSetting defaults()
      Gives the data setting can be changed for applying any SettingAware globally.
      Returns:
      The default data setting.
      See Also:
    • givenType

      public <T> ColumnConfig<T,DataSetting> givenType(JDBCType jdbcType)
      Starts to configure Supplier for columns matched by given JDBCType.
      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

      public <T> ColumnConfig<T,DataSetting> givenType(String typeName)
      Starts to configure Supplier for 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

      public <T> ColumnConfig<T,DataSetting> columnMatcher(ColumnMatcher matcher)
      Starts to configure Supplier for columns matched by given ColumnMatcher.

      The priority of multiple matchers is not determined You have to provide a valid Supplier in 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
      The default value is 1024.
      Specified by:
      getDefaultNumberOfRows in interface DataSettingInfo
      Returns:
      The default number of rows for generated data
    • setDefaultNumberOfRows

      public DataSetting setDefaultNumberOfRows(int numberOfRows)
      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:
    • autoGenerateFor

      public DataSetting autoGenerateFor(ColumnMeta.Property... properties)
      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

      public DataSetting notAutoGenerateFor(ColumnMeta.Property... properties)
      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

      public DataSetting generateNull(boolean enabled)
      Sets to generate possible null for nullable columns.

      Default is not to generate null.

      Parameters:
      enabled - Whether or not to generate possible null
      Returns:
      The data setting itself
      See Also:
    • generateNull

      public DataSetting generateNull(int diceSides)
      Enables null value generating and sets the dice sides to generate possible null for nullable columns, by ratio of 1/diceSides.

      Default sides of dice is 6.

      Parameters:
      diceSides - The sides of dice to generate possible null
      Returns:
      The data setting itself
      See Also:
    • excludeWhen

      public DataSetting excludeWhen(ColumnMatcher matcher)
      Excludes columns matched by given ColumnMatcher from 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

      public DataSetting largeTextLength(int length)
      Sets the length for types of CLOB, LONGVARCHAR, etc.
      Parameters:
      length - The fixed length of large text
      Returns:
      The data setting itself
      See Also:
    • largeTextLength

      public DataSetting largeTextLength(int minLength, int maxLength)
      Sets the length range for types of CLOB, LONGVARCHAR, etc.
      Parameters:
      minLength - The minimum length of large text
      maxLength - The maximum length of large text
      Returns:
      The data setting itself
      See Also:
    • resolveSupplier

      public <T> Optional<Supplier<T>> resolveSupplier(ColumnMeta columnMeta)
      Resolves the Supplier for the given column metadata. The priority of resolution is:
      1. Column matcher configured by columnMatcher(ColumnMatcher)
      2. Type name configured by givenType(String)
      3. JDBC type configured by givenType(JDBCType)
      Specified by:
      resolveSupplier in interface DataSettingInfo
      Type Parameters:
      T - The type of value supplied by the resolved Supplier
      Parameters:
      columnMeta - The metadata of column used to resolve Supplier
      Returns:
      The resolved Supplier or empty
    • isAutoGenerating

      public boolean isAutoGenerating(ColumnMeta column)
      Gets whether or not to generate value automatically by the given properties of a column. Additionally, the excludeWhen(ColumnMatcher) also affects this behavior.

      The default properties to generate value automatically:

      The conditions used by this method will gives true for a column:

      1. Not-excluded by excludeWhen(ColumnMatcher)
      2. Matches any customized matching by columnMatcher(ColumnMatcher)
      3. Not-excluded by ColumnMeta.properties()
      4. Matches type by givenType(String)
      5. Matches type by givenType(JDBCType)
      6. Not-excluded by not supported JDBCTypes
      Specified by:
      isAutoGenerating in interface DataSettingInfo
      Parameters:
      column - The metadata of a column
      Returns:
      Whether or not to generate value automatically