wocommunity/wonder — pull request #592 by sgaertner (2014-06-24 15:37:55+00:00)
Title: Bugfix for first migration when using ERXJDBCAdaptor

Problem: When starting an application with an empty database and the default adaptor, the _dbupdater table will be created automatically by ERXJDBCMigrationLock. However when using ERXJDBCAdaptor with a connection broker, this fails due to a NullPointerException. To test this the following properties must be set and the application must be started with an empty database.

er.extensions.ERXJDBCAdaptor.className=er.extensions.jdbc.ERXJDBCAdaptor
er.extensions.ERXJDBCAdaptor.useConnectionBroker=true

Analysis: The NPE happens because the context doesn't have a connection anymore, when trying to create the _dbupdater table (ERXJDBCMigrationLock._tryLock, last catch-block). This is because ERXJDBCAdaptor.Context.transactionDidRollback calls freeConnection, which simply sets _jdbcConnection to null when using connection broker.

Solution: Start a new transaction directly after rolling back the previous one. Actually it would be sufficient to begin the new transaction right before creating _dbupdater (so only if createTableIfMissing), but doing it after rollbackTransaction seems safer with future extensions in mind. The change has been tested successfully with the default adaptor and with ERXJDBCAdaptor (with and without a connection broker).