Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2 JDBC extension #10349

Merged
merged 5 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,12 @@ jobs:
- category: Data2
db2: "true"
mysql: "true"
postgres: "true"
mariadb: "true"
timeout: 65
test-modules: >
jpa
jpa-postgresql
jpa-mysql
jpa-db2
reactive-mysql-client
reactive-db2-client
hibernate-reactive-db2
Expand All @@ -445,8 +444,9 @@ jobs:
hibernate-orm-rest-data-panache
- category: Data5
postgres: "true"
timeout: 55
timeout: 60
test-modules: >
jpa-postgresql
aguibert marked this conversation as resolved.
Show resolved Hide resolved
hibernate-search-elasticsearch
narayana-stm
narayana-jta
Expand Down
11 changes: 11 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<mysql-jdbc.version>8.0.20</mysql-jdbc.version>
<mssql-jdbc.version>7.2.2.jre8</mssql-jdbc.version>
<derby-jdbc.version>10.14.2.0</derby-jdbc.version>
<db2-jdbc.version>11.5.4.0</db2-jdbc.version>
<shrinkwrap.version>1.2.6</shrinkwrap.version>
<rest-assured.version>4.3.0</rest-assured.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
Expand Down Expand Up @@ -708,6 +709,11 @@
<artifactId>quarkus-jaeger-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-db2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
Expand Down Expand Up @@ -3305,6 +3311,11 @@
<artifactId>derbytools</artifactId>
<version>${derby-jdbc.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2-jdbc.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum Feature {
INFINISPAN_CLIENT,
INFINISPAN_EMBEDDED,
JAEGER,
JDBC_DB2,
JDBC_DERBY,
JDBC_H2,
JDBC_POSTGRESQL,
Expand Down
17 changes: 15 additions & 2 deletions docs/src/main/asciidoc/datasource.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ If you want a better understanding of how all this works, this guide has a lot m

=== JDBC datasource

Add the `agroal` extension plus one of `jdbc-derby`, `jdbc-h2`, `jdbc-mariadb`, `jdbc-mssql`, `jdbc-mysql` or `jdbc-postgresql`.
Add the `agroal` extension plus one of `jdbc-db2`, `jdbc-derby`, `jdbc-h2`, `jdbc-mariadb`, `jdbc-mssql`, `jdbc-mysql`, or `jdbc-postgresql`.

Then configure your datasource:

Expand Down Expand Up @@ -89,7 +89,7 @@ The database kind defines which type of database you will connect to.

We currently include these built-in database kinds:

* DB2: `db2` (reactive only)
* DB2: `db2`
* Derby: `derby`
* H2: `h2`
* MariaDB: `mariadb`
Expand Down Expand Up @@ -151,6 +151,7 @@ You will also need to choose, and add, the Quarkus extension for your relational

Quarkus provides driver extensions for:

* DB2 - `jdbc-db2`
* Derby - `jdbc-derby`
* H2 - `jdbc-h2`
* MariaDB - `jdbc-mariadb`
Expand Down Expand Up @@ -203,6 +204,10 @@ When using one of the built-in datasource kinds, the JDBC driver is resolved aut
|===
|Database kind |JDBC driver |XA driver

|`db2`
|`com.ibm.db2.jcc.DBDriver`
|`com.ibm.db2.jcc.DB2XADataSource`

|`derby`
|`org.apache.derby.jdbc.ClientDriver`
|`org.apache.derby.jdbc.ClientXADataSource`
Expand Down Expand Up @@ -524,6 +529,14 @@ Defaults for the different parts are as follows:

The https://jdbc.postgresql.org/documentation/head/connect.html[official documentation] go into more detail and list optional parameters as well.

=== DB2

`jdbc:db2://<serverName>[:<portNumber>]/<databaseName>[:<key1>=<value>;[<key2>=<value2>;]]`

Example:: `jdbc:db2://localhost:50000/MYDB:user=dbadm;password=dbadm;`

See the https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0052342.html[official documentation] for more detail on URL syntax and additional supported options.

=== MariaDB

`jdbc:mariadb:[replication:|failover:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<value1>[&<key2>=<value2>]]`
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/hibernate-orm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Add the following dependencies to your project:

* the Hibernate ORM extension: `io.quarkus:quarkus-hibernate-orm`
* your JDBC driver extension; the following options are available:
- `quarkus-jdbc-db2` for link:https://www.ibm.com/products/db2-database[IBM DB2]
- `quarkus-jdbc-derby` for link:https://db.apache.org/derby/[Apache Derby]
- `quarkus-jdbc-h2` for link:https://www.h2database.com/html/main.html[H2]
- `quarkus-jdbc-mariadb` for link:https://mariadb.com/[MariaDB]
Expand Down
50 changes: 50 additions & 0 deletions extensions/jdbc/jdbc-db2/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-jdbc-db2-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-jdbc-db2-deployment</artifactId>
<name>Quarkus - JDBC - DB2 - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-db2</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.quarkus.jdbc.db2.deployment;

import io.quarkus.agroal.deployment.JdbcDriverBuildItem;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.processor.BuiltinScope;
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem;
import io.quarkus.deployment.builditem.SslNativeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem;
import io.quarkus.jdbc.db2.runtime.DB2AgroalConnectionConfigurer;

public class JDBCDB2Processor {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.JDBC_DB2);
}

@BuildStep
void registerDriver(BuildProducer<JdbcDriverBuildItem> jdbcDriver,
SslNativeConfigBuildItem sslNativeConfigBuildItem) {
jdbcDriver.produce(new JdbcDriverBuildItem(DatabaseKind.DB2, "com.ibm.db2.jcc.DB2Driver",
"com.ibm.db2.jcc.DB2XADataSource"));
}

@BuildStep
void configureAgroalConnection(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
Capabilities capabilities) {
if (capabilities.isPresent(Capability.AGROAL)) {
additionalBeans
.produce(new AdditionalBeanBuildItem.Builder().addBeanClass(DB2AgroalConnectionConfigurer.class)
.setDefaultScope(BuiltinScope.APPLICATION.getName())
.setUnremovable()
.build());
}
}

@BuildStep
NativeImageConfigBuildItem build() {
// The DB2 JDBC driver has been updated with conditional checks for the
// "QuarkusWithJcc" system property which will no-op some code paths that
// are not needed for T4 JDBC usage and are incompatible with native mode
return NativeImageConfigBuildItem.builder()
.addNativeImageSystemProperty("QuarkusWithJcc", "true")
.build();
}

@BuildStep
NativeImageEnableAllCharsetsBuildItem enableAllCharsets() {
// When connecting to DB2 on z/OS the Cp037 charset is required
return new NativeImageEnableAllCharsetsBuildItem();
}
}
21 changes: 21 additions & 0 deletions extensions/jdbc/jdbc-db2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-jdbc-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-jdbc-db2-parent</artifactId>
<name>Quarkus - JDBC - DB2</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>


</project>
56 changes: 56 additions & 0 deletions extensions/jdbc/jdbc-db2/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-jdbc-db2-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-jdbc-db2</artifactId>
<name>Quarkus - JDBC - DB2 - Runtime</name>
<description>Connect to the DB2 database via JDBC</description>

<dependencies>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.jdbc.db2.runtime;

import io.quarkus.agroal.runtime.AgroalConnectionConfigurer;
import io.quarkus.agroal.runtime.JdbcDriver;
import io.quarkus.datasource.common.runtime.DatabaseKind;

@JdbcDriver(DatabaseKind.DB2)
public class DB2AgroalConnectionConfigurer implements AgroalConnectionConfigurer {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: "JDBC Driver - DB2"
metadata:
keywords:
- "jdbc-db2"
- "jdbc"
- "db2"
categories:
- "data"
1 change: 1 addition & 0 deletions extensions/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<packaging>pom</packaging>
<modules>
<module>jdbc-postgresql</module>
<module>jdbc-db2</module>
<module>jdbc-derby</module>
<module>jdbc-h2</module>
<module>jdbc-mariadb</module>
Expand Down
40 changes: 40 additions & 0 deletions integration-tests/jpa-db2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# JPA example with DB2

## Running the tests

By default, the tests of this module are disabled.

To run the tests in a standard JVM with DB2 started as a Docker container, you can run the following command:

```
mvn verify -Dtest-db2 -Ddocker
```

Additionally, you can generate a native image and run the tests for this native image by adding `-Dnative`:

```
mvn verify -Dtest-db2 -Ddocker -Dnative
```

## To manually run an equivalent DB2 container instead of through Testcontainers, do the following:

1. Start DB2 in a container

```
docker run \
-e DBNAME=hreact \
-e DB2INSTANCE=hreact \
-e DB2INST1_PASSWORD=hreact \
-e AUTOCONFIG=false \
-e ARCHIVE_LOGS=false \
-e LICENSE=accept \
-p 50000:50000 \
--privileged \
ibmcom/db2:11.5.0.0a
```

2. Run the test, specifying the JDBC URL for the container you started in the previous step

```
mvn verify -Dtest-db2 -Djdbc-db2.url=jdbc:db2://localhost:50000/hreact
```
Loading