Skip to content

Commit

Permalink
fix: fix method to determine if Db is MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Jan 26, 2022
1 parent 4c21be2 commit edf5a8d
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class SqlConnectionProvider {
private PasswordEncryptionMethod passwordEncryptionMethod;

private String dbType;
private String dbVersion;

private boolean mariaDb = false;

private String schemaName;

private SQLTemplates sqlTemplates;
Expand All @@ -88,6 +92,7 @@ public class SqlConnectionProvider {
private Map<String, Map<String, String>> tableColumnsMap;
private Map<String, String> tableEnginesMap = new HashMap<>();


protected SqlConnectionProvider() {
}

Expand Down Expand Up @@ -192,6 +197,10 @@ protected void init() throws Exception {
try (Connection con = this.poolingDataSource.getConnection()) {
DatabaseMetaData databaseMetaData = con.getMetaData();
this.dbType = databaseMetaData.getDatabaseProductName().toLowerCase();
this.dbVersion = databaseMetaData.getDatabaseProductVersion().toLowerCase();
if ((this.dbVersion != null) && this.dbVersion.toLowerCase().contains("mariadb")) {
this.mariaDb = true;
}
LOG.debug("Database product name: '{}'", dbType);
loadTableMetaData(databaseMetaData, con);
} catch (Exception ex) {
Expand Down Expand Up @@ -231,7 +240,7 @@ private void loadTableMetaData(DatabaseMetaData databaseMetaData, Connection con
String columTypeName = columnResultSet.getString("TYPE_NAME").toLowerCase();

String remark = columnResultSet.getString("REMARKS");
if ("mariadb".equalsIgnoreCase(engineType) && "longtext".equalsIgnoreCase(columTypeName) && "json".equalsIgnoreCase(remark)) {
if (mariaDb && "longtext".equalsIgnoreCase(columTypeName) && "json".equalsIgnoreCase(remark)) {
columTypeName = JSON_TYPE_NAME;
}
tableColumns.put(columnName, columTypeName);
Expand Down

0 comments on commit edf5a8d

Please sign in to comment.