IMDG refactoring для дочерних таблиц объединил общий код
This commit is contained in:
parent
e3bc062346
commit
f701b0db8c
9 changed files with 195 additions and 308 deletions
|
|
@ -0,0 +1,83 @@
|
|||
package ru.spcex.clearing.imdg.businessevent;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import ru.clearing.classes.objects.BusinessEvent;
|
||||
import ru.clearing.classes.statics.data.security.Security;
|
||||
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Двойная запись в 2 таблицы:
|
||||
* SECURITY_HISTORY
|
||||
* *_SECURITY_HISTORY
|
||||
*/
|
||||
public abstract class ASecurityHistoryMapStore<STH extends BusinessEvent<? extends Security>> extends TemplateEventMapStore<STH> {
|
||||
|
||||
protected final int validateSecuritySize;
|
||||
|
||||
public ASecurityHistoryMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
this.validateSecuritySize = getFieldsSecurity().length;
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{
|
||||
"ID", "EVENT_TIME", "EVENT_USER_ID", "EVENT_TYPE",
|
||||
"SECURITY_ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
protected Object[] securityField(STH historyLog) {
|
||||
Security object = historyLog.getObject();
|
||||
Object[] args = new Object[]{
|
||||
historyLog.getId(),
|
||||
historyLog.getEventTime(),
|
||||
historyLog.getUserId(),
|
||||
historyLog.getEventType(),
|
||||
|
||||
object.getId(), // securitytId
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, STH> map) {
|
||||
List<Object[]> tableArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, STH> entry : map.entrySet()) {
|
||||
STH obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
tableArgs.add(args);
|
||||
Object[] securityItemArgs = securityField(obj);
|
||||
|
||||
if (securityItemArgs.length != validateSecuritySize) {
|
||||
throw new IllegalArgumentException("securityField return " + securityItemArgs.length + " arguments, but expected " + validateSecuritySize);
|
||||
}
|
||||
securityArgs.add(securityItemArgs);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, tableArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,15 +5,9 @@ import org.springframework.stereotype.Component;
|
|||
import ru.clearing.classes.statics.data.instrument.issue.EquitySecurity;
|
||||
import ru.clearing.classes.statics.data.instrument.issue.EquitySecurityHistory;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class EquitySecurityHistoryMapStore extends TemplateEventMapStore<EquitySecurityHistory> {
|
||||
public class EquitySecurityHistoryMapStore extends ASecurityHistoryMapStore<EquitySecurityHistory> {
|
||||
|
||||
public EquitySecurityHistoryMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
|
|
@ -37,16 +31,6 @@ public class EquitySecurityHistoryMapStore extends TemplateEventMapStore<EquityS
|
|||
"EQUITY_SECURITY_ID", "SECURITY_ID", "SHARE_TYPE"};
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{
|
||||
"ID", "EVENT_TIME", "EVENT_USER_ID", "EVENT_TYPE",
|
||||
"SECURITY_ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(EquitySecurityHistory historyLog) {
|
||||
EquitySecurity equitySecurity = historyLog.getObject();
|
||||
|
|
@ -63,45 +47,4 @@ public class EquitySecurityHistoryMapStore extends TemplateEventMapStore<EquityS
|
|||
return args;
|
||||
}
|
||||
|
||||
protected Object[] securityField(EquitySecurityHistory historyLog) {
|
||||
EquitySecurity object = historyLog.getObject();
|
||||
Object[] args = new Object[]{
|
||||
historyLog.getId(),
|
||||
historyLog.getEventTime(),
|
||||
historyLog.getUserId(),
|
||||
historyLog.getEventType(),
|
||||
|
||||
object.getSecurityId(),
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, EquitySecurityHistory> map) {
|
||||
List<Object[]> moneyMarketArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, EquitySecurityHistory> entry : map.entrySet()) {
|
||||
EquitySecurityHistory obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
moneyMarketArgs.add(args);
|
||||
securityArgs.add(securityField(obj));
|
||||
}
|
||||
batchInsertUpdate(insertStatement, moneyMarketArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@ import org.springframework.stereotype.Component;
|
|||
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurity;
|
||||
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurityHistory;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class FixedIncomeSecurityHistoryMapStore extends TemplateEventMapStore<FixedIncomeSecurityHistory> {
|
||||
public class FixedIncomeSecurityHistoryMapStore extends ASecurityHistoryMapStore<FixedIncomeSecurityHistory> {
|
||||
|
||||
public FixedIncomeSecurityHistoryMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
|
|
@ -38,16 +34,6 @@ public class FixedIncomeSecurityHistoryMapStore extends TemplateEventMapStore<Fi
|
|||
};
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{
|
||||
"ID", "EVENT_TIME", "EVENT_USER_ID", "EVENT_TYPE",
|
||||
"SECURITY_ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(FixedIncomeSecurityHistory historyLog) {
|
||||
FixedIncomeSecurity fixedIncomeSecurity = historyLog.getObject();
|
||||
|
|
@ -69,45 +55,4 @@ public class FixedIncomeSecurityHistoryMapStore extends TemplateEventMapStore<Fi
|
|||
return args;
|
||||
}
|
||||
|
||||
protected Object[] securityField(FixedIncomeSecurityHistory historyLog) {
|
||||
FixedIncomeSecurity object = historyLog.getObject();
|
||||
Object[] args = new Object[]{
|
||||
historyLog.getId(),
|
||||
historyLog.getEventTime(),
|
||||
historyLog.getUserId(),
|
||||
historyLog.getEventType(),
|
||||
|
||||
object.getSecurityId(),
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, FixedIncomeSecurityHistory> map) {
|
||||
List<Object[]> moneyMarketArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, FixedIncomeSecurityHistory> entry : map.entrySet()) {
|
||||
FixedIncomeSecurityHistory obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
moneyMarketArgs.add(args);
|
||||
securityArgs.add(securityField(obj));
|
||||
}
|
||||
batchInsertUpdate(insertStatement, moneyMarketArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class MoneyMarketSecurityHistoryMapStore extends TemplateEventMapStore<MoneyMarketSecurityHistory> {
|
||||
public class MoneyMarketSecurityHistoryMapStore extends ASecurityHistoryMapStore<MoneyMarketSecurityHistory> {
|
||||
|
||||
public MoneyMarketSecurityHistoryMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
|
|
@ -37,15 +37,6 @@ public class MoneyMarketSecurityHistoryMapStore extends TemplateEventMapStore<Mo
|
|||
"MONEY_MARKET_SECURITY_ID", "SECURITY_ID", "DESCRIPTION", "START_DATE", "END_DATE", "NOMINAL_VALUE", "NOMINAL_CURRENCY", "TERM_TYPE"};
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{
|
||||
"ID", "EVENT_TIME", "EVENT_USER_ID", "EVENT_TYPE",
|
||||
"SECURITY_ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(MoneyMarketSecurityHistory historyLog) {
|
||||
|
|
@ -68,45 +59,4 @@ public class MoneyMarketSecurityHistoryMapStore extends TemplateEventMapStore<Mo
|
|||
return args;
|
||||
}
|
||||
|
||||
protected Object[] securityField(MoneyMarketSecurityHistory historyLog) {
|
||||
MoneyMarketSecurity object = historyLog.getObject();
|
||||
Object[] args = new Object[]{
|
||||
historyLog.getId(),
|
||||
historyLog.getEventTime(),
|
||||
historyLog.getUserId(),
|
||||
historyLog.getEventType(),
|
||||
|
||||
object.getSecurityId(),
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, MoneyMarketSecurityHistory> map) {
|
||||
List<Object[]> moneyMarketArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, MoneyMarketSecurityHistory> entry : map.entrySet()) {
|
||||
MoneyMarketSecurityHistory obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
moneyMarketArgs.add(args);
|
||||
securityArgs.add(securityField(obj));
|
||||
}
|
||||
batchInsertUpdate(insertStatement, moneyMarketArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|||
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
// Abstract table: ASecurityHistoryMapStore
|
||||
@Component
|
||||
public class SecurityHistoryMapStore extends TemplateEventMapStore<SecurityHistory> {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,105 @@
|
|||
package ru.spcex.clearing.imdg.businessobject;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.security.Security;
|
||||
import ru.spcex.clearing.imdg.base.TemplateMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Двойная запись в 2 таблицы:
|
||||
* SECURITY_HISTORY
|
||||
* *_SECURITY_HISTORY
|
||||
*
|
||||
* objectReader() надо использовать fillBySecurity(object, object.getSecurityId());
|
||||
* objectToField() требуется возвращать только поля в дополнительную таблицу, без полей для SECURITY
|
||||
*/
|
||||
@Component
|
||||
public abstract class ASecurityMapStore <S extends Security> extends TemplateMapStore<S> {
|
||||
|
||||
protected final int validateSecuritySize;
|
||||
|
||||
public ASecurityMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
validateSecuritySize = getFieldsSecurity().length;
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{"ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
|
||||
protected void fillBySecurity(S object, Long securityId) {
|
||||
List<S> resouts = jdbcTemplate.query(
|
||||
"SELECT * FROM SECURITY WHERE id = ?", new Object[]{securityId},
|
||||
(rs, rowNum) -> {
|
||||
object.setCreated(getInstantFromTimestamp(rs, "CREATED_AT"));
|
||||
object.setUpdated(getInstantFromTimestamp(rs, "UPDATED_AT"));
|
||||
object.setInstrumentType(rs.getObject("INSTRUMENT_TYPE", String.class));
|
||||
object.setIssuerId(rs.getObject("issuer_id", Long.class));
|
||||
object.setShortName(rs.getObject("short_name", String.class));
|
||||
object.setFullName(rs.getObject("FULL_NAME", String.class));
|
||||
object.setShortNameEng(rs.getObject("short_name_eng", String.class));
|
||||
object.setFullNameEng(rs.getObject("full_name_eng", String.class));
|
||||
object.setSecuritySymbol(rs.getObject("SECURITY_SYMBOL", String.class));
|
||||
object.setIsin(rs.getObject("ISIN", String.class));
|
||||
object.setWorkflowStatus(rs.getObject("workflow_status", String.class));
|
||||
return object;
|
||||
}
|
||||
);
|
||||
if (resouts.size() != 1) {
|
||||
log.warn("Result size={} not expected for table SECURITY, {} where id={}", getTableName(), resouts.size(), securityId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Object[] securityField(S object) {
|
||||
Object[] args = new Object[]{
|
||||
object.getId(), // SecurityId
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, S> map) {
|
||||
List<Object[]> childTableArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, S> entry : map.entrySet()) {
|
||||
S obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
childTableArgs.add(args);
|
||||
Object[] argsSecurityItem = securityField(obj);
|
||||
if (argsSecurityItem.length != validateSecuritySize) {
|
||||
throw new IllegalArgumentException("securityField return " + argsSecurityItem.length + " arguments, but expected " + validateSecuritySize);
|
||||
}
|
||||
securityArgs.add(argsSecurityItem);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, childTableArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class EquitySecurityMapStore extends TemplateMapStore<EquitySecurity> {
|
||||
public class EquitySecurityMapStore extends ASecurityMapStore<EquitySecurity> {
|
||||
|
||||
public EquitySecurityMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
|
|
@ -37,18 +37,6 @@ public class EquitySecurityMapStore extends TemplateMapStore<EquitySecurity> {
|
|||
};
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{"ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected EquitySecurity objectReader(ResultSet resultSet) throws SQLException {
|
||||
|
|
@ -62,29 +50,6 @@ public class EquitySecurityMapStore extends TemplateMapStore<EquitySecurity> {
|
|||
return object;
|
||||
}
|
||||
|
||||
private void fillBySecurity(EquitySecurity object, Long securityId) {
|
||||
List<EquitySecurity> resouts = jdbcTemplate.query(
|
||||
"SELECT * FROM SECURITY WHERE id = ?", new Object[]{securityId},
|
||||
(rs, rowNum) -> {
|
||||
object.setCreated(getInstantFromTimestamp(rs, "CREATED_AT"));
|
||||
object.setUpdated(getInstantFromTimestamp(rs, "UPDATED_AT"));
|
||||
object.setInstrumentType(rs.getObject("INSTRUMENT_TYPE", String.class));
|
||||
object.setIssuerId(rs.getObject("issuer_id", Long.class));
|
||||
object.setShortName(rs.getObject("short_name", String.class));
|
||||
object.setFullName(rs.getObject("FULL_NAME", String.class));
|
||||
object.setShortNameEng(rs.getObject("short_name_eng", String.class));
|
||||
object.setFullNameEng(rs.getObject("full_name_eng", String.class));
|
||||
object.setSecuritySymbol(rs.getObject("SECURITY_SYMBOL", String.class));
|
||||
object.setIsin(rs.getObject("ISIN", String.class));
|
||||
object.setWorkflowStatus(rs.getObject("workflow_status", String.class));
|
||||
return object;
|
||||
}
|
||||
);
|
||||
if (resouts.size() != 1) {
|
||||
log.warn("Result size={} not expected for table MONEY_MARKET_SECURITY where id={}", resouts.size(), securityId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(EquitySecurity equity) {
|
||||
Object[] args = new Object[]{
|
||||
|
|
@ -95,40 +60,4 @@ public class EquitySecurityMapStore extends TemplateMapStore<EquitySecurity> {
|
|||
return args;
|
||||
}
|
||||
|
||||
protected Object[] securityField(EquitySecurity object) {
|
||||
Object[] args = new Object[]{
|
||||
object.getSecurityId(),
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, EquitySecurity> map) {
|
||||
List<Object[]> moneyMarketArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, EquitySecurity> entry : map.entrySet()) {
|
||||
EquitySecurity obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
moneyMarketArgs.add(args);
|
||||
securityArgs.add(securityField(obj));
|
||||
}
|
||||
batchInsertUpdate(insertStatement, moneyMarketArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,16 +4,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurity;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.imdg.base.TemplateMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class FixedIncomeSecurityMapStore extends TemplateMapStore<FixedIncomeSecurity> {
|
||||
public class FixedIncomeSecurityMapStore extends ASecurityMapStore<FixedIncomeSecurity> {
|
||||
|
||||
public FixedIncomeSecurityMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
|
|
@ -36,14 +34,6 @@ public class FixedIncomeSecurityMapStore extends TemplateMapStore<FixedIncomeSec
|
|||
};
|
||||
}
|
||||
|
||||
public String[] getFieldsSecurity() {
|
||||
return new String[]{"ID", "CREATED_AT", "UPDATED_AT", "INSTRUMENT_TYPE", "ISSUER_ID", "SHORT_NAME", "FULL_NAME", "SHORT_NAME_ENG", "FULL_NAME_ENG", "SECURITY_SYMBOL", "ISIN", "WORKFLOW_STATUS"};
|
||||
}
|
||||
|
||||
private final String insertToSecurityStatement = makeInsertSql("SECURITY",
|
||||
getFieldsSecurity(), "id");
|
||||
|
||||
|
||||
@Override
|
||||
protected FixedIncomeSecurity objectReader(ResultSet resultSet) throws SQLException {
|
||||
FixedIncomeSecurity object = new FixedIncomeSecurity();
|
||||
|
|
@ -61,29 +51,6 @@ public class FixedIncomeSecurityMapStore extends TemplateMapStore<FixedIncomeSec
|
|||
return object;
|
||||
}
|
||||
|
||||
private void fillBySecurity(FixedIncomeSecurity object, Long securityId) {
|
||||
List<FixedIncomeSecurity> resouts = jdbcTemplate.query(
|
||||
"SELECT * FROM SECURITY WHERE id = ?", new Object[]{securityId},
|
||||
(rs, rowNum) -> {
|
||||
object.setCreated(getInstantFromTimestamp(rs, "CREATED_AT"));
|
||||
object.setUpdated(getInstantFromTimestamp(rs, "UPDATED_AT"));
|
||||
object.setInstrumentType(rs.getObject("INSTRUMENT_TYPE", String.class));
|
||||
object.setIssuerId(rs.getObject("issuer_id", Long.class));
|
||||
object.setShortName(rs.getObject("short_name", String.class));
|
||||
object.setFullName(rs.getObject("FULL_NAME", String.class));
|
||||
object.setShortNameEng(rs.getObject("short_name_eng", String.class));
|
||||
object.setFullNameEng(rs.getObject("full_name_eng", String.class));
|
||||
object.setSecuritySymbol(rs.getObject("SECURITY_SYMBOL", String.class));
|
||||
object.setIsin(rs.getObject("ISIN", String.class));
|
||||
object.setWorkflowStatus(rs.getObject("workflow_status", String.class));
|
||||
return object;
|
||||
}
|
||||
);
|
||||
if (resouts.size() != 1) {
|
||||
log.warn("Result size={} not expected for table MONEY_MARKET_SECURITY where id={}", resouts.size(), securityId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(FixedIncomeSecurity object) {
|
||||
Object[] args = new Object[]{
|
||||
|
|
@ -99,41 +66,4 @@ public class FixedIncomeSecurityMapStore extends TemplateMapStore<FixedIncomeSec
|
|||
return args;
|
||||
}
|
||||
|
||||
protected Object[] securityField(FixedIncomeSecurity object) {
|
||||
Object[] args = new Object[]{
|
||||
object.getSecurityId(),
|
||||
TimeUtil.toDateFromInstant(object.getCreated()),
|
||||
TimeUtil.toDateFromInstant(object.getUpdated()),
|
||||
object.getInstrumentType(),
|
||||
object.getIssuerId(),
|
||||
object.getShortName(),
|
||||
object.getFullName(),
|
||||
object.getShortNameEng(),
|
||||
object.getFullNameEng(),
|
||||
object.getSecuritySymbol(),
|
||||
object.getIsin(),
|
||||
object.getWorkflowStatus()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, FixedIncomeSecurity> map) {
|
||||
List<Object[]> moneyMarketArgs = new ArrayList<>();
|
||||
List<Object[]> securityArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, FixedIncomeSecurity> entry : map.entrySet()) {
|
||||
FixedIncomeSecurity obj = entry.getValue();
|
||||
Object[] args = objectToField(obj);
|
||||
if (args.length != validateSize) {
|
||||
throw new IllegalArgumentException("objectToField return " + args.length + " arguments, but expected " + validateSize);
|
||||
}
|
||||
moneyMarketArgs.add(args);
|
||||
securityArgs.add(securityField(obj));
|
||||
}
|
||||
batchInsertUpdate(insertStatement, moneyMarketArgs);
|
||||
batchInsertUpdate(insertToSecurityStatement, securityArgs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import ru.spcex.platform.utils.time.TimeUtil;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
// Abstract table: ASecurityHistoryMapStore
|
||||
@Component
|
||||
public class SecurityMapStore extends TemplateMapStore<Security> {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue