Working on java config

This commit is contained in:
jamesagnew 2015-10-15 08:27:58 -04:00
parent e9d18af5d9
commit 7e2d486d17
20 changed files with 536 additions and 28 deletions

View File

@ -95,6 +95,14 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.cli;
import static org.fusesource.jansi.Ansi.ansi;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
@ -13,6 +15,7 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.fusesource.jansi.Ansi.Color;
import org.fusesource.jansi.AnsiConsole;
import org.slf4j.LoggerFactory;
@ -20,10 +23,7 @@ import ca.uhn.fhir.util.VersionUtil;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import static org.fusesource.jansi.Ansi.*;
import static org.fusesource.jansi.Ansi.Color.*;
import static org.fusesource.jansi.Ansi.*;
import static org.fusesource.jansi.Ansi.Color.*;
public class App {
private static List<BaseCommand> ourCommands;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(App.class);
@ -36,6 +36,7 @@ public class App {
ourCommands.add(new ExampleDataUploader());
ourCommands.add(new ValidateCommand());
ourCommands.add(new ValidationDataUploader());
ourCommands.add(new WebsocketSubscribeCommand());
Collections.sort(ourCommands);
}
@ -43,6 +44,10 @@ public class App {
private static void logCommandUsage(BaseCommand theCommand) {
logAppHeader();
logCommandUsageNoHeader(theCommand);
}
private static void logCommandUsageNoHeader(BaseCommand theCommand) {
System.out.println("Usage:");
System.out.println(" hapi-fhir-cli " + theCommand.getCommandName() + " [options]");
System.out.println();
@ -166,9 +171,11 @@ public class App {
command.run(parsedOptions);
} catch (ParseException e) {
ourLog.error("Invalid command options for command: " + command.getCommandName());
ourLog.error(e.getMessage());
ourLog.error("Aborting!");
loggingConfigOff();
System.err.println("Invalid command options for command: " + command.getCommandName());
System.err.println(" " + ansi().fg(Color.RED).bold() + e.getMessage());
System.err.println("" + ansi().fg(Color.WHITE).boldOff());
logCommandUsageNoHeader(command);
return;
} catch (CommandFailureException e) {
ourLog.error(e.getMessage());

View File

@ -0,0 +1,127 @@
package ca.uhn.fhir.cli;
import static org.apache.commons.lang3.StringUtils.isBlank;
import java.net.URI;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import ca.uhn.fhir.model.primitive.IdDt;
public class WebsocketSubscribeCommand extends BaseCommand {
private static final org.slf4j.Logger LOG_RECV = org.slf4j.LoggerFactory.getLogger("websocket.RECV");
private static final org.slf4j.Logger LOG_SEND = org.slf4j.LoggerFactory.getLogger("websocket.SEND");
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebsocketSubscribeCommand.class);
private boolean myQuit;
@Override
public String getCommandDescription() {
return "Opens a websocket client connection to a server for the purposes of binding to a Subscription, and then outputs the results";
}
@Override
public String getCommandName() {
return "subscription-client";
}
@Override
public Options getOptions() {
Options options = new Options();
options.addOption("t", "target", true, "Target URL, e.g. \"ws://fhirtest.uhn.ca/websocket/dstu2\"");
options.addOption("i", "subscriptionid", true, "Subscription ID, e.g. \"5235\"");
return options;
}
@Override
public void run(CommandLine theCommandLine) throws ParseException, Exception {
String target = theCommandLine.getOptionValue("t");
if (isBlank(target) || (!target.startsWith("ws://") && !target.startsWith("wss://"))) {
throw new ParseException("Target (-t) needs to be in the form \"ws://foo\" or \"wss://foo\"");
}
IdDt subsId = new IdDt(theCommandLine.getOptionValue("i"));
WebSocketClient client = new WebSocketClient();
SimpleEchoSocket socket = new SimpleEchoSocket(subsId.getIdPart());
try {
client.start();
URI echoUri = new URI(target);
ClientUpgradeRequest request = new ClientUpgradeRequest();
ourLog.info("Connecting to : {}", echoUri);
client.connect(socket, echoUri, request);
while (!myQuit) {
Thread.sleep(500L);
}
ourLog.info("Shutting down websocket client");
} finally {
try {
client.stop();
} catch (Exception e) {
ourLog.error("Failure", e);
}
}
}
/**
* Basic Echo Client Socket
*/
@WebSocket(maxTextMessageSize = 64 * 1024)
public class SimpleEchoSocket {
private String mySubsId;
@SuppressWarnings("unused")
private Session session;
public SimpleEchoSocket(String theSubsId) {
mySubsId = theSubsId;
}
@OnWebSocketError
public void onError(Throwable theError) {
ourLog.error("Websocket error: ", theError);
myQuit = true;
}
@OnWebSocketFrame
public void onFrame(Frame theFrame) {
ourLog.info("Websocket frame: {}", theFrame);
myQuit = true;
}
@OnWebSocketConnect
public void onConnect(Session theSession) {
ourLog.info("Successfully connected");
this.session = theSession;
try {
String sending = "bind " + mySubsId;
LOG_SEND.info("{}", sending);
theSession.getRemote().sendString(sending);
} catch (Throwable t) {
ourLog.error("Failure", t);
myQuit = true;
}
}
@OnWebSocketMessage
public void onMessage(String theMsg) {
LOG_RECV.info("{}", theMsg);
}
}
}

View File

@ -12,6 +12,14 @@
<appender-ref ref="STDOUT" />
</logger>
<!-- These two are used by the websocket client -->
<logger name="websocket.RECV" additivity="false" level="info">
<appender-ref ref="STDOUT" />
</logger>
<logger name="websocket.SEND" additivity="false" level="info">
<appender-ref ref="STDOUT" />
</logger>
<root level="warn">
<appender-ref ref="STDOUT" />
</root>

View File

@ -205,6 +205,23 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return InstantDt.withCurrentTime();
}
public void setConfig(DaoConfig theConfig) {
myConfig = theConfig;
}
public void setEntityManager(EntityManager theEntityManager) {
myEntityManager = theEntityManager;
}
public void setPlatformTransactionManager(PlatformTransactionManager thePlatformTransactionManager) {
myPlatformTransactionManager = thePlatformTransactionManager;
}
public void setResourceDaos(List<IFhirResourceDao<?>> theResourceDaos) {
myResourceDaos = theResourceDaos;
}
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IResource theResource) {
Set<ResourceLink> retVal = new HashSet<ResourceLink>();

View File

@ -222,6 +222,14 @@ public abstract class BaseHapiFhirSystemDao<T> extends BaseHapiFhirDao<IBaseReso
}
}
public void setEntityManager(EntityManager theEntityManager) {
myEntityManager = theEntityManager;
}
public void setTxManager(PlatformTransactionManager theTxManager) {
myTxManager = theTxManager;
}
protected ResourceTable tryToLoadEntity(IdDt nextId) {
ResourceTable entity;
try {

View File

@ -21,7 +21,10 @@ public class FhirResourceDaoSearchParameterDstu2 extends FhirResourceDaoDstu2<Se
@Scheduled(fixedDelay=DateUtils.MILLIS_PER_MINUTE)
public void performReindexingPass() {
mySystemDao.performReindexingPass(250);
int count = mySystemDao.performReindexingPass(100);
for (int i = 0; i < 10 && count > 0; i++) {
count = mySystemDao.performReindexingPass(100);
}
}

View File

@ -0,0 +1,76 @@
package ca.uhn.fhir.jpa.config;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.dialect.DerbyTenSevenDialect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.rp.dstu.BaseJavaConfigDstu1;
@Configuration
@EnableTransactionManagement()
public class TestDstu1Config extends BaseJavaConfigDstu1 {
@Override
@Bean(name="myDaoConfigDstu1")
public DaoConfig daoConfigDstu1() {
return new DaoConfig();
}
@Bean(name="myPersistenceDataSourceDstu1")
public DataSource dataSourceDstu1() {
BasicDataSource retVal = new BasicDataSource();
retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
retVal.setUrl("jdbc:derby:memory:myUnitTestDB;create=true");
retVal.setUsername("");
retVal.setPassword("");
return retVal;
}
@Override
@Bean(name="myTransactionManagerDstu1")
public JpaTransactionManager platformTransactionManagerDstu1() {
JpaTransactionManager retVal = new JpaTransactionManager();
retVal.setEntityManagerFactory(entityManagerFactoryDstu1());
retVal.afterPropertiesSet();
return retVal;
}
@Bean
public EntityManagerFactory entityManagerFactoryDstu1() {
LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean();
retVal.setDataSource(dataSourceDstu1());
retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
retVal.setJpaVendorAdapter(jpaVendorAdapter());
retVal.afterPropertiesSet();
return retVal.getNativeEntityManagerFactory();
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter retVal = new HibernateJpaVendorAdapter();
retVal.setGenerateDdl(true);
retVal.setDatabasePlatform(DerbyTenSevenDialect.class.getName());
return retVal;
}
@Override
protected EntityManager entityManagerDstu1() {
return entityManagerFactoryDstu1().createEntityManager();
}
}

View File

@ -0,0 +1,75 @@
package ca.uhn.fhir.jpa.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.dialect.DerbyTenSevenDialect;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.rp.dstu2.BaseJavaConfigDstu2;
@Configuration
@EnableTransactionManagement()
public class TestDstu2Config extends BaseJavaConfigDstu2 implements TransactionManagementConfigurer {
@Bean(name="myDaoConfigDstu2")
public DaoConfig daoConfigDstu2() {
return new DaoConfig();
}
@Bean(name="myPersistenceDataSourceDstu2")
public DataSource dataSourceDstu2() {
BasicDataSource retVal = new BasicDataSource();
retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
retVal.setUrl("jdbc:derby:memory:myUnitTestDB;create=true");
retVal.setUsername("");
retVal.setPassword("");
return retVal;
}
@Bean(name="myTransactionManagerDstu2")
public JpaTransactionManager platformTransactionManagerDstu2() {
JpaTransactionManager retVal = new JpaTransactionManager();
retVal.setEntityManagerFactory(entityManagerFactoryDstu2().getNativeEntityManagerFactory());
retVal.afterPropertiesSet();
return retVal;
}
@Bean()
public LocalContainerEntityManagerFactoryBean entityManagerFactoryDstu2() {
LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean();
retVal.setPersistenceUnitName("PU_HapiFhirJpaDstu2");
retVal.setDataSource(dataSourceDstu2());
retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
retVal.setPersistenceProvider(new HibernatePersistenceProvider());
retVal.setJpaProperties(jpaProperties());
retVal.afterPropertiesSet();
return retVal;
}
private Properties jpaProperties() {
Properties extraProperties = new Properties();
extraProperties.put("hibernate.format_sql", "true");
extraProperties.put("hibernate.show_sql", "false");
extraProperties.put("hibernate.hbm2ddl.auto", "update");
return extraProperties;
}
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return platformTransactionManagerDstu2();
}
}

View File

@ -25,6 +25,7 @@ import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.config.TestDstu2Config;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTag;
@ -68,9 +69,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
//@formatter:off
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"classpath:hapi-fhir-server-resourceproviders-dstu2.xml",
"classpath:fhir-jpabase-spring-test-config.xml"})
@ContextConfiguration(classes= {TestDstu2Config.class})
//@formatter:on
public abstract class BaseJpaDstu2Test extends BaseJpaTest {

View File

@ -1,9 +0,0 @@
package ca.uhn.fhir.jpa.demo;
public class DerbyInit {
public DerbyInit() throws ClassNotFoundException {
Class.forName("org.apache.derby.jdbc.ClientDriver");
}
}

View File

@ -46,7 +46,7 @@ public class TestRestfulServer extends RestfulServer {
// Get the spring context from the web container (it's declared in web.xml)
WebApplicationContext parentAppCtx = ContextLoaderListener.getCurrentWebApplicationContext();
myAppCtx = (parentAppCtx);
myAppCtx = parentAppCtx;
// These two parmeters are also declared in web.xml
String implDesc = getInitParameter("ImplementationDescription");
@ -67,6 +67,11 @@ public class TestRestfulServer extends RestfulServer {
String baseUrlProperty;
switch (fhirVersionParam.trim().toUpperCase()) {
case "DSTU1": {
// String[] configLocations = new String[] {
// "/hapi-fhir-server-database-config-dstu1.xml",
// "/hapi-fhir-server-resourceproviders-dstu1.xml"
// };
// myAppCtx = new ClassPathXmlApplicationContext(configLocations, parentAppCtx);
setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
@ -79,6 +84,13 @@ public class TestRestfulServer extends RestfulServer {
break;
}
case "DSTU2": {
// String[] configLocations = new String[] {
// "/hapi-fhir-server-database-config-dstu2.xml",
// "/hapi-fhir-server-resourceproviders-dstu2.xml",
// "/fhir-spring-subscription-config-dstu2.xml",
// "/fhir-spring-search-config-dstu2.xml"
// };
// myAppCtx = new ClassPathXmlApplicationContext(configLocations, parentAppCtx);
setFhirContext(FhirContext.forDstu2());
beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class);
systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);

View File

@ -12,15 +12,18 @@
/WEB-INF/hapi-fhir-server-config.xml
/WEB-INF/hapi-fhir-tester-application-context.xml
/WEB-INF/hapi-fhir-tester-config.xml
</param-value>
</context-param>
<!--
classpath:/hapi-fhir-server-database-config-dstu1.xml
classpath:/hapi-fhir-server-database-config-dstu2.xml
classpath:hapi-fhir-server-resourceproviders-dstu1.xml
classpath:hapi-fhir-server-resourceproviders-dstu2.xml
classpath:fhir-spring-subscription-config-dstu2.xml
classpath:fhir-spring-search-config-dstu2.xml
</param-value>
</context-param>
-->
<!-- Servlets -->
<servlet>

View File

@ -154,20 +154,33 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
v.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
v.setProperty("runtime.references.strict", Boolean.TRUE);
/*
* Spring XML
*/
InputStream templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/jpa_spring_beans.vm");
InputStreamReader templateReader = new InputStreamReader(templateIs);
targetResourceDirectory.mkdirs();
File f = new File(targetResourceDirectory, targetResourceSpringBeansFile);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
v.evaluate(ctx, w, "", templateReader);
w.close();
Resource resource = new Resource();
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
resource.addInclude(targetResourceSpringBeansFile);
myProject.addResource(resource);
/*
* Spring Java
*/
templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/jpa_spring_beans_java.vm");
templateReader = new InputStreamReader(templateIs);
f = new File(directoryBase, "BaseJavaConfig" + capitalize + ".java");
w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
v.evaluate(ctx, w, "", templateReader);
w.close();
} catch (Exception e) {
throw new MojoFailureException("Failed to generate server", e);
}

View File

@ -19,7 +19,7 @@ import ca.uhn.fhir.model.${version}.resource.*;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.param.*;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.model.dstu.resource.Binary;
// import ca.uhn.fhir.model.dstu.resource.Binary;
// import ca.uhn.fhir.model.dstu2.resource.Bundle;
// import ca.uhn.fhir.model.api.Bundle;

View File

@ -0,0 +1,161 @@
package ${packageBase};
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import javax.persistence.EntityManager;
import org.springframework.transaction.PlatformTransactionManager;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
@Configuration
@EnableScheduling()
#if ( ${versionCapitalized} == 'Dstu2' )
@EnableJpaRepositories(basePackages="ca.uhn.fhir.jpa.dao.data", entityManagerFactoryRef="entityManagerFactoryDstu2", transactionManagerRef="transactionManagerDstu2")
#end
public abstract class BaseJavaConfig${versionCapitalized} implements SchedulingConfigurer {
private static FhirContext ourFhirContextDstu2;
private static FhirContext ourFhirContextDstu1;
private static FhirContext ourFhirContextDstu2Hl7Org;
@Bean(name="myFhirContextDstu2")
@Lazy
public FhirContext fhirContextDstu2() {
if (ourFhirContextDstu2 == null) {
ourFhirContextDstu2 = FhirContext.forDstu2();
}
return ourFhirContextDstu2;
}
@Bean(name="myFhirContextDstu1")
@Lazy
public FhirContext fhirContextDstu1() {
if (ourFhirContextDstu1 == null) {
ourFhirContextDstu1 = FhirContext.forDstu1();
}
return ourFhirContextDstu1;
}
@Bean(name="myFhirContextDstu2Hl7Org")
@Lazy
public FhirContext fhirContextDstu2Hl7Org() {
if (ourFhirContextDstu2Hl7Org == null) {
ourFhirContextDstu2Hl7Org = FhirContext.forDstu2Hl7Org();
}
return ourFhirContextDstu2Hl7Org;
}
#if ( ${versionCapitalized} == 'Dstu1' )
@Bean(name="mySystemDaoDstu1", autowire=Autowire.BY_NAME)
public ca.uhn.fhir.jpa.dao.IFhirSystemDao<List<IResource>> fhirSystemDaoDstu1() {
ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1();
return retVal;
}
@Bean(name="mySystemProviderDstu1")
public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1 systemDaoDstu1() {
ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1();
retVal.setDao(fhirSystemDaoDstu1());
return retVal;
}
#end
#if ( ${versionCapitalized} == 'Dstu2' )
@Bean(name="mySystemDaoDstu2")
public IFhirSystemDao<ca.uhn.fhir.model.dstu2.resource.Bundle> fhirSystemDao${versionCapitalized}() {
ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2();
applyDaoConfiguration(retVal);
return retVal;
}
@Bean(name="mySystemProviderDstu2")
public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 systemDaoDstu2() {
ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2();
retVal.setDao(fhirSystemDaoDstu2());
return retVal;
}
#end
@Bean(destroyMethod="shutdown")
public Executor taskScheduler() {
return Executors.newScheduledThreadPool(5);
}
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskScheduler());
}
#if ( ${versionCapitalized} == 'Dstu2' )
@Bean(name="myJpaValidationSupportDstu2", autowire=Autowire.BY_NAME)
public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() {
ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2();
return retVal;
}
#end
@Bean(name="myResourceProviders${versionCapitalized}")
public List<IResourceProvider> resourceProviders${versionCapitalized}() {
List<IResourceProvider> retVal = new ArrayList<IResourceProvider>();
#foreach ( $res in $resources )
retVal.add(rp${res.declaringClassNameComplete}${versionCapitalized}());
#end
return retVal;
}
@Bean(name="myResourceDaos${versionCapitalized}")
public List<IFhirResourceDao<?>> resourceDaos${versionCapitalized}() {
List<IFhirResourceDao<?>> retVal = new ArrayList<IFhirResourceDao<?>>();
#foreach ( $res in $resources )
retVal.add(dao${res.declaringClassNameComplete}${versionCapitalized}());
#end
return retVal;
}
#foreach ( $res in $resources )
@Bean(name="my${res.name}Dao${versionCapitalized}", autowire=Autowire.BY_NAME)
@Lazy
public IFhirResourceDao<ca.uhn.fhir.model.${version}.resource.${res.declaringClassNameComplete}> dao${res.declaringClassNameComplete}${versionCapitalized}() {
ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized}<ca.uhn.fhir.model.${version}.resource.${res.declaringClassNameComplete}> retVal;
#if ( ${versionCapitalized} == 'Dstu2' && ( ${res.name} == 'Bundle' || ${res.name} == 'Encounter' || ${res.name} == 'Everything' || ${res.name} == 'Patient' || ${res.name} == 'Subscription' || ${res.name} == 'ValueSet' || ${res.name} == 'QuestionnaireResponse' || ${res.name} == 'SearchParameter'))
retVal = new ca.uhn.fhir.jpa.dao.FhirResourceDao${res.name}${versionCapitalized}();
#else
retVal = new ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized}<ca.uhn.fhir.model.${version}.resource.${res.declaringClassNameComplete}>();
#end
retVal.setResourceType(ca.uhn.fhir.model.${version}.resource.${res.declaringClassNameComplete}.class);
retVal.setContext(fhirContext${versionCapitalized}());
return retVal;
}
@Bean(name="my${res.declaringClassNameComplete}Rp${versionCapitalized}")
@Lazy
public ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider rp${res.declaringClassNameComplete}${versionCapitalized}() {
ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider retVal;
retVal = new ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider();
retVal.setContext(fhirContext${versionCapitalized}());
retVal.setDao(dao${res.declaringClassNameComplete}${versionCapitalized}());
return retVal;
}
#end
}