Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.0M6
-
None
Description
Using maven-cayenne-plugin for Derby embedded database scheme generation for unit test with Pax Exam lead to exception in test: "Another instance of Derby might have already booted the database". This is because Derby database already loaded by JVM running maven-cayenne-plugin, and same database cannot be loaded by Pax Exam test running in isolated JVM through RMI.
Patch below trying to shutdowns (embedded) database after scheme population:
Index: src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
===================================================================
— src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java (revision 807961)
+++ src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java (working copy)
@@ -34,6 +34,10 @@
import java.io.File;
import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.Properties;
/**
- Maven mojo to perform class generation from data map. This class is a Maven
@@ -139,6 +143,7 @@
logger.info(String.format("generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]",
dropTables, dropPK, createTables, createPK, createFK));
+ Driver registeredDriver = null;
try
@@ -170,6 +176,29 @@
logger.error(message);
throw new MojoExecutionException(message, th);
}
+ // Shutdown embedded database
+ if (registeredDriver != null) {
+ Properties shutdownProperties = new Properties();
+ shutdownProperties.put("shutdown", "true");
+ try
catch (SQLException e)
{ + logger.debug(String.format("Shutdown %s: %s", driver, e.getMessage())); + }+ }
+ // Unregister drivers
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ while (drivers.hasMoreElements()) {
+ registeredDriver = drivers.nextElement();
+ try {
+ if (registeredDriver.acceptsURL(url))
+ logger.debug("Unregistered driver " + registeredDriver);
+ } catch (SQLException e)
+ }
}
/** Loads and returns DataMap based on <code>map</code> attribute. */