cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor Antonovich (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAY-1264) Shutdown embedded database after scheme generation by maven-cayenne-plugin
Date Thu, 27 Aug 2009 11:14:59 GMT

    [ https://issues.apache.org/jira/browse/CAY-1264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748335#action_12748335
] 

Victor Antonovich commented on CAY-1264:
----------------------------------------

I agree, proposed patch is "dirty fix" of problem and needs to be reworked, but some users
can consider it useful.

> Shutdown embedded database after scheme generation by maven-cayenne-plugin
> --------------------------------------------------------------------------
>
>                 Key: CAY-1264
>                 URL: https://issues.apache.org/jira/browse/CAY-1264
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Cayenne Core Library
>    Affects Versions: 3.0M6
>            Reporter: Victor Antonovich
>
> 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 {
>              final DbAdapter adapterInst = (adapter == null) ? new JdbcAdapter()
>                                                              : (DbAdapter) Class.forName(adapter).newInstance();
> @@ -153,8 +158,9 @@
>              generator.setShouldDropTables(dropTables);
>  
>              // load driver taking custom CLASSPATH into account...
> -            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(
> -                    driver).newInstance(), url, username, password);
> +            registeredDriver = (Driver) Class.forName(driver).newInstance();
> +            DriverDataSource dataSource = new DriverDataSource(registeredDriver,
> +                    url, username, password);
>  
>              generator.runGenerator(dataSource);
>          }
> @@ -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 {
> +                registeredDriver.connect(url, shutdownProperties).close();
> +            } 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)) {
> +                    DriverManager.deregisterDriver(registeredDriver);
> +                }
> +                logger.debug("Unregistered driver " + registeredDriver);
> +            } catch (SQLException e) {
> +                logger.error("Can't unregister driver " + registeredDriver, e);
> +            }
> +        }
>      }
>  
>      /** Loads and returns DataMap based on <code>map</code> attribute. */

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message