-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide @DataSourceDefinition for app-level DB config. #6819
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
1 parent
7ed1de7
commit e90d9e7
Showing
3 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/edu/harvard/iq/dataverse/util/DataSourceProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters