Skip to content

Commit

Permalink
FINERACT-2181: Refactor ResultColumnHeaderData using Lombok and moder…
Browse files Browse the repository at this point in the history
…n Java new features
  • Loading branch information
a7med3del1973 committed Mar 6, 2025
1 parent 3a5888e commit 609b152
Showing 1 changed file with 14 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.database.DatabaseType;
import org.apache.fineract.infrastructure.core.service.database.JdbcJavaType;

/**
* Immutable data object representing a resultset column.
*/
@Getter
public final class ResultsetColumnHeaderData implements Serializable {

private final String columnName;
Expand All @@ -39,7 +41,6 @@ public final class ResultsetColumnHeaderData implements Serializable {
private final boolean isColumnPrimaryKey;
private final boolean isColumnUnique;
private final boolean isColumnIndexed;

private final List<ResultsetColumnValueData> columnValues;
private final String columnCode;

Expand Down Expand Up @@ -80,22 +81,10 @@ private ResultsetColumnHeaderData(final String columnName, String columnType, fi
this.columnDisplayType = calcDisplayType();
}

public String getColumnName() {
return this.columnName;
}

public boolean isNamed(final String columnName) {
return this.columnName.equalsIgnoreCase(columnName);
}

public JdbcJavaType getColumnType() {
return this.columnType;
}

public Long getColumnLength() {
return this.columnLength;
}

public boolean getIsColumnNullable() {
return isColumnNullable;
}
Expand All @@ -112,18 +101,6 @@ public boolean getIsColumnIndexed() {
return isColumnIndexed;
}

public DisplayType getColumnDisplayType() {
return this.columnDisplayType;
}

public String getColumnCode() {
return this.columnCode;
}

public List<ResultsetColumnValueData> getColumnValues() {
return this.columnValues;
}

public boolean isDateDisplayType() {
return columnDisplayType == DisplayType.DATE;
}
Expand Down Expand Up @@ -195,27 +172,17 @@ public boolean hasPrecision(@NotNull DatabaseType dialect) {
}

// --- Calculation ---

private String adjustColumnType(String type) {
type = type.toUpperCase();
switch (type) {
case "CLOB":
case "ENUM":
case "SET":
return "VARCHAR";
case "NEWDECIMAL":
return "DECIMAL";
case "LONGLONG":
return "BIGINT";
case "SHORT":
return "SMALLINT";
case "TINY":
return "TINYINT";
case "INT24":
return "INT";
default:
return type;
}
return switch (type) {
case "CLOB", "ENUM", "SET" -> "VARCHAR";
case "NEWDECIMAL" -> "DECIMAL";
case "LONGLONG" -> "BIGINT";
case "SHORT" -> "SMALLINT";
case "TINY" -> "TINYINT";
case "INT24" -> "INT";
default -> type;
};
}

@NotNull
Expand Down Expand Up @@ -272,7 +239,9 @@ public static DisplayType calcColumnDisplayType(JdbcJavaType columnType) {
return null;
}

// Enum representing the different ways a column can be displayed.
public enum DisplayType {
TEXT, STRING, INTEGER, FLOAT, DECIMAL, DATE, TIME, DATETIME, BOOLEAN, BINARY, CODELOOKUP, CODEVALUE,;
TEXT, STRING, INTEGER, FLOAT, DECIMAL, DATE, TIME, DATETIME, BOOLEAN, BINARY, CODELOOKUP, CODEVALUE;
}

}

0 comments on commit 609b152

Please sign in to comment.