Step 1

After creating a new database, create two tables which will be filled with mass data. I prepared a simple SQL script for creating tables below (you might be required to change it slightly so it can work with your DBMS):

 create table Customer(
        id numeric(18, 0),
        first_name varchar(255),
        last_name varchar(255),
        email varchar(255),
        order_id numeric(18, 0),
                
        foreign key order_id references Order(id)
 )
        
 create table Order(
        id numeric(18, 0),
                
        product_number int8
)

Step 2

Now you have to prepare Scala specification for mass-data loading. You could use SQLParser to make things easier and pre-generate it from the DDL script. I'm not going to use it here, since right now it supports selected products only.

First let's describe database schema in Scala specification:

DatabaseSpecification(
        new Table(
                "Customer", 
                100, 
                Map (
                        "id" -> null,
                        "first_name" -> null,
                        "last_name" -> null,
                        "email" -> null,
                        "order_id" -> null)
                ), 
        new Table(
                "Order", 
                100, 
                Map (
                        "id" -> null,
                        "product_number" -> null)
                )
)

I believe it is pretty straightforward and resembles typical DDL script. Description consists of all tables and columns you'd like to fill. The magic number '100' - 2nd argument of Table constructor - states how many tuples should be filled for each table.
As you've probably noticed there is always a 'null' value on the right side of an arrow. It has to be changed to a certain generator class for every column.

Step 3

Now you have to decide which generator you'd like to use for each column. Of course if there were no existing generators you could write one by subclassing Generator trait.

Map (
        "id" -> new Increment(),
        "first_name" -> new StringGenerator(5, 12, StringConstants.ALPHABETIC),
        "last_name" -> new StringGenerator(5, 12, StringConstants.ALPHABETIC),
        "email" -> new StringGenerator(5, 10) + new Constant("@") 
        + new StringGenerator(5, 10) + new Constant(".com") 
        "order_id" -> new Unique(new ForeignKey("order", "id", loader.getConnection))
)
  • id - it is a numeric primary key - I decided to use generator similar to database sequence
  • first_name - it can be any string containing just alphabetic characters (actually StringGenerator uses alphabetic character set by default so the last argument could be omitted in this case)
  • last_name - same as above
  • email - this can be pretty tricky - I chose an easy solution - concatenation works perfectly here
  • order_id - order_id is a foreign key so I used corresponding generator class. There also should not exist more than one order for a customer, that's why ForeignKey generator is decorated with Unique generator.
Map (
        "id" -> new Increment(),
        "product_number" -> new NumberGenerator(1, 500)
)
  • id - same as above
  • product_number - it can be any number from a range (1, 500).

Step 4

You should prepare a file (dage.properties) with connection properties and put it in the same directory as scala file:

dage.jdbc.driver_class=org.postgresql.Driver
dage.jdbc.url=jdbc:postgresql://localhost:5432/example01
dage.jdbc.username=<YOUR_USERNAME>
dage.jdbc.password=<YOUR_PASSWORD>

Step 5

Now you're ready to execute the specification:

object Example {
 def main(args : Array[String]) = {
  val properties = new Properties();
  properties.load(Example.getClass().getResourceAsStream("dage.properties"));
  val loader = new DatabaseLoader(properties);
  val specification = DatabaseSpecification(
        new Table(
                "Customer", 
                100, 
                Map (
                        "id" -> new Increment(),
                        "first_name" -> new StringGenerator(5, 12),  
                        "last_name" -> new StringGenerator(5, 12),
                        "email" -> new StringGenerator(5, 10) + new Constant("@"),
                        + new StringGenerator(5, 10) + new Constant(".com"),
                        "order_id" -> new Unique(new ForeignKey("order", "id", loader.getConnection))
        ), 
        new Table(
                "Order", 
                100, 
                Map (
                        "id" -> new Increment(),
                        "product_number" -> new NumberGenerator(1, 500))
        )
  )
  loader.fillDatabase(specification);
 }
} 

This is it :) Pretty easy, ha ? More information about Dage features can be found in Scaladoc .