Permalink
Browse files

Merge branch '3.9' of https://github.com/JumpMind/symmetric-ds.git in…

…to 3.9
  • Loading branch information...
jumpmind-josh committed Jan 9, 2019
2 parents 994ffb3 + 538d3ca commit 2bd01279e6162dde7fbf036491ebdec4306fac81
@@ -478,23 +478,23 @@ public Object getParsedDefaultValue() {
switch (mappedTypeCode) {
case Types.TINYINT:
case Types.SMALLINT:
return new Short(defaultValue);
return new Short(getCleanDefaultValue());
case Types.INTEGER:
try {
return new Integer(defaultValue);
return new Integer(getCleanDefaultValue());
} catch (NumberFormatException e) {
return new Long(defaultValue);
return new Long(getCleanDefaultValue());
}
case Types.BIGINT:
return new Long(defaultValue);
return new Long(getCleanDefaultValue());
case Types.DECIMAL:
case Types.NUMERIC:
return new BigDecimal(defaultValue);
return new BigDecimal(getCleanDefaultValue());
case Types.REAL:
return new Float(defaultValue);
return new Float(getCleanDefaultValue());
case Types.DOUBLE:
case Types.FLOAT:
return new Double(defaultValue);
return new Double(getCleanDefaultValue());
case Types.DATE:
return Date.valueOf(defaultValue);
case Types.TIME:
@@ -518,6 +518,10 @@ public Object getParsedDefaultValue() {
}
return defaultValue;
}

private String getCleanDefaultValue() {
return defaultValue.replace("'", "");
}

public void removePlatformColumn(String databaseName) {
if (platformColumns != null) {
@@ -117,7 +117,8 @@
public static final String NCLOB = "NCLOB";
public static final String IMAGE = "IMAGE";
public static final String DATETIME2 = "DATETIME2";

public static final String TSVECTOR = "TSVECTOR";

/** Maps type names to the corresponding {@link java.sql.Types} constants. */
private static HashMap<String, Integer> _typeNameToTypeCode = new HashMap<String, Integer>();

@@ -125,6 +125,8 @@ protected void appendColumnParameter(StringBuilder sql, Column column) {
column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY) ||
column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY))) {
sql.append("ST_GEOMFROMTEXT(?)").append(",");
} else if (column.getJdbcTypeName().toUpperCase().contains(TypeMap.TSVECTOR)) {
sql.append("cast(? as tsvector)").append(",");
} else {
super.appendColumnParameter(sql, column);
}
@@ -148,6 +150,8 @@ protected void appendColumnEquals(StringBuilder sql, Column column) {
column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) {
sql.append(quote).append(column.getName()).append(quote)
.append(" = ST_GEOMFROMTEXT(?)");
} else if (column.getJdbcTypeName().toUpperCase().contains(TypeMap.TSVECTOR)) {
sql.append(quote).append(column.getName()).append(quote).append(" = cast(? as tsvector)");
} else {
super.appendColumnEquals(sql, column);
}
@@ -295,21 +295,15 @@ public static synchronized IDatabasePlatform createNewPlatformInstance(DataSourc
private static boolean isGreenplumDatabase(Connection connection) {
Statement stmt = null;
ResultSet rs = null;
String productName = null;
boolean isGreenplum = false;
int greenplumCount = 0;
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(GreenplumPlatform.SQL_GET_GREENPLUM_NAME);
while (rs.next()) {
productName = rs.getString(1);
}
if (productName != null && productName.equalsIgnoreCase("Greenplum")) {
isGreenplum = true;
rs = stmt.executeQuery(GreenplumPlatform.SQL_GET_GREENPLUM_COUNT);
if (rs.next()) {
greenplumCount = rs.getInt(1);
}
} catch (SQLException ex) {
// ignore the exception, if it is caught, then this is most likely
// not
// a greenplum database
throw new RuntimeException(ex);
} finally {
try {
if (rs != null) {
@@ -321,7 +315,7 @@ private static boolean isGreenplumDatabase(Connection connection) {
} catch (SQLException ex) {
}
}
return isGreenplum;
return greenplumCount > 0;
}

private static boolean isRedshiftDatabase(Connection connection) {
@@ -31,7 +31,7 @@
public class GreenplumPlatform extends PostgreSqlDatabasePlatform {

/* PostgreSql can be either PostgreSql or Greenplum. Metadata queries to determine which one */
public static final String SQL_GET_GREENPLUM_NAME = "select gpname from gp_id";
public static final String SQL_GET_GREENPLUM_COUNT = "select count(*) from information_schema.tables where table_name = 'gp_id'";
public static final String SQL_GET_GREENPLUM_VERSION = "select productversion from gp_version_at_initdb";

public GreenplumPlatform(DataSource dataSource, SqlTemplateSettings settings) {

0 comments on commit 2bd0127

Please sign in to comment.