diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index d9dbd5b..50b5851 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -17,11 +17,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Change to Timestamped Version run: | initialVersion=$((grep -w 'version' | cut -d= -f2) < gradle.properties ) @@ -46,7 +46,7 @@ jobs: - name: Generate CodeCov Report uses: codecov/codecov-action@v2 - name: Upload Artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ballerina-runtime path: target/ballerina-runtime/ diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 7825cb7..1d5e61c 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -18,11 +18,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 92188a7..ee52b12 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,11 +11,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/.github/workflows/publish-snapshot-nexus.yml b/.github/workflows/publish-snapshot-nexus.yml index b13aaea..e9d7cba 100644 --- a/.github/workflows/publish-snapshot-nexus.yml +++ b/.github/workflows/publish-snapshot-nexus.yml @@ -9,11 +9,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 3e1f6fd..edfdf54 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/README.md b/README.md index 49f285d..eb42a7c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,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 78286a9..ca76b79 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,25 +1,25 @@ [package] org = "ballerinax" name = "persist.inmemory" -version = "1.4.0" +version = "1.4.1" authors = ["Ballerina"] keywords = ["persist", "inmemory"] repository = "https://github.com/ballerina-platform/module-ballerinax-persist.inmemory" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.10.0-20241011-161100-51978649" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist.inmemory-native" -version = "1.4.0" -path = "../native/build/libs/persist.inmemory-native-1.4.0.jar" +version = "1.4.1" +path = "../native/build/libs/persist.inmemory-native-1.4.1-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist-native" -version = "1.4.0" -path = "./lib/persist-native-1.4.0.jar" +version = "1.4.1" +path = "./lib/persist-native-1.4.1-20241001-120600-2395f0f.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index b84757a..cc431a4 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.10.0-20241011-161100-51978649" [[package]] org = "ballerina" @@ -53,7 +53,7 @@ scope = "testOnly" [[package]] org = "ballerina" name = "persist" -version = "1.4.0" +version = "1.4.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -78,7 +78,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.5.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -90,7 +90,7 @@ modules = [ [[package]] org = "ballerinax" name = "persist.inmemory" -version = "1.4.0" +version = "1.4.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "persist"}, diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index e4590e5..c2fab79 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,18 +7,18 @@ keywords = ["persist", "inmemory"] repository = "https://github.com/ballerina-platform/module-ballerinax-persist.inmemory" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.10.0-20241011-161100-51978649" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist.inmemory-native" version = "@toml.version@" path = "../native/build/libs/persist.inmemory-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "@persist.version@" diff --git a/gradle.properties b/gradle.properties index 53621f8..b4453f5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ version=1.4.1-SNAPSHOT puppycrawlCheckstyleVersion=10.12.0 checkstyleToolVersion=10.12.0 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=5.4.0 researchgateReleaseVersion=2.8.0 @@ -11,19 +11,19 @@ testngVersion=7.6.1 gsonVersion=2.10 ballerinaGradlePluginVersion=2.0.1 -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 # Direct Dependencies # Level 01 -stdlibTimeVersion=2.4.0 +stdlibTimeVersion=2.6.0-20241113-073800-201b904 # Level 08 -stdlibPersistVersion=1.4.0 +stdlibPersistVersion=1.4.1-20241113-122000-306cc63 # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d # Enabled publishing insecure checksums, due to fail to publish to maven central # Refer https://github.com/gradle/gradle/issues/11308 diff --git a/native/build.gradle b/native/build.gradle index 0fda668..42a304f 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -43,7 +43,7 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 jacoco { toolVersion = "0.8.6" @@ -76,9 +76,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/persist/inmemory/Utils.java b/native/src/main/java/io/ballerina/stdlib/persist/inmemory/Utils.java index d75b8d0..45a0e87 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/inmemory/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/inmemory/Utils.java @@ -18,9 +18,9 @@ package io.ballerina.stdlib.persist.inmemory; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; diff --git a/native/src/main/java/io/ballerina/stdlib/persist/inmemory/datastore/InMemoryProcessor.java b/native/src/main/java/io/ballerina/stdlib/persist/inmemory/datastore/InMemoryProcessor.java index 634260e..24e309e 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/inmemory/datastore/InMemoryProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/inmemory/datastore/InMemoryProcessor.java @@ -19,27 +19,15 @@ package io.ballerina.stdlib.persist.inmemory.datastore; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.creators.TypeCreator; -import io.ballerina.runtime.api.types.ErrorType; import io.ballerina.runtime.api.types.RecordType; -import io.ballerina.runtime.api.types.StreamType; -import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BStream; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.persist.ModuleUtils; import io.ballerina.stdlib.persist.inmemory.Utils; -import java.util.Map; - -import static io.ballerina.stdlib.persist.Constants.ERROR; -import static io.ballerina.stdlib.persist.Constants.KEY_FIELDS; import static io.ballerina.stdlib.persist.Constants.RUN_READ_BY_KEY_QUERY_METHOD; import static io.ballerina.stdlib.persist.Constants.RUN_READ_QUERY_METHOD; import static io.ballerina.stdlib.persist.ErrorGenerator.wrapError; @@ -47,8 +35,6 @@ import static io.ballerina.stdlib.persist.Utils.getKey; import static io.ballerina.stdlib.persist.Utils.getMetadata; import static io.ballerina.stdlib.persist.Utils.getPersistClient; -import static io.ballerina.stdlib.persist.Utils.getRecordTypeWithKeyFields; -import static io.ballerina.stdlib.persist.Utils.getTransactionContextProperties; /** * This class provides the in-memory query processing implementations for persistence. @@ -65,57 +51,36 @@ public static BStream query(Environment env, BObject client, BTypedesc targetTyp BString entity = getEntity(env); BObject persistClient = getPersistClient(client, entity); - BArray keyFields = (BArray) persistClient.get(KEY_FIELDS); RecordType recordType = (RecordType) targetType.getDescribingType(); - - RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); - StreamType streamTypeWithIdFields = TypeCreator.createStreamType(recordTypeWithIdFields, - PredefinedTypes.TYPE_NULL); - BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; BArray includes = metadata[1]; BArray typeDescriptions = metadata[2]; - Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `InMemoryClient.runReadQuery(string[] fields = [])` - // which returns `stream` - - persistClient, RUN_READ_QUERY_METHOD, strandName, env.getStrandMetadata(), new Callback() { - @Override - public void notifySuccess(Object o) { - BStream stream = (BStream) o; - balFuture.complete(Utils.createPersistInMemoryStreamValue(stream, targetType, fields, - includes, typeDescriptions, persistClient, null)); - } - - @Override - public void notifyFailure(BError bError) { - balFuture.complete(Utils.createPersistInMemoryStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, wrapError(bError))); - } - }, trxContextProperties, streamTypeWithIdFields, fields, true - ); - - return null; + return env.yieldAndRun(() -> { + try { + Object result = env.getRuntime().callMethod( + // Call `InMemoryClient.runReadQuery(string[] fields = [])` + // which returns `stream` + persistClient, RUN_READ_QUERY_METHOD, null, fields + ); + BStream stream = (BStream) result; + return Utils.createPersistInMemoryStreamValue(stream, targetType, fields, + includes, typeDescriptions, persistClient, null); + } catch (BError bError) { + return Utils.createPersistInMemoryStreamValue(null, targetType, fields, includes, + typeDescriptions, persistClient, wrapError(bError)); + } + + }); } public static Object queryOne(Environment env, BObject client, BArray path, BTypedesc targetType) { // This method will return `targetType|persist:Error` BString entity = getEntity(env); - BObject persistClient = getPersistClient(client, entity); - BArray keyFields = (BArray) persistClient.get(KEY_FIELDS); RecordType recordType = (RecordType) targetType.getDescribingType(); - RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); - ErrorType persistErrorType = TypeCreator.createErrorType(ERROR, ModuleUtils.getModule()); - Type unionType = TypeCreator.createUnionType(recordTypeWithIdFields, persistErrorType); - BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; BArray includes = metadata[1]; @@ -123,33 +88,14 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp Object key = getKey(env, path); - Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `InMemoryClient.runReadByKeyQuery( - // typedesc rowType, anydata key, string[] fields = [], string[] include = [], - // typedesc[] typeDescriptions = [] - // )` - // which returns `record {}|persist:Error` - - getPersistClient(client, entity), RUN_READ_BY_KEY_QUERY_METHOD, strandName, env.getStrandMetadata(), - new Callback() { - @Override - public void notifySuccess(Object o) { - balFuture.complete(o); - } - - @Override - public void notifyFailure(BError bError) { - balFuture.complete(wrapError(bError)); - } - }, trxContextProperties, unionType, - targetType, true, key, true, fields, true, includes, true, - typeDescriptions, true - ); + return env.yieldAndRun(() -> { + try { + return env.getRuntime().callMethod(getPersistClient(client, entity), RUN_READ_BY_KEY_QUERY_METHOD, + null, targetType, key, fields, includes, typeDescriptions); - return null; + } catch (BError bError) { + return wrapError(bError); + } + }); } }