Split databases for test server into one for each FHIR version

This commit is contained in:
jamesagnew 2015-07-07 09:10:26 -04:00
parent 70222ecf15
commit 564746a9a8
6 changed files with 111 additions and 47 deletions

View File

@ -8,8 +8,9 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
@ -33,7 +34,7 @@ public class TestRestfulServer extends RestfulServer {
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);
private ApplicationContext myAppCtx; private ClassPathXmlApplicationContext myAppCtx;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@ -41,7 +42,7 @@ public class TestRestfulServer extends RestfulServer {
super.initialize(); super.initialize();
// Get the spring context from the web container (it's declared in web.xml) // Get the spring context from the web container (it's declared in web.xml)
myAppCtx = ContextLoaderListener.getCurrentWebApplicationContext(); WebApplicationContext parentAppCtx = ContextLoaderListener.getCurrentWebApplicationContext();
// These two parmeters are also declared in web.xml // These two parmeters are also declared in web.xml
String implDesc = getInitParameter("ImplementationDescription"); String implDesc = getInitParameter("ImplementationDescription");
@ -56,23 +57,15 @@ public class TestRestfulServer extends RestfulServer {
List<IResourceProvider> beans; List<IResourceProvider> beans;
JpaSystemProviderDstu1 systemProviderDstu1 = null; JpaSystemProviderDstu1 systemProviderDstu1 = null;
JpaSystemProviderDstu2 systemProviderDstu2 = null; JpaSystemProviderDstu2 systemProviderDstu2 = null;
@SuppressWarnings("rawtypes")
IFhirSystemDao systemDao; IFhirSystemDao systemDao;
ETagSupportEnum etagSupport; ETagSupportEnum etagSupport;
String baseUrlProperty; String baseUrlProperty;
switch (fhirVersionParam.trim().toUpperCase()) { switch (fhirVersionParam.trim().toUpperCase()) {
case "BASE": {
setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
systemDao = myAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
etagSupport = ETagSupportEnum.DISABLED;
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
confProvider.setImplementationDescription(implDesc);
setServerConformanceProvider(confProvider);
baseUrlProperty = "fhir.baseurl";
break;
}
case "DSTU1": { case "DSTU1": {
myAppCtx = new ClassPathXmlApplicationContext(new String[] {
"hapi-fhir-server-database-config-dstu1.xml",
"hapi-fhir-server-resourceproviders-dstu1.xml"}, parentAppCtx);
setFhirContext(FhirContext.forDstu1()); setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class); beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class); systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
@ -85,6 +78,10 @@ public class TestRestfulServer extends RestfulServer {
break; break;
} }
case "DSTU2": { case "DSTU2": {
myAppCtx = new ClassPathXmlApplicationContext(new String[] {
"hapi-fhir-server-database-config-dstu2.xml",
"hapi-fhir-server-resourceproviders-dstu2.xml",
}, parentAppCtx);
setFhirContext(FhirContext.forDstu2()); setFhirContext(FhirContext.forDstu2());
beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class); beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class);
systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class); systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);

View File

@ -9,28 +9,8 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- <context:annotation-config />
<bean class="ca.uhn.fhirtest.HsqldbServer" id="dbServer" init-method="start"> <context:mbean-server />
<constructor-arg>
<value>
server.database.0=file:#{systemProperties['fhir.db.location']}/hsql-fhir-db
server.dbname.0=uhnfhirdb
server.remote_open=true
hsqldb.reconfig_logging=false
hsqldb.default_table_type=cached
</value>
</constructor-arg>
</bean>
-->
<bean id="dbServer" class="ca.uhn.fhirtest.DerbyNetworkServer">
</bean>
<!--for mysql-->
<!--
<bean id="dbServer" class="ca.uhn.fhirtest.MySqlServer">
</bean>
-->
<bean depends-on="dbServer" id="myPersistenceDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <bean depends-on="dbServer" id="myPersistenceDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<!-- ;create=true /opt/glassfish/glassfish4/glassfish/nodes/localhost-domain1/fhirtest/fhirdb --> <!-- ;create=true /opt/glassfish/glassfish4/glassfish/nodes/localhost-domain1/fhirtest/fhirdb -->
@ -71,4 +51,9 @@
</property> </property>
</bean> </bean>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
</beans> </beans>

View File

@ -0,0 +1,64 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:annotation-config />
<context:mbean-server />
<bean depends-on="dbServer" id="myPersistenceDataSource"
class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<!-- ;create=true /opt/glassfish/glassfish4/glassfish/nodes/localhost-domain1/fhirtest/fhirdb -->
<!-- <property name="url" value="jdbc:hsqldb:hsql://localhost/uhnfhirdb"/> -->
<!-- <property name="url" value="jdbc:derby:directory:#{systemproperties['fhir.db.location']};create=true"
/> -->
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"></property>
<property name="url"
value="jdbc:derby://localhost:1527/#{systemProperties['fhir.db.location.dstu2']};create=true" />
<!-- <property name="url" value="jdbc:derby://localhost:1527//opt/glassfish/fhirtest/fhirtest;create=true"
/> -->
<!--<property name="url" value="jdbc:derby://localhost:1527#{systemProperties['fhir.db.location']};create=true"
/> -->
<property name="username" value="SA" />
<property name="password" value="SA" />
</bean>
<!--for mysql -->
<!-- <bean depends-on="dbServer" id="myPersistenceDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://fhirdb.url/fhirdbname" /> <property
name="username" value="sa"/> <property name="password" value="sa"/> <property
name="testOnBorrow" value="true"/> <property name="validationQuery" value="select
1;"/> </bean> -->
<bean depends-on="dbServer" id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myPersistenceDataSource" />
<property name="persistenceXmlLocation" value="classpath:META-INF/fhirtest_persistence.xml" />
<property name="persistenceUnitName" value="FHIR_UT" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.DerbyTenSevenDialect" />
<!-- <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"
/> -->
<!-- <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"
/> -->
</bean>
</property>
</bean>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
</beans>

View File

@ -16,15 +16,33 @@
<bean id="myDaoConfig" class="ca.uhn.fhir.jpa.dao.DaoConfig"> <bean id="myDaoConfig" class="ca.uhn.fhir.jpa.dao.DaoConfig">
</bean> </bean>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
<util:list id="myServerInterceptors"> <util:list id="myServerInterceptors">
<ref bean="myLoggingInterceptor"/> <ref bean="myLoggingInterceptor"/>
</util:list> </util:list>
<!--
<bean class="ca.uhn.fhirtest.HsqldbServer" id="dbServer" init-method="start">
<constructor-arg>
<value>
server.database.0=file:#{systemProperties['fhir.db.location']}/hsql-fhir-db
server.dbname.0=uhnfhirdb
server.remote_open=true
hsqldb.reconfig_logging=false
hsqldb.default_table_type=cached
</value>
</constructor-arg>
</bean>
-->
<!--for mysql-->
<!--
<bean id="dbServer" class="ca.uhn.fhirtest.MySqlServer">
</bean>
-->
<bean id="dbServer" class="ca.uhn.fhirtest.DerbyNetworkServer">
</bean>
<!-- <!--
Do some fancy logging to create a nice access log that has details Do some fancy logging to create a nice access log that has details
about each incoming request. about each incoming request.

View File

@ -9,10 +9,7 @@
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
/WEB-INF/hapi-fhir-server-database-config.xml
/WEB-INF/hapi-fhir-server-config.xml /WEB-INF/hapi-fhir-server-config.xml
classpath:hapi-fhir-server-resourceproviders-dstu1.xml
classpath:hapi-fhir-server-resourceproviders-dstu2.xml
/WEB-INF/hapi-fhir-tester-application-context.xml /WEB-INF/hapi-fhir-tester-application-context.xml
/WEB-INF/hapi-fhir-tester-config.xml /WEB-INF/hapi-fhir-tester-config.xml
</param-value> </param-value>
@ -33,6 +30,7 @@
<load-on-startup>2</load-on-startup> <load-on-startup>2</load-on-startup>
</servlet> </servlet>
<!--
<servlet> <servlet>
<servlet-name>fhirServletBase</servlet-name> <servlet-name>fhirServletBase</servlet-name>
<servlet-class>ca.uhn.fhirtest.TestRestfulServer</servlet-class> <servlet-class>ca.uhn.fhirtest.TestRestfulServer</servlet-class>
@ -46,6 +44,7 @@
</init-param> </init-param>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
-->
<servlet> <servlet>
<servlet-name>fhirServletDstu1</servlet-name> <servlet-name>fhirServletDstu1</servlet-name>
@ -76,7 +75,7 @@
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>fhirServletBase</servlet-name> <servlet-name>fhirServletDstu1</servlet-name>
<url-pattern>/base/*</url-pattern> <url-pattern>/base/*</url-pattern>
</servlet-mapping> </servlet-mapping>

View File

@ -28,6 +28,7 @@ public class UhnFhirTestApp {
// new File("target/testdb").mkdirs(); // new File("target/testdb").mkdirs();
System.setProperty("fhir.db.location", "./target/testdb"); System.setProperty("fhir.db.location", "./target/testdb");
System.setProperty("fhir.db.location.dstu2", "./target/testdb_dstu2");
System.setProperty("fhir.baseurl", base); System.setProperty("fhir.baseurl", base);
Server server = new Server(myPort); Server server = new Server(myPort);
@ -67,7 +68,7 @@ public class UhnFhirTestApp {
ResourceMetadataKeyEnum.TAG_LIST.put(p1, list); ResourceMetadataKeyEnum.TAG_LIST.put(p1, list);
client.create(p1); client.create(p1);
List<IResource> resources = ctx.newJsonParser().parseBundle(IOUtils.toString(UhnFhirTestApp.class.getResourceAsStream("/test-server-seed-bundle.json"))).toListOfResources(); List<IResource> resources = ctx.newJsonParser().parseBundle(IOUtils.toString(UhnFhirTestApp.class.getResourceAsStream("/bundle.json"))).toListOfResources();
client.transaction().withResources(resources).execute(); client.transaction().withResources(resources).execute();
// for (int i = 0; i < 1000; i++) { // for (int i = 0; i < 1000; i++) {