http://jira.mfd.msk:8088/browse/CLS-754 bug fixed
This commit is contained in:
parent
6a8c716f3f
commit
7a03fd1f62
3 changed files with 19 additions and 15 deletions
|
|
@ -158,12 +158,16 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
|||
}
|
||||
|
||||
protected void batchInsertUpdate(@NonNull String insertStatement, @NonNull List<Object[]> args) {
|
||||
readMetaData();
|
||||
batchInsertUpdate(insertStatement, args, getTableName(), getFields());
|
||||
}
|
||||
|
||||
protected void batchInsertUpdate(@NonNull String insertStatement, @NonNull List<Object[]> args, String tableName, String[] fields) {
|
||||
readMetaData(tableName);
|
||||
try {
|
||||
int[][] ret = jdbcTemplate.batchUpdate(insertStatement, args, BATCH_SIZE, (ps, params) -> {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
Object value = params[i];
|
||||
value = normalizeValue(value, ps.getParameterMetaData(), columnMetaDataMap, i, insertStatement, params);
|
||||
value = normalizeValue(value, ps.getParameterMetaData(), columnMetaDataMap, i, insertStatement, params, tableName, fields);
|
||||
try {
|
||||
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, value);
|
||||
} catch (SQLException e) {
|
||||
|
|
@ -172,23 +176,23 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
|||
}
|
||||
});
|
||||
int batchSize = ret.length > 0 ? ret[0].length : ret.length;
|
||||
log.debug("{} {} rows stored", getTableName(), batchSize);
|
||||
log.debug("{} {} rows stored", tableName, batchSize);
|
||||
} catch (Exception e) {
|
||||
log.error("SQL error at batch UPDATE OR INSERT INTO {}\n{}", getTableName(), ExceptionUtils.getStackTrace(e));
|
||||
log.error("SQL error at batch UPDATE OR INSERT INTO {}\n{}", tableName, ExceptionUtils.getStackTrace(e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Object normalizeValue(Object value, ParameterMetaData metaData, Map<String, ColumnMetaData> columnMetaDataMap, int i,
|
||||
String insertStatement, Object[] params) throws SQLException {
|
||||
if (getFields().length <= i || value == null)
|
||||
String insertStatement, Object[] params, String tableName, String[] fields) throws SQLException {
|
||||
if (value == null)
|
||||
return null;
|
||||
i++; // нумерация в ParameterMetaData начинается с 1
|
||||
final int type = metaData.getParameterType(i);
|
||||
|
||||
final String fieldName = getFields()[i - 1].toLowerCase();
|
||||
final String fieldName = fields[i - 1].toLowerCase();
|
||||
if (columnMetaDataMap == null) {
|
||||
log.trace("Column metadata was empty, can not verify {}.{}", getTableName(), fieldName);
|
||||
log.trace("Column metadata was empty, can not verify {}.{}", tableName, fieldName);
|
||||
}
|
||||
if ((type == Types.VARCHAR || type == Types.CHAR) && value instanceof String stringValue) {
|
||||
int length;
|
||||
|
|
@ -310,9 +314,9 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
|||
return TextUtil.format(INSERT_TEMPLATE, params);
|
||||
}
|
||||
|
||||
private void readMetaData() {
|
||||
if (columnMetaDataMap == null) synchronized (this) {
|
||||
columnMetaDataMap = PostgresColumnTypeUtil.extractTableMetadata(jdbcTemplate, getTableName());
|
||||
private void readMetaData(String tableName) {
|
||||
synchronized (this) {
|
||||
columnMetaDataMap = PostgresColumnTypeUtil.extractTableMetadata(jdbcTemplate, tableName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,6 @@ public abstract class ASecurityHistoryMapStore<STH extends BusinessEvent<? exten
|
|||
securityArgs.add(securityItemArgs);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, tableArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs, "SECURITY_HISTORY", this.getFieldsSecurity());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public abstract class ASecurityMapStore <S extends Security> extends TemplateMap
|
|||
securityArgs.add(argsSecurityItem);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, childTableArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs, "SECURITY", this.getFieldsSecurity());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue