Skip to content

Commit

Permalink
Showing 3 changed files with 121 additions and 35 deletions.
45 changes: 45 additions & 0 deletions vcell-rest/pom.xml
Original file line number Diff line number Diff line change
@@ -231,6 +231,51 @@
</plugins>
</build>
<profiles>
<profile>
<id>pg</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>${ojdbc-bom.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-oracle</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>oracle</id>
<activation>
<property>
<name>oracle</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>${ojdbc-bom.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-oracle</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>native</id>
<activation>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vcell.restq.db;

import io.agroal.api.AgroalDataSource;
import io.quarkus.agroal.DataSource;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -16,11 +17,21 @@
@ApplicationScoped
public class AgroalConnectionFactory implements ConnectionFactory {


@Inject
@DataSource("oracle")
AgroalDataSource oracle_ds;

@Inject
AgroalDataSource ds;
@DataSource("postgresql")
AgroalDataSource postgresql_ds;

@ConfigProperty(name = "vcell.quarkus.db-kind")
String db_kind;
@Inject
@DataSource("devservices")
AgroalDataSource devservices_ds;

@ConfigProperty(name = "quarkus.profile")
String activeProfile;


public AgroalConnectionFactory() {
@@ -36,9 +47,24 @@ public void failed(Connection con, Object lock) {

@Override
public Connection getConnection(Object lock) throws SQLException {
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
return conn;
switch (activeProfile) {
case "test" -> {
Connection conn = devservices_ds.getConnection();
conn.setAutoCommit(false);
return conn;
}
case "dev" -> {
Connection conn = postgresql_ds.getConnection();
conn.setAutoCommit(false);
return conn;
}
case "prod" -> {
Connection conn = oracle_ds.getConnection();
conn.setAutoCommit(false);
return conn;
}
default -> throw new IllegalStateException("Unexpected value: " + activeProfile);
}
}

@Override
@@ -56,10 +82,11 @@ public KeyFactory getKeyFactory() {
}

private boolean usePostgresql() {
return switch (db_kind) {
case "postgresql" -> true;
case "oracle" -> false;
default -> throw new IllegalStateException("Unexpected value: " + db_kind);
return switch (activeProfile) {
case "test" -> true;
case "dev" -> true;
case "prod" -> false;
default -> throw new IllegalStateException("Unexpected value: " + activeProfile);
};
}

64 changes: 39 additions & 25 deletions vcell-rest/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -14,38 +14,52 @@ quarkus.datasource.metrics.enabled=true
quarkus.datasource.jdbc.enable-metrics=true

#
# prod datasource - remote Oracle
# select active datasource based on profile (test/dev/prod)
#
%prod.vcell.quarkus.db-kind=oracle
%prod.quarkus.datasource.db-kind=other
%prod.quarkus.datasource.jdbc.url=jdbc:oracle:thin:@vcell-oracle.cam.uchc.edu:1521/ORCLPDB1
%prod.quarkus.datasource.jdbc.driver=oracle.jdbc.driver.OracleDriver
%prod.quarkus.datasource.username=vcell
#%prod.quarkus.datasource.password=
%prod.oracle.jdbc.javaNetNio=false
%prod.oracle.jdbc.autoCommitSpecCompliant=falsey
%prod.quarkus.datasource.jdbc.acquisition-timeout=20S
%prod.quarkus.datasource.oracle.active=true
%prod.quarkus.datasource.postgresql.active=false
%prod.quarkus.datasource.postgresql.devservices.active=false

%dev.quarkus.datasource.oracle.active=false
%dev.quarkus.datasource.postgresql.active=true
%dev.quarkus.datasource.devservices.active=false

%test.quarkus.datasource.oracle.active=false
%test.quarkus.datasource.postgresql.active=false
%test.quarkus.datasource.devservices.active=true


#
# prod datasource - remote Oracle - see AgroalConnectionFactory
#
quarkus.datasource.oracle.db-kind=other
quarkus.datasource.oracle.jdbc.url=jdbc:oracle:thin:@vcell-oracle.cam.uchc.edu:1521/ORCLPDB1
quarkus.datasource.oracle.jdbc.driver=oracle.jdbc.driver.OracleDriver
quarkus.datasource.oracle.username=vcell
#quarkus.datasource.oracle.password=
quarkus.datasource.oracle.jdbc.acquisition-timeout=20S
oracle.jdbc.javaNetNio=false
oracle.jdbc.autoCommitSpecCompliant=falsey


#
# dev datasource - local PostgreSQL (see /scripts/init.sql and /scripts/start_dev_postgres.sh)
# dev datasource - local PostgreSQL (see /scripts/init.sql and /scripts/start_dev_postgres.sh) - see AgroalConnectionFactory
#
%dev.vcell.quarkus.db-kind=postgresql
%dev.quarkus.datasource.db-kind=postgresql
%dev.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres
%dev.quarkus.datasource.jdbc.driver=org.postgresql.Driver
%dev.quarkus.datasource.username=system
%dev.quarkus.datasource.password=quarkus
%dev.quarkus.datasource.jdbc.acquisition-timeout=20S
quarkus.datasource.postgresql.db-kind=postgresql
quarkus.datasource.postgresql.jdbc.url=jdbc:postgresql://localhost:5432/postgres
quarkus.datasource.postgresql.jdbc.driver=org.postgresql.Driver
quarkus.datasource.postgresql.username=quarkus
quarkus.datasource.postgresql.password=quarkus
quarkus.datasource.postgresql.jdbc.acquisition-timeout=20S

#
# test datasource - ephemeral PostgreSQL from testcontainers (see /scripts/init.sql)
# test datasource - ephemeral PostgreSQL from testcontainers (see /scripts/init.sql) - see AgroalConnectionFactory
#
%test.vcell.quarkus.db-kind=postgresql
%test.quarkus.datasource.devservices.db-kind=postgresql
%test.quarkus.datasource.devservices.init-script-path=scripts/init.sql
%test.quarkus.datasource.devservices.enabled=true
%test.quarkus.datasource.devservices.image-name=postgres:14.2
%test.quarkus.datasource.jdbc.acquisition-timeout=620S
quarkus.datasource.devservices.db-kind=postgresql
quarkus.datasource.devservices.init-script-path=scripts/init.sql
quarkus.datasource.devservices.enabled=true
quarkus.datasource.devservices.devservices.image-name=postgres:14.2
quarkus.datasource.devservices.jdbc.acquisition-timeout=120S

%test.quarkus.keycloak.devservices.users.alice=alice
%test.quarkus.keycloak.devservices.roles.alice=user,admin,curator,owner

0 comments on commit 8784ca0

Please sign in to comment.