This post is our first one in English. I decided to write it in English because, you know, it might be of interest to people who don’t speak French. I could have chosen to write it in Dutch, but it would have been harder, and wouldn’t be useful to people not speaking Dutch. And since there are even fewer Dutch speakers than French speakers, it would be counter-productive. Everybody speaks English, right? Anyway, if you don’t like our blog posts to be written in English, please tell us and explain why. And if you prefer it in English, please say it as well. If you don’t care, you may keep your mouth shut.
This long introduction to announce the version 1.1.0 of DbSetup, our tiny (but gorgeous, and useful) full-Java, no-XML database population library. For those who missed the post about the initial release (1.0-RC1), please read this blog post (in French). Or read why you should be using it, in English.
What’s sure is that you missed the announce for the 1.0 version of DbSetup: I’ve been too busy lazy stupid to write about it. So let’s fix this mistake, and tell what’s new in 1.0 and 1.1.0.
First of all, as you just noticed, we went from 1.0 to 1.1.0. This change in the numbering is motivated by my desire to adopt semantic versioning. Consider that 1.0 should have been named 1.0.0, and that the 1.1.0 release brings a backward-compatible (tiny) new feature to DbSetup (thanks to Alexis Hassler): you can now use a factory method to create a DataSourceDestination or a DriverManagerDestination.
The 1.0 release brought a more important feature: the possibility to automatically generate values for some columns.
A typical insert looks like this:
Operation countries = Insert.into("COUNTRY") .columns("ID", "CODE", "LABEL") .values(1, "FR", "France") .values(2, "BE", "Belgium") .values(3, "IT", "Italy") .build();
Now suppose that your test doesn’t care about the IDs and the labels, but only about the codes. Since 1.0-RC1, you can insert a dummy label in all the rows using
Operation countries = Insert.into("COUNTRY") .columns("ID", "CODE") .withDefaultValue("LABEL", "dummy label") .values(1, "FR") .values(2, "BE") .values(3, "IT") .build();
But this is not an option for the ID: it must be unique. Version 1.0 introduces value generators. The above can be replaced by
Operation countries = Insert.into("COUNTRY") .columns("CODE") .withDefaultValue("LABEL", "dummy label") .withGeneratedValue("ID", ValueGenerators.sequence()) .values("FR") .values("BE") .values("IT") .build();
You can use generators for as many columns you want, and there are default implementations for several data types. All use a fluent pattern for easy and readable configuration. For example, to insert a sequence of strings into a column, you might use
Operation logRecords = Insert.into("COUNTRY") .columns("ID", "CODE") .withGeneratedValue("LABEL", ValueGenerators.stringSequence("LABEL_") .startingAt(10) .withLeftPadding(3)) .values(1, "FR") .values(2, "BE") .values(3, "IT") .build();
This would generate countries with labels
Thanks to Gaetan Zoritchak for the suggestion and his feedback on the feature.
If you have any idea for 1.2.0, please tell us about them, or contribute by sending pull requests.