db-data-generator

Database data generator. Based on Spring Data

This project is maintained by besok

Introduction:

Database data generator based on Spring Data Repository. This tool can be used in your spring data project for generating some data.

Requirements

Work stages:

Properties:

Notes:

Usage examples:

Get the factory:
     @Autowired
     private DatabaseDataGeneratorFactory factory;
     
Generate all values
    String report =
            factory
                .generator()
                .generateAll()
                .report();

Generate by Class
    String report =
            factory
                .generator()
                .generateBy(Limit.class)
                .generateBy(Customer.class)
                .generateBy(Currency.class)
                .generateBy(OrganizationUnit.class)
                .report();

Generate by Table
       String report =
            factory
                .generator()
                .generateBy("schema","table")
                .report();

Generate by Table with exception

    try {
      InnerLog log =
          factory
              .generator()
              .generateBy("schema", "table")
              .withException()
              .log;
    } catch (DataGenerationException e) {
      e.printStackTrace();
    }

Generate by Class and repeate it 10 times
 InnerLog log =
          factory
              .generator().repeate(10)
              .generateBy(Limit.class)
              .log;

Generate by Class and do it till exprected log size
    InnerLog s =
        factory
            .generator().metronome(1, TimeUnit.SECONDS)
            .predicate(countPredicate(10))
            .generateBy(Customer.class)
            .log();

    InnerLog s =
        factory
            .generator()
            .metronome(1, TimeUnit.SECONDS,ctx -> ctx.log.markerValue() < 10)
            .generateBy(Customer.class)
            .log();
Generate by Class and get cache
    InnerCache cache = factory
        .generator()
        .metronome(10,TimeUnit.MILLISECONDS,COUNT(10))
        .generateBy(SimplePlainObject.class)
        .cache();
Generate by Class and do it async
    factory
        .generator().async()
        .repeate(100)
        .generateBy(SimplePlainObject1.class)
        .generateBy(SimplePlainObject2.class)
        .generateBy(SimplePlainObject3.class)
        .finish();
Add specific logic for generated value - rule(ColumnPredicate, Action, Class<?>)
    import static ru.gpb.utils.db.data.generator.worker.Action.*;
    import static ru.gpb.utils.db.data.generator.worker.ColumnPredicate.*;
    ... 
    
    NakedObject spo = factory
    	  .generator()
    	  .rule(FIELD("fieldWithCamel"), CONST("newValue"), String.class)
    	  .generateBy(NakedObject.class)
    	  .cache()
    	  .getValueList(NakedObject.class)
    	  .get(0);
    
    	assertEquals("newValue", spo.getFieldWithCamel());
    	
    NakedObject spo = factory
          .generator()
          .rule(
            COMPOSE(CLASS(NakedObject.class), FIELD("fieldWithCamel")), 
            CONST("newValue"), String.class)
          .generateBy(NakedObject.class)
          .generateBy(NakedObject2.class)
          .generateBy(NakedObject3.class)
          
    List<SeqIncObject> list =
    	  factory.generator()
    		.repeate(10)
    		.rule(FIELD("lRight"), INCREMENT_L(0), long.class)
    		.rule(FIELD("random"), RANDOM(10), int.class)
    		.rule(FIELD("random"), PEEK(System.out::println), int.class)
    		.generateBy(SeqIncObject.class)
    		.cache()
    		.getValueList(SeqIncObject.class);      
    	

License

This project is licensed under the terms of the MIT license.