a7med3del1973 commented on code in PR #4307:
URL: https://github.com/apache/fineract/pull/4307#discussion_r1948022450
##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:
##########
@@ -39,240 +51,85 @@ 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;
public static ResultsetColumnHeaderData basic(final String columnName,
final String columnType, DatabaseType dialect) {
- final Long columnLength = null;
- final boolean columnNullable = false;
- final boolean columnIsPrimaryKey = false;
- final List<ResultsetColumnValueData> columnValues = new ArrayList<>();
- final String columnCode = null;
- final boolean columnIsUnique = false;
- final boolean columnIsIndexed = false;
- return new ResultsetColumnHeaderData(columnName, columnType,
columnLength, columnNullable, columnIsPrimaryKey, columnValues,
- columnCode, columnIsUnique, columnIsIndexed, dialect);
+ return ResultsetColumnHeaderData.builder()
+ .columnName(columnName)
+ .columnType(JdbcJavaType.getByTypeName(dialect,
adjustColumnType(columnType), true))
+ .columnLength(null)
+ .isColumnNullable(false)
+ .isColumnPrimaryKey(false)
+ .isColumnUnique(false)
+ .isColumnIndexed(false)
+ .columnValues(new ArrayList<>())
+ .columnCode(null)
+ .columnDisplayType(calcDisplayType(null,
JdbcJavaType.getByTypeName(dialect, adjustColumnType(columnType), true)))
+ .build();
}
public static ResultsetColumnHeaderData detailed(final String columnName,
final String columnType, final Long columnLength,
- final boolean columnNullable, final boolean columnIsPrimaryKey,
final List<ResultsetColumnValueData> columnValues,
- final String columnCode, final boolean columnIsUnique, final
boolean columnIsIndexed, DatabaseType dialect) {
- return new ResultsetColumnHeaderData(columnName, columnType,
columnLength, columnNullable, columnIsPrimaryKey, columnValues,
- columnCode, columnIsUnique, columnIsIndexed, dialect);
- }
-
- private ResultsetColumnHeaderData(final String columnName, String
columnType, final Long columnLength, final boolean columnNullable,
- final boolean columnIsPrimaryKey, final
List<ResultsetColumnValueData> columnValues, final String columnCode,
- final boolean columnIsUnique, final boolean columnIsIndexed,
DatabaseType dialect) {
- this.columnName = columnName;
- this.columnLength = columnLength;
- this.isColumnNullable = columnNullable;
- this.isColumnPrimaryKey = columnIsPrimaryKey;
- this.columnValues = columnValues;
- this.columnCode = columnCode;
- this.isColumnUnique = columnIsUnique;
- this.isColumnIndexed = columnIsIndexed;
-
- // Refer org.drizzle.jdbc.internal.mysql.MySQLType.java
- this.columnType = JdbcJavaType.getByTypeName(dialect,
adjustColumnType(columnType), true);
-
- 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;
- }
-
- public boolean getIsColumnPrimaryKey() {
- return isColumnPrimaryKey;
- }
-
- public boolean getIsColumnUnique() {
- return isColumnUnique;
- }
-
- 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;
- }
-
- public boolean isDateTimeDisplayType() {
- return columnDisplayType == DisplayType.DATETIME;
- }
-
- public boolean isTimeDisplayType() {
- return columnDisplayType == DisplayType.TIME;
- }
-
- public boolean isIntegerDisplayType() {
- return columnDisplayType == DisplayType.INTEGER;
- }
-
- public boolean isDecimalDisplayType() {
- return columnDisplayType == DisplayType.DECIMAL;
- }
-
- public boolean isStringDisplayType() {
- return columnDisplayType == DisplayType.STRING;
- }
-
- public boolean isTextDisplayType() {
- return columnDisplayType == DisplayType.TEXT;
- }
-
- public boolean isBooleanDisplayType() {
- return columnDisplayType == DisplayType.BOOLEAN;
- }
-
- public boolean isCodeValueDisplayType() {
- return columnDisplayType == DisplayType.CODEVALUE;
- }
-
- public boolean isCodeLookupDisplayType() {
- return columnDisplayType == DisplayType.CODELOOKUP;
- }
-
- public boolean isMandatory() {
- return !this.isColumnNullable;
- }
-
- public boolean hasColumnValues() {
- return columnValues != null && !columnValues.isEmpty();
- }
-
- public boolean isColumnValueAllowed(final String match) {
- for (final ResultsetColumnValueData allowedValue : this.columnValues) {
- if (allowedValue.matches(match)) {
- return true;
- }
- }
- return false;
- }
-
- public boolean isColumnCodeAllowed(final Integer match) {
- for (final ResultsetColumnValueData allowedValue : this.columnValues) {
- if (allowedValue.codeMatches(match)) {
- return true;
- }
- }
- return false;
- }
-
- public boolean hasPrecision(@NotNull DatabaseType dialect) {
- return columnType.hasPrecision(dialect);
- }
-
- // --- Calculation ---
-
- private String adjustColumnType(String type) {
+ final boolean
columnNullable, final boolean columnIsPrimaryKey, final
List<ResultsetColumnValueData> columnValues,
+ final String columnCode,
final boolean columnIsUnique, final boolean columnIsIndexed, DatabaseType
dialect) {
+ JdbcJavaType jdbcType = JdbcJavaType.getByTypeName(dialect,
adjustColumnType(columnType), true);
+ return ResultsetColumnHeaderData.builder()
+ .columnName(columnName)
+ .columnType(jdbcType)
+ .columnLength(columnLength)
+ .isColumnNullable(columnNullable)
+ .isColumnPrimaryKey(columnIsPrimaryKey)
+ .isColumnUnique(columnIsUnique)
+ .isColumnIndexed(columnIsIndexed)
+ .columnValues(columnValues)
+ .columnCode(columnCode)
+ .columnDisplayType(calcDisplayType(columnCode, jdbcType))
+ .build();
+ }
+
+ private static 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
- private DisplayType calcDisplayType() {
- DisplayType displayType = null;
- if (this.columnCode == null) {
- displayType = calcColumnDisplayType(columnType);
- } else {
- if (columnType.isIntegerType()) {
- displayType = DisplayType.CODELOOKUP;
- } else if (columnType.isVarcharType()) {
- displayType = DisplayType.CODEVALUE;
- }
-
- }
- if (displayType == null) {
- throw new
PlatformDataIntegrityException("error.msg.invalid.lookup.type",
- "Invalid Lookup Type:" + this.columnType + " - Column
Name: " + this.columnName);
+ private static DisplayType calcDisplayType(String columnCode, JdbcJavaType
columnType) {
+ if (columnCode == null) {
+ return calcColumnDisplayType(columnType);
+ } else if (columnType.isIntegerType()) {
+ return DisplayType.CODELOOKUP;
+ } else if (columnType.isVarcharType()) {
+ return DisplayType.CODEVALUE;
}
- return displayType;
+
+ throw new
PlatformDataIntegrityException("error.msg.invalid.lookup.type",
+ "Invalid Lookup Type: " + columnType + " - Column Name: " +
columnCode);
}
public static DisplayType calcColumnDisplayType(JdbcJavaType columnType) {
- if (columnType.isTextType()) {
- return DisplayType.TEXT;
- }
- if (columnType.isStringType()) {
- return DisplayType.STRING;
- }
- if (columnType.isAnyIntegerType()) {
- return DisplayType.INTEGER;
- }
- if (columnType.isAnyFloatType()) {
- return DisplayType.FLOAT;
- }
- if (columnType.isDecimalType()) { // Refer
org.drizzle.jdbc.internal.mysql.MySQLType.java
- return DisplayType.DECIMAL;
- }
- if (columnType.isDateType()) {
- return DisplayType.DATE;
- }
- if (columnType.isDateTimeType()) {
- return DisplayType.DATETIME;
- }
- if (columnType.isTimeType()) {
- return DisplayType.TIME;
- }
- if (columnType.isBooleanType()) {
- return DisplayType.BOOLEAN;
- }
- if (columnType.isBinaryType()) {
- return DisplayType.BINARY;
- }
+ if (columnType.isTextType()) return DisplayType.TEXT;
+ if (columnType.isStringType()) return DisplayType.STRING;
+ if (columnType.isAnyIntegerType()) return DisplayType.INTEGER;
Review Comment:
@oluexpert99
Thanks for your response .. i noted your comments then refactored the code
according to yours and waiting for feedback
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]