Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #108 #163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*application.properties
.idea/
*.iml
sandbox/
/target/
.settings
Expand Down
32 changes: 32 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 74 additions & 75 deletions src/main/java/org/ohdsi/webapi/DataAccessConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,98 +28,97 @@
@EnableTransactionManagement
public class DataAccessConfig {

@Autowired
private Environment env;

@Autowired
private Environment env;

private Properties getJPAProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.default_schema", this.env.getProperty("spring.jpa.properties.hibernate.default_schema"));
properties.setProperty("hibernate.dialect", this.env.getProperty("spring.jpa.properties.hibernate.dialect"));
return properties;
}
private Properties getJPAProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.default_schema", this.env.getProperty("spring.jpa.properties.hibernate.default_schema"));
properties.setProperty("hibernate.dialect", this.env.getProperty("spring.jpa.properties.hibernate.dialect"));
return properties;
}

@Bean
@Primary
public DataSource primaryDataSource() {
@Bean
@Primary
public DataSource primaryDataSource() {
String driver = this.env.getRequiredProperty("datasource.driverClassName");
String url = this.env.getRequiredProperty("datasource.url");
String user = this.env.getRequiredProperty("datasource.username");
String pass = this.env.getRequiredProperty("datasource.password");
boolean autoCommit = false;

String driver = this.env.getRequiredProperty("datasource.driverClassName");
String url = this.env.getRequiredProperty("datasource.url");
String user = this.env.getRequiredProperty("datasource.username");
String pass = this.env.getRequiredProperty("datasource.password");
boolean autoCommit = false;

//pooling - currently issues with (at least) oracle with use of temp tables and "on commit preserve rows" instead of "on commit delete rows";
//http://forums.ohdsi.org/t/transaction-vs-session-scope-for-global-temp-tables-statements/333/2
//http://forums.ohdsi.org/t/transaction-vs-session-scope-for-global-temp-tables-statements/333/2
/*final PoolConfiguration pc = new org.apache.tomcat.jdbc.pool.PoolProperties();
pc.setDriverClassName(driver);
pc.setUrl(url);
pc.setUsername(user);
pc.setPassword(pass);
pc.setDefaultAutoCommit(autoCommit);*/
//non-pooling
DriverManagerDataSource ds = new DriverManagerDataSource(url, user, pass);
ds.setDriverClassName(driver);
//non-pooling
DriverManagerDataSource ds = new DriverManagerDataSource(url, user, pass);
ds.setDriverClassName(driver);
//note autocommit defaults vary across vendors. use provided @Autowired TransactionTemplate

String[] supportedDrivers;
supportedDrivers = new String[]{"org.postgresql.Driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "oracle.jdbc.driver.OracleDriver", "com.amazon.redshift.jdbc41.Driver"};

for (String driverName : supportedDrivers) {
try {
Class.forName(driverName);
System.out.println("driver loaded: " + driverName);
} catch (Exception ex) {
System.out.println("error loading " + driverName + " driver.");
}
String[] supportedDrivers;
supportedDrivers = new String[]{"org.postgresql.Driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "oracle.jdbc.driver.OracleDriver", "com.amazon.redshift.jdbc41.Driver"};

for (String driverName : supportedDrivers) {
try {
Class.forName(driverName);
System.out.println("driver loaded: " + driverName);
} catch (Exception ex) {
System.out.println("error loading " + driverName + " driver.");
}
}
return ds;
//return new org.apache.tomcat.jdbc.pool.DataSource(pc);
}
return ds;
//return new org.apache.tomcat.jdbc.pool.DataSource(pc);
}

@Bean
public EntityManagerFactory entityManagerFactory() {
@Bean
public EntityManagerFactory entityManagerFactory() {

HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(false);
vendorAdapter.setShowSql(Boolean.valueOf(this.env.getRequiredProperty("spring.jpa.show-sql")));
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(false);
vendorAdapter.setShowSql(Boolean.valueOf(this.env.getRequiredProperty("spring.jpa.show-sql")));
//hibernate.dialect is resolved based on driver
//vendorAdapter.setDatabasePlatform(hibernateDialect);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setJpaProperties(getJPAProperties());
factory.setPackagesToScan("org.ohdsi.webapi");
factory.setDataSource(primaryDataSource());
factory.afterPropertiesSet();

return factory.getObject();
}

@Bean
@Primary
//This is needed so that JpaTransactionManager is used for autowiring, instead of DataSourceTransactionManager
public PlatformTransactionManager jpaTransactionManager() {//EntityManagerFactory entityManagerFactory) {

JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory());
return txManager;
}

@Bean
public TransactionTemplate transactionTemplate(PlatformTransactionManager transactionManager) {
TransactionTemplate transactionTemplate = new TransactionTemplate();
transactionTemplate.setTransactionManager(transactionManager);
return transactionTemplate;
}

@Bean
public TransactionTemplate transactionTemplateRequiresNew(PlatformTransactionManager transactionManager) {
TransactionTemplate transactionTemplate = new TransactionTemplate();
transactionTemplate.setTransactionManager(transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return transactionTemplate;
}
//vendorAdapter.setDatabasePlatform(hibernateDialect);

LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setJpaProperties(getJPAProperties());
factory.setPackagesToScan("org.ohdsi.webapi");
factory.setDataSource(primaryDataSource());
factory.afterPropertiesSet();

return factory.getObject();
}

@Bean
@Primary
//This is needed so that JpaTransactionManager is used for autowiring, instead of DataSourceTransactionManager
public PlatformTransactionManager jpaTransactionManager() {//EntityManagerFactory entityManagerFactory) {

JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory());
return txManager;
}

@Bean
public TransactionTemplate transactionTemplate(PlatformTransactionManager transactionManager) {
TransactionTemplate transactionTemplate = new TransactionTemplate();
transactionTemplate.setTransactionManager(transactionManager);
return transactionTemplate;
}

@Bean
public TransactionTemplate transactionTemplateRequiresNew(PlatformTransactionManager transactionManager) {
TransactionTemplate transactionTemplate = new TransactionTemplate();
transactionTemplate.setTransactionManager(transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return transactionTemplate;
}

/*
public String getSparqlEndpoint()
Expand Down
Loading