in adb3client/src/main/java/com/alibaba/cloud/analyticdb/adb3client/impl/UpsertStatementBuilder.java [518:560]
public List<PreparedStatementWithBatchInfo> buildStatements(Connection conn, TableSchema schema, TableName tableName, Collection<Record> recordList,
WriteMode mode) throws
SQLException {
Map<Tuple<BitSet, BitSet>, List<Record>> insertRecordList = new HashMap<>();
List<PreparedStatementWithBatchInfo> preparedStatementList = new ArrayList<>();
try {
for (Record record : recordList) {
prepareRecord(conn, record, mode);
insertRecordList.computeIfAbsent(new Tuple<>(record.getBitSet(), record.getOnlyInsertColumnSet()), t -> new ArrayList<>()).add(record);
}
try {
for (Map.Entry<Tuple<BitSet, BitSet>, List<Record>> entry : insertRecordList.entrySet()) {
buildInsertStatement(conn, schema, tableName, entry.getKey(), entry.getValue(), preparedStatementList, mode);
}
} catch (SQLException e) {
for (PreparedStatementWithBatchInfo psWithInfo : preparedStatementList) {
PreparedStatement ps = psWithInfo.l;
if (null != ps) {
try {
ps.close();
} catch (SQLException e1) {
}
}
}
throw e;
}
return preparedStatementList;
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
} finally {
if (insertCache.getSize() > 500) {
insertCache.clear();
}
if (deleteCache.size() > 500) {
deleteCache.clear();
}
}
}