What is needed to make JDataStore 4.0 recover properly from out of memory or Inusfficient disk space exceptions?

Abstract: What is needed to make JDataStore 4.0 recover properly from out of memory or Inusfficient disk space exceptions?

If an exception due to insufficient memory or disk space is encountered during an insert/delete/update operation to a JDataStore database, the connection that encountered this error must not commit or
rollback its transaction. The only way to properly recover from such an abnormal event is to exit and reenter the application. When the database is reopened, the crash recovery logic will properly back
out the transaction that could not be completed due to insufficient resources.

If JVM 1.3 or higher is in use, additional work is required to ensure that the errant transaction is not committed or rolledback. With 1.3 and higher JVMs, unclosed connections are automatically
committed and closed on exit. There is a workaround that can prevent this from occurring.

Use the following code to prevent automatic connection close and commit:

1) Establish a DataStore instance that has a ResponseEventListener. This DataStore should be opened before any other connections are made to this database. Upon normal application termination,
DataStore.shutdown() method should be called for this DataStore instance.

dataStore.setFileName("YourDatabase.jds");
dataStore.addResponseListener(new PreventCommitOnClose());
dataStore.open();

2) Implement PreventCommitOnClose class as follows:

class PreventCommitOnClose implements ResponseListener
{
public void response(ResponseEvent response) {
if (response.getCode() == ResponseEvent.COMMIT_ON_CLOSE) {
throw new RuntimeException("Commit on close prevented");
}
}
}

3) With this workaround in place your application can no longer rely on connection close to commit a transaction. You must commit all transactions that have not encountered Insufficient resource errors
if you want their changes to be persistent.

Future versions of JDataStore will make this workaround unnecessary.