/** get a connection */
 public static Connection getConnection() throws Exception {
   if (tranConnection.get() != null) {
     return tranConnection.get();
   } else {
     return eds.getConnection();
   }
 }
  @Override
  protected void shutdownDb() throws SQLException {
    // annoyingly, shutting down a derby instance involves catching an exception
    // and checking error codes to make sure it shut down "normally"

    try {
      EmbeddedDataSource dataSource = new EmbeddedDataSource();
      dataSource.setDatabaseName(dbDir.getAbsolutePath());
      dataSource.setShutdownDatabase("shutdown");
      dataSource.getConnection();
    } catch (SQLException e) {
      // make sure we get the correct error codes
      if (e.getErrorCode() != 45000 || !"08006".equals(e.getSQLState())) {
        throw e;
      }
    }
  }
Exemplo n.º 3
0
 @Override
 public void destroy() throws Exception {
   logger.info("Attempting Derby database shut down on: " + dataSource);
   if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource) {
     EmbeddedDataSource ds = (EmbeddedDataSource) dataSource;
     try {
       ds.setShutdownDatabase("shutdown");
       ds.getConnection();
     } catch (SQLException except) {
       if (except.getSQLState().equals("08006")) {
         // SQLState derby throws when shutting down the database
         logger.info("Derby database is now shut down.");
         isShutdown = true;
       } else {
         logger.error("Problem shutting down Derby " + except.getMessage());
       }
     }
   }
 }