You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2022/12/09 17:05:33 UTC

[GitHub] [fineract] ruchiD opened a new pull request, #2798: FINERACT-1760-Index-or-Unique-column-creation-datatables

ruchiD opened a new pull request, #2798:
URL: https://github.com/apache/fineract/pull/2798

   ## Description
   1.Added unique and indexed attributes for datatable columns
   2.Updated column details to show unique or indexed status
   3.Modified to add support for columns to indexed or unique for datable creation and modification
   4.Integration Test
   
   Describe the changes made and why they were made.
   
   Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] ruchiD commented on a diff in pull request #2798: FINERACT-1760-Index-or-Unique-column-creation-datatables

Posted by GitBox <gi...@apache.org>.
ruchiD commented on code in PR #2798:
URL: https://github.com/apache/fineract/pull/2798#discussion_r1045507415


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java:
##########
@@ -871,6 +884,24 @@ public CommandProcessingResult createDatatable(final JsonCommand command) {
         return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
     }
 
+    private void createIndexesForTable(String datatableName, JsonArray columns) {
+        for (final JsonElement column : columns) {
+            createIndexForColumn(datatableName, column.getAsJsonObject());
+        }
+    }
+
+    private void createIndexForColumn(String datatableName, JsonObject column) {
+        String name = column.has("name") ? column.get("name").getAsString() : null;
+        final Boolean unique = column.has("unique") ? column.get("unique").getAsBoolean() : false;
+        final Boolean indexed = column.has("indexed") ? column.get("indexed").getAsBoolean() : false;
+        if (indexed) {
+            if (!unique) {

Review Comment:
   When unique constraint is added on a column, an index is created by database with the same name as unique constraint name. so no need to create index separately.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] galovics commented on a diff in pull request #2798: FINERACT-1760-Index-or-Unique-column-creation-datatables

Posted by GitBox <gi...@apache.org>.
galovics commented on code in PR #2798:
URL: https://github.com/apache/fineract/pull/2798#discussion_r1045499016


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/database/DatabaseQueryService.java:
##########
@@ -29,4 +29,6 @@ public interface DatabaseQueryService {
 
     // TODO: This needs to be improved to have a custom POJO return type instead of the raw SqlRowSet
     SqlRowSet getTableColumns(DataSource dataSource, String tableName);
+
+    SqlRowSet getTableIndexes(DataSource dataSource, String tableName);

Review Comment:
   As I originally wrote in the comment above, a POJO/DTO return type would be better here instead of a plain SqlRowSet.
   
   @ruchiD do you think you could change at least the new method (getTableIndexes)?



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/GenericDataServiceImpl.java:
##########
@@ -238,12 +244,36 @@ public List<ResultsetColumnHeaderData> fillResultsetColumnHeaders(final String d
             }
 
             columnHeaders.add(ResultsetColumnHeaderData.detailed(columnName, columnType, columnLength, columnNullable, columnIsPrimaryKey,
-                    columnValues, codeName));
+                    columnValues, codeName, columnIsUnique, columnIsIndexed));
         }
 
         return columnHeaders;
     }
 
+    private boolean checkUniqueOrIndexed(String datatable, String columnName, SqlRowSet indexDefinitions, Boolean isUnique) {
+        String keyNameToCheck = "uk_" + datatable + "_" + columnName;
+        if (!isUnique) {

Review Comment:
   Can't we create 2 separate methods, one for checking whether a column is unique and another one for checking whether its indexed?
   Would be much more cleaner and responsibilities wouldn't mix.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java:
##########
@@ -871,6 +884,24 @@ public CommandProcessingResult createDatatable(final JsonCommand command) {
         return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
     }
 
+    private void createIndexesForTable(String datatableName, JsonArray columns) {
+        for (final JsonElement column : columns) {
+            createIndexForColumn(datatableName, column.getAsJsonObject());
+        }
+    }
+
+    private void createIndexForColumn(String datatableName, JsonObject column) {
+        String name = column.has("name") ? column.get("name").getAsString() : null;
+        final Boolean unique = column.has("unique") ? column.get("unique").getAsBoolean() : false;
+        final Boolean indexed = column.has("indexed") ? column.get("indexed").getAsBoolean() : false;
+        if (indexed) {
+            if (!unique) {

Review Comment:
   Can you pls explain why we don't create the index if the column is also marked as unique? Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] galovics commented on a diff in pull request #2798: FINERACT-1760-Index-or-Unique-column-creation-datatables

Posted by GitBox <gi...@apache.org>.
galovics commented on code in PR #2798:
URL: https://github.com/apache/fineract/pull/2798#discussion_r1045939862


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java:
##########
@@ -871,6 +884,24 @@ public CommandProcessingResult createDatatable(final JsonCommand command) {
         return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
     }
 
+    private void createIndexesForTable(String datatableName, JsonArray columns) {
+        for (final JsonElement column : columns) {
+            createIndexForColumn(datatableName, column.getAsJsonObject());
+        }
+    }
+
+    private void createIndexForColumn(String datatableName, JsonObject column) {
+        String name = column.has("name") ? column.get("name").getAsString() : null;
+        final Boolean unique = column.has("unique") ? column.get("unique").getAsBoolean() : false;
+        final Boolean indexed = column.has("indexed") ? column.get("indexed").getAsBoolean() : false;
+        if (indexed) {
+            if (!unique) {

Review Comment:
   Yeah, right.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] galovics merged pull request #2798: FINERACT-1760-Index-or-Unique-column-creation-datatables

Posted by GitBox <gi...@apache.org>.
galovics merged PR #2798:
URL: https://github.com/apache/fineract/pull/2798


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org