Skip to content

Commit

Permalink
Create JDBC connection from glassfish-resources.xml
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.

Most certainly, this is only compatible with Payara 5.x as
Glassfish 5.x is unknown to support system properties in
config files and it certainly does not support password aliases.

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 Dec 10, 2018
1 parent df2b8cc commit e1b3f42
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion conf/docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ARG LIB_PATH="${PAYARA_DIR}/glassfish/domains/${DOMAIN_NAME}/lib/"

COPY --chown=payara maven/lib/* ${LIB_PATH}

COPY maven/${project.build.finalName}.war ${DEPLOY_DIR}
COPY maven/${project.build.finalName}.war ${DEPLOY_DIR}

COPY --chown=payara init_2_configure.sh ${SCRIPT_DIR}
17 changes: 17 additions & 0 deletions conf/docker/app/init_2_configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

# TEST FOR POSTBOOT: THIS WILL NEED TO BE ENHANCED WITH A) ENV VARS
# AND B) SECRETS FILE...

echo "AS_ADMIN_ALIASPASSWORD=test1234" > ${PAYARA_DIR}/dbpass

cat > ${POSTBOOT_COMMANDS}.tmp << 'EOF'
create-system-properties "postgres.host=postgres"
create-system-properties "postgres.port=5432"
create-system-properties "postgres.database=dataverse
create-system-properties "postgres.user=dataverse"
create-password-alias "postgres-pass" --passwordfile ${PAYARA_DIR}/dbpass
EOF

echo "$(cat ${POSTBOOT_COMMANDS}.tmp | cat - ${POSTBOOT_COMMANDS} )" > ${POSTBOOT_COMMANDS}
cat ${POSTBOOT_COMMANDS}
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,11 @@
<dependencies>
<!-- Adding this as a dependency will copy it to the domains /lib folder, where it needs to be. -->
<!-- FIXME: Gassfish should be capable to load the driver directly from the WAR, too. That would render
the installer a tiny bit simpler and make distribution easier. Needs testing. -->
the installer a tiny bit simpler and make distribution easier.
Needs testing. See also:
https://github.com/eclipse-ee4j/glassfish/issues/19451
https://github.com/eclipse-ee4j/glassfish/issues/20944
-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
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/DV/VDCNetDS</jta-data-source>
<properties>
<!--property name="toplink.logging.level" value="FINE"/-->
<!-- disabling weaving, as an experiment: - L.A. -->
Expand Down
17 changes: 17 additions & 0 deletions src/main/webapp/WEB-INF/glassfish-resources.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<!-- Java DataBase Connection Configuration -->
<jdbc-connection-pool
res-type="javax.sql.DataSource"
datasource-classname="org.postgresql.ds.PGPoolingDataSource"
name="dvnDbPool">
<property name="serverName" value="${postgres.host}"/>
<property name="portNumber" value="${postgres.port}"/>
<property name="databaseName" value="${postgres.database}"/>
<property name="User" value="${postgres.user}"/>
<property name="Password" value="${ALIAS=postgres-pass}"/>
<property name="create" value="true" />
</jdbc-connection-pool>
<jdbc-resource jndi-name="java:app/DV/VDCNetDS" pool-name="dvnDbPool"/>
</resources>

0 comments on commit e1b3f42

Please sign in to comment.