Skip to content
Permalink
Browse files

0003757: Stream LOB uses multiple queries per row when a table has

multiple LOB columns
  • Loading branch information...
erilong committed Oct 12, 2018
1 parent ed8d263 commit 86cc0ed8bbe490fe58fd2edf5a3d1252cac1a809
@@ -33,6 +33,7 @@
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.Row;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.io.data.Batch;
import org.jumpmind.symmetric.io.data.CsvData;
@@ -190,11 +191,13 @@ protected CsvData enhanceWithLobsFromSourceIfNeeded(Table table, CsvData data) {
args[i] = columnDataMap.get(pkColumns[i].getName());
}

String sql = buildSelect(table, lobColumns, pkColumns);
Row row = sqlTemplate.queryForRow(sql, args);

for (Column lobColumn : lobColumns) {
String sql = buildSelect(table, lobColumn, pkColumns);
String valueForCsv = null;
if (platform.isBlob(lobColumn.getMappedTypeCode())) {
byte[] binaryData = sqlTemplate.queryForBlob(sql, lobColumn.getJdbcTypeCode(),lobColumn.getJdbcTypeName(), args);
byte[] binaryData = row.getBytes(lobColumn.getName());
if (binaryData != null) {
if (batch.getBinaryEncoding() == BinaryEncoding.BASE64) {
valueForCsv = new String(Base64.encodeBase64(binaryData));
@@ -206,12 +209,11 @@ protected CsvData enhanceWithLobsFromSourceIfNeeded(Table table, CsvData data) {
binaryData = null;
}
} else {
valueForCsv = sqlTemplate.queryForClob(sql, lobColumn.getJdbcTypeCode(),lobColumn.getJdbcTypeName(), args);
valueForCsv = row.getString(lobColumn.getName());
}

int index = ArrayUtils.indexOf(columnNames, lobColumn.getName());
rowData[index] = valueForCsv;

}

data.putParsedData(CsvData.ROW_DATA, rowData);
@@ -220,32 +222,27 @@ protected CsvData enhanceWithLobsFromSourceIfNeeded(Table table, CsvData data) {
return data;
}

protected String buildSelect(Table table, Column lobColumn, Column[] pkColumns) {
protected String buildSelect(Table table, List<Column> lobColumns, Column[] pkColumns) {
StringBuilder sql = new StringBuilder("select ");
DatabaseInfo dbInfo = platform.getDatabaseInfo();
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? dbInfo.getDelimiterToken() : "";

if ("XMLTYPE".equalsIgnoreCase(lobColumn.getJdbcTypeName()) && 2009 == lobColumn.getJdbcTypeCode()) {
sql.append("extract(");
sql.append(quote);
sql.append(lobColumn.getName());
sql.append(quote);
sql.append(", '/').getClobVal()");
} else {
sql.append(quote);
sql.append(lobColumn.getName());
sql.append(quote);

for (Column lobColumn : lobColumns) {
if ("XMLTYPE".equalsIgnoreCase(lobColumn.getJdbcTypeName()) && 2009 == lobColumn.getJdbcTypeCode()) {
sql.append("extract(").append(quote).append(lobColumn.getName()).append(quote);
sql.append(", '/').getClobVal()");
} else {
sql.append(quote).append(lobColumn.getName()).append(quote);
}
sql.append(",");
}
sql.append(",");

sql.delete(sql.length() - 1, sql.length());
sql.append(" from ");
sql.append(table.getQualifiedTableName(quote, dbInfo.getCatalogSeparator(),
dbInfo.getSchemaSeparator()));
sql.append(table.getQualifiedTableName(quote, dbInfo.getCatalogSeparator(), dbInfo.getSchemaSeparator()));
sql.append(" where ");
for (Column col : pkColumns) {
sql.append(quote);
sql.append(col.getName());
sql.append(quote);
sql.append(quote).append(col.getName()).append(quote);
sql.append("=? and ");
}
sql.delete(sql.length() - 5, sql.length());

0 comments on commit 86cc0ed

Please sign in to comment.
You can’t perform that action at this time.