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-unsubscr...@fineract.apache.org

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

Reply via email to