net.sixpointsix.springboot.datafixture.DataFixture Maven / Gradle / Ivy
package net.sixpointsix.springboot.datafixture;
/**
* Basic data initializer that can be used to persist a custom set of data.
*
* Example usage:
*
*
* public class MyInitializer implements DataFixture {
*
* @Autowired
* private UserRepository userRepository;
*
* public boolean shouldRun() { userRepository.findUserByName("Bob") == null; }
*
* public void run() {
* userRepository.save(new User("Bob"));
* }
* }
*
*/
public interface DataFixture {
int DEFAULT_ORDER = 1000;
/**
* Test if this initializer should be run
* @return true if this should be executed
*/
boolean shouldRun();
/**
* Run the data initialization
*/
void run();
/**
* Get the order of the data initializer, to be sorted lowest to highest
* @return Order
*/
default int getOrder() {
return DEFAULT_ORDER;
}
}