Herdwick is also a library for easily populating databases with dummy data. It analyses database schema for foreign key references and other constraints to make generation of data as painless as possible.
Consider the following database schema:
create table department ( id serial primary key, name varchar(20) not null unique, ); create table employee ( id serial primary key, department_id int not null references department, name varchar(50) not null unique );
To automatically populate the schema with valid values, you can use the following code:
Populator populator = Populator.forUrlAndCredentials("jdbc:example-url", "login", "password"); populator.populate("department", 50); populator.populate("employee", 10000);
populator.populate("department", 50) call will generate 50 random departments whose names
will be unique and
populator.populate("employee", 10000) will generate 10000 employees randomly
assigned to those departments.
Integration with Dalesbred
If you are using Dalesbred, you can construct a new
populator using your
Database db = ... Populator populator = new Populator(db);
Like this you can integrate population with your existing transactions.