Skip to content

Commit

Permalink
Provide @DataSourceDefinition for app-level DB config. IQSS#7418
Browse files Browse the repository at this point in the history
The JNDI names have been changed to be conform with Java EE 7.
See https://github.com/javaee-samples/javaee7-samples/tree/master/jpa/datasourcedefinition-applicationxml-pu
and others for working examples. (Staying with the old name was not successfull.)
  • Loading branch information
poikilotherm committed Nov 18, 2020
1 parent 3fcc239 commit 9dfe7b8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@TransactionManagement(value = TransactionManagementType.BEAN)
public class StartupFlywayMigrator {

@Resource(lookup = "jdbc/VDCNetDS")
@Resource(lookup = "java:app/jdbc/dataverse")
private DataSource dataSource;

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.harvard.iq.dataverse.util;

import javax.annotation.Resource;
import javax.annotation.sql.DataSourceDefinition;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import javax.sql.DataSource;

@Singleton
@DataSourceDefinition(
name = "java:app/jdbc/dataverse",
// Using PGXADataSource instead of deprecated PGPoolingDataSource
className = "org.postgresql.xa.PGXADataSource",
user = "dataverse",
password = "${ALIAS=db_password_alias}",
serverName = "postgresql",
portNumber = 5432,
databaseName = "dataverse",
minPoolSize = 10,
maxPoolSize = 200)
public class DataSourceProducer {

@Resource(lookup="java:app/jdbc/dataverse")
DataSource ds;

@Produces
public DataSource getDatasource() {
return ds;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<persistence-unit name="VDCNet-ejbPU" transaction-type="JTA">
<!-- provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider-->
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/VDCNetDS</jta-data-source>
<jta-data-source>java:app/jdbc/dataverse</jta-data-source>
<properties>
<!--property name="toplink.logging.level" value="FINE"/-->
<!-- disabling weaving, as an experiment: - L.A. -->
Expand Down

0 comments on commit 9dfe7b8

Please sign in to comment.