Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow builds and pushes the Docker image for the OJP server.
# It should only trigger when there are changes in the `ojp-server` or `ojp-grpc-commons` modules.
name: Main OJP Server Docker Image CI

on:
push:
branches: [ main ]
paths:
- '.github/workflows/main-docker.yml'
- 'ojp-server/**'
- 'ojp-grpc-commons/**'

jobs:
build-docker-image:
name: Build Docker Image
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

steps:
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: 22
distribution: 'temurin'
cache: maven

- name: Build and push Docker image
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO }}
run: |
mvn compile jib:build -pl ojp-server \
-Dimage="${DOCKERHUB_REPO}:latest" \
-Djib.to.auth.username="${DOCKERHUB_USER}" \
-Djib.to.auth.password="${DOCKERHUB_TOKEN}" \
-Djib.to.image="${DOCKERHUB_REPO}:latest" \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to keep the repository and image name hard-coded here. I use env vars to test with my own DockerHub account.
Another thing you may want to change is the tag. I set it to latest, but I saw that you are creating as 0.0.1-alpha
Let me know if you want to change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to make only DockerHub repository configurable through Action vars.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version is 0.0.3-alpha, we are not using latest for now to not look like it is a production ready version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repurposed the workflow to be dispatched manually.
You can run the workflow by providing tag (default: latest) and repository (default: rrobetti)

-Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \
-Djib.container.ports=1059
31 changes: 25 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ on:

jobs:
build-test:
name: Build & Test
name: Build & Test Server
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
strategy:
matrix:
java-version: [ 11, 17, 21, 22 ]

services:
postgres:
Expand All @@ -36,18 +39,34 @@ jobs:
with:
fetch-depth: 0

- name: Set up JDK 22
- name: Set up JDK 22 for ojp-server
uses: actions/setup-java@v4
with:
java-version: 22
distribution: 'temurin'
cache: maven

- name: Build
- name: Build (ojp-server)
run: mvn clean install -DskipTests

- name: Run ojp-server
- name: Test (ojp-server)
run: mvn test -pl ojp-server

- name: Run (ojp-server)
run: mvn verify -pl ojp-server -Prun-ojp-server > ojp-server.log 2>&1 &

- name: Run tests
run: mvn test
- name: Wait for ojp-server to start
run: sleep 10

- name: Set up JDK ${{ matrix.java-version }} for ojp-grpc-commons and ojp-jdbc-driver
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: maven

- name: Build (ojp-grpc-commons, ojp-jdbc-driver)
run: mvn clean install -pl ojp-grpc-commons,ojp-jdbc-driver -DskipTests

- name: Test (ojp-grpc-commons, ojp-jdbc-driver)
run: mvn test -pl ojp-grpc-commons,ojp-jdbc-driver
3 changes: 3 additions & 0 deletions ojp-grpc-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
</parent>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<grpc.version>1.73.0</grpc.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<lombok.version>1.18.38</lombok.version>
Expand Down
104 changes: 104 additions & 0 deletions ojp-jdbc-driver/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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/maven-v4_0_0.xsd">
<parent>
<artifactId>ojp-parent</artifactId>
<groupId>org.openjdbcproxy</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ojp-jdbc-driver</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer />
<transformer />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.38</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.3.232</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.12.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<slf4j.version>2.0.17</slf4j.version>
<maven.compiler.source>11</maven.compiler.source>
</properties>
</project>
3 changes: 3 additions & 0 deletions ojp-jdbc-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
</parent>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<slf4j.version>2.0.17</slf4j.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ public void onNext(LobReference lobReference) {

@Override
public void onError(Throwable throwable) {
if (throwable instanceof StatusRuntimeException sre) {
if (throwable instanceof StatusRuntimeException) {
try {
StatusRuntimeException sre = (StatusRuntimeException) throwable;
handle(sre);//To convert to SQLException if possible
sfFirstLobReference.setException(sre);
sfFinalLobReference.setException(sre); //When conversion to SQLException not possible
Expand Down Expand Up @@ -334,8 +335,8 @@ public void onCompleted() {

//Wait to receive at least one successful block before returning.
if (!sfFirstBlockReceived.get() && errorReceived[0] != null) {
if (errorReceived[0] instanceof Exception e) {
throw e;
if (errorReceived[0] instanceof Exception) {
throw (Exception) errorReceived[0];
} else {
throw new RuntimeException(errorReceived[0]);
}
Expand Down Expand Up @@ -401,9 +402,9 @@ public void onNext(SessionTerminationStatus sessionTerminationStatus) {
@Override
public void onError(Throwable throwable) {
Throwable t = throwable;
if (throwable instanceof StatusRuntimeException sre) {
if (throwable instanceof StatusRuntimeException) {
try {
handle(sre);
handle((StatusRuntimeException) throwable);
} catch (SQLException e) {
t = e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public LobDataBlock next() {
if (this.error != null) {
throw new RuntimeException(this.error);
}
LobDataBlock block = this.blocksReceived.getFirst();
this.blocksReceived.removeFirst();
LobDataBlock block = this.blocksReceived.get(0);
this.blocksReceived.remove(0);
return block;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -107,7 +108,7 @@ public PreparedStatement(Connection connection, String sql, StatementService sta
public ResultSet executeQuery() throws SQLException {
this.checkClosed();
Iterator<OpResult> itOpResult = this.statementService
.executeQuery(this.connection.getSession(), this.sql, this.paramsMap.values().stream().toList(), this.properties);
.executeQuery(this.connection.getSession(), this.sql, new ArrayList<>(this.paramsMap.values()), this.properties);
return new ResultSet(itOpResult, this.statementService, this);
}

Expand All @@ -116,7 +117,7 @@ public int executeUpdate() throws SQLException {
this.checkClosed();
log.info("Executing update for -> {}", this.sql);
OpResult result = this.statementService.executeUpdate(this.connection.getSession(), this.sql,
this.paramsMap.values().stream().toList(), this.getStatementUUID(), null);
new ArrayList<>(this.paramsMap.values()), this.getStatementUUID(), null);
this.connection.setSession(result.getSession());
return deserialize(result.getValue().toByteArray(), Integer.class);
}
Expand All @@ -128,7 +129,7 @@ public void addBatch() throws SQLException {
Map<String, Object> properties = new HashMap<>();
properties.put(CommonConstants.PREPARED_STATEMENT_ADD_BATCH_FLAG, Boolean.TRUE);
OpResult result = this.statementService.executeUpdate(this.connection.getSession(), this.sql,
this.paramsMap.values().stream().toList(), this.getStatementUUID(), properties);
new ArrayList<>(this.paramsMap.values()), this.getStatementUUID(), properties);
this.connection.setSession(result.getSession());
if (StringUtils.isBlank(this.getStatementUUID()) && ResultType.UUID_STRING.equals(result.getType()) &&
!result.getValue().isEmpty()) {
Expand Down Expand Up @@ -751,7 +752,7 @@ private <T> T callProxy(CallType callType, String targetName, Class<?> returnTyp
);
CallResourceResponse response = this.statementService.callResource(reqBuilder.build());
this.connection.setSession(response.getSession());
if (this.getStatementUUID() == null && !response.getResourceUUID().isBlank()) {
if (this.getStatementUUID() == null && StringUtils.isNotBlank(response.getResourceUUID())) {
this.setStatementUUID(response.getResourceUUID());
}
if (Void.class.equals(returnType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public int getInt(int columnIndex) throws SQLException {
try {
return (int) currentDataBlock.get(blockIdx.get())[columnIndex - 1];
} catch (ClassCastException e) {
if (currentDataBlock.get(blockIdx.get())[columnIndex - 1] instanceof Long longValue) {
if (currentDataBlock.get(blockIdx.get())[columnIndex - 1] instanceof Long) {
Long longValue = (Long) currentDataBlock.get(blockIdx.get())[columnIndex - 1];
if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
return longValue.intValue();
} else {
Expand Down Expand Up @@ -231,7 +232,8 @@ public int getInt(String columnLabel) throws SQLException {
try {
return (int) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())];
}catch (ClassCastException e) {
if (currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())] instanceof Long longValue) {
if (currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())] instanceof Long) {
Long longValue = (Long) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())];
if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
return longValue.intValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public ResultSetMetaData(PreparedStatement ps, StatementService statementService

@Override
public int getColumnCount() throws SQLException {
if (resultSet instanceof org.openjdbcproxy.jdbc.ResultSet rs) {
if (resultSet instanceof org.openjdbcproxy.jdbc.ResultSet) {
org.openjdbcproxy.jdbc.ResultSet rs = (org.openjdbcproxy.jdbc.ResultSet) resultSet;
return rs.getLabelsMap().size();
} else {
return this.retrieveMetadataAttribute(CallType.CALL_GET, "ColumnCount",-1, Integer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ public void crudTestSuccessful(String driverClass, String url, String user, Stri
System.out.println("Testing for url -> " + url);

try {
executeUpdate(conn, """
drop table test_table
""");
executeUpdate(conn, "drop table test_table");
} catch (Exception e) {
//Does not matter
}
executeUpdate(conn, """
create table test_table(
id INT NOT NULL,
title VARCHAR(50) NOT NULL)
""");

executeUpdate(conn, """
insert into test_table (id, title) values (1, 'TITLE_1')
""");
executeUpdate(conn, "create table test_table(" +
"id INT NOT NULL," +
"title VARCHAR(50) NOT NULL" +
")");

executeUpdate(conn, " insert into test_table (id, title) values (1, 'TITLE_1')");

java.sql.PreparedStatement psSelect = conn.prepareStatement("select * from test_table where id = ?");
psSelect.setInt(1, 1);
Expand All @@ -60,9 +56,7 @@ insert into test_table (id, title) values (1, 'TITLE_1')
Assert.assertEquals(1, id);
Assert.assertEquals("TITLE_1", title);

executeUpdate(conn, """
update test_table set title='TITLE_1_UPDATED'
""");
executeUpdate(conn, "update test_table set title='TITLE_1_UPDATED'");

ResultSet resultSetUpdated = psSelect.executeQuery();
resultSetUpdated.next();
Expand All @@ -71,9 +65,7 @@ insert into test_table (id, title) values (1, 'TITLE_1')
Assert.assertEquals(1, idUpdated);
Assert.assertEquals("TITLE_1_UPDATED", titleUpdated);

executeUpdate(conn, """
delete from test_table where id=1 and title='TITLE_1_UPDATED'
""");
executeUpdate(conn, " delete from test_table where id=1 and title='TITLE_1_UPDATED'");

ResultSet resultSetAfterDeletion = psSelect.executeQuery();
Assert.assertFalse(resultSetAfterDeletion.next());
Expand Down
Loading