From e7f4da2f7093cb75922174209c70c64517059b51 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 12 Jun 2025 22:17:16 -0700 Subject: [PATCH 1/9] Converted project to multi-module, added CI workflow --- .github/workflows/main.yml | 35 +++++++++++++ .gitignore | 2 +- README.md | 27 +++++----- ojp-grpc-commons/pom.xml | 22 ++++---- ojp-jdbc-driver/pom.xml | 21 +++----- .../jdbc/BasicCrudIntegrationTest.java | 11 ++++ .../jdbc/BinaryStreamIntegrationTest.java | 13 +++++ ojp-server/dependency-reduced-pom.xml | 9 ++-- ojp-server/pom.xml | 12 +++-- pom.xml | 50 +++++++++++++++++++ 10 files changed, 158 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 pom.xml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5b34474 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: Main CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build-test: + name: Build & Test + 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 + run: mvn clean install -DskipTests + + - name: Run ojp-server + run: mvn verify -pl ojp-server -Prun-ojp-server + + - name: Run tests + run: mvn test -DdisablePostgresTests \ No newline at end of file diff --git a/.gitignore b/.gitignore index d6e82a8..980b806 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ # ignore all files in any directory named .idea */.idea/ - +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index c14390a..40b6c3e 100644 --- a/README.md +++ b/README.md @@ -58,24 +58,27 @@ This intelligent allocation of connections helps prevent overloading databases a ### ojp-server The ojp-server is a gRPC server that manages a Hikari connection pool and abstracts the creation and management of database connections. It supports one or multiple relational databases and provides virtual connections to the ojp-jdbc-driver. The server ensures the number of open real connections is always under control, according to predefined settings, improving database scalability. -#### How to start from source code ->Build the ojp-grpc-commons first. - -> Run the class GrpcServer main method. ### ojp-jdbc-driver The ojp-jdbc-driver is an implementation of the JDBC specification. It connects to the ojp-server via the gRPC protocol, sending SQL statements to be executed against the database and reading the responses. The driver works with virtual connections provided by the ojp-server, allowing the application to interact with the database without directly managing real database connections. -#### How to run ->Build the ojp-grpc-commons first. - ->Run any integration tests, the ojp-server is expected to be running in the same machine. - -Connections configuration: There are csv files under test/resources with connection details defaulted to H2 database, the name of each file implies which database connections can be added to it, for example the file h2_postgres_connections.csv can contain connections to H2 and/or postgres databases, integration tests classes that relly on this file will run all their tests against each connection in the file. ### ojp-grpc-commons The ojp-grpc-commons module contains the shared gRPC contracts used between the ojp-server and ojp-jdbc-driver. These contracts define the communication protocol and structure for requests and responses exchanged between the server and the driver. -#### How to build -``mvn clean install`` + +## How to build & test + +### Build modules + +``mvn clean install -DskipTests`` + +### Run ojp-server + +``mvn verify -pl ojp-server -Prun-ojp-server`` + +### Run tests +Connections configuration: There are csv files under test/resources with connection details defaulted to H2 database, the name of each file implies which database connections can be added to it, for example the file h2_postgres_connections.csv can contain connections to H2 and/or postgres databases, integration tests classes that relly on this file will run all their tests against each connection in the file. + +``mvn test`` ## Partners diff --git a/ojp-grpc-commons/pom.xml b/ojp-grpc-commons/pom.xml index b7b6137..9130642 100644 --- a/ojp-grpc-commons/pom.xml +++ b/ojp-grpc-commons/pom.xml @@ -4,15 +4,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.openjdbcproxy ojp-grpc-commons 1.0-SNAPSHOT + + org.openjdbcproxy + ojp-parent + 1.0-SNAPSHOT + ../pom.xml + + - 22 - 22 - UTF-8 - 1.70.0 + 1.73.0 + 1.7.1 + 1.18.38 @@ -36,17 +41,16 @@ kr.motd.maven os-maven-plugin - 1.7.1 + ${os-maven-plugin.version} org.projectlombok lombok - 1.18.30 + ${lombok.version} provided - @@ -54,7 +58,7 @@ kr.motd.maven os-maven-plugin - 1.6.1 + 1.7.0 diff --git a/ojp-jdbc-driver/pom.xml b/ojp-jdbc-driver/pom.xml index 8e6450d..081a0e7 100644 --- a/ojp-jdbc-driver/pom.xml +++ b/ojp-jdbc-driver/pom.xml @@ -4,15 +4,17 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example ojp-jdbc-driver 1.0-SNAPSHOT + + org.openjdbcproxy + ojp-parent + 1.0-SNAPSHOT + ../pom.xml + + - 22 - 22 - UTF-8 - 1.70.0 2.0.17 @@ -23,17 +25,11 @@ 1.0-SNAPSHOT - - io.grpc - grpc-netty - ${grpc.version} - - org.projectlombok lombok - 1.18.36 + 1.18.38 provided @@ -88,7 +84,6 @@ 5.12.1 test - diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java index 1712d8c..28db984 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java @@ -2,6 +2,8 @@ import lombok.extern.slf4j.Slf4j; import org.junit.Assert; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; @@ -15,9 +17,18 @@ @Slf4j public class BasicCrudIntegrationTest { + private static boolean isTestDisabled; + + @BeforeAll + public static void setup() { + isTestDisabled = Boolean.parseBoolean(System.getProperty("disablePostgresTests", "false")); + } + @ParameterizedTest @CsvFileSource(resources = "/h2_postgres_connections.csv") public void crudTestSuccessful(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException { + Assumptions.assumeFalse(isTestDisabled, "Skipping Postgres tests"); + Class.forName(driverClass); Connection conn = DriverManager.getConnection(url, user, pwd); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java index 5f93c7a..c7af248 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java @@ -1,6 +1,8 @@ package openjdbcproxy.jdbc; import org.junit.Assert; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; @@ -17,9 +19,18 @@ public class BinaryStreamIntegrationTest { + private static boolean isTestDisabled; + + @BeforeAll + public static void setup() { + isTestDisabled = Boolean.parseBoolean(System.getProperty("disablePostgresTests", "false")); + } + @ParameterizedTest @CsvFileSource(resources = "/postgres_connection.csv") public void createAndReadingBinaryStreamSuccessful(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException { + Assumptions.assumeFalse(isTestDisabled, "Skipping Postgres tests"); + Class.forName(driverClass); Connection conn = DriverManager.getConnection(url, user, pwd); @@ -90,6 +101,8 @@ insert into test_table_blob (val_blob1, val_blob2) values (?, ?) @ParameterizedTest @CsvFileSource(resources = "/postgres_connection.csv") public void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException { + Assumptions.assumeFalse(isTestDisabled, "Skipping Postgres tests"); + Class.forName(driverClass); Connection conn = DriverManager.getConnection(url, user, pwd); diff --git a/ojp-server/dependency-reduced-pom.xml b/ojp-server/dependency-reduced-pom.xml index 18e5894..4b76631 100644 --- a/ojp-server/dependency-reduced-pom.xml +++ b/ojp-server/dependency-reduced-pom.xml @@ -1,7 +1,11 @@ + + ojp-parent + org.openjdbcproxy + 1.0-SNAPSHOT + 4.0.0 - org.example ojp-server 1.0-SNAPSHOT @@ -52,10 +56,7 @@ - 22 2.0.17 - 22 - UTF-8 1.70.0 diff --git a/ojp-server/pom.xml b/ojp-server/pom.xml index c265ed1..79ebd4b 100644 --- a/ojp-server/pom.xml +++ b/ojp-server/pom.xml @@ -4,14 +4,17 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example ojp-server 1.0-SNAPSHOT + + org.openjdbcproxy + ojp-parent + 1.0-SNAPSHOT + ../pom.xml + + - 22 - 22 - UTF-8 1.70.0 2.0.17 @@ -86,7 +89,6 @@ slf4j-simple ${slf4j.version} - diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bf1af89 --- /dev/null +++ b/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + org.openjdbcproxy + ojp-parent + 1.0-SNAPSHOT + pom + + + ojp-grpc-commons + ojp-jdbc-driver + ojp-server + + + + 22 + 22 + UTF-8 + + + + + run-ojp-server + + + + org.codehaus.mojo + exec-maven-plugin + 3.5.1 + + + run-grpc-server + verify + + java + + + org.openjdbcproxy.grpc.server.GrpcServer + + + + + + + + + + \ No newline at end of file From 89355d5698549752ad2d19cae05a9e32bc5a68c0 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 12 Jun 2025 22:24:18 -0700 Subject: [PATCH 2/9] Fixed workflow to run ojp-serve as non-blocking step --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b34474..9eb31dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: run: mvn clean install -DskipTests - name: Run ojp-server - run: mvn verify -pl ojp-server -Prun-ojp-server + run: mvn verify -pl ojp-server -Prun-ojp-server > ojp-server.log 2>&1 & - name: Run tests run: mvn test -DdisablePostgresTests \ No newline at end of file From bdb65ac5f9ff3345049787de85cbc96e04c93f21 Mon Sep 17 00:00:00 2001 From: Roger Floriano <31597636+petruki@users.noreply.github.com> Date: Fri, 20 Jun 2025 19:34:34 -0700 Subject: [PATCH 3/9] Improved CI workflow to build, test (matrix), push server Docker img (#4) * Improved CI workflow to build, test (matrix), push server Docker img * Merged jobs server and driver * Removed modules from matrix to test all at once * Fixes build/test matrix execution Fixes ojp-server build step by including missing modules (#5) chore: lint ojp-server pom file Moved ojp-server image build job to different workflow Fixes main.docker.yml incorrect job ci: added delay for server to start, fixed server docker settings --- .github/workflows/main-docker.yml | 44 ++++++++ .github/workflows/main.yml | 31 +++++- ojp-grpc-commons/pom.xml | 3 + ojp-jdbc-driver/dependency-reduced-pom.xml | 104 ++++++++++++++++++ ojp-jdbc-driver/pom.xml | 3 + .../client/StatementServiceGrpcClient.java | 11 +- .../openjdbcproxy/jdbc/LobGrpcIterator.java | 4 +- .../openjdbcproxy/jdbc/PreparedStatement.java | 9 +- .../org/openjdbcproxy/jdbc/ResultSet.java | 6 +- .../openjdbcproxy/jdbc/ResultSetMetaData.java | 3 +- .../jdbc/BasicCrudIntegrationTest.java | 26 ++--- .../jdbc/BinaryStreamIntegrationTest.java | 49 +++------ .../jdbc/BlobIntegrationTest.java | 52 +++------ .../jdbc/MultipleTypesIntegrationTest.java | 54 ++++----- ...adMultipleBlocksOfDataIntegrationTest.java | 20 +--- ojp-server/dependency-reduced-pom.xml | 35 +++--- ojp-server/pom.xml | 5 +- pom.xml | 2 - 18 files changed, 289 insertions(+), 172 deletions(-) create mode 100644 .github/workflows/main-docker.yml create mode 100644 ojp-jdbc-driver/dependency-reduced-pom.xml diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml new file mode 100644 index 0000000..680c193 --- /dev/null +++ b/.github/workflows/main-docker.yml @@ -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" \ + -Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \ + -Djib.container.ports=1059 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0a9a371..81193a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/ojp-grpc-commons/pom.xml b/ojp-grpc-commons/pom.xml index 9130642..5a1a4a8 100644 --- a/ojp-grpc-commons/pom.xml +++ b/ojp-grpc-commons/pom.xml @@ -15,6 +15,9 @@ + 11 + 11 + 1.73.0 1.7.1 1.18.38 diff --git a/ojp-jdbc-driver/dependency-reduced-pom.xml b/ojp-jdbc-driver/dependency-reduced-pom.xml new file mode 100644 index 0000000..470ee2a --- /dev/null +++ b/ojp-jdbc-driver/dependency-reduced-pom.xml @@ -0,0 +1,104 @@ + + + + ojp-parent + org.openjdbcproxy + 1.0-SNAPSHOT + + 4.0.0 + ojp-jdbc-driver + 1.0-SNAPSHOT + + + + maven-surefire-plugin + 3.2.5 + + alphabetical + + + + maven-shade-plugin + 3.5.1 + + + package + + shade + + + true + + + + + + + + + + + + + org.projectlombok + lombok + 1.18.38 + provided + + + junit + junit + 4.13.2 + test + + + hamcrest-core + org.hamcrest + + + + + com.h2database + h2 + 2.3.232 + test + + + org.junit.jupiter + junit-jupiter + 5.12.1 + test + + + junit-jupiter-api + org.junit.jupiter + + + junit-jupiter-engine + org.junit.jupiter + + + + + org.junit.jupiter + junit-jupiter-params + 5.12.1 + test + + + apiguardian-api + org.apiguardian + + + junit-jupiter-api + org.junit.jupiter + + + + + + 11 + 2.0.17 + 11 + + diff --git a/ojp-jdbc-driver/pom.xml b/ojp-jdbc-driver/pom.xml index cc17b62..afcb7ce 100644 --- a/ojp-jdbc-driver/pom.xml +++ b/ojp-jdbc-driver/pom.xml @@ -15,6 +15,9 @@ + 11 + 11 + 2.0.17 diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java index 6d03426..5701aed 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java @@ -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 @@ -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]); } @@ -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; } diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java index e1b9cf6..98e15b6 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java @@ -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; } diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java index 56e8889..c3b96f0 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java @@ -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; @@ -107,7 +108,7 @@ public PreparedStatement(Connection connection, String sql, StatementService sta public ResultSet executeQuery() throws SQLException { this.checkClosed(); Iterator 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); } @@ -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); } @@ -128,7 +129,7 @@ public void addBatch() throws SQLException { Map 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()) { @@ -751,7 +752,7 @@ private 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)) { diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java index 182dba6..29c4ab5 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java @@ -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 { @@ -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 { diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java index 65a5f81..e8bdca4 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java @@ -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); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java index 28db984..6466f59 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java @@ -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); @@ -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(); @@ -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()); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java index c7af248..772a9a0 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java @@ -37,28 +37,22 @@ public void createAndReadingBinaryStreamSuccessful(String driverClass, String ur System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob1 BYTEA, - val_blob2 BYTEA - ) - """); + "create table test_table_blob(" + + " val_blob1 BYTEA," + + " val_blob2 BYTEA" + + ")" + ); conn.setAutoCommit(false); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob1, val_blob2) values (?, ?) - """ + "insert into test_table_blob (val_blob1, val_blob2) values (?, ?)" ); String testString = "BLOB VIA INPUT STREAM"; @@ -87,10 +81,7 @@ insert into test_table_blob (val_blob1, val_blob2) values (?, ?) String fromBlobByIdx2 = new String(blobResult2.readAllBytes()); Assert.assertEquals(testString.substring(0, 5), fromBlobByIdx2); - executeUpdate(conn, - """ - delete from test_table_blob - """ + executeUpdate(conn, "delete from test_table_blob" ); resultSet.close(); @@ -109,25 +100,19 @@ public void createAndReadingLargeBinaryStreamSuccessful(String driverClass, Stri System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BYTEA - ) - """); + "create table test_table_blob(" + + " val_blob BYTEA" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob) values (?) - """ + "insert into test_table_blob (val_blob) values (?)" ); @@ -152,11 +137,7 @@ insert into test_table_blob (val_blob) values (?) byteFile = inputStreamTestFile.read(); } - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java index f40b567..cec3a1c 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java @@ -27,27 +27,21 @@ public void createAndReadingBLOBsSuccessful(String driverClass, String url, Stri System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BLOB, - val_blob2 BLOB, - val_blob3 BLOB - ) - """); + "create table test_table_blob(" + + " val_blob BLOB," + + " val_blob2 BLOB," + + " val_blob3 BLOB" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?) - """ + " insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?)" ); String testString = "TEST STRING BLOB"; @@ -82,11 +76,7 @@ insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?) String fromBlobByIdx3 = new String(blobResult3.getBinaryStream().readAllBytes()); Assert.assertEquals(testString2.substring(0, 5), fromBlobByIdx3); - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); @@ -102,25 +92,19 @@ public void creatingAndReadingLargeBLOBsSuccessful(String driverClass, String ur System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BLOB - ) - """); + "create table test_table_blob(" + + " val_blob BLOB" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob) values (?) - """ + "insert into test_table_blob (val_blob) values (?)" ); @@ -154,11 +138,7 @@ insert into test_table_blob (val_blob) values (?) byteFile = inputStreamTestFile.read(); } - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/MultipleTypesIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/MultipleTypesIntegrationTest.java index 2344f92..aba6c57 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/MultipleTypesIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/MultipleTypesIntegrationTest.java @@ -28,39 +28,33 @@ public void typesCoverageTestSuccessful(String driverClass, String url, String u System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table - """); + executeUpdate(conn, "drop table test_table"); } catch (Exception e) { //Might not find it, not an issue } executeUpdate(conn, - """ - create table test_table( - val_int INT NOT NULL, - val_varchar VARCHAR(50) NOT NULL, - val_double_precision DOUBLE PRECISION, - val_bigint BIGINT, - val_tinyint TINYINT, - val_smallint SMALLINT, - val_boolean BOOLEAN, - val_decimal DECIMAL, - val_float FLOAT(2), - val_byte BINARY, - val_binary BINARY(4), - val_date DATE, - val_time TIME, - val_timestamp TIMESTAMP) - """); + "create table test_table(" + + " val_int INT NOT NULL," + + " val_varchar VARCHAR(50) NOT NULL," + + " val_double_precision DOUBLE PRECISION," + + " val_bigint BIGINT," + + " val_tinyint TINYINT," + + " val_smallint SMALLINT," + + " val_boolean BOOLEAN," + + " val_decimal DECIMAL," + + " val_float FLOAT(2)," + + " val_byte BINARY," + + " val_binary BINARY(4)," + + " val_date DATE," + + " val_time TIME," + + " val_timestamp TIMESTAMP)" + ); java.sql.PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, val_tinyint, - val_smallint, val_boolean, val_decimal, val_float, val_byte, val_binary, val_date, val_time, - val_timestamp) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - """ + "insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, val_tinyint, " + + "val_smallint, val_boolean, val_decimal, val_float, val_byte, val_binary, val_date, val_time, " + + "val_timestamp) " + + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); psInsert.setInt(1, 1); @@ -116,11 +110,7 @@ insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, Assert.assertEquals("11:12:13", sdfTime.format(resultSet.getTime("val_time"))); Assert.assertEquals("30/03/2025 21:22:23", sdfTimestamp.format(resultSet.getTimestamp("val_timestamp"))); - executeUpdate(conn, - """ - delete from test_table where val_int=1 - """ - ); + executeUpdate(conn, "delete from test_table where val_int=1"); ResultSet resultSetAfterDeletion = psSelect.executeQuery(); Assert.assertFalse(resultSetAfterDeletion.next()); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java index c0c3aa5..37fe69b 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java @@ -22,19 +22,15 @@ public void multiplePagesOfRowsResultSetSuccessful(int totalRecords, String driv System.out.println("Testing retrieving " + totalRecords + " records from url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_multi - """); + executeUpdate(conn, "drop table test_table_multi"); } catch (Exception e) { //Does not matter } executeUpdate(conn, - """ - create table test_table_multi( - id INT NOT NULL, - title VARCHAR(50) NOT NULL) - """); + "create table test_table_multi(" + + "id INT NOT NULL, " + + "title VARCHAR(50) NOT NULL)" + ); for (int i = 0; i < totalRecords; i++) { //TODO make this test parameterized with multiple parameters executeUpdate(conn, @@ -53,11 +49,7 @@ title VARCHAR(50) NOT NULL) Assert.assertEquals("TITLE_" + i, title); } - executeUpdate(conn, - """ - delete from test_table_multi - """ - ); + executeUpdate(conn, "delete from test_table_multi"); ResultSet resultSetAfterDeletion = psSelect.executeQuery(); Assert.assertFalse(resultSetAfterDeletion.next()); diff --git a/ojp-server/dependency-reduced-pom.xml b/ojp-server/dependency-reduced-pom.xml index 4b76631..f556674 100644 --- a/ojp-server/dependency-reduced-pom.xml +++ b/ojp-server/dependency-reduced-pom.xml @@ -29,21 +29,23 @@ - com.jolira - onejar-maven-plugin - - - - one-jar - - - org.baeldung.executable. - ExecutableMavenJar - true - ${project.build.finalName}.${project.packaging} - - - + com.google.cloud.tools + jib-maven-plugin + ${jib.plugin.version} + + + eclipse-temurin:22-jre + + + rrobetti/ojp:0.0.1-alpha + + + org.openjdbcproxy.grpc.server.GrpcServer + + 1059 + + + @@ -56,7 +58,10 @@ + 22 2.0.17 + 3.4.5 + 22 1.70.0 diff --git a/ojp-server/pom.xml b/ojp-server/pom.xml index 6f4c62c..f0ca5c7 100644 --- a/ojp-server/pom.xml +++ b/ojp-server/pom.xml @@ -15,6 +15,9 @@ + 22 + 22 + 1.70.0 2.0.17 3.4.5 @@ -61,7 +64,6 @@ 6.2.1 - org.apache.commons @@ -77,7 +79,6 @@ provided - org.slf4j diff --git a/pom.xml b/pom.xml index bf1af89..32b136e 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,6 @@ - 22 - 22 UTF-8 From a14979666e4ab8609940bdd09f57bf7a5ab8b451 Mon Sep 17 00:00:00 2001 From: rogerio Date: Sat, 21 Jun 2025 21:10:02 +0100 Subject: [PATCH 4/9] Simplified PreparedStatement implementation to extend Statement. Few extra fixes of issues found during draft performance testing. --- .../java/org/openjdbcproxy/jdbc/Driver.java | 10 +- .../openjdbcproxy/jdbc/PreparedStatement.java | 338 +++++------------- .../org/openjdbcproxy/jdbc/ResultSet.java | 27 +- .../openjdbcproxy/jdbc/ResultSetMetaData.java | 6 +- .../org/openjdbcproxy/jdbc/Statement.java | 15 +- 5 files changed, 121 insertions(+), 275 deletions(-) diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Driver.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Driver.java index 7a1c87a..e7e1d9b 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Driver.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Driver.java @@ -17,9 +17,11 @@ public class Driver implements java.sql.Driver { + private static final StatementServiceGrpcClient grpcStub = new StatementServiceGrpcClient(); + static { try { - DriverManager.registerDriver(new Driver(new StatementServiceGrpcClient())); + DriverManager.registerDriver(new Driver()); } catch (SQLException var1) { throw new RuntimeException("Can't register driver!"); } @@ -27,8 +29,8 @@ public class Driver implements java.sql.Driver { private final StatementService statementService; - public Driver(StatementService statementService) { - this.statementService = statementService; + public Driver() { + this.statementService = grpcStub; } @Override @@ -54,7 +56,7 @@ public java.sql.Connection connect(String url, Properties info) throws SQLExcept public boolean acceptsURL(String url) throws SQLException { if (url == null) { throw new SQLException("URL is null"); - } else if (url.startsWith("jdbc:ojp_")) { + } else if (url.contains("jdbc:ojp")) { return true; } else { return false; diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java index 20c4265..f8a4604 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java @@ -10,7 +10,6 @@ import com.openjdbcproxy.grpc.ResourceType; import com.openjdbcproxy.grpc.ResultType; import com.openjdbcproxy.grpc.TargetCall; -import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.openjdbcproxy.constants.CommonConstants; @@ -33,7 +32,6 @@ import java.sql.ResultSetMetaData; import java.sql.RowId; import java.sql.SQLException; -import java.sql.SQLWarning; import java.sql.SQLXML; import java.sql.Time; import java.sql.Timestamp; @@ -43,7 +41,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.SortedMap; import java.util.TreeMap; @@ -79,17 +76,15 @@ import static org.openjdbcproxy.grpc.dto.ParameterType.URL; @Slf4j -public class PreparedStatement implements java.sql.PreparedStatement { +public class PreparedStatement extends Statement implements java.sql.PreparedStatement { private final Connection connection; private String sql; private SortedMap paramsMap; private Map properties; private StatementService statementService; - @Getter - private String prepareStatementUUID;//If present represents the UUID of this PreparedStatement in the server - private Statement statement; public PreparedStatement(Connection connection, String sql, StatementService statementService) { + super(connection, statementService, null, ResourceType.RES_PREPARED_STATEMENT); this.connection = connection; this.sql = sql; this.properties = null; @@ -99,6 +94,7 @@ public PreparedStatement(Connection connection, String sql, StatementService sta public PreparedStatement(Connection connection, String sql, StatementService statementService, Map properties) { + super(connection, statementService, properties, ResourceType.RES_PREPARED_STATEMENT); this.connection = connection; this.sql = sql; this.properties = properties; @@ -108,6 +104,7 @@ public PreparedStatement(Connection connection, String sql, StatementService sta @Override public ResultSet executeQuery() throws SQLException { + this.checkClosed(); Iterator itOpResult = this.statementService .executeQuery(this.connection.getSession(), this.sql, this.paramsMap.values().stream().toList(), this.properties); return new ResultSet(itOpResult, this.statementService, this); @@ -115,32 +112,34 @@ public ResultSet executeQuery() throws SQLException { @Override 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.prepareStatementUUID, null); + this.paramsMap.values().stream().toList(), this.getStatementUUID(), null); this.connection.setSession(result.getSession()); return deserialize(result.getValue().toByteArray(), Integer.class); } @Override public void addBatch() throws SQLException { + this.checkClosed(); log.info("Executing add batch for -> {}", this.sql); Map 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.prepareStatementUUID, properties); + this.paramsMap.values().stream().toList(), this.getStatementUUID(), properties); this.connection.setSession(result.getSession()); - if (StringUtils.isBlank(this.prepareStatementUUID) && ResultType.UUID_STRING.equals(result.getType()) && - !result.getValue().isEmpty()) { + if (StringUtils.isBlank(this.getStatementUUID()) && ResultType.UUID_STRING.equals(result.getType()) && + !result.getValue().isEmpty()) { String psUUID = deserialize(result.getValue().toByteArray(), String.class); - this.prepareStatementUUID = psUUID; - this.getStatement().setStatementUUID(psUUID); + this.setStatementUUID(psUUID); } this.paramsMap = new TreeMap<>(); } @Override public void setNull(int parameterIndex, int sqlType) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(NULL) @@ -150,6 +149,7 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { @Override public void setBoolean(int parameterIndex, boolean x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(BOOLEAN) @@ -160,6 +160,7 @@ public void setBoolean(int parameterIndex, boolean x) throws SQLException { @Override public void setByte(int parameterIndex, byte x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(BYTE) @@ -170,6 +171,7 @@ public void setByte(int parameterIndex, byte x) throws SQLException { @Override public void setShort(int parameterIndex, short x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(SHORT) @@ -180,6 +182,7 @@ public void setShort(int parameterIndex, short x) throws SQLException { @Override public void setInt(int parameterIndex, int x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(INT) @@ -190,6 +193,7 @@ public void setInt(int parameterIndex, int x) throws SQLException { @Override public void setLong(int parameterIndex, long x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(LONG) @@ -200,6 +204,7 @@ public void setLong(int parameterIndex, long x) throws SQLException { @Override public void setFloat(int parameterIndex, float x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(FLOAT) @@ -210,6 +215,7 @@ public void setFloat(int parameterIndex, float x) throws SQLException { @Override public void setDouble(int parameterIndex, double x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(DOUBLE) @@ -220,6 +226,7 @@ public void setDouble(int parameterIndex, double x) throws SQLException { @Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(BIG_DECIMAL) @@ -230,6 +237,7 @@ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException @Override public void setString(int parameterIndex, String x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(STRING) @@ -240,6 +248,7 @@ public void setString(int parameterIndex, String x) throws SQLException { @Override public void setBytes(int parameterIndex, byte[] x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(BYTES) @@ -250,6 +259,7 @@ public void setBytes(int parameterIndex, byte[] x) throws SQLException { @Override public void setDate(int parameterIndex, Date x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(DATE) @@ -260,6 +270,7 @@ public void setDate(int parameterIndex, Date x) throws SQLException { @Override public void setTime(int parameterIndex, Time x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(TIME) @@ -270,6 +281,7 @@ public void setTime(int parameterIndex, Time x) throws SQLException { @Override public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(TIMESTAMP) @@ -280,6 +292,7 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { @Override public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(ASCII_STREAM) @@ -290,6 +303,7 @@ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws @Override public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(UNICODE_STREAM) @@ -300,16 +314,19 @@ public void setUnicodeStream(int parameterIndex, InputStream x, int length) thro @Override public void setBinaryStream(int parameterIndex, InputStream inputStream, int length) throws SQLException { + this.checkClosed(); this.setBinaryStream(parameterIndex, inputStream, (long) length); } @Override public void clearParameters() throws SQLException { + this.checkClosed(); this.paramsMap = new TreeMap<>(); } @Override public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(OBJECT) @@ -320,6 +337,7 @@ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQ @Override public void setObject(int parameterIndex, Object x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(OBJECT) @@ -330,11 +348,25 @@ public void setObject(int parameterIndex, Object x) throws SQLException { @Override public boolean execute() throws SQLException { - throw new SQLException("Not supported."); + this.checkClosed(); + String trimmedSql = sql.trim().toUpperCase(); + if (trimmedSql.startsWith("SELECT")) { + // Delegate to executeQuery + ResultSet resultSet = this.executeQuery(); + // Store the ResultSet for later retrieval if needed + this.lastResultSet = resultSet; + this.lastUpdateCount = -1; + return true; // Indicates a ResultSet was returned + } else { + // Delegate to executeUpdate + this.lastUpdateCount = this.executeUpdate(); + return false; // Indicates no ResultSet was returned + } } @Override public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + this.checkClosed(); //TODO this will require an implementation of Reader that communicates across GRPC this.paramsMap.put(parameterIndex, Parameter.builder() @@ -346,6 +378,7 @@ public void setCharacterStream(int parameterIndex, Reader reader, int length) th @Override public void setRef(int parameterIndex, Ref x) throws SQLException { + this.checkClosed(); if (DbInfo.isH2DB()) { throw new SQLException("Not supported."); } @@ -359,6 +392,7 @@ public void setRef(int parameterIndex, Ref x) throws SQLException { @Override public void setBlob(int parameterIndex, Blob x) throws SQLException { + this.checkClosed(); String blobUUID = (x != null) ? ((org.openjdbcproxy.jdbc.Blob) x).getUUID() : null; this.paramsMap.put(parameterIndex, Parameter.builder() @@ -370,6 +404,7 @@ public void setBlob(int parameterIndex, Blob x) throws SQLException { @Override public void setClob(int parameterIndex, Clob x) throws SQLException { + this.checkClosed(); String clobUUID = (x != null) ? ((org.openjdbcproxy.jdbc.Clob) x).getUUID() : null; this.paramsMap.put(parameterIndex, Parameter.builder() @@ -381,6 +416,7 @@ public void setClob(int parameterIndex, Clob x) throws SQLException { @Override public void setArray(int parameterIndex, Array x) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(ARRAY) @@ -391,11 +427,13 @@ public void setArray(int parameterIndex, Array x) throws SQLException { @Override public ResultSetMetaData getMetaData() throws SQLException { + this.checkClosed(); return new org.openjdbcproxy.jdbc.ResultSetMetaData(this, this.statementService); } @Override public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(DATE) @@ -406,6 +444,7 @@ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLExceptio @Override public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(TIME) @@ -416,6 +455,7 @@ public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLExceptio @Override public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(TIMESTAMP) @@ -426,6 +466,7 @@ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws S @Override public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(NULL) @@ -436,6 +477,7 @@ public void setNull(int parameterIndex, int sqlType, String typeName) throws SQL @Override public void setURL(int parameterIndex, URL x) throws SQLException { + this.checkClosed(); if (DbInfo.isH2DB()) { throw new SQLException("Not supported."); } @@ -449,11 +491,13 @@ public void setURL(int parameterIndex, URL x) throws SQLException { @Override public ParameterMetaData getParameterMetaData() throws SQLException { + this.checkClosed(); return new org.openjdbcproxy.jdbc.ParameterMetaData(); } @Override public void setRowId(int parameterIndex, RowId x) throws SQLException { + this.checkClosed(); if (DbInfo.isH2DB()) { throw new SQLException("Not supported."); } @@ -467,6 +511,7 @@ public void setRowId(int parameterIndex, RowId x) throws SQLException { @Override public void setNString(int parameterIndex, String value) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(N_STRING) @@ -477,6 +522,7 @@ public void setNString(int parameterIndex, String value) throws SQLException { @Override public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + this.checkClosed(); //TODO see if can use similar/same reader communication layer as other methods that require reader this.paramsMap.put(parameterIndex, Parameter.builder() @@ -488,6 +534,7 @@ public void setNCharacterStream(int parameterIndex, Reader value, long length) t @Override public void setNClob(int parameterIndex, NClob value) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(N_CLOB) @@ -498,6 +545,7 @@ public void setNClob(int parameterIndex, NClob value) throws SQLException { @Override public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + this.checkClosed(); try { org.openjdbcproxy.jdbc.Clob clob = (org.openjdbcproxy.jdbc.Clob) this.getConnection().createClob(); OutputStream os = clob.setAsciiStream(1); @@ -523,6 +571,7 @@ public void setClob(int parameterIndex, Reader reader, long length) throws SQLEx @Override public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + this.checkClosed(); try { org.openjdbcproxy.jdbc.Blob blob = (org.openjdbcproxy.jdbc.Blob) this.getConnection().createBlob(); OutputStream os = blob.setBinaryStream(1); @@ -548,6 +597,7 @@ public void setBlob(int parameterIndex, InputStream inputStream, long length) th @Override public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + this.checkClosed(); //TODO see if can use similar/same reader communication layer as other methods that require reader this.paramsMap.put(parameterIndex, Parameter.builder() @@ -559,6 +609,7 @@ public void setNClob(int parameterIndex, Reader reader, long length) throws SQLE @Override public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(SQL_XML) @@ -569,6 +620,7 @@ public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException @Override public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(OBJECT) @@ -579,6 +631,7 @@ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale @Override public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + this.checkClosed(); this.paramsMap.put(parameterIndex, Parameter.builder() .type(ASCII_STREAM) @@ -589,6 +642,7 @@ public void setAsciiStream(int parameterIndex, InputStream x, long length) throw @Override public void setBinaryStream(int parameterIndex, InputStream is, long length) throws SQLException { + this.checkClosed(); try { BinaryStream binaryStream = new BinaryStream(this.getConnection(), new LobServiceImpl(this.connection, this.statementService), @@ -597,9 +651,9 @@ public void setBinaryStream(int parameterIndex, InputStream is, long length) thr metadata.put(CommonConstants.PREPARED_STATEMENT_BINARY_STREAM_INDEX, parameterIndex); metadata.put(CommonConstants.PREPARED_STATEMENT_BINARY_STREAM_LENGTH, length); metadata.put(CommonConstants.PREPARED_STATEMENT_BINARY_STREAM_SQL, this.sql); - metadata.put(CommonConstants.PREPARED_STATEMENT_UUID_BINARY_STREAM, this.prepareStatementUUID); + metadata.put(CommonConstants.PREPARED_STATEMENT_UUID_BINARY_STREAM, this.getStatementUUID()); LobReference lobReference = binaryStream.sendBinaryStream(LobType.LT_BINARY_STREAM, is, metadata); - this.prepareStatementUUID = lobReference.getUuid();//Lob reference UUID for binary streams is the prepared statement uuid. + this.setStatementUUID(lobReference.getUuid());//Lob reference UUID for binary streams is the prepared statement uuid. } catch (RuntimeException e) { throw new SQLException("Unable to write binary stream: " + e.getMessage(), e); } @@ -607,30 +661,33 @@ public void setBinaryStream(int parameterIndex, InputStream is, long length) thr @Override public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + this.checkClosed(); } @Override public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - + this.checkClosed(); } @Override public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + this.checkClosed(); this.setBinaryStream(parameterIndex, x, -1); //-1 means not provided in OJP BynaryStrem server side } @Override public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { - + this.checkClosed(); } @Override public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - + this.checkClosed(); } @Override public void setClob(int parameterIndex, Reader reader) throws SQLException { + this.checkClosed(); this.setClob(parameterIndex, reader, Long.MAX_VALUE); } @@ -641,238 +698,7 @@ public void setBlob(int parameterIndex, InputStream inputStream) throws SQLExcep @Override public void setNClob(int parameterIndex, Reader reader) throws SQLException { - - } - - // --- Statement interface methods (delegated to this.getStatement()) --- - - @Override - public ResultSet executeQuery(String sql) throws SQLException { - return this.getStatement().executeQuery(sql); - } - - @Override - public int executeUpdate(String sql) throws SQLException { - return this.getStatement().executeUpdate(sql); - } - - @Override - public void close() throws SQLException { - this.getStatement().close(); - } - - @Override - public int getMaxFieldSize() throws SQLException { - return this.getStatement().getMaxFieldSize(); - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - this.getStatement().setMaxFieldSize(max); - } - - @Override - public int getMaxRows() throws SQLException { - return this.getStatement().getMaxRows(); - } - - @Override - public void setMaxRows(int max) throws SQLException { - this.getStatement().setMaxRows(max); - } - - @Override - public void setEscapeProcessing(boolean enable) throws SQLException { - this.getStatement().setEscapeProcessing(enable); - } - - @Override - public int getQueryTimeout() throws SQLException { - return this.getStatement().getQueryTimeout(); - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - this.getStatement().setQueryTimeout(seconds); - } - - @Override - public void cancel() throws SQLException { - this.getStatement().cancel(); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return this.getStatement().getWarnings(); - } - - @Override - public void clearWarnings() throws SQLException { - this.getStatement().clearWarnings(); - } - - @Override - public void setCursorName(String name) throws SQLException { - this.getStatement().setCursorName(name); - } - - @Override - public boolean execute(String sql) throws SQLException { - return this.getStatement().execute(sql); - } - - @Override - public ResultSet getResultSet() throws SQLException { - return this.getStatement().getResultSet(); - } - - @Override - public int getUpdateCount() throws SQLException { - return this.getStatement().getUpdateCount(); - } - - @Override - public boolean getMoreResults() throws SQLException { - return this.getStatement().getMoreResults(); - } - - @Override - public void setFetchDirection(int direction) throws SQLException { - this.getStatement().setFetchDirection(direction); - } - - @Override - public int getFetchDirection() throws SQLException { - return this.getStatement().getFetchDirection(); - } - - @Override - public void setFetchSize(int rows) throws SQLException { - this.getStatement().setFetchSize(rows); - } - - @Override - public int getFetchSize() throws SQLException { - return this.getStatement().getFetchSize(); - } - - @Override - public int getResultSetConcurrency() throws SQLException { - return this.getStatement().getResultSetConcurrency(); - } - - @Override - public int getResultSetType() throws SQLException { - return this.getStatement().getResultSetType(); - } - - @Override - public void addBatch(String sql) throws SQLException { - this.getStatement().addBatch(sql); - } - - @Override - public void clearBatch() throws SQLException { - this.getStatement().clearBatch(); - } - - @Override - public int[] executeBatch() throws SQLException { - return this.getStatement().executeBatch(); - } - - @Override - public Connection getConnection() throws SQLException { - return this.connection; - } - - @Override - public boolean getMoreResults(int current) throws SQLException { - return this.getStatement().getMoreResults(current); - } - - @Override - public RemoteProxyResultSet getGeneratedKeys() throws SQLException { - return this.getStatement().getGeneratedKeys(); - } - - @Override - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - return this.getStatement().executeUpdate(sql, autoGeneratedKeys); - } - - @Override - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - return this.getStatement().executeUpdate(sql, columnIndexes); - } - - @Override - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - return this.getStatement().executeUpdate(sql, columnNames); - } - - @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return this.getStatement().execute(sql, autoGeneratedKeys); - } - - @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - return this.getStatement().execute(sql, columnIndexes); - } - - @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - return this.getStatement().execute(sql, columnNames); - } - - @Override - public int getResultSetHoldability() throws SQLException { - return this.getStatement().getResultSetHoldability(); - } - - @Override - public boolean isClosed() throws SQLException { - return this.getStatement().isClosed(); - } - - @Override - public void setPoolable(boolean poolable) throws SQLException { - this.getStatement().setPoolable(poolable); - } - - @Override - public boolean isPoolable() throws SQLException { - return this.getStatement().isPoolable(); - } - - @Override - public void closeOnCompletion() throws SQLException { - this.getStatement().closeOnCompletion(); - } - - @Override - public boolean isCloseOnCompletion() throws SQLException { - return this.getStatement().isCloseOnCompletion(); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } - - private synchronized Statement getStatement() throws SQLException { - if (this.statement == null) { - this.propertiesHaveSqlStatement(); - this.statement = new Statement(this.connection, this.statementService, this.properties, - ResourceType.RES_PREPARED_STATEMENT); - } - return this.statement; + this.checkClosed(); } public Map getProperties() { @@ -895,13 +721,13 @@ private void propertiesHaveSqlStatement() { } } - private CallResourceRequest.Builder newCallBuilder() { + private CallResourceRequest.Builder newCallBuilder() throws SQLException { this.propertiesHaveSqlStatement(); CallResourceRequest.Builder builder = CallResourceRequest.newBuilder() .setSession(this.connection.getSession()) .setResourceType(ResourceType.RES_PREPARED_STATEMENT); - if (this.prepareStatementUUID != null) { - builder.setResourceUUID(this.prepareStatementUUID); + if (this.getStatementUUID() != null) { + builder.setResourceUUID(this.getStatementUUID()); } if (this.properties != null) { builder.setProperties(ByteString.copyFrom(serialize(this.properties))); @@ -924,8 +750,8 @@ private T callProxy(CallType callType, String targetName, Class returnTyp ); CallResourceResponse response = this.statementService.callResource(reqBuilder.build()); this.connection.setSession(response.getSession()); - if (this.prepareStatementUUID == null && !response.getResourceUUID().isBlank()) { - this.prepareStatementUUID = response.getResourceUUID(); + if (this.getStatementUUID() == null && !response.getResourceUUID().isBlank()) { + this.setStatementUUID(response.getResourceUUID()); } if (Void.class.equals(returnType)) { return null; diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java index 4aefef1..91d3d83 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSet.java @@ -126,7 +126,12 @@ public short getShort(int columnIndex) throws SQLException { @Override public int getInt(int columnIndex) throws SQLException { - return (int) currentDataBlock.get(blockIdx.get())[columnIndex - 1]; + Object value = currentDataBlock.get(blockIdx.get())[columnIndex - 1]; + if (value instanceof Long lValue) { + return lValue.intValue(); + } else { + return (int) value; + } } @Override @@ -136,12 +141,20 @@ public long getLong(int columnIndex) throws SQLException { @Override public float getFloat(int columnIndex) throws SQLException { - return (float) currentDataBlock.get(blockIdx.get())[columnIndex -1]; + Object value = currentDataBlock.get(blockIdx.get())[columnIndex -1]; + if (value instanceof BigDecimal bdValue) { + return bdValue.floatValue(); + } + return (float) value; } @Override public double getDouble(int columnIndex) throws SQLException { - return (double) currentDataBlock.get(blockIdx.get())[columnIndex -1]; + Object value = currentDataBlock.get(blockIdx.get())[columnIndex -1]; + if (value instanceof BigDecimal bdValue) { + return bdValue.doubleValue(); + } + return (double) value; } @Override @@ -217,22 +230,22 @@ public short getShort(String columnLabel) throws SQLException { @Override public int getInt(String columnLabel) throws SQLException { - return (int) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())]; + return this.getInt(this.labelsMap.get(columnLabel.toUpperCase()) + 1); } @Override public long getLong(String columnLabel) throws SQLException { - return (long) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())]; + return this.getLong(this.labelsMap.get(columnLabel.toUpperCase()) + 1); } @Override public float getFloat(String columnLabel) throws SQLException { - return (float) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())]; + return this.getFloat(this.labelsMap.get(columnLabel.toUpperCase()) + 1); } @Override public double getDouble(String columnLabel) throws SQLException { - return (double) currentDataBlock.get(blockIdx.get())[this.labelsMap.get(columnLabel.toUpperCase())]; + return this.getDouble(this.labelsMap.get(columnLabel.toUpperCase())); } @Override diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java index e233f69..1b5f2c7 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java @@ -53,8 +53,8 @@ private CallResourceRequest.Builder newCallBuilder() throws SQLException { .setSession(this.ps.getConnection().getSession()) .setResourceType(ResourceType.RES_PREPARED_STATEMENT) .setProperties(ByteString.copyFrom(serialize(this.ps.getProperties()))); - if (StringUtils.isNotBlank(this.ps.getPrepareStatementUUID())) { - builder.setResourceUUID(this.ps.getPrepareStatementUUID()); + if (StringUtils.isNotBlank(this.ps.getStatementUUID())) { + builder.setResourceUUID(this.ps.getStatementUUID()); } return builder; } @@ -196,4 +196,4 @@ private T retrieveMetadataAttribute(CallType callType, String attrName, Inte } return (T) deserialize(response.getValues().toByteArray(), returnType); } -} +} \ No newline at end of file diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Statement.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Statement.java index 9134ad3..c2c22a2 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Statement.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/Statement.java @@ -7,6 +7,7 @@ import com.openjdbcproxy.grpc.OpResult; import com.openjdbcproxy.grpc.ResourceType; import com.openjdbcproxy.grpc.TargetCall; +import lombok.Getter; import lombok.Setter; import org.openjdbcproxy.grpc.client.StatementService; @@ -27,14 +28,16 @@ public class Statement implements java.sql.Statement { private final Connection connection; private final StatementService statementService; private final Map properties; - private ResultSet lastResultSet; - private int lastUpdateCount; - private boolean closed; @Setter + @Getter private String statementUUID; private int maxRows; private ResourceType resourceType; + protected boolean closed; + protected ResultSet lastResultSet; + protected int lastUpdateCount; + public Statement(Connection connection, StatementService statementService) { this(connection, statementService, null); } @@ -52,7 +55,7 @@ public Statement(Connection connection, StatementService statementService, Map Date: Sat, 21 Jun 2025 13:14:36 -0700 Subject: [PATCH 5/9] ci: fixed job build-test title and docker image name --- .github/workflows/main-docker.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml index 680c193..b804b6c 100644 --- a/.github/workflows/main-docker.yml +++ b/.github/workflows/main-docker.yml @@ -39,6 +39,6 @@ jobs: -Dimage="${DOCKERHUB_REPO}:latest" \ -Djib.to.auth.username="${DOCKERHUB_USER}" \ -Djib.to.auth.password="${DOCKERHUB_TOKEN}" \ - -Djib.to.image="${DOCKERHUB_REPO}:latest" \ + -Djib.to.image="${DOCKERHUB_REPO}/ojp:latest" \ -Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \ -Djib.container.ports=1059 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81193a9..f2162c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ on: jobs: build-test: - name: Build & Test Server + name: Build & Test runs-on: ubuntu-latest if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" strategy: From ec3a42c9c4936aeb798485092f6d5821388d166a Mon Sep 17 00:00:00 2001 From: Roger Floriano <31597636+petruki@users.noreply.github.com> Date: Fri, 20 Jun 2025 19:34:34 -0700 Subject: [PATCH 6/9] Improved CI workflow to build, test (matrix), push server Docker img (#4) * Improved CI workflow to build, test (matrix), push server Docker img * Merged jobs server and driver * Removed modules from matrix to test all at once * Fixes build/test matrix execution Fixes ojp-server build step by including missing modules (#5) chore: lint ojp-server pom file Moved ojp-server image build job to different workflow Fixes main.docker.yml incorrect job ci: added delay for server to start, fixed server docker settings --- .github/workflows/main-docker.yml | 44 ++++++++ .github/workflows/main.yml | 31 +++++- ojp-grpc-commons/pom.xml | 3 + ojp-jdbc-driver/dependency-reduced-pom.xml | 104 ++++++++++++++++++ ojp-jdbc-driver/pom.xml | 3 + .../client/StatementServiceGrpcClient.java | 11 +- .../openjdbcproxy/jdbc/LobGrpcIterator.java | 4 +- .../openjdbcproxy/jdbc/PreparedStatement.java | 9 +- .../openjdbcproxy/jdbc/ResultSetMetaData.java | 3 +- .../jdbc/BasicCrudIntegrationTest.java | 26 ++--- .../jdbc/BinaryStreamIntegrationTest.java | 49 +++------ .../jdbc/BlobIntegrationTest.java | 52 +++------ .../jdbc/H2MultipleTypesIntegrationTest.java | 54 ++++----- ...adMultipleBlocksOfDataIntegrationTest.java | 20 +--- ojp-server/pom.xml | 5 +- pom.xml | 2 - 16 files changed, 265 insertions(+), 155 deletions(-) create mode 100644 .github/workflows/main-docker.yml create mode 100644 ojp-jdbc-driver/dependency-reduced-pom.xml diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml new file mode 100644 index 0000000..680c193 --- /dev/null +++ b/.github/workflows/main-docker.yml @@ -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" \ + -Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \ + -Djib.container.ports=1059 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0a9a371..81193a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/ojp-grpc-commons/pom.xml b/ojp-grpc-commons/pom.xml index 9130642..5a1a4a8 100644 --- a/ojp-grpc-commons/pom.xml +++ b/ojp-grpc-commons/pom.xml @@ -15,6 +15,9 @@ + 11 + 11 + 1.73.0 1.7.1 1.18.38 diff --git a/ojp-jdbc-driver/dependency-reduced-pom.xml b/ojp-jdbc-driver/dependency-reduced-pom.xml new file mode 100644 index 0000000..470ee2a --- /dev/null +++ b/ojp-jdbc-driver/dependency-reduced-pom.xml @@ -0,0 +1,104 @@ + + + + ojp-parent + org.openjdbcproxy + 1.0-SNAPSHOT + + 4.0.0 + ojp-jdbc-driver + 1.0-SNAPSHOT + + + + maven-surefire-plugin + 3.2.5 + + alphabetical + + + + maven-shade-plugin + 3.5.1 + + + package + + shade + + + true + + + + + + + + + + + + + org.projectlombok + lombok + 1.18.38 + provided + + + junit + junit + 4.13.2 + test + + + hamcrest-core + org.hamcrest + + + + + com.h2database + h2 + 2.3.232 + test + + + org.junit.jupiter + junit-jupiter + 5.12.1 + test + + + junit-jupiter-api + org.junit.jupiter + + + junit-jupiter-engine + org.junit.jupiter + + + + + org.junit.jupiter + junit-jupiter-params + 5.12.1 + test + + + apiguardian-api + org.apiguardian + + + junit-jupiter-api + org.junit.jupiter + + + + + + 11 + 2.0.17 + 11 + + diff --git a/ojp-jdbc-driver/pom.xml b/ojp-jdbc-driver/pom.xml index cc17b62..afcb7ce 100644 --- a/ojp-jdbc-driver/pom.xml +++ b/ojp-jdbc-driver/pom.xml @@ -15,6 +15,9 @@ + 11 + 11 + 2.0.17 diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java index 6d03426..5701aed 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java @@ -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 @@ -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]); } @@ -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; } diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java index e1b9cf6..98e15b6 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java @@ -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; } diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java index 67cbbb9..263ffb0 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java @@ -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; @@ -108,7 +109,7 @@ public ResultSet executeQuery() throws SQLException { this.checkClosed(); log.info("Executing query for -> {}", this.sql); Iterator 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); } @@ -117,7 +118,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); } @@ -129,7 +130,7 @@ public void addBatch() throws SQLException { Map 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()) { @@ -752,7 +753,7 @@ private 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)) { diff --git a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java index 65a5f81..e8bdca4 100644 --- a/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java +++ b/ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/ResultSetMetaData.java @@ -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); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java index 84c0017..ce8b9b4 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BasicCrudIntegrationTest.java @@ -34,21 +34,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); @@ -59,9 +55,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(); @@ -70,9 +64,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()); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java index b9dca95..30a5621 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BinaryStreamIntegrationTest.java @@ -36,28 +36,22 @@ public void createAndReadingBinaryStreamSuccessful(String driverClass, String ur System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob1 BYTEA, - val_blob2 BYTEA - ) - """); + "create table test_table_blob(" + + " val_blob1 BYTEA," + + " val_blob2 BYTEA" + + ")" + ); conn.setAutoCommit(false); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob1, val_blob2) values (?, ?) - """ + "insert into test_table_blob (val_blob1, val_blob2) values (?, ?)" ); String testString = "BLOB VIA INPUT STREAM"; @@ -86,10 +80,7 @@ insert into test_table_blob (val_blob1, val_blob2) values (?, ?) String fromBlobByIdx2 = new String(blobResult2.readAllBytes()); Assert.assertEquals(testString.substring(0, 5), fromBlobByIdx2); - executeUpdate(conn, - """ - delete from test_table_blob - """ + executeUpdate(conn, "delete from test_table_blob" ); resultSet.close(); @@ -107,25 +98,19 @@ public void createAndReadingLargeBinaryStreamSuccessful(String driverClass, Stri System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BYTEA - ) - """); + "create table test_table_blob(" + + " val_blob BYTEA" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob) values (?) - """ + "insert into test_table_blob (val_blob) values (?)" ); @@ -150,11 +135,7 @@ insert into test_table_blob (val_blob) values (?) byteFile = inputStreamTestFile.read(); } - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java index 292d58b..691e3eb 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/BlobIntegrationTest.java @@ -26,27 +26,21 @@ public void createAndReadingBLOBsSuccessful(String driverClass, String url, Stri System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BLOB, - val_blob2 BLOB, - val_blob3 BLOB - ) - """); + "create table test_table_blob(" + + " val_blob BLOB," + + " val_blob2 BLOB," + + " val_blob3 BLOB" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?) - """ + " insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?)" ); String testString = "TEST STRING BLOB"; @@ -81,11 +75,7 @@ insert into test_table_blob (val_blob, val_blob2, val_blob3) values (?, ?, ?) String fromBlobByIdx3 = new String(blobResult3.getBinaryStream().readAllBytes()); Assert.assertEquals(testString2.substring(0, 5), fromBlobByIdx3); - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); @@ -100,25 +90,19 @@ public void creatingAndReadingLargeBLOBsSuccessful(String driverClass, String ur System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_blob - """); + executeUpdate(conn, "drop table test_table_blob"); } catch (Exception e) { //If fails disregard as per the table is most possibly not created yet } executeUpdate(conn, - """ - create table test_table_blob( - val_blob BLOB - ) - """); + "create table test_table_blob(" + + " val_blob BLOB" + + ")" + ); PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table_blob (val_blob) values (?) - """ + "insert into test_table_blob (val_blob) values (?)" ); @@ -152,11 +136,7 @@ insert into test_table_blob (val_blob) values (?) byteFile = inputStreamTestFile.read(); } - executeUpdate(conn, - """ - delete from test_table_blob - """ - ); + executeUpdate(conn, "delete from test_table_blob"); resultSet.close(); psSelect.close(); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/H2MultipleTypesIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/H2MultipleTypesIntegrationTest.java index bf9fe1f..fa883c4 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/H2MultipleTypesIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/H2MultipleTypesIntegrationTest.java @@ -27,39 +27,33 @@ public void typesCoverageTestSuccessful(String driverClass, String url, String u System.out.println("Testing for url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table - """); + executeUpdate(conn, "drop table test_table"); } catch (Exception e) { //Might not find it, not an issue } executeUpdate(conn, - """ - create table test_table( - val_int INT NOT NULL, - val_varchar VARCHAR(50) NOT NULL, - val_double_precision DOUBLE PRECISION, - val_bigint BIGINT, - val_tinyint TINYINT, - val_smallint SMALLINT, - val_boolean BOOLEAN, - val_decimal DECIMAL, - val_float FLOAT(2), - val_byte BINARY, - val_binary BINARY(4), - val_date DATE, - val_time TIME, - val_timestamp TIMESTAMP) - """); + "create table test_table(" + + " val_int INT NOT NULL," + + " val_varchar VARCHAR(50) NOT NULL," + + " val_double_precision DOUBLE PRECISION," + + " val_bigint BIGINT," + + " val_tinyint TINYINT," + + " val_smallint SMALLINT," + + " val_boolean BOOLEAN," + + " val_decimal DECIMAL," + + " val_float FLOAT(2)," + + " val_byte BINARY," + + " val_binary BINARY(4)," + + " val_date DATE," + + " val_time TIME," + + " val_timestamp TIMESTAMP)" + ); java.sql.PreparedStatement psInsert = conn.prepareStatement( - """ - insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, val_tinyint, - val_smallint, val_boolean, val_decimal, val_float, val_byte, val_binary, val_date, val_time, - val_timestamp) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - """ + "insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, val_tinyint, " + + "val_smallint, val_boolean, val_decimal, val_float, val_byte, val_binary, val_date, val_time, " + + "val_timestamp) " + + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); psInsert.setInt(1, 1); @@ -115,11 +109,7 @@ insert into test_table (val_int, val_varchar, val_double_precision, val_bigint, Assert.assertEquals("11:12:13", sdfTime.format(resultSet.getTime("val_time"))); Assert.assertEquals("30/03/2025 21:22:23", sdfTimestamp.format(resultSet.getTimestamp("val_timestamp"))); - executeUpdate(conn, - """ - delete from test_table where val_int=1 - """ - ); + executeUpdate(conn, "delete from test_table where val_int=1"); ResultSet resultSetAfterDeletion = psSelect.executeQuery(); Assert.assertFalse(resultSetAfterDeletion.next()); diff --git a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java index c773fef..ebee73c 100644 --- a/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java +++ b/ojp-jdbc-driver/src/test/java/openjdbcproxy/jdbc/ReadMultipleBlocksOfDataIntegrationTest.java @@ -21,19 +21,15 @@ public void multiplePagesOfRowsResultSetSuccessful(int totalRecords, String driv System.out.println("Testing retrieving " + totalRecords + " records from url -> " + url); try { - executeUpdate(conn, - """ - drop table test_table_multi - """); + executeUpdate(conn, "drop table test_table_multi"); } catch (Exception e) { //Does not matter } executeUpdate(conn, - """ - create table test_table_multi( - id INT NOT NULL, - title VARCHAR(50) NOT NULL) - """); + "create table test_table_multi(" + + "id INT NOT NULL, " + + "title VARCHAR(50) NOT NULL)" + ); for (int i = 0; i < totalRecords; i++) { //TODO make this test parameterized with multiple parameters executeUpdate(conn, @@ -52,11 +48,7 @@ title VARCHAR(50) NOT NULL) Assert.assertEquals("TITLE_" + i, title); } - executeUpdate(conn, - """ - delete from test_table_multi - """ - ); + executeUpdate(conn, "delete from test_table_multi"); ResultSet resultSetAfterDeletion = psSelect.executeQuery(); Assert.assertFalse(resultSetAfterDeletion.next()); diff --git a/ojp-server/pom.xml b/ojp-server/pom.xml index 3a86bbf..b1e5dbe 100644 --- a/ojp-server/pom.xml +++ b/ojp-server/pom.xml @@ -15,6 +15,9 @@ + 22 + 22 + 1.70.0 2.0.17 3.4.5 @@ -61,7 +64,6 @@ 6.2.1 - org.apache.commons @@ -77,7 +79,6 @@ provided - org.slf4j diff --git a/pom.xml b/pom.xml index bf1af89..32b136e 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,6 @@ - 22 - 22 UTF-8 From a39413c48dc8ce99696a3b135d291d1c495449be Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:14:36 -0700 Subject: [PATCH 7/9] ci: fixed job build-test title and docker image name --- .github/workflows/main-docker.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml index 680c193..b804b6c 100644 --- a/.github/workflows/main-docker.yml +++ b/.github/workflows/main-docker.yml @@ -39,6 +39,6 @@ jobs: -Dimage="${DOCKERHUB_REPO}:latest" \ -Djib.to.auth.username="${DOCKERHUB_USER}" \ -Djib.to.auth.password="${DOCKERHUB_TOKEN}" \ - -Djib.to.image="${DOCKERHUB_REPO}:latest" \ + -Djib.to.image="${DOCKERHUB_REPO}/ojp:latest" \ -Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \ -Djib.container.ports=1059 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81193a9..f2162c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ on: jobs: build-test: - name: Build & Test Server + name: Build & Test runs-on: ubuntu-latest if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" strategy: From 56fd161f834700d371b48746818a2a48430f8f12 Mon Sep 17 00:00:00 2001 From: Roger Floriano <31597636+petruki@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:46:45 -0700 Subject: [PATCH 8/9] ci: fixes server module build JDK setup (#6) * ci: fixes server module build JDK setup * fix: instanceof in ResultSet incompatibility --- .github/workflows/main-docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml index b804b6c..614a7ae 100644 --- a/.github/workflows/main-docker.yml +++ b/.github/workflows/main-docker.yml @@ -36,7 +36,6 @@ jobs: 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}/ojp:latest" \ From 8a6cd5065cea815d80ac1a5436fcc13de4a9b024 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 26 Jun 2025 18:45:39 -0700 Subject: [PATCH 9/9] Repurposed Docker build workflow for manual dispatch --- .../{main-docker.yml => docker-build.yml} | 25 ++++++++++--------- .github/workflows/main.yml | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) rename .github/workflows/{main-docker.yml => docker-build.yml} (66%) diff --git a/.github/workflows/main-docker.yml b/.github/workflows/docker-build.yml similarity index 66% rename from .github/workflows/main-docker.yml rename to .github/workflows/docker-build.yml index 614a7ae..b10554f 100644 --- a/.github/workflows/main-docker.yml +++ b/.github/workflows/docker-build.yml @@ -1,20 +1,21 @@ # 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 +name: OJP Server Docker Image Build on: - push: - branches: [ main ] - paths: - - '.github/workflows/main-docker.yml' - - 'ojp-server/**' - - 'ojp-grpc-commons/**' - + workflow_dispatch: + inputs: + tag: + description: 'Docker image tag' + required: true + default: 'latest' + repository: + description: 'Repository name' + required: true + default: 'rrobetti' 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 @@ -33,11 +34,11 @@ jobs: env: DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO }} + DOCKERHUB_REPO: ${{ github.event.inputs.repository }} run: | mvn compile jib:build -pl ojp-server \ -Djib.to.auth.username="${DOCKERHUB_USER}" \ -Djib.to.auth.password="${DOCKERHUB_TOKEN}" \ - -Djib.to.image="${DOCKERHUB_REPO}/ojp:latest" \ + -Djib.to.image="${DOCKERHUB_REPO}/ojp:${{ github.event.inputs.tag }}" \ -Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \ -Djib.container.ports=1059 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f2162c5..76b4063 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,7 @@ jobs: runs-on: ubuntu-latest if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" strategy: + fail-fast: false matrix: java-version: [ 11, 17, 21, 22 ]