Thursday, August 02, 2007

dbmonster as pure data generator

According to their website " DB Monster is a tool which helps database application developers with tuning the structure of the database, tuning the usage of indexes, and testing the application performance under heavy database load." DB monster can use a supplied schema to populate your database tables. This is a real help if you are planning to tune your database and want to analyze index usage etc. You always want to do tuning against a volume database , the one which has lot of rows and has data distributions that match your expected usage.

However I stumbled on db monster when i was only looking for data generator tools. I had already written some code to populate various tables in my database. I was looking for some data generator that I can just wire into my code. DB Monster has different data generators like string generator , number generator etc. Below , I show you how to use the DB monster String generator.

import java.util.Random;

import pl.kernelpanic.dbmonster.DBMonster;
import pl.kernelpanic.dbmonster.DBMonsterContext;
import pl.kernelpanic.dbmonster.DictionaryManager;
import pl.kernelpanic.dbmonster.generator.StringGenerator;

public class StringGeneratorProxy {

//real generator
private StringGenerator generator ;
String val ;
public StringGeneratorProxy() throws Exception{

generator = new StringGenerator();
DBMonsterContext ctx = new DBMonsterContext();
DictionaryManager dictmanager = new DictionaryManager();
Random random = new java.util.Random();
dictmanager.setRandom(random);
ctx.setProperty(DBMonster.DICTIONARY_MANAGER_KEY,
dictmanager);
ctx.setProperty(DBMonster.RANDOM_KEY, random);
generator.initialize(ctx);

}
public void setMinLength(int length) {
this.generator.setMinLength(length);
}

public void setMaxLength(int length) {
this.generator.setMaxLength(length);
}

public String generate() {
val = (String) generator.generate();
return val ;
}


public static void main(String[] args) throws Exception{
StringGeneratorProxy generator = new
StringGeneratorProxy ();
generator.setMinLength(100);
generator.setMaxLength(500);
System.out.println(generator.generate());

}
}




© Life of a third world developer
Maira Gall