Unload Derby on shutdown for #332

This commit is contained in:
jamesagnew 2016-04-12 08:08:34 -04:00
parent fe0824fd7c
commit 3f64340ec1
5 changed files with 37 additions and 9 deletions

View File

@ -3,6 +3,10 @@ package ca.uhn.fhirtest;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer; import java.io.Writer;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import org.apache.derby.drda.NetworkServerControl; import org.apache.derby.drda.NetworkServerControl;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
@ -18,8 +22,20 @@ public class DerbyNetworkServer implements InitializingBean, DisposableBean {
try { try {
ourLog.info("Shutting down derby"); ourLog.info("Shutting down derby");
// DriverManager.getConnection("jdbc:derby:directory:" + System.getProperty("fhir.db.location") + ";shutdown=true"); // DriverManager.getConnection("jdbc:derby:directory:" + System.getProperty("fhir.db.location") + ";shutdown=true");
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
ourLog.error("Unregistering driver: {}", driver.getClass());
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {
ourLog.error("Failed to unregister driver", e);
}
}
} catch (Exception e) { } catch (Exception e) {
ourLog.info("Failed to create database: {}", e.getMessage()); ourLog.info("Failed to shut down database: {}", e.getMessage());
} }
} }

View File

@ -38,6 +38,10 @@ import ca.uhn.fhirtest.config.TestDstu2Config;
public class TestRestfulServer extends RestfulServer { public class TestRestfulServer extends RestfulServer {
public static final String FHIR_BASEURL_DSTU2 = "fhir.baseurl.dstu2";
public static final String FHIR_BASEURL_DSTU3 = "fhir.baseurl.dstu3";
public static final String FHIR_BASEURL_DSTU1 = "fhir.baseurl.dstu1";
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestRestfulServer.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestRestfulServer.class);
@ -85,7 +89,7 @@ public class TestRestfulServer extends RestfulServer {
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao); JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
confProvider.setImplementationDescription(implDesc); confProvider.setImplementationDescription(implDesc);
setServerConformanceProvider(confProvider); setServerConformanceProvider(confProvider);
baseUrlProperty = "fhir.baseurl.dstu1"; baseUrlProperty = FHIR_BASEURL_DSTU1;
break; break;
} }
case "DSTU2": { case "DSTU2": {
@ -102,7 +106,7 @@ public class TestRestfulServer extends RestfulServer {
JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao, myAppCtx.getBean(DaoConfig.class)); JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao, myAppCtx.getBean(DaoConfig.class));
confProvider.setImplementationDescription(implDesc); confProvider.setImplementationDescription(implDesc);
setServerConformanceProvider(confProvider); setServerConformanceProvider(confProvider);
baseUrlProperty = "fhir.baseurl.dstu2"; baseUrlProperty = FHIR_BASEURL_DSTU2;
break; break;
} }
case "DSTU3": { case "DSTU3": {
@ -119,7 +123,7 @@ public class TestRestfulServer extends RestfulServer {
JpaConformanceProviderDstu3 confProvider = new JpaConformanceProviderDstu3(this, systemDao, myAppCtx.getBean(DaoConfig.class)); JpaConformanceProviderDstu3 confProvider = new JpaConformanceProviderDstu3(this, systemDao, myAppCtx.getBean(DaoConfig.class));
confProvider.setImplementationDescription(implDesc); confProvider.setImplementationDescription(implDesc);
setServerConformanceProvider(confProvider); setServerConformanceProvider(confProvider);
baseUrlProperty = "fhir.baseurl.dstu3"; baseUrlProperty = FHIR_BASEURL_DSTU3;
break; break;
} }
default: default:

View File

@ -25,7 +25,9 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
@EnableTransactionManagement() @EnableTransactionManagement()
public class TestDstu1Config extends BaseJavaConfigDstu1 { public class TestDstu1Config extends BaseJavaConfigDstu1 {
@Value("${fhir.db.location}") public static final String FHIR_DB_LOCATION = "${fhir.db.location}";
@Value(FHIR_DB_LOCATION)
private String myFhirDbLocation; private String myFhirDbLocation;
/** /**

View File

@ -29,10 +29,13 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
@EnableTransactionManagement() @EnableTransactionManagement()
public class TestDstu2Config extends BaseJavaConfigDstu2 { public class TestDstu2Config extends BaseJavaConfigDstu2 {
@Value("${fhir.db.location.dstu2}") public static final String FHIR_LUCENE_LOCATION_DSTU2 = "${fhir.lucene.location.dstu2}";
public static final String FHIR_DB_LOCATION_DSTU2 = "${fhir.db.location.dstu2}";
@Value(FHIR_DB_LOCATION_DSTU2)
private String myFhirDbLocation; private String myFhirDbLocation;
@Value("${fhir.lucene.location.dstu2}") @Value(FHIR_LUCENE_LOCATION_DSTU2)
private String myFhirLuceneLocation; private String myFhirLuceneLocation;
/** /**

View File

@ -34,10 +34,13 @@ import ca.uhn.fhir.validation.ResultSeverityEnum;
@EnableTransactionManagement() @EnableTransactionManagement()
public class TestDstu3Config extends BaseJavaConfigDstu3 { public class TestDstu3Config extends BaseJavaConfigDstu3 {
@Value("${fhir.db.location.dstu3}") public static final String FHIR_LUCENE_LOCATION_DSTU3 = "${fhir.lucene.location.dstu3}";
public static final String FHIR_DB_LOCATION_DSTU3 = "${fhir.db.location.dstu3}";
@Value(FHIR_DB_LOCATION_DSTU3)
private String myFhirDbLocation; private String myFhirDbLocation;
@Value("${fhir.lucene.location.dstu3}") @Value(FHIR_LUCENE_LOCATION_DSTU3)
private String myFhirLuceneLocation; private String myFhirLuceneLocation;
@Bean() @Bean()