From 25ea79e5bc9e354f4769f5b3ec71c0f3270da2e6 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Fri, 25 Oct 2024 14:00:23 +0530 Subject: [PATCH] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/fossa_scan.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- README.md | 2 +- ballerina/Ballerina.toml | 12 ++--- ballerina/Dependencies.toml | 43 +++++++-------- build-config/resources/Ballerina.toml | 12 ++--- build-config/spotbugs-exclude.xml | 12 +++++ compiler-plugin-tests/build.gradle | 9 ++-- compiler-plugin/build.gradle | 7 ++- gradle.properties | 42 +++++++-------- native/build.gradle | 9 ++-- .../sql/datasource/SQLWorkerThreadPool.java | 54 ------------------- .../stdlib/sql/nativeimpl/CallProcessor.java | 13 ++--- .../sql/nativeimpl/ExecuteProcessor.java | 24 ++------- .../stdlib/sql/nativeimpl/QueryProcessor.java | 26 +++------ test-utils/build.gradle | 7 ++- 21 files changed, 108 insertions(+), 178 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 2d154ffc..f202d1aa 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -14,5 +14,5 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 65d785ad..341a7a88 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -30,7 +30,7 @@ jobs: call_stdlib_workflow: name: Run StdLib Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21 with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 11922b55..ebe213e7 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -15,7 +15,7 @@ jobs: call_workflow: name: Run Central Publish Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21 secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/fossa_scan.yml b/.github/workflows/fossa_scan.yml index 651f73a6..a2862efe 100644 --- a/.github/workflows/fossa_scan.yml +++ b/.github/workflows/fossa_scan.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: fossas/fossa-action@main + - uses: fossas/fossa-action@java21 env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 5e6adfe3..2478fd39 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ jobs: call_workflow: name: Run Release Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21 secrets: inherit with: package-name: sql diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c717ff55..f85a9816 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,7 +10,7 @@ jobs: call_workflow: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21 secrets: inherit with: additional-windows-test-flags: "-x test" diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index c02c8ff4..41e8f6ad 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,5 +9,5 @@ jobs: call_workflow: name: Run Trivy Scan Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21 secrets: inherit diff --git a/README.md b/README.md index e79392d9..4cf972ff 100644 --- a/README.md +++ b/README.md @@ -429,7 +429,7 @@ This repository only contains the source code for the package. ### Set up the prerequisites -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). +1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations). * [Oracle](https://www.oracle.com/java/technologies/downloads/) * [OpenJDK](https://adoptium.net/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index e283ceee..7e0a9a99 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -7,27 +7,27 @@ keywords = ["database", "client", "network", "SQL", "RDBMS"] repository = "https://github.com/ballerina-platform/module-ballerina-sql" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.10.0-20241019-091600-89e54c08" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "sql-native" version = "1.14.2" path = "../native/build/libs/sql-native-1.14.2-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "../test-utils/build/libs/sql-test-utils-1.14.2-SNAPSHOT.jar" scope = "testOnly" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "com.zaxxer" artifactId = "HikariCP" version = "3.3.1" path = "./lib/HikariCP-3.3.1.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/hsqldb-2.7.1.jar" scope = "testOnly" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 91958039..eebd5468 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.10.0-20241019-091600-89e54c08" [[package]] org = "ballerina" name = "auth" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "crypto"}, @@ -23,19 +23,18 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.8.0" +version = "3.8.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"} + {org = "ballerina", name = "task"} ] [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.5.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -44,7 +43,7 @@ dependencies = [ [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.7.3" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -54,7 +53,7 @@ dependencies = [ [[package]] org = "ballerina" name = "file" -version = "1.10.0" +version = "1.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -69,7 +68,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -98,7 +97,7 @@ dependencies = [ [[package]] org = "ballerina" name = "io" -version = "1.6.1" +version = "1.6.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -118,7 +117,7 @@ modules = [ [[package]] org = "ballerina" name = "jwt" -version = "2.13.0" +version = "2.13.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "cache"}, @@ -127,8 +126,7 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.int"}, {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"} + {org = "ballerina", name = "log"} ] [[package]] @@ -245,7 +243,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -257,7 +255,7 @@ dependencies = [ [[package]] org = "ballerina" name = "mime" -version = "2.10.0" +version = "2.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -269,21 +267,20 @@ dependencies = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"}, {org = "ballerina", name = "url"} ] [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.3.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -292,7 +289,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.8.0" +version = "1.8.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -322,7 +319,7 @@ modules = [ [[package]] org = "ballerina" name = "task" -version = "2.5.0" +version = "2.5.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -346,7 +343,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.5.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -357,7 +354,7 @@ modules = [ [[package]] org = "ballerina" name = "url" -version = "2.4.0" +version = "2.4.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -366,7 +363,7 @@ dependencies = [ [[package]] org = "ballerina" name = "uuid" -version = "1.8.0" +version = "1.8.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "crypto"}, diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 63cfb32d..84bcbef0 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,27 +7,27 @@ keywords = ["database", "client", "network", "SQL", "RDBMS"] repository = "https://github.com/ballerina-platform/module-ballerina-sql" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.10.0-20241019-091600-89e54c08" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "sql-native" version = "@toml.version@" path = "../native/build/libs/sql-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "../test-utils/build/libs/sql-test-utils-@project.version@.jar" scope = "testOnly" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "com.zaxxer" artifactId = "HikariCP" version = "@hikkaricp.lib.version@" path = "./lib/HikariCP-@hikkaricp.lib.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/hsqldb-@hsql.connector.version@.jar" scope = "testOnly" diff --git a/build-config/spotbugs-exclude.xml b/build-config/spotbugs-exclude.xml index 9e424c12..5970bd25 100644 --- a/build-config/spotbugs-exclude.xml +++ b/build-config/spotbugs-exclude.xml @@ -87,4 +87,16 @@ + + + + + + + + + + + + diff --git a/compiler-plugin-tests/build.gradle b/compiler-plugin-tests/build.gradle index cd9216c5..012f45ee 100644 --- a/compiler-plugin-tests/build.gradle +++ b/compiler-plugin-tests/build.gradle @@ -48,7 +48,7 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 jacoco { toolVersion = "0.8.10" @@ -83,9 +83,12 @@ jacocoTestReport { } spotbugsTest { + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW ignoreFailures = true - effort = "max" - reportLevel = "low" reportsDir = file("$project.buildDir/reports/spotbugs") def excludeFile = file("${rootDir}/build-config/spotbugs-exclude.xml") if (excludeFile.exists()) { diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle index 3c5e610a..dfd6ccaf 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -47,8 +47,11 @@ checkstyle { checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/gradle.properties b/gradle.properties index 8d15e091..6ad5dcc9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,52 +7,52 @@ hsqlDriverVersion=2.7.1 h2Version=1.4.200 atomikosLibVersion=5.0.8 checkstyleToolVersion=10.12.1 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=5.4.0 researchgateReleaseVersion=2.8.0 testngVersion=7.6.1 ballerinaGradlePluginVersion=2.0.1 -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.10.0-20241019-091600-89e54c08 # Direct Dependencies # Level 01 -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 +stdlibIoVersion=1.6.2-20240928-084100-656404f +stdlibTimeVersion=2.5.1-20240930-120200-e59222b # Level 02 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 +stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4 +stdlibOsVersion=1.8.1-20241001-120600-dd1626e # Level 03 -stdlibFileVersion=1.10.0 +stdlibFileVersion=1.10.1-20241007-160900-03f7b64 # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.3.1-20241007-161000-645452d +observeInternalVersion=1.3.1-20241015-172900-cdc3cb3 # Transitive Dependencies # Level 01 -stdlibConstraintVersion=1.5.0 -stdlibUrlVersion=2.4.0 +stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 +stdlibUrlVersion=2.4.1-20240930-120200-b7fb9e1 # Level 02 -stdlibCryptoVersion=2.7.2 -stdlibTaskVersion=2.5.0 +stdlibCryptoVersion=2.7.3-20240930-132000-5ecc9ab +stdlibTaskVersion=2.5.1-20241002-145700-5bdb843 # Level 03 -stdlibCacheVersion=3.8.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +stdlibCacheVersion=3.8.1-20241007-154900-63f4403 +stdlibMimeVersion=2.10.1-20241009-141200-8b6c9f0 +stdlibUuidVersion=1.8.1-20241009-134600-a05012b # Level 04 -stdlibAuthVersion=2.12.0 -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241010-130800-733dbef +stdlibJwtVersion=2.13.1-20241010-123600-5ea6a94 +stdlibOAuth2Version=2.12.1-20241010-123600-0e0cfcc # Level 05 -stdlibHttpVersion=2.12.0 +stdlibHttpVersion=2.13.0-20241022-163700-67b6515 # Level 06 -stdlibTransactionVersion=1.10.0 +stdlibTransactionVersion=1.10.1-20241021-105400-f7e16a8 diff --git a/native/build.gradle b/native/build.gradle index 8cd4179f..c95e08c8 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -47,7 +47,7 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 jacoco { toolVersion = "0.8.10" @@ -80,9 +80,12 @@ jacocoTestReport { } spotbugsMain { + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW ignoreFailures = true - effort = "max" - reportLevel = "low" reportsDir = file("$project.buildDir/reports/spotbugs") def excludeFile = file("${rootDir}/build-config/spotbugs-exclude.xml") if (excludeFile.exists()) { diff --git a/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java b/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java deleted file mode 100644 index e1443075..00000000 --- a/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.ballerina.stdlib.sql.datasource; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import static io.ballerina.stdlib.sql.Constants.BALLERINA_SQL_MAX_POOL_SIZE; - -/** - * Class to hold the static cachedThreadPool for SQL. - */ -public class SQLWorkerThreadPool { - - private SQLWorkerThreadPool() { - } - - static final int MAX_POOL_SIZE = Integer.parseInt( - System.getenv(BALLERINA_SQL_MAX_POOL_SIZE) != null ? - System.getenv(BALLERINA_SQL_MAX_POOL_SIZE) : "50" - ); - - // This is similar to cachedThreadPool util from Executors.newCachedThreadPool(..); but with upper cap on threads - public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, MAX_POOL_SIZE, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new SQLThreadFactory()); - - static class SQLThreadFactory implements ThreadFactory { - @Override - public Thread newThread(Runnable r) { - Thread ballerinaSql = new Thread(r); - ballerinaSql.setName("bal-sql-thread"); - return ballerinaSql; - } - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java index 885a9e8f..9bc7baeb 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.sql.nativeimpl; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; @@ -61,7 +60,6 @@ import static io.ballerina.stdlib.sql.Constants.RESULT_SET_TOTAL_NATIVE_DATA_FIELD; import static io.ballerina.stdlib.sql.Constants.STATEMENT_NATIVE_DATA_FIELD; import static io.ballerina.stdlib.sql.Constants.TYPE_DESCRIPTIONS_NATIVE_DATA_FIELD; -import static io.ballerina.stdlib.sql.datasource.SQLWorkerThreadPool.SQL_EXECUTOR_SERVICE; import static io.ballerina.stdlib.sql.utils.Utils.getColumnDefinitions; import static io.ballerina.stdlib.sql.utils.Utils.getDefaultStreamConstraint; import static io.ballerina.stdlib.sql.utils.Utils.getSqlQuery; @@ -95,14 +93,9 @@ public static Object nativeCall(Environment env, BObject client, BObject paramSQ boolean withinTrxBlock = Utils.isWithinTrxBlock(trxResourceManager); boolean trxManagerEnabled = trxResourceManager.getTransactionManagerEnabled(); TransactionLocalContext currentTrxContext = trxResourceManager.getCurrentTransactionContext(); - Future balFuture = env.markAsync(); - SQL_EXECUTOR_SERVICE.execute(() -> { - Object resultStream = - nativeCallExecutable(client, paramSQLString, recordTypes, statementParameterProcessor, - resultParameterProcessor, withinTrxBlock, currentTrxContext, trxManagerEnabled); - balFuture.complete(resultStream); - }); - return null; + return env.yieldAndRun(() -> nativeCallExecutable(client, paramSQLString, recordTypes, + statementParameterProcessor, resultParameterProcessor, withinTrxBlock, + currentTrxContext, trxManagerEnabled)); } private static Object nativeCallExecutable(BObject client, BObject paramSQLString, BArray recordTypes, diff --git a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java index 212b47eb..69065dcf 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.sql.nativeimpl; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.values.BArray; @@ -49,7 +48,6 @@ import java.util.Locale; import java.util.Map; -import static io.ballerina.stdlib.sql.datasource.SQLWorkerThreadPool.SQL_EXECUTOR_SERVICE; import static io.ballerina.stdlib.sql.utils.Utils.closeResources; import static io.ballerina.stdlib.sql.utils.Utils.getGeneratedKeys; import static io.ballerina.stdlib.sql.utils.Utils.getSqlQuery; @@ -78,15 +76,8 @@ public static Object nativeExecute(Environment env, BObject client, BObject para boolean withinTrxBlock = Utils.isWithinTrxBlock(trxResourceManager); boolean trxManagerEnabled = trxResourceManager.getTransactionManagerEnabled(); TransactionLocalContext currentTrxContext = trxResourceManager.getCurrentTransactionContext(); - Future balFuture = env.markAsync(); - SQL_EXECUTOR_SERVICE.execute(() -> { - Object resultStream = - nativeExecuteExecutable(client, paramSQLString, statementParameterProcessor, withinTrxBlock, - currentTrxContext, trxManagerEnabled); - balFuture.complete(resultStream); - }); - - return null; + return env.yieldAndRun(() -> nativeExecuteExecutable(client, paramSQLString, statementParameterProcessor, + withinTrxBlock, currentTrxContext, trxManagerEnabled)); } private static Object nativeExecuteExecutable(BObject client, BObject paramSQLString, @@ -159,15 +150,8 @@ public static Object nativeBatchExecute(Environment env, BObject client, BArray boolean withinTrxBlock = Utils.isWithinTrxBlock(trxResourceManager); boolean trxManagerEnabled = trxResourceManager.getTransactionManagerEnabled(); TransactionLocalContext currentTrxContext = trxResourceManager.getCurrentTransactionContext(); - Future balFuture = env.markAsync(); - SQL_EXECUTOR_SERVICE.execute(() -> { - Object resultStream = - nativeBatchExecuteExecutable(client, paramSQLStrings, statementParameterProcessor, - withinTrxBlock, currentTrxContext, trxManagerEnabled); - balFuture.complete(resultStream); - }); - - return null; + return env.yieldAndRun(() -> nativeBatchExecuteExecutable(client, paramSQLStrings, statementParameterProcessor, + withinTrxBlock, currentTrxContext, trxManagerEnabled)); } private static Object nativeBatchExecuteExecutable(BObject client, BArray paramSQLStrings, diff --git a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/QueryProcessor.java b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/QueryProcessor.java index ff4524fd..c2e2af0c 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/QueryProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/QueryProcessor.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.sql.nativeimpl; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; @@ -54,7 +53,6 @@ import java.sql.SQLException; import java.util.List; -import static io.ballerina.stdlib.sql.datasource.SQLWorkerThreadPool.SQL_EXECUTOR_SERVICE; import static io.ballerina.stdlib.sql.utils.Utils.getErrorStream; /** @@ -84,14 +82,9 @@ public static BStream nativeQuery(Environment env, BObject client, BObject param boolean withinTrxBlock = Utils.isWithinTrxBlock(trxResourceManager); boolean trxManagerEnabled = trxResourceManager.getTransactionManagerEnabled(); TransactionLocalContext currentTrxContext = trxResourceManager.getCurrentTransactionContext(); - Future balFuture = env.markAsync(); - SQL_EXECUTOR_SERVICE.execute(() -> { - BStream resultStream = - nativeQueryExecutable(client, paramSQLString, recordType, statementParameterProcessor, - resultParameterProcessor, withinTrxBlock, currentTrxContext, trxManagerEnabled); - balFuture.complete(resultStream); - }); - return null; + return env.yieldAndRun(() -> nativeQueryExecutable(client, paramSQLString, recordType, + statementParameterProcessor, resultParameterProcessor, withinTrxBlock, + currentTrxContext, trxManagerEnabled)); } private static BStream nativeQueryExecutable(BObject client, BObject paramSQLString, Object recordType, @@ -156,16 +149,9 @@ public static Object nativeQueryRow(Environment env, BObject client, BObject par boolean withinTrxBlock = Utils.isWithinTrxBlock(trxResourceManager); boolean trxManagerEnabled = trxResourceManager.getTransactionManagerEnabled(); TransactionLocalContext currentTrxContext = trxResourceManager.getCurrentTransactionContext(); - Future balFuture = env.markAsync(); - SQL_EXECUTOR_SERVICE.execute(() -> { - Object resultStream = - nativeQueryRowExecutable(client, paramSQLString, bTypedesc, statementParameterProcessor, - resultParameterProcessor, withinTrxBlock, currentTrxContext, - trxManagerEnabled); - balFuture.complete(resultStream); - }); - - return null; + return env.yieldAndRun(() -> nativeQueryRowExecutable(client, paramSQLString, bTypedesc, + statementParameterProcessor, resultParameterProcessor, withinTrxBlock, + currentTrxContext, trxManagerEnabled)); } private static Object nativeQueryRowExecutable( diff --git a/test-utils/build.gradle b/test-utils/build.gradle index 8c07af5d..f9c906db 100644 --- a/test-utils/build.gradle +++ b/test-utils/build.gradle @@ -32,9 +32,12 @@ dependencies { } spotbugsMain { + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW ignoreFailures = true - effort = "max" - reportLevel = "low" reportsDir = file("$project.buildDir/reports/spotbugs") def excludeFile = file("${rootDir}/build-config/spotbugs-exclude.xml") if (excludeFile.exists()) {