provideUsageNotes() {
+ String versions = "The following versions are supported: " +
+ Arrays.stream(VersionEnum.values()).map(Enum::name).collect(Collectors.joining(", "));
+ return Collections.singletonList(versions);
+ }
+
+ @Override
+ public void run(CommandLine theCommandLine) throws ParseException, ExecutionException {
+
+ }
+}
diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/RunServerCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/RunServerCommand.java
index 2a5d0034f22..d97a5557b98 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/RunServerCommand.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/RunServerCommand.java
@@ -26,6 +26,7 @@ import ca.uhn.fhir.jpa.demo.FhirServerConfig;
import ca.uhn.fhir.jpa.demo.FhirServerConfigDstu3;
import ca.uhn.fhir.jpa.demo.FhirServerConfigR4;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils;
@@ -71,6 +72,8 @@ public class RunServerCommand extends BaseCommand {
options.addOption(null, OPTION_ALLOW_EXTERNAL_REFS, false, "If this flag is set, the server will allow resources to be persisted contaning external resource references");
options.addOption(null, OPTION_DISABLE_REFERENTIAL_INTEGRITY, false, "If this flag is set, the server will not enforce referential integrity");
+ addOptionalOption(options, "u", "url", "Url", "If this option is set, specifies the JDBC URL to use for the database connection");
+
Long defaultReuseSearchResults = DaoConfig.DEFAULT_REUSE_CACHED_SEARCH_RESULTS_FOR_MILLIS;
String defaultReuseSearchResultsStr = defaultReuseSearchResults == null ? "off" : String.valueOf(defaultReuseSearchResults);
options.addOption(null, OPTION_REUSE_SEARCH_RESULTS_MILLIS, true, "The time in milliseconds within which the same results will be returned for multiple identical searches, or \"off\" (default is " + defaultReuseSearchResultsStr + ")");
@@ -106,6 +109,8 @@ public class RunServerCommand extends BaseCommand {
ContextHolder.setDisableReferentialIntegrity(true);
}
+ ContextHolder.setDatabaseUrl(theCommandLine.getOptionValue("u"));
+
String reuseSearchResults = theCommandLine.getOptionValue(OPTION_REUSE_SEARCH_RESULTS_MILLIS);
if (reuseSearchResults != null) {
if (reuseSearchResults.equals("off")) {
diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/ContextHolder.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/ContextHolder.java
index 451ec6dd163..0f051150151 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/ContextHolder.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/ContextHolder.java
@@ -12,6 +12,7 @@ public class ContextHolder {
private static boolean ourDisableReferentialIntegrity;
private static String ourPath;
private static Long ourReuseSearchResultsMillis;
+ private static String ourDatabaseUrl;
static {
ourReuseSearchResultsMillis = DaoConfig.DEFAULT_REUSE_CACHED_SEARCH_RESULTS_FOR_MILLIS;
@@ -27,12 +28,15 @@ public class ContextHolder {
case DSTU2:
ourPath = "/baseDstu2/";
break;
+ case DSTU2_1:
+ break;
case DSTU3:
ourPath = "/baseDstu3/";
break;
case R4:
ourPath = "/baseR4/";
break;
+ case DSTU2_HL7ORG:
default:
throw new ParseException("FHIR version not supported by this command: " + theCtx.getVersion().getVersion());
}
@@ -68,4 +72,12 @@ public class ContextHolder {
public static void setDisableReferentialIntegrity(boolean theDisableReferentialIntegrity) {
ourDisableReferentialIntegrity = theDisableReferentialIntegrity;
}
+
+ public static String getDatabaseUrl() {
+ return ourDatabaseUrl;
+ }
+
+ public static void setDatabaseUrl(String theDatabaseUrl) {
+ ourDatabaseUrl = theDatabaseUrl;
+ }
}
diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirDbConfig.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirDbConfig.java
index 42a147b98c7..19a7706e450 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirDbConfig.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirDbConfig.java
@@ -4,14 +4,38 @@ import java.util.Properties;
import ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory;
import ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect;
+import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import javax.sql.DataSource;
+
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
+
+@SuppressWarnings("Duplicates")
@Configuration
public class FhirDbConfig {
-
- private boolean ourLowMemMode;
+ /**
+ * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
+ * directory called "jpaserver_derby_files".
+ *
+ * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
+ */
+ @Bean(destroyMethod = "close")
+ public DataSource dataSource() {
+ String url = "jdbc:derby:directory:target/jpaserver_derby_files;create=true";
+ if (isNotBlank(ContextHolder.getDatabaseUrl())) {
+ url = ContextHolder.getDatabaseUrl();
+ }
+
+ BasicDataSource retVal = new BasicDataSource();
+ retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
+ retVal.setUrl(url);
+ retVal.setUsername("");
+ retVal.setPassword("");
+ return retVal;
+ }
@Bean()
public Properties jpaProperties() {
diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java
index 6001186a104..32270707137 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java
@@ -1,11 +1,11 @@
package ca.uhn.fhir.jpa.demo;
-import java.util.Properties;
-
-import javax.persistence.EntityManagerFactory;
-import javax.sql.DataSource;
-
-import org.apache.commons.dbcp2.BasicDataSource;
+import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu2;
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu2;
+import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Autowire;
@@ -18,18 +18,21 @@ import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu2;
-import ca.uhn.fhir.jpa.dao.DaoConfig;
-import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu2;
-import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
@Configuration
@EnableTransactionManagement()
@Import(FhirDbConfig.class)
public class FhirServerConfig extends BaseJavaConfigDstu2 {
+ @Autowired
+ private DataSource myDataSource;
+ @Autowired()
+ @Qualifier("jpaProperties")
+ private Properties myJpaProperties;
+
/**
* Configure FHIR properties around the the JPA server via this bean
*/
@@ -43,32 +46,12 @@ public class FhirServerConfig extends BaseJavaConfigDstu2 {
return retVal;
}
- /**
- * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
- * directory called "jpaserver_derby_files".
- *
- * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
- */
- @Bean(destroyMethod = "close")
- public DataSource dataSource() {
- BasicDataSource retVal = new BasicDataSource();
- retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
- retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
- retVal.setUsername("");
- retVal.setPassword("");
- return retVal;
- }
-
- @Autowired()
- @Qualifier("jpaProperties")
- private Properties myJpaProperties;
-
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
retVal.setPersistenceUnitName("HAPI_PU");
- retVal.setDataSource(dataSource());
+ retVal.setDataSource(myDataSource);
retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
retVal.setPersistenceProvider(new HibernatePersistenceProvider());
retVal.setJpaProperties(myJpaProperties);
@@ -83,7 +66,7 @@ public class FhirServerConfig extends BaseJavaConfigDstu2 {
LoggingInterceptor retVal = new LoggingInterceptor();
retVal.setLoggerName("fhirtest.access");
retVal.setMessageFormat(
- "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
+ "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
retVal.setLogExceptions(true);
retVal.setErrorMessageFormat("ERROR - ${requestVerb} ${requestUrl}");
return retVal;
diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu3.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu3.java
index 6ab41b41972..88053206124 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu3.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu3.java
@@ -1,13 +1,12 @@
package ca.uhn.fhir.jpa.demo;
-import java.util.Properties;
-
-import javax.persistence.EntityManagerFactory;
-import javax.sql.DataSource;
-
-import org.apache.commons.dbcp2.BasicDataSource;
+import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3;
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3;
+import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.apache.commons.lang3.time.DateUtils;
-import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -18,18 +17,15 @@ import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3;
-import ca.uhn.fhir.jpa.dao.DaoConfig;
-import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3;
-import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
/**
- * This class isn't used by default by the example, but
+ * This class isn't used by default by the example, but
* you can use it as a config if you want to support DSTU3
* instead of DSTU2 in your server.
- *
+ *
* See https://github.com/jamesagnew/hapi-fhir/issues/278
*/
@Configuration
@@ -37,6 +33,12 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
@Import(FhirDbConfig.class)
public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
+ @Autowired
+ private DataSource myDataSource;
+ @Autowired()
+ @Qualifier("jpaProperties")
+ private Properties myJpaProperties;
+
/**
* Configure FHIR properties around the the JPA server via this bean
*/
@@ -50,36 +52,16 @@ public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
return retVal;
}
- /**
- * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
- * directory called "jpaserver_derby_files".
- *
- * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
- */
- @Bean(destroyMethod = "close")
- public DataSource dataSource() {
- BasicDataSource retVal = new BasicDataSource();
- retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
- retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
- retVal.setUsername("");
- retVal.setPassword("");
- return retVal;
- }
-
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
retVal.setPersistenceUnitName("HAPI_PU");
- retVal.setDataSource(dataSource());
+ retVal.setDataSource(myDataSource);
retVal.setJpaProperties(myJpaProperties);
return retVal;
}
- @Autowired()
- @Qualifier("jpaProperties")
- private Properties myJpaProperties;
-
/**
* Do some fancy logging to create a nice access log that has details about each incoming request.
*/
@@ -87,7 +69,7 @@ public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
LoggingInterceptor retVal = new LoggingInterceptor();
retVal.setLoggerName("fhirtest.access");
retVal.setMessageFormat(
- "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
+ "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
retVal.setLogExceptions(true);
retVal.setErrorMessageFormat("ERROR - ${requestVerb} ${requestUrl}");
return retVal;
diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigR4.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigR4.java
index 7454ea6b677..3012865d606 100644
--- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigR4.java
+++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigR4.java
@@ -1,13 +1,12 @@
package ca.uhn.fhir.jpa.demo;
-import java.util.Properties;
-
-import javax.persistence.EntityManagerFactory;
-import javax.sql.DataSource;
-
-import org.apache.commons.dbcp2.BasicDataSource;
+import ca.uhn.fhir.jpa.config.BaseJavaConfigR4;
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorR4;
+import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
+import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.apache.commons.lang3.time.DateUtils;
-import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -18,18 +17,15 @@ import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import ca.uhn.fhir.jpa.config.BaseJavaConfigR4;
-import ca.uhn.fhir.jpa.dao.DaoConfig;
-import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorR4;
-import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
/**
- * This class isn't used by default by the example, but
+ * This class isn't used by default by the example, but
* you can use it as a config if you want to support DSTU3
* instead of DSTU2 in your server.
- *
+ *
* See https://github.com/jamesagnew/hapi-fhir/issues/278
*/
@Configuration
@@ -37,6 +33,12 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
@Import(FhirDbConfig.class)
public class FhirServerConfigR4 extends BaseJavaConfigR4 {
+ @Autowired
+ private DataSource myDataSource;
+ @Autowired()
+ @Qualifier("jpaProperties")
+ private Properties myJpaProperties;
+
/**
* Configure FHIR properties around the the JPA server via this bean
*/
@@ -50,36 +52,16 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
return retVal;
}
- /**
- * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
- * directory called "jpaserver_derby_files".
- *
- * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
- */
- @Bean(destroyMethod = "close")
- public DataSource dataSource() {
- BasicDataSource retVal = new BasicDataSource();
- retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
- retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
- retVal.setUsername("");
- retVal.setPassword("");
- return retVal;
- }
-
@Override
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean retVal = super.entityManagerFactory();
retVal.setPersistenceUnitName("HAPI_PU");
- retVal.setDataSource(dataSource());
+ retVal.setDataSource(myDataSource);
retVal.setJpaProperties(myJpaProperties);
return retVal;
}
- @Autowired()
- @Qualifier("jpaProperties")
- private Properties myJpaProperties;
-
/**
* Do some fancy logging to create a nice access log that has details about each incoming request.
*/
@@ -87,7 +69,7 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
LoggingInterceptor retVal = new LoggingInterceptor();
retVal.setLoggerName("fhirtest.access");
retVal.setMessageFormat(
- "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
+ "Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
retVal.setLogExceptions(true);
retVal.setErrorMessageFormat("ERROR - ${requestVerb} ${requestUrl}");
return retVal;
diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml
index cfe0b212030..4fda409f45b 100644
--- a/hapi-fhir-jpaserver-base/pom.xml
+++ b/hapi-fhir-jpaserver-base/pom.xml
@@ -343,6 +343,10 @@
org.jboss.spec.javax.transaction
jboss-transaction-api_1.2_spec
+
+ javax.activation
+ activation
+