Skip to content

Commit

Permalink
Provide @DataSourceDefinition for app-level DB config. #6819
Browse files Browse the repository at this point in the history
This commit is a first test to apply database configuration and
credentials to the application server without using a config
on domain level but on application level. It is not very configurable yet.

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.)

We had to use the "global" scope, so the persistent EJB timers are successfully created
and stored in the database. Using the "app" scope crashes the deployment.
  • Loading branch information
poikilotherm committed Jul 13, 2020
1 parent 7ed1de7 commit e90d9e7
Show file tree
Hide file tree
Showing 3 changed files with 31 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:global/jdbc/dataverse")
private DataSource dataSource;

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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:global/jdbc/dataverse",
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:global/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:global/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 e90d9e7

Please sign in to comment.