diff --git a/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java b/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java index 43bac6d1..dd4a70f4 100644 --- a/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java +++ b/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java @@ -14,12 +14,10 @@ import java.util.Map; @Slf4j -@RequiredArgsConstructor -public class MariaDBDialect implements Dialect { - - private final ObjectMapper objectMapper; - - private String coverChar = "`"; +public class MariaDBDialect extends Dialect { + public MariaDBDialect(ObjectMapper objectMapper) { + super(objectMapper, "`"); + } @Override public boolean isSupportedDb(String productName, int majorVersion) { @@ -37,7 +35,7 @@ public void processTypes(DbTable table, List insertableColumns, Map insertableColumns, Map insertableColumns, Map insertableColumns, Map insertableColumns, Map insertableColumns, Map insertableColumns, Map insertableColumns, Map convertToStringArray(Object object) { } catch (Exception e) { throw new GenericDataAccessException("Error converting to Array type - " + e.getLocalizedMessage()); } - } - return Dialect.super.convertToStringArray(object); + return convertToStringArray(object); } } diff --git a/rdbms-common/src/main/java/com/homihq/db2rest/jdbc/config/dialect/Dialect.java b/rdbms-common/src/main/java/com/homihq/db2rest/jdbc/config/dialect/Dialect.java index ec8bbbdf..66f7def9 100644 --- a/rdbms-common/src/main/java/com/homihq/db2rest/jdbc/config/dialect/Dialect.java +++ b/rdbms-common/src/main/java/com/homihq/db2rest/jdbc/config/dialect/Dialect.java @@ -1,6 +1,7 @@ package com.homihq.db2rest.jdbc.config.dialect; +import com.fasterxml.jackson.databind.ObjectMapper; import com.homihq.db2rest.jdbc.config.model.DbColumn; import com.homihq.db2rest.jdbc.config.model.DbTable; @@ -10,40 +11,48 @@ import java.util.List; import java.util.Map; +public abstract class Dialect { + private final ObjectMapper objectMapper; + private final String coverChar; -public interface Dialect { + public abstract boolean isSupportedDb(String productName, int majorVersion); + public abstract void processTypes(DbTable table, List insertableColumns, Map data); + public abstract String renderTableName(DbTable table, boolean containsWhere, boolean deleteOp); + public abstract String renderTableNameWithoutAlias(DbTable table); - boolean isSupportedDb(String productName, int majorVersion); + protected Dialect(ObjectMapper objectMapper, String coverChar) { + this.objectMapper = objectMapper; + this.coverChar = coverChar; + } + + protected ObjectMapper getObjectMapper() { + return objectMapper; + } - default boolean supportBatchReturnKeys() { + protected String getCoverChar() { + return coverChar; + } + + public boolean supportBatchReturnKeys() { return true; } - default boolean supportAlias() { + public boolean supportAlias() { return true; } - default int getMajorVersion() { + public int getMajorVersion() { return -1; } - - void processTypes(DbTable table, List insertableColumns, Map data); - - String renderTableName(DbTable table, boolean containsWhere, boolean deleteOp); - - String renderTableNameWithoutAlias(DbTable table); - - default String getAliasedName(DbColumn dbColumn, boolean deleteOp) { + public String getAliasedName(DbColumn dbColumn, boolean deleteOp) { return dbColumn.tableAlias() + "."+ dbColumn.name(); } - default String getAliasedNameParam(DbColumn dbColumn, boolean deleteOp) { + public String getAliasedNameParam(DbColumn dbColumn, boolean deleteOp) { return dbColumn.tableAlias() + "_"+ dbColumn.name(); } - - - default List parseListValues(List values, Class type) { + public List parseListValues(List values, Class type) { return values.stream() .map(v -> processValue(v, type, null)) @@ -52,7 +61,7 @@ default List parseListValues(List values, Class type) { //TODO use Spring converter @Deprecated - default Object processValue(String value, Class type, String format) { + public Object processValue(String value, Class type, String format) { //System.out.println("type " + type); if (String.class == type) { //return "'" + value + "'"; @@ -83,36 +92,35 @@ else if(java.sql.Timestamp.class == type) { } - default List convertToStringArray(Object object) {return List.of();} + public List convertToStringArray(Object object) {return List.of();} - default Object convertJsonToVO(Object object) {return null;} + public Object convertJsonToVO(Object object) {return null;} - default String getCountSqlTemplate() { + public String getCountSqlTemplate() { return "count"; } - default String getDeleteSqlTemplate() { + public String getDeleteSqlTemplate() { return "delete"; } - default String getExistSqlTemplate() { + public String getExistSqlTemplate() { return "exists"; } - default String getFindOneSqlTemplate() { + public String getFindOneSqlTemplate() { return "find-one"; } - default String getInsertSqlTemplate() { + public String getInsertSqlTemplate() { return "insert"; } - default String getReadSqlTemplate() { + public String getReadSqlTemplate() { return "read"; } - default String getUpdateSqlTemplate() { + public String getUpdateSqlTemplate() { return "update"; } - }