Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
https://github.com/cloudstore/cloudstore/issues/90
  • Loading branch information
Marco Nguitragool committed Apr 19, 2020
1 parent 6791a8e commit af9f616
Showing 1 changed file with 16 additions and 3 deletions.
Expand Up @@ -12,6 +12,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -505,7 +506,7 @@ protected void copyTableData(Table sourceTable, Table targetTable,
String sql = String.format("delete from \"%s\"", targetTable.name);
logger.debug("copyTableData: Executing: {}", sql);
int rowsAffected = deleteStatement.executeUpdate(sql);
logger.debug("copyTableData: rowsAffected: {}", rowsAffected);
logger.debug("copyTableData: Deleted {} rows from '{}'.", rowsAffected, targetTable.name);
}
targetConnection.commit();

Expand Down Expand Up @@ -644,10 +645,19 @@ protected String getJdbcTypeAsString(int dataType) {
}

protected Object convertValue(Column sourceColumn, Column targetColumn, Object sourceValue) throws Exception {
if (sourceValue == null
|| sourceColumn.dataType == targetColumn.dataType)
if (sourceValue == null)
return sourceValue;

if (sourceValue instanceof Clob) {
Clob sourceClob = (Clob) sourceValue;
long length = sourceClob.length();
if (length > Integer.MAX_VALUE)
throw new IllegalStateException("sourceClob.length > Integer.MAX_VALUE!!!");

String string = sourceClob.getSubString(1, (int) length);
return string;
}

if (sourceValue instanceof Blob) {
Blob sourceBlob = (Blob) sourceValue;
long length = sourceBlob.length();
Expand All @@ -658,6 +668,9 @@ protected Object convertValue(Column sourceColumn, Column targetColumn, Object s
return bytes;
}

if (sourceColumn.dataType == targetColumn.dataType)
return sourceValue;

switch (targetColumn.dataType) {
case Types.BOOLEAN:
case Types.BIT: // PostgreSQL returns BIT even though it shows 'boolean' as data-type in the pgAdmin3 -- strange, but true.
Expand Down

0 comments on commit af9f616

Please sign in to comment.