From 93c6b8d03ce9f193c4b0871ef5b0f576a5124c30 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Mon, 4 Mar 2024 00:05:12 +0530 Subject: [PATCH 1/9] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 2137098a..1769eb42 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.0" +distribution-version = "2201.8.2" [[package]] org = "ballerina" From 207ed8cd36664b6e2d7496fa5a85d2fb141a85b7 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Mon, 4 Mar 2024 00:20:46 +0530 Subject: [PATCH 2/9] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1769eb42..2137098a 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.2" +distribution-version = "2201.8.0" [[package]] org = "ballerina" From f9a71504dfb4617d171121dc1d0c7232f30af6c8 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Fri, 8 Mar 2024 12:18:37 +0530 Subject: [PATCH 3/9] Add model validations for Redis DB --- ballerina/utils.bal | 2 + .../persist/compiler/CompilerPluginTest.java | 43 ++++++++++ .../test/resources/project_7/Ballerina.toml | 7 ++ .../resources/project_7/persist/all_types.bal | 70 ++++++++++++++++ .../project_7/persist/nillable_types.bal | 21 +++++ .../project_7/persist/optional_fields.bal | 21 +++++ .../resources/project_7/persist/rainier.bal | 52 ++++++++++++ .../stdlib/persist/compiler/Constants.java | 1 + .../PersistModelDefinitionValidator.java | 60 +++++++------ .../compiler/utils/ValidatorsByDatastore.java | 84 ++++++++++++++++++- 10 files changed, 335 insertions(+), 26 deletions(-) create mode 100644 compiler-plugin-test/src/test/resources/project_7/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/project_7/persist/all_types.bal create mode 100644 compiler-plugin-test/src/test/resources/project_7/persist/nillable_types.bal create mode 100644 compiler-plugin-test/src/test/resources/project_7/persist/optional_fields.bal create mode 100644 compiler-plugin-test/src/test/resources/project_7/persist/rainier.bal diff --git a/ballerina/utils.bal b/ballerina/utils.bal index a6838078..b6e07b1c 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -14,6 +14,8 @@ // specific language governing permissions and limitations // under the License. +// just a comment + import ballerina/jballerina.java; public isolated function convertToArray(typedesc elementType, record {}[] arr) returns elementType[] = @java:Method { 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 22ba409e..814c8267 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 @@ -667,6 +667,49 @@ public void validateEntityNamesCaseSensitivity() { ); } + @Test + public void validateUseOfOptionalFieldForRedisDB() { + List diagnostics = getErrorDiagnostics("project_7", "optional_fields.bal", 0); + } + + @Test + public void validateNillableTypesForRedisDB(){ + List diagnostics = getErrorDiagnostics("project_7", "nillable_types.bal", 8); + testDiagnostic( + diagnostics, + new String[]{ + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode() + }, + new String[]{ + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field", + "an entity does not support nillable field" + }, + new String[]{ + "(12:4,12:12)", + "(13:4,13:8)", + "(14:4,14:10)", + "(15:4,15:12)", + "(16:4,16:11)", + "(17:4,17:14)", + "(18:4,18:19)", + "(19:4,19:13)" + } + ); + } + private List getErrorDiagnostics(String modelDirectory, String modelFileName, int count) { DiagnosticResult diagnosticResult = loadPersistModelFile(modelDirectory, modelFileName).getCompilation() .diagnosticResult(); diff --git a/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml b/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml new file mode 100644 index 00000000..6241934b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_7/Ballerina.toml @@ -0,0 +1,7 @@ +[package] +org = "root" +name = "project_7" +version = "0.1.0" + +[persist] +datastore = "redis" diff --git a/compiler-plugin-test/src/test/resources/project_7/persist/all_types.bal b/compiler-plugin-test/src/test/resources/project_7/persist/all_types.bal new file mode 100644 index 00000000..8d9d7d6e --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_7/persist/all_types.bal @@ -0,0 +1,70 @@ +import ballerina/persist as _; +import ballerina/time; + +enum EnumType { + TYPE_1, + TYPE_2, + TYPE_3, + TYPE_4 +} + +type AllTypes record {| + readonly int id; + boolean booleanType; + int intType; + float floatType; + decimal decimalType; + string stringType; + time:Date dateType; + time:TimeOfDay timeOfDayType; + EnumType enumType; + boolean booleanTypeOptional?; + int intTypeOptional?; + float floatTypeOptional?; + decimal decimalTypeOptional?; + string stringTypeOptional?; + time:Date dateTypeOptional?; + time:TimeOfDay timeOfDayTypeOptional?; + EnumType enumTypeOptional?; +|}; + +type StringIdRecord record {| + readonly string id; + string randomField; +|}; + +type IntIdRecord record {| + readonly int id; + string randomField; +|}; + +type FloatIdRecord record {| + readonly float id; + string randomField; +|}; + +type DecimalIdRecord record {| + readonly decimal id; + string randomField; +|}; + +type BooleanIdRecord record {| + readonly boolean id; + string randomField; +|}; + +type CompositeAssociationRecord record {| + readonly string id; + string randomField; + AllTypesIdRecord allTypesIdRecord; +|}; + +type AllTypesIdRecord record {| + readonly boolean booleanType; + readonly int intType; + readonly float floatType; + readonly decimal decimalType; + readonly string stringType; + string randomField; + CompositeAssociationRecord? compositeAssociationRecord; +|}; diff --git a/compiler-plugin-test/src/test/resources/project_7/persist/nillable_types.bal b/compiler-plugin-test/src/test/resources/project_7/persist/nillable_types.bal new file mode 100644 index 00000000..af14ec21 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_7/persist/nillable_types.bal @@ -0,0 +1,21 @@ +import ballerina/persist as _; +import ballerina/time; + +enum EnumType { + TYPE_1, + TYPE_2, + TYPE_3, + TYPE_4 +} + +type AllTypes record {| + readonly int id; + boolean? booleanType; + int? intType; + float? floatType; + decimal? decimalType; + string? stringType; + time:Date? dateType; + time:TimeOfDay? timeOfDayType; + EnumType? enumType; +|}; \ No newline at end of file diff --git a/compiler-plugin-test/src/test/resources/project_7/persist/optional_fields.bal b/compiler-plugin-test/src/test/resources/project_7/persist/optional_fields.bal new file mode 100644 index 00000000..45681d0b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_7/persist/optional_fields.bal @@ -0,0 +1,21 @@ +import ballerina/persist as _; +import ballerina/time; + +enum EnumType { + TYPE_1, + TYPE_2, + TYPE_3, + TYPE_4 +} + +type AllTypes record {| + readonly int id; + boolean booleanType?; + int intType?; + float floatType?; + decimal decimalType?; + string stringType?; + time:Date dateType?; + time:TimeOfDay timeOfDayType?; + EnumType enumType?; +|}; \ No newline at end of file diff --git a/compiler-plugin-test/src/test/resources/project_7/persist/rainier.bal b/compiler-plugin-test/src/test/resources/project_7/persist/rainier.bal new file mode 100644 index 00000000..4d8ec2c5 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/project_7/persist/rainier.bal @@ -0,0 +1,52 @@ +import ballerina/persist as _; +import ballerina/time; + +enum Gender { + MALE, + FEMALE +} + +type Employee record {| + readonly string empNo; + string firstName; + string lastName; + time:Date birthDate; + Gender gender; + time:Date hireDate; + + Department department; + Workspace workspace; +|}; + +type Workspace record {| + readonly string workspaceId; + string workspaceType; + + Building location; + Employee[] employees; +|}; + +type Building record {| + readonly string buildingCode; + string city; + string state; + string country; + string postalCode; + string 'type; + + Workspace[] workspaces; +|}; + +type Department record {| + readonly string deptNo; + string deptName; + + Employee[] employees; +|}; + +type OrderItem record {| + readonly string orderId; + readonly string itemId; + int quantity; + string notes; +|}; 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 176d2bf8..1d891f29 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 @@ -74,6 +74,7 @@ public static final class Datastores { public static final String POSTGRESQL = "postgresql"; public static final String IN_MEMORY = "inmemory"; public static final String GOOGLE_SHEETS = "googlesheets"; + public static final String REDIS = "redis"; private Datastores() { } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java index fb99deb6..9f4ad7d5 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java @@ -41,6 +41,7 @@ import io.ballerina.projects.plugins.AnalysisTask; import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; import io.ballerina.projects.util.ProjectConstants; +import io.ballerina.stdlib.persist.compiler.Constants.Datastores; import io.ballerina.stdlib.persist.compiler.model.Entity; import io.ballerina.stdlib.persist.compiler.model.GroupedRelationField; import io.ballerina.stdlib.persist.compiler.model.IdentityField; @@ -270,7 +271,7 @@ private void validateEntityFields(Entity entity, String datastore) { fieldNames.add(fieldName.toLowerCase(Locale.ROOT)); // Check if optional field - if (recordFieldNode.questionMarkToken().isPresent()) { + if (recordFieldNode.questionMarkToken().isPresent() && !datastore.equals(Constants.Datastores.REDIS)) { int startOffset = recordFieldNode.questionMarkToken().get().textRange().startOffset(); int length = recordFieldNode.semicolonToken().textRange().startOffset() - startOffset; entity.reportDiagnostic(PERSIST_304.getCode(), PERSIST_304.getMessage(), PERSIST_304.getSeverity(), @@ -322,30 +323,39 @@ private void validateEntityFields(Entity entity, String datastore) { String modulePrefix = stripEscapeCharacter(qualifiedName.modulePrefix().text()); String identifier = stripEscapeCharacter(qualifiedName.identifier().text()); fieldType = modulePrefix + ":" + identifier; - if (ValidatorsByDatastore.isValidImportedType(modulePrefix, identifier, datastore)) { - if (isArrayType && !ValidatorsByDatastore.isValidArrayType(fieldType, datastore)) { - fieldType = isOptionalType - ? modulePrefix + ":" + identifier + "?" - : modulePrefix + ":" + identifier; - entity.reportDiagnostic(PERSIST_306.getCode(), - MessageFormat.format(PERSIST_306.getMessage(), modulePrefix + ":" + identifier), - PERSIST_306.getSeverity(), typeNode.location(), - List.of(new BNumericProperty(arrayStartOffset), new BNumericProperty(arrayLength), - new BStringProperty(fieldType))); - } else { - isValidType = true; - } - } else { - if (isArrayType) { - entity.reportDiagnostic(PERSIST_306.getCode(), MessageFormat.format(PERSIST_306.getMessage(), - modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), - typeNode.location()); - } else { - entity.reportDiagnostic(PERSIST_305.getCode(), MessageFormat.format(PERSIST_305.getMessage(), - modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), - typeNode.location()); - } - } + + List> properties = List.of( + new BNumericProperty(arrayStartOffset), + new BNumericProperty(arrayLength), + new BStringProperty(isOptionalType ? fieldType + "?" : fieldType)); + + isValidType = ValidatorsByDatastore.validateImportedTypes( + entity, typeNode, isArrayType, isOptionalType, properties, modulePrefix, identifier, datastore); + +// if (ValidatorsByDatastore.isValidImportedType(modulePrefix, identifier, datastore)) { +// if (isArrayType && !ValidatorsByDatastore.isValidArrayType(fieldType, datastore)) { +// fieldType = isOptionalType +// ? modulePrefix + ":" + identifier + "?" +// : modulePrefix + ":" + identifier; +// entity.reportDiagnostic(PERSIST_306.getCode(), +// MessageFormat.format(PERSIST_306.getMessage(), modulePrefix + ":" + identifier), +// PERSIST_306.getSeverity(), typeNode.location(), +// List.of(new BNumericProperty(arrayStartOffset), new BNumericProperty(arrayLength), +// new BStringProperty(fieldType))); +// } else { +// isValidType = true; +// } +// } else { +// if (isArrayType) { +// entity.reportDiagnostic(PERSIST_306.getCode(), MessageFormat.format(PERSIST_306.getMessage(), +// modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), +// typeNode.location()); +// } else { +// entity.reportDiagnostic(PERSIST_305.getCode(), MessageFormat.format(PERSIST_305.getMessage(), +// modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), +// typeNode.location()); +// } +// } isSimpleType = true; } else if (processedTypeNode instanceof SimpleNameReferenceNode) { String typeName = stripEscapeCharacter( 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 b58d4bbd..d663cbe6 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 @@ -22,6 +22,8 @@ import io.ballerina.stdlib.persist.compiler.Constants; import io.ballerina.stdlib.persist.compiler.model.Entity; import io.ballerina.tools.diagnostics.DiagnosticProperty; +import org.wso2.ballerinalang.compiler.diagnostic.properties.BNumericProperty; +import org.wso2.ballerinalang.compiler.diagnostic.properties.BStringProperty; import java.text.MessageFormat; import java.util.List; @@ -55,7 +57,8 @@ public static boolean validateSimpleTypes(Entity entity, Node typeNode, String t List> properties, String type, String datastore) { boolean validFlag = true; - if (isOptionalType && datastore.equals(Constants.Datastores.GOOGLE_SHEETS)) { + if (isOptionalType && (datastore.equals(Constants.Datastores.GOOGLE_SHEETS) + || datastore.equals(Constants.Datastores.REDIS))) { entity.reportDiagnostic(PERSIST_308.getCode(), MessageFormat.format(PERSIST_308.getMessage(), type), PERSIST_308.getSeverity(), typeNode.location(), properties); @@ -86,6 +89,45 @@ public static boolean validateSimpleTypes(Entity entity, Node typeNode, String t return validFlag; } + public static boolean validateImportedTypes(Entity entity, Node typeNode, + boolean isArrayType, boolean isOptionalType, + List> properties, + String modulePrefix, String identifier, String datastore){ + boolean validFlag = true; + + if (isOptionalType && datastore.equals(Constants.Datastores.REDIS)) { + entity.reportDiagnostic(PERSIST_308.getCode(), + MessageFormat.format(PERSIST_308.getMessage(), modulePrefix + ":" + identifier), + PERSIST_308.getSeverity(), typeNode.location(), properties); + validFlag = false; + } + + if (ValidatorsByDatastore.isValidImportedType(modulePrefix, identifier, datastore)) { + if (isArrayType && !ValidatorsByDatastore.isValidArrayType(modulePrefix + ":" + identifier, + datastore)) { + + entity.reportDiagnostic(PERSIST_306.getCode(), + MessageFormat.format(PERSIST_306.getMessage(), modulePrefix + ":" + identifier), + PERSIST_306.getSeverity(), typeNode.location(), + properties); + } else { + validFlag = true; + } + } else { + if (isArrayType) { + entity.reportDiagnostic(PERSIST_306.getCode(), MessageFormat.format(PERSIST_306.getMessage(), + modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), + typeNode.location()); + } else { + entity.reportDiagnostic(PERSIST_305.getCode(), MessageFormat.format(PERSIST_305.getMessage(), + modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), + typeNode.location()); + } + } + + return validFlag; + } + public static boolean isValidSimpleType(String type, String datastore) { switch (datastore) { case Constants.Datastores.MYSQL: @@ -98,6 +140,8 @@ public static boolean isValidSimpleType(String type, String datastore) { return isValidInMemoryType(type); case Constants.Datastores.GOOGLE_SHEETS: return isValidGoogleSheetsType(type); + case Constants.Datastores.REDIS: + return isValidRedisType(type); default: return false; } @@ -115,12 +159,15 @@ public static boolean isValidArrayType(String type, String datastore) { return isValidInMemoryArrayType(type); case Constants.Datastores.GOOGLE_SHEETS: return isValidGoogleSheetsArrayType(type); + case Constants.Datastores.REDIS: + return isValidRedisArrayType(type); default: return false; } } public static boolean isValidImportedType(String modulePrefix, String identifier, String datastore) { + switch (datastore) { case Constants.Datastores.MYSQL: return isValidMysqlImportedType(modulePrefix, identifier); @@ -132,6 +179,8 @@ public static boolean isValidImportedType(String modulePrefix, String identifier return isValidInMemoryImportedType(modulePrefix, identifier); case Constants.Datastores.GOOGLE_SHEETS: return isValidGoogleSheetsImportedType(modulePrefix, identifier); + case Constants.Datastores.REDIS: + return isValidRedisImportedType(modulePrefix, identifier); default: return false; } @@ -197,6 +246,20 @@ public static boolean isValidGoogleSheetsType(String type) { } } + public static boolean isValidRedisType(String type) { + switch (type) { + case INT: + case BOOLEAN: + case DECIMAL: + case FLOAT: + case STRING: + case ENUM: + return true; + default: + return false; + } + } + public static boolean isValidMysqlArrayType(String type) { switch (type) { case BYTE: @@ -232,6 +295,10 @@ public static boolean isValidGoogleSheetsArrayType(String type) { return false; } + public static boolean isValidRedisArrayType(String type) { + return false; + } + public static boolean isValidMysqlImportedType(String modulePrefix, String identifier) { if (!modulePrefix.equals(TIME_MODULE)) { return false; @@ -296,4 +363,19 @@ public static boolean isValidGoogleSheetsImportedType(String modulePrefix, Strin } } + public static boolean isValidRedisImportedType(String modulePrefix, String identifier) { + if (!modulePrefix.equals(TIME_MODULE)) { + return false; + } + switch (identifier) { + case DATE: + case TIME_OF_DAY: + case CIVIL: + case UTC: + return true; + default: + return false; + } + } + } From bf0c39d763046b5e52996a59ac9096213ad41d00 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Tue, 12 Mar 2024 10:30:16 +0530 Subject: [PATCH 4/9] Add test cases for Redis DB model validations --- .../ballerina/stdlib/persist/compiler/CompilerPluginTest.java | 3 ++- .../persist/compiler/PersistModelDefinitionValidator.java | 1 - .../stdlib/persist/compiler/utils/ValidatorsByDatastore.java | 4 +--- 3 files changed, 3 insertions(+), 5 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 814c8267..5c1dccb9 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 @@ -670,10 +670,11 @@ public void validateEntityNamesCaseSensitivity() { @Test public void validateUseOfOptionalFieldForRedisDB() { List diagnostics = getErrorDiagnostics("project_7", "optional_fields.bal", 0); + testDiagnostic(diagnostics, new String[]{}, new String[]{}, new String[]{}); } @Test - public void validateNillableTypesForRedisDB(){ + public void validateNillableTypesForRedisDB() { List diagnostics = getErrorDiagnostics("project_7", "nillable_types.bal", 8); testDiagnostic( diagnostics, diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java index 9f4ad7d5..87eafa13 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java @@ -41,7 +41,6 @@ import io.ballerina.projects.plugins.AnalysisTask; import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.stdlib.persist.compiler.Constants.Datastores; import io.ballerina.stdlib.persist.compiler.model.Entity; import io.ballerina.stdlib.persist.compiler.model.GroupedRelationField; import io.ballerina.stdlib.persist.compiler.model.IdentityField; 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 d663cbe6..82850ff5 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 @@ -22,8 +22,6 @@ import io.ballerina.stdlib.persist.compiler.Constants; import io.ballerina.stdlib.persist.compiler.model.Entity; import io.ballerina.tools.diagnostics.DiagnosticProperty; -import org.wso2.ballerinalang.compiler.diagnostic.properties.BNumericProperty; -import org.wso2.ballerinalang.compiler.diagnostic.properties.BStringProperty; import java.text.MessageFormat; import java.util.List; @@ -92,7 +90,7 @@ public static boolean validateSimpleTypes(Entity entity, Node typeNode, String t public static boolean validateImportedTypes(Entity entity, Node typeNode, boolean isArrayType, boolean isOptionalType, List> properties, - String modulePrefix, String identifier, String datastore){ + String modulePrefix, String identifier, String datastore) { boolean validFlag = true; if (isOptionalType && datastore.equals(Constants.Datastores.REDIS)) { From c068c0e49f3a4091e498462e6be0bebb20d02f46 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Wed, 13 Mar 2024 11:50:37 +0530 Subject: [PATCH 5/9] Add diagnostics for readonly optional fields in Redis --- .../persist/compiler/DiagnosticsCodes.java | 1 + .../PersistModelDefinitionValidator.java | 55 ++++++++----------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/DiagnosticsCodes.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/DiagnosticsCodes.java index 4788bbc8..d0e82b56 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/DiagnosticsCodes.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/DiagnosticsCodes.java @@ -54,6 +54,7 @@ public enum DiagnosticsCodes { PERSIST_306("PERSIST_306", "an entity does not support {0} array field type", ERROR), PERSIST_307("PERSIST_307", "redeclared field ''{0}''", ERROR), PERSIST_308("PERSIST_308", "an entity does not support nillable field", ERROR), + PERSIST_309("PERSIST_309", "an entity does not support optional readonly field", ERROR), PERSIST_401("PERSIST_401", "an entity cannot reference itself in a relation field", ERROR), diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java index 7d2b4bce..59754aba 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java @@ -89,6 +89,7 @@ import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_305; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_306; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_307; +import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_309; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_401; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_402; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_403; @@ -278,12 +279,22 @@ private void validateEntityFields(Entity entity, String datastore) { fieldNames.add(fieldName.toLowerCase(Locale.ROOT)); // Check if optional field - if (recordFieldNode.questionMarkToken().isPresent() && !datastore.equals(Constants.Datastores.REDIS)) { - int startOffset = recordFieldNode.questionMarkToken().get().textRange().startOffset(); - int length = recordFieldNode.semicolonToken().textRange().startOffset() - startOffset; - entity.reportDiagnostic(PERSIST_304.getCode(), PERSIST_304.getMessage(), PERSIST_304.getSeverity(), - recordFieldNode.location(), - List.of(new BNumericProperty(startOffset), new BNumericProperty(length))); + if (recordFieldNode.questionMarkToken().isPresent()) { + if (datastore.equals(Constants.Datastores.REDIS)) { + if (recordFieldNode.readonlyKeyword().isPresent()) { + int startOffset = recordFieldNode.questionMarkToken().get().textRange().startOffset(); + int length = recordFieldNode.semicolonToken().textRange().startOffset() - startOffset; + entity.reportDiagnostic(PERSIST_309.getCode(), PERSIST_309.getMessage(), + PERSIST_309.getSeverity(), recordFieldNode.location(), + List.of(new BNumericProperty(startOffset), new BNumericProperty(length))); + } + } else { + int startOffset = recordFieldNode.questionMarkToken().get().textRange().startOffset(); + int length = recordFieldNode.semicolonToken().textRange().startOffset() - startOffset; + entity.reportDiagnostic(PERSIST_304.getCode(), PERSIST_304.getMessage(), PERSIST_304.getSeverity(), + recordFieldNode.location(), + List.of(new BNumericProperty(startOffset), new BNumericProperty(length))); + } } Node typeNode = recordFieldNode.typeName(); @@ -330,31 +341,13 @@ private void validateEntityFields(Entity entity, String datastore) { String modulePrefix = stripEscapeCharacter(qualifiedName.modulePrefix().text()); String identifier = stripEscapeCharacter(qualifiedName.identifier().text()); fieldType = modulePrefix + ":" + identifier; - if (ValidatorsByDatastore.isValidImportedType(modulePrefix, identifier, datastore)) { - if (isArrayType && !ValidatorsByDatastore.isValidArrayType(fieldType, datastore)) { - fieldType = isOptionalType - ? modulePrefix + ":" + identifier + "?" - : modulePrefix + ":" + identifier; - entity.reportDiagnostic(PERSIST_306.getCode(), - MessageFormat.format(PERSIST_306.getMessage(), - modulePrefix + ":" + identifier), - PERSIST_306.getSeverity(), typeNode.location(), - List.of(new BNumericProperty(arrayStartOffset), new BNumericProperty(arrayLength), - new BStringProperty(fieldType))); - } else { - isValidType = true; - } - } else { - if (isArrayType) { - entity.reportDiagnostic(PERSIST_306.getCode(), MessageFormat.format(PERSIST_306.getMessage(), - modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), - typeNode.location()); - } else { - entity.reportDiagnostic(PERSIST_305.getCode(), MessageFormat.format(PERSIST_305.getMessage(), - modulePrefix + ":" + identifier), PERSIST_305.getSeverity(), - typeNode.location()); - } - } + List> properties = List.of( + new BNumericProperty(arrayStartOffset), + new BNumericProperty(arrayLength), + new BStringProperty(isOptionalType ? fieldType + "?" : fieldType)); + + isValidType = ValidatorsByDatastore.validateImportedTypes( + entity, typeNode, isArrayType, isOptionalType, properties, modulePrefix, identifier, datastore); isSimpleType = true; } else if (processedTypeNode instanceof SimpleNameReferenceNode) { String typeName = stripEscapeCharacter( From 0883c61881dba37907eba41e097bc08fdda0bfb9 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Wed, 13 Mar 2024 12:25:33 +0530 Subject: [PATCH 6/9] Add testcases for persist Redis module --- ballerina/utils.bal | 2 -- .../stdlib/persist/compiler/CompilerPluginTest.java | 13 +++++++++++-- .../src/test/resources/project_10/Ballerina.toml | 2 +- .../resources/project_10/persist/nillable_types.bal | 2 +- .../project_10/persist/optional_fields.bal | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ballerina/utils.bal b/ballerina/utils.bal index b6e07b1c..a6838078 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -14,8 +14,6 @@ // specific language governing permissions and limitations // under the License. -// just a comment - import ballerina/jballerina.java; public isolated function convertToArray(typedesc elementType, record {}[] arr) returns elementType[] = @java:Method { 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 e74a0965..d1b35ade 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 @@ -692,10 +692,19 @@ public void validateEntityNamesCaseSensitivity() { ); } + @Test + public void validateAllTypesForRedisDB() { + getErrorDiagnostics("project_10", "all_types.bal", 0); + } + + @Test + public void validateRainierForRedisDB() { + getErrorDiagnostics("project_10", "rainier.bal", 0); + } + @Test public void validateUseOfOptionalFieldForRedisDB() { - List diagnostics = getErrorDiagnostics("project_10", "optional_fields.bal", 0); - testDiagnostic(diagnostics, new String[]{}, new String[]{}, new String[]{}); + getErrorDiagnostics("project_10", "optional_fields.bal", 0); } @Test diff --git a/compiler-plugin-test/src/test/resources/project_10/Ballerina.toml b/compiler-plugin-test/src/test/resources/project_10/Ballerina.toml index 68450e37..42893a4b 100644 --- a/compiler-plugin-test/src/test/resources/project_10/Ballerina.toml +++ b/compiler-plugin-test/src/test/resources/project_10/Ballerina.toml @@ -1,6 +1,6 @@ [package] org = "root" -name = "project_7" +name = "project_10" version = "0.1.0" [[tool.persist]] diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal b/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal index af14ec21..c47bcf80 100644 --- a/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal +++ b/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal @@ -18,4 +18,4 @@ type AllTypes record {| time:Date? dateType; time:TimeOfDay? timeOfDayType; EnumType? enumType; -|}; \ No newline at end of file +|}; diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal b/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal index 45681d0b..a7bc35c9 100644 --- a/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal +++ b/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal @@ -18,4 +18,4 @@ type AllTypes record {| time:Date dateType?; time:TimeOfDay timeOfDayType?; EnumType enumType?; -|}; \ No newline at end of file +|}; From 2d73bcfecd8dec157a67dc34b79fbfdb98ca629e Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Wed, 13 Mar 2024 15:23:29 +0530 Subject: [PATCH 7/9] Combine test cases into a single one for Redis --- .../persist/compiler/CompilerPluginTest.java | 85 +++++++++---------- .../project_10/persist/all_types.bal | 70 --------------- .../persist/{rainier.bal => field-types.bal} | 39 ++++++++- .../project_10/persist/nillable_types.bal | 21 ----- .../project_10/persist/optional_fields.bal | 21 ----- 5 files changed, 77 insertions(+), 159 deletions(-) delete mode 100644 compiler-plugin-test/src/test/resources/project_10/persist/all_types.bal rename compiler-plugin-test/src/test/resources/project_10/persist/{rainier.bal => field-types.bal} (53%) delete mode 100644 compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal delete mode 100644 compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.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 d1b35ade..942ad7cc 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 @@ -45,6 +45,7 @@ import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_306; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_307; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_308; +import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_309; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_401; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_402; import static io.ballerina.stdlib.persist.compiler.DiagnosticsCodes.PERSIST_403; @@ -693,54 +694,52 @@ public void validateEntityNamesCaseSensitivity() { } @Test - public void validateAllTypesForRedisDB() { - getErrorDiagnostics("project_10", "all_types.bal", 0); - } - - @Test - public void validateRainierForRedisDB() { - getErrorDiagnostics("project_10", "rainier.bal", 0); - } - - @Test - public void validateUseOfOptionalFieldForRedisDB() { - getErrorDiagnostics("project_10", "optional_fields.bal", 0); - } - - @Test - public void validateNillableTypesForRedisDB() { - List diagnostics = getErrorDiagnostics("project_10", "nillable_types.bal", 8); + public void validateFieldTypesForRedisDB() { + List diagnostics = getErrorDiagnostics("project_10", + "field-types.bal", 12); testDiagnostic( diagnostics, new String[]{ - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode(), - PERSIST_308.getCode() - }, - new String[]{ - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field", - "an entity does not support nillable field" + PERSIST_309.getCode(), + PERSIST_305.getCode(), + PERSIST_305.getCode(), + PERSIST_305.getCode(), + PERSIST_305.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode(), + PERSIST_306.getCode() }, new String[]{ - "(12:4,12:12)", - "(13:4,13:8)", - "(14:4,14:10)", - "(15:4,15:12)", - "(16:4,16:11)", - "(17:4,17:14)", - "(18:4,18:19)", - "(19:4,19:13)" + "an entity does not support optional readonly field", + "an entity does not support redis:Client-typed field", + "an entity does not support json-typed field", + "an entity does not support error-typed field", + "an entity does not support union-typed field", + "an entity does not support enum array field type", + "an entity does not support byte array field type", + "an entity does not support boolean array field type", + "an entity does not support json array field type", + "an entity does not support time:Civil array field type", + "an entity does not support error array field type", + "an entity does not support redis:Client array field type" + }, + new String[]{ + "(11:4,11:34)", + "(23:4,23:16)", + "(24:4,24:8)", + "(25:4,25:9)", + "(28:4,28:21)", + "(30:4,30:12)", + "(31:4,31:10)", + "(32:4,32:13)", + "(33:4,33:10)", + "(34:4,34:16)", + "(35:4,35:11)", + "(36:4,36:18)" } ); } diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/all_types.bal b/compiler-plugin-test/src/test/resources/project_10/persist/all_types.bal deleted file mode 100644 index 8d9d7d6e..00000000 --- a/compiler-plugin-test/src/test/resources/project_10/persist/all_types.bal +++ /dev/null @@ -1,70 +0,0 @@ -import ballerina/persist as _; -import ballerina/time; - -enum EnumType { - TYPE_1, - TYPE_2, - TYPE_3, - TYPE_4 -} - -type AllTypes record {| - readonly int id; - boolean booleanType; - int intType; - float floatType; - decimal decimalType; - string stringType; - time:Date dateType; - time:TimeOfDay timeOfDayType; - EnumType enumType; - boolean booleanTypeOptional?; - int intTypeOptional?; - float floatTypeOptional?; - decimal decimalTypeOptional?; - string stringTypeOptional?; - time:Date dateTypeOptional?; - time:TimeOfDay timeOfDayTypeOptional?; - EnumType enumTypeOptional?; -|}; - -type StringIdRecord record {| - readonly string id; - string randomField; -|}; - -type IntIdRecord record {| - readonly int id; - string randomField; -|}; - -type FloatIdRecord record {| - readonly float id; - string randomField; -|}; - -type DecimalIdRecord record {| - readonly decimal id; - string randomField; -|}; - -type BooleanIdRecord record {| - readonly boolean id; - string randomField; -|}; - -type CompositeAssociationRecord record {| - readonly string id; - string randomField; - AllTypesIdRecord allTypesIdRecord; -|}; - -type AllTypesIdRecord record {| - readonly boolean booleanType; - readonly int intType; - readonly float floatType; - readonly decimal decimalType; - readonly string stringType; - string randomField; - CompositeAssociationRecord? compositeAssociationRecord; -|}; diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/rainier.bal b/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal similarity index 53% rename from compiler-plugin-test/src/test/resources/project_10/persist/rainier.bal rename to compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal index 4d8ec2c5..e015ad76 100644 --- a/compiler-plugin-test/src/test/resources/project_10/persist/rainier.bal +++ b/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal @@ -1,11 +1,42 @@ -import ballerina/persist as _; import ballerina/time; +import ballerinax/redis; +import ballerina/persist as _; -enum Gender { - MALE, - FEMALE +public enum Gender { + M, + F } +public type MedicalNeed record {| + readonly int needId; + readonly string stringNeedId?; + + boolean booleanType; + int intType; + float floatType; + decimal decimalType; + string stringType; + time:Date dateType; + time:TimeOfDay timeOfDayType; + time:Utc utcType; + time:Civil civilType; + Gender gender; + redis:Client clientType; + json jsonTest; + error errorType; + + boolean booleanTypeOptional?; + time:Civil|string unionType; + + Gender[] genderArray; + byte[] beneficiaryIdByteArray; + boolean[] booleanArray; + json[] jsonArray; + time:Civil[] periodArray; + error[] errorArrayType; + redis:Client[] clientArrayType; +|}; + type Employee record {| readonly string empNo; string firstName; diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal b/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal deleted file mode 100644 index c47bcf80..00000000 --- a/compiler-plugin-test/src/test/resources/project_10/persist/nillable_types.bal +++ /dev/null @@ -1,21 +0,0 @@ -import ballerina/persist as _; -import ballerina/time; - -enum EnumType { - TYPE_1, - TYPE_2, - TYPE_3, - TYPE_4 -} - -type AllTypes record {| - readonly int id; - boolean? booleanType; - int? intType; - float? floatType; - decimal? decimalType; - string? stringType; - time:Date? dateType; - time:TimeOfDay? timeOfDayType; - EnumType? enumType; -|}; diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal b/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal deleted file mode 100644 index a7bc35c9..00000000 --- a/compiler-plugin-test/src/test/resources/project_10/persist/optional_fields.bal +++ /dev/null @@ -1,21 +0,0 @@ -import ballerina/persist as _; -import ballerina/time; - -enum EnumType { - TYPE_1, - TYPE_2, - TYPE_3, - TYPE_4 -} - -type AllTypes record {| - readonly int id; - boolean booleanType?; - int intType?; - float floatType?; - decimal decimalType?; - string stringType?; - time:Date dateType?; - time:TimeOfDay timeOfDayType?; - EnumType enumType?; -|}; From db9c3a108b05a00d5c64c1a47222aaf6527c4f88 Mon Sep 17 00:00:00 2001 From: Dinuka Amarasinghe Date: Wed, 13 Mar 2024 16:54:54 +0530 Subject: [PATCH 8/9] Address missing test cases for Redis DB --- .../persist/compiler/CompilerPluginTest.java | 28 +++++++++++-------- .../project_10/persist/field-types.bal | 2 ++ 2 files changed, 19 insertions(+), 11 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 942ad7cc..93ddf32d 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 @@ -696,11 +696,13 @@ public void validateEntityNamesCaseSensitivity() { @Test public void validateFieldTypesForRedisDB() { List diagnostics = getErrorDiagnostics("project_10", - "field-types.bal", 12); + "field-types.bal", 14); testDiagnostic( diagnostics, new String[]{ PERSIST_309.getCode(), + PERSIST_308.getCode(), + PERSIST_308.getCode(), PERSIST_305.getCode(), PERSIST_305.getCode(), PERSIST_305.getCode(), @@ -715,6 +717,8 @@ public void validateFieldTypesForRedisDB() { }, new String[]{ "an entity does not support optional readonly field", + "an entity does not support nillable field", + "an entity does not support nillable field", "an entity does not support redis:Client-typed field", "an entity does not support json-typed field", "an entity does not support error-typed field", @@ -729,17 +733,19 @@ public void validateFieldTypesForRedisDB() { }, new String[]{ "(11:4,11:34)", - "(23:4,23:16)", - "(24:4,24:8)", - "(25:4,25:9)", - "(28:4,28:21)", - "(30:4,30:12)", - "(31:4,31:10)", - "(32:4,32:13)", + "(18:4,18:11)", + "(20:4,20:14)", + "(25:4,25:16)", + "(26:4,26:8)", + "(27:4,27:9)", + "(30:4,30:21)", + "(32:4,32:12)", "(33:4,33:10)", - "(34:4,34:16)", - "(35:4,35:11)", - "(36:4,36:18)" + "(34:4,34:13)", + "(35:4,35:10)", + "(36:4,36:16)", + "(37:4,37:11)", + "(38:4,38:18)" } ); } diff --git a/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal b/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal index e015ad76..5c8a5828 100644 --- a/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal +++ b/compiler-plugin-test/src/test/resources/project_10/persist/field-types.bal @@ -16,7 +16,9 @@ public type MedicalNeed record {| float floatType; decimal decimalType; string stringType; + string? stringNillableType; time:Date dateType; + time:Date? dateNillableType; time:TimeOfDay timeOfDayType; time:Utc utcType; time:Civil civilType; From 459b1d25327846d069d179095c371bf461b00f78 Mon Sep 17 00:00:00 2001 From: Haritha Hasathcharu Date: Thu, 14 Mar 2024 11:27:21 +0530 Subject: [PATCH 9/9] Rename relation annotation refs field to keys --- .../java/io/ballerina/stdlib/persist/compiler/Constants.java | 2 +- .../persist/compiler/PersistModelDefinitionValidator.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 a8e5ef89..bd72ba14 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 @@ -32,7 +32,7 @@ public final class Constants { public static final String ARRAY = "[]"; public static final String LS = System.lineSeparator(); public static final String SQL_RELATION_MAPPING_ANNOTATION_NAME = "sql:Relation"; - public static final String ANNOTATION_REFS_FIELD = "refs"; + public static final String ANNOTATION_KEYS_FIELD = "keys"; private Constants() { } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java index 59754aba..ee7e1619 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java @@ -65,7 +65,7 @@ import java.util.Locale; import java.util.Map; -import static io.ballerina.stdlib.persist.compiler.Constants.ANNOTATION_REFS_FIELD; +import static io.ballerina.stdlib.persist.compiler.Constants.ANNOTATION_KEYS_FIELD; import static io.ballerina.stdlib.persist.compiler.Constants.BallerinaTypes.BOOLEAN; import static io.ballerina.stdlib.persist.compiler.Constants.BallerinaTypes.DECIMAL; import static io.ballerina.stdlib.persist.compiler.Constants.BallerinaTypes.FLOAT; @@ -845,7 +845,7 @@ private void validateRelationAnnotationFieldName(SimpleTypeField field, Entity r RelationField ownerRelationField) { List references = readStringArrayValueFromAnnotation (ownerRelationField.getAnnotations(), Constants.SQL_RELATION_MAPPING_ANNOTATION_NAME, - ANNOTATION_REFS_FIELD); + ANNOTATION_KEYS_FIELD); if (references == null || !references.contains(field.getName())) { reportDiagnosticsEntity.reportDiagnostic(PERSIST_422.getCode(), MessageFormat.format( PERSIST_422.getMessage(), foreignKey, referredEntity.getEntityName()),