fix insert to db
This commit is contained in:
parent
9c056718bb
commit
0726c3e321
5 changed files with 14 additions and 31 deletions
|
|
@ -49,6 +49,15 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>application.properties</exclude>
|
||||
</excludes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class DBFExporterConfig {
|
|||
params.setClusterMembers(properties.getHazelcastClusterMembers());
|
||||
params.setLogin(properties.getHazelcastLogin());
|
||||
params.setPassword(properties.getHazelcastPassword());
|
||||
params.setInstanceName("dbf-exporter");
|
||||
// params.setInstanceName("dbf-exporter");
|
||||
return new HazelcastService(taskExecutorHazelcastClientInitializer, taskExecutorIdGeneratorAwaiter, params);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>./logs/dbf_exporter.log</file>
|
||||
<file>./logs/dbf-exporter.log</file>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||
<fileNamePattern>
|
||||
../logs/dbf_export.%i.log
|
||||
../logs/dbf-export.%i.log
|
||||
</fileNamePattern>
|
||||
<minIndex>1</minIndex>
|
||||
<maxIndex>10</maxIndex>
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>./logs/dbf_importer.log</file>
|
||||
<file>./logs/dbf-importer.log</file>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||
<fileNamePattern>
|
||||
../logs/dbf_loader.%i.log
|
||||
../logs/dbf-importer.%i.log
|
||||
</fileNamePattern>
|
||||
<minIndex>1</minIndex>
|
||||
<maxIndex>10</maxIndex>
|
||||
|
|
|
|||
|
|
@ -8,14 +8,11 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||
import org.springframework.jdbc.core.SqlTypeValue;
|
||||
import org.springframework.jdbc.core.StatementCreatorUtils;
|
||||
import org.springframework.lang.NonNull;
|
||||
import ru.spcex.clearing.imdg.utils.BigDecimalUtil;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
|
@ -147,30 +144,7 @@ public abstract class SimpleObjectMapStore<T extends SpcexObjectBase> implements
|
|||
try {
|
||||
int[][] ret = jdbcTemplate.batchUpdate(insertStatement, args, bathSize, (ps, params) -> {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
int type = ps.getParameterMetaData().getParameterType(i + 1);
|
||||
Object value = params[i];
|
||||
if (value != null) {
|
||||
if ((type == Types.VARCHAR || type == Types.CHAR) && value instanceof String) {
|
||||
String stringValue = (String) value;
|
||||
int length = ps.getParameterMetaData().getPrecision(i + 1);
|
||||
if (stringValue.length() > length) {
|
||||
value = stringValue.substring(0, length);
|
||||
log.error("String value for insert is too large [ insertSql: {}, params: {}, incorrect value : {}, normalized value: {} ]",
|
||||
insertStatement, Arrays.toString(params), stringValue, value);
|
||||
}
|
||||
} else if ((type == Types.DECIMAL || type == Types.NUMERIC) && value instanceof BigDecimal) {
|
||||
BigDecimal bigDecimalValue = (BigDecimal) value;
|
||||
int dbScalePartLength = ps.getParameterMetaData().getScale(i + 1);
|
||||
int precision = ps.getParameterMetaData().getPrecision(i + 1);
|
||||
if (!BigDecimalUtil.checkSize(bigDecimalValue, precision, dbScalePartLength)) {
|
||||
value = BigDecimalUtil.genMaxValueForInsert(precision, dbScalePartLength);
|
||||
log.error("BigDecimal value for insert is too large [ insertSql: {}, params: {}, incorrect value : {}, normalized value: {} ]",
|
||||
insertStatement, Arrays.toString(params), bigDecimalValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
//в batchUpdate(String sql, List<Object[]> batchArgs), как типа поля всегда передавался SqlTypeValue.TYPE_UNKNOWN,
|
||||
//см. BatchUpdateUtils.setStatementParameters
|
||||
try {
|
||||
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, value);
|
||||
} catch (SQLException e) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue