For my current project i decided to use ActiveObjects as ORM layer. Additionally i looked for a free, java based database engine which offers support for
- Embedded Mode
- Full Text Search
- Blobs and Clobs
Finally i decided to use the H2 database. Unfortunately i was lazy and didn’t check ActiveObjects list of supported databases.
ActiveObjects doesn’t support the H2 database out of the box.
Using ActiveObjects HSQLDatabaseProvider (H2 is known to be highly compatible with HSQL) doesn’t work because in ActiveObjects a DataBaseProvider has to return the appropriate JDBC driver class.
To use the HSQLDatabaseProvider for H2 anyway you can just extend it and overwrite the getDriverClass() method:
package net.java.ao.db;
import java.sql.Driver;
/**
* @author netseeker
*
*/
public class H2DatabaseProvider extends HSQLDatabaseProvider {
/**
* @param uri
* @param username
* @param password
*/
public H2DatabaseProvider(String uri, String username, String password) {
super(uri, username, password);
}
/*
* (non-Javadoc)
*
* @see net.java.ao.db.HSQLDatabaseProvider#getDriverClass()
*/
@SuppressWarnings("unchecked")
@Override
public Class< ? extends Driver> getDriverClass()
throws ClassNotFoundException {
return (Class< ? extends Driver>) Class.forName("org.h2.Driver");
}
}
The new DataBaseProvider can then be used like this:
EntityManager manager = new EntityManager(new H2DatabaseProvider(
dbProperties.getProperty("db.uri"),
dbProperties.getProperty("db.username"),
dbProperties.getProperty("db.password")));
Unsteter Gedankenfluss aus dem Leben eines Projektleiters, Entwicklers, Freizeitautors, eBook-Enthusiasten und last but not least sächsischen Asylschwaben.
You know, if H2 support is really that simple, I can move this functionality into the core distribution. That way you could still have auto-magical JDBC URI-based driver detection.
The one wrinkle is AO is into feature freeze for 1.0, which means that it still wouldn’t be “official” support for H2, but I don’t mind adding it to the list of supported databases and marking it as “experimental”.