tags:

views:

49

answers:

3

I am using Datanucleus JDO on top of HSqlDb.

I would like to execute the following SQL statement to tell HsqlDb to set the write delay to 0:
"SET WRITE_DELAY 0"

Is there a way I can do this from a JDO PersistenceManager or a PersistenceManagerFactory?

On a sidenote: I have tried to modify write_delay by using the following connection URL: jdbc:hsqldb:file:data/hsqldb/dbbench;write_delay=false

It didn't work. I debugged the HsqlDb sources and I could still see the write delay being set to 10 seconds.

+1  A: 

I think I have found a solution that will work for me:

public PersistenceManager getPersistenceManager() {
    PersistenceManager persistenceManager = 
        _persistenceManagerFactory.getPersistenceManager();
    JDOConnection dataStoreConnection = 
        persistenceManager.getDataStoreConnection();
    Object nativeConnection = dataStoreConnection.getNativeConnection();
    if(! (nativeConnection instanceof Connection) ){
        return persistenceManager;
    }

    Connection connection = (Connection) nativeConnection;
    try {
        Statement statement = connection.createStatement();
        statement.executeUpdate("SET WRITE_DELAY 0");
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return persistenceManager;
}
Carl Rosenberger
Note: I found out later that you have to close a connection you get this way, otherwise you will run out of connections. This is a little bit counter-intuitive because of the naming. "get"NativeConnection() will typically open a connection.
Carl Rosenberger
+1  A: 

You can write a startup script, dbbench.script in this example, and put the SQL in there.

See: http://best-practice-software-engineering.ifs.tuwien.ac.at/technology/tech-hsqldb.html

Todd Owen
Thanks, yes, that's certainly a possible solution for my usecase also.
Carl Rosenberger
+2  A: 

I think this page http://www.datanucleus.org/products/accessplatform/jdo/datastore_connection.html tells all needed. No ?

Yes indeed, and that's pretty much what I used anyway, see my own answer.
Carl Rosenberger