From d501b4f86bc21923caf35e2dea88e3738ea84757 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Wed, 29 Nov 2023 15:59:39 +0530 Subject: [PATCH 1/7] [Automated] Update native jar versions in toml files --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 489375dd..6e02b0b0 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "persist" -version = "1.2.0" +version = "1.2.1" authors = ["Ballerina"] keywords = ["persist"] repository = "https://github.com/ballerina-platform/module-ballerina-persist" @@ -15,5 +15,5 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.persist" artifactId = "persist-native" -version = "1.2.0" -path = "../native/build/libs/persist-native-1.2.0.jar" +version = "1.2.1" +path = "../native/build/libs/persist-native-1.2.1-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 6f2a9850..9af387f4 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "persist-compiler-plugin" class = "io.ballerina.stdlib.persist.compiler.PersistCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/persist-compiler-plugin-1.2.0.jar" +path = "../compiler-plugin/build/libs/persist-compiler-plugin-1.2.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1fdf391e..2137098a 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -18,7 +18,7 @@ modules = [ [[package]] org = "ballerina" name = "persist" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] From 264bdff722f23f67359f903f10648610cfb44218 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Wed, 29 Nov 2023 19:55:09 +0530 Subject: [PATCH 2/7] Add support for postgresql data types --- .../stdlib/persist/compiler/Constants.java | 1 + .../compiler/utils/ValidatorsByDatastore.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java index ae9f92a3..176d2bf8 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/Constants.java @@ -71,6 +71,7 @@ public static final class Datastores { public static final String MYSQL = "mysql"; public static final String MSSQL = "mssql"; + public static final String POSTGRESQL = "postgresql"; public static final String IN_MEMORY = "inmemory"; public static final String GOOGLE_SHEETS = "googlesheets"; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java index 9bd5251a..6629d0d0 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java @@ -92,6 +92,8 @@ public static boolean isValidSimpleType(String type, String datastore) { return isValidMysqlType(type); case Constants.Datastores.MSSQL: return isValidMssqlType(type); + case Constants.Datastores.POSTGRESQL: + return isValidPostgresqlType(type); case Constants.Datastores.IN_MEMORY: return isValidInMemoryType(type); case Constants.Datastores.GOOGLE_SHEETS: @@ -107,6 +109,8 @@ public static boolean isValidArrayType(String type, String datastore) { return isValidMysqlArrayType(type); case Constants.Datastores.MSSQL: return isValidMssqlArrayType(type); + case Constants.Datastores.POSTGRESQL: + return isValidPostgresqlArrayType(type); case Constants.Datastores.IN_MEMORY: return isValidInMemoryArrayType(type); case Constants.Datastores.GOOGLE_SHEETS: @@ -122,6 +126,8 @@ public static boolean isValidImportedType(String modulePrefix, String identifier return isValidMysqlImportedType(modulePrefix, identifier); case Constants.Datastores.MSSQL: return isValidMssqlImportedType(modulePrefix, identifier); + case Constants.Datastores.POSTGRESQL: + return isValidPostgresqlImportedType(modulePrefix, identifier); case Constants.Datastores.IN_MEMORY: return isValidInMemoryImportedType(modulePrefix, identifier); case Constants.Datastores.GOOGLE_SHEETS: @@ -159,6 +165,21 @@ public static boolean isValidMssqlType(String type) { } } + public static boolean isValidPostgresqlType(String type) { + switch (type) { + case INT: + case BOOLEAN: + case DECIMAL: + case FLOAT: + case STRING: + case ENUM: + return true; + default: + return false; + } + } + + public static boolean isValidInMemoryType(String type) { return true; } @@ -195,6 +216,16 @@ public static boolean isValidMssqlArrayType(String type) { } } + public static boolean isValidPostgresqlArrayType(String type) { + switch (type) { + case BYTE: + return true; + default: + return false; + } + } + + public static boolean isValidInMemoryArrayType(String type) { return true; } @@ -233,6 +264,22 @@ public static boolean isValidMssqlImportedType(String modulePrefix, String ident } } + public static boolean isValidPostgresqlImportedType(String modulePrefix, String identifier) { + if (!modulePrefix.equals(TIME_MODULE)) { + return false; + } + switch (identifier) { + case DATE: + case TIME_OF_DAY: + case UTC: + case CIVIL: + return true; + default: + return false; + } + } + + public static boolean isValidInMemoryImportedType(String modulePrefix, String identifier) { return true; } From bed8795b832de0aba037295e45d43b9007de757b Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 30 Nov 2023 01:41:03 +0530 Subject: [PATCH 3/7] Add test case for postgresql data types --- .../persist/compiler/CompilerPluginTest.java | 44 +++++++++++++++++++ .../project_6/persist/field-types.bal | 36 +++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 compiler-plugin-test/src/test/resources/project_6/persist/field-types.bal diff --git a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java index 9626adf8..b550623c 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java @@ -245,6 +245,50 @@ public void validateEntityFieldTypeForMssql() { ); } + public void validateEntityFieldTypeForPostgresql() { + List diagnostics = getErrorDiagnostics("project_5", "field-types.bal", 10); + testDiagnostic( + diagnostics, + new String[]{ + PERSIST_306.getCode(), + PERSIST_305.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_305.getCode(), + PERSIST_305.getCode(), + PERSIST_306.getCode(), + PERSIST_305.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + }, + new String[]{ + "an entity does not support boolean array field type", + "an entity does not support json-typed field", + "an entity does not support json array field type", + "an entity does not support time:Civil array field type", + "an entity does not support union-typed field", + "an entity does not support error-typed field", + "an entity does not support error array field type", + "an entity does not support mysql:Client-typed field", + "an entity does not support mysql:Client array field type", + "an entity does not support enum array field type" + }, + new String[]{ + "(18:4,18:13)", + "(20:4,20:8)", + "(21:4,21:10)", + "(24:4,24:16)", + "(25:4,25:21)", + "(27:4,27:9)", + "(28:4,28:11)", + "(30:4,30:16)", + "(31:4,31:18)", + "(34:4,34:12)" + } + ); + } + + @Test public void validateEntityFieldTypeForGoogleSheets() { List diagnostics = getErrorDiagnostics("project_3", "field-types.bal", 12); diff --git a/compiler-plugin-test/src/test/resources/project_6/persist/field-types.bal b/compiler-plugin-test/src/test/resources/project_6/persist/field-types.bal new file mode 100644 index 00000000..1936522d --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_6/persist/field-types.bal @@ -0,0 +1,36 @@ +import ballerina/time; +import ballerinax/mysql; +import ballerina/persist as _; + +public enum Gender { + M, + F +} + +public type MedicalNeed record {| + readonly int needId; + boolean booleanTest; + int itemId; + float floatTest; + decimal decimalTest; + string beneficiaryId; + byte[] beneficiaryIdByteArray; + + boolean[] booleanArray; + + json jsonTest; + json[] jsonArray; + + time:Civil period; + time:Civil[] periodArray; + time:Civil|string unionType; + + error errorType; + error[] errorArrayType; + + mysql:Client clientType; + mysql:Client[] clientArrayType; + + Gender gender; + Gender[] genderArray; +|}; From ddff3febea8559bc8799fbde80c784f6f08555f0 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 30 Nov 2023 01:44:01 +0530 Subject: [PATCH 4/7] Update changelog --- changelog.md | 1 + .../src/test/resources/project_6/Ballerina.toml | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 compiler-plugin-test/src/test/resources/project_6/Ballerina.toml diff --git a/changelog.md b/changelog.md index 1a6ae17d..7f085863 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- [Added compiler plugin validations for MSSQL as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5829) ### Changed diff --git a/compiler-plugin-test/src/test/resources/project_6/Ballerina.toml b/compiler-plugin-test/src/test/resources/project_6/Ballerina.toml new file mode 100644 index 00000000..95501f6b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_6/Ballerina.toml @@ -0,0 +1,7 @@ +[package] +org = "root" +name = "project_2" +version = "0.1.0" + +[persist] +datastore = "postgresql" From e74ee593169f384d6db40082ec40d3953bd3b6c4 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 30 Nov 2023 01:45:20 +0530 Subject: [PATCH 5/7] Remove unnecessary newline --- .../ballerina/stdlib/persist/compiler/CompilerPluginTest.java | 1 - .../stdlib/persist/compiler/utils/ValidatorsByDatastore.java | 3 --- 2 files changed, 4 deletions(-) diff --git a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java index b550623c..e5d34d2f 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java @@ -288,7 +288,6 @@ public void validateEntityFieldTypeForPostgresql() { ); } - @Test public void validateEntityFieldTypeForGoogleSheets() { List diagnostics = getErrorDiagnostics("project_3", "field-types.bal", 12); diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java index 6629d0d0..b58d4bbd 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java @@ -179,7 +179,6 @@ public static boolean isValidPostgresqlType(String type) { } } - public static boolean isValidInMemoryType(String type) { return true; } @@ -225,7 +224,6 @@ public static boolean isValidPostgresqlArrayType(String type) { } } - public static boolean isValidInMemoryArrayType(String type) { return true; } @@ -279,7 +277,6 @@ public static boolean isValidPostgresqlImportedType(String modulePrefix, String } } - public static boolean isValidInMemoryImportedType(String modulePrefix, String identifier) { return true; } From 885edd7c389cc0bef3c6594b0e1aab1f35a6a42d Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 30 Nov 2023 01:54:43 +0530 Subject: [PATCH 6/7] Add annotation to postgresql test case --- .../ballerina/stdlib/persist/compiler/CompilerPluginTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java index e5d34d2f..22ba409e 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/stdlib/persist/compiler/CompilerPluginTest.java @@ -245,8 +245,9 @@ public void validateEntityFieldTypeForMssql() { ); } + @Test public void validateEntityFieldTypeForPostgresql() { - List diagnostics = getErrorDiagnostics("project_5", "field-types.bal", 10); + List diagnostics = getErrorDiagnostics("project_6", "field-types.bal", 10); testDiagnostic( diagnostics, new String[]{ From 18d623ba84747f729940ae9072b898bdb29dbe5c Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 30 Nov 2023 09:45:55 +0530 Subject: [PATCH 7/7] Update changelog.md --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 7f085863..731fcfcc 100644 --- a/changelog.md +++ b/changelog.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- [Added compiler plugin validations for MSSQL as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5829) +- [Added compiler plugin validations for Postgresql as a datasource](https://github.com/ballerina-platform/ballerina-library/issues/5829) ### Changed