something ready for test

This commit is contained in:
akulikov 2024-08-05 14:47:04 +03:00
parent 761204b076
commit 8d797212b5
4 changed files with 319 additions and 34 deletions

View file

@ -28,7 +28,6 @@ public class DBMap<T extends SpcexObjectBase> implements Imdg<T> {
return jdbcTemplate.queryForObject("select * from %s where ID = %d".formatted(tableName, id), clazz);
}
@SuppressWarnings("sql")
@Override
public Collection<T> getCollectionObjectsByPredicate(ImdgPredicate predicate) {
String sql = predicate.toString();

View file

@ -1,5 +1,9 @@
package ru.spcex.clearing.reports.db_direct;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
@ -7,58 +11,74 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
import ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate.ImdgPredicateBuilderHazelcast;
public class DBPredicateBuilder extends ImdgPredicateBuilderHazelcast {
private final DateTimeFormatter localDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
private final DateTimeFormatter localTimeFormatter = DateTimeFormatter.ISO_LOCAL_TIME;
private final DateTimeFormatter localDateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
private final Map<String, String> fieldMatcherMap;
public DBPredicateBuilder(Map<String, String> fieldMatcherMap) {
this.fieldMatcherMap = fieldMatcherMap;
}
private String replaced(String key) {
return fieldMatcherMap.get(key);
private String replaceKey(String key) {
String result = fieldMatcherMap.get(key);
return result == null ? key : result;
}
private String replaceValue(Object object) {
if (object == null)
throw new UnsupportedOperationException("For compare 'is null' or 'is not null' use methods isNull() and notNull()");
if (object instanceof String strObj) return " '%s' ".formatted(strObj);
if (object instanceof Character charObj) return " '%s' ".formatted(charObj);
if (object instanceof LocalDate ldObj) return " '%s' ".formatted(ldObj.format(localDateFormatter));
if (object instanceof LocalTime ltObj) return " '%s' ".formatted(ltObj.format(localTimeFormatter));
if (object instanceof LocalDateTime ldtObj) return " '%s' ".formatted(ldtObj.format(localDateTimeFormatter));
return " %s ".formatted(object.toString());
}
@Override
public ImdgPredicate equals(String key, Object value) {
return new DBPredicate(" (%s = %s) ".formatted(replaced(key), value.toString()));
return new DBPredicate(" (%s = %s) ".formatted(replaceKey(key), replaceValue(value)));
}
@Override
public ImdgPredicate greatEqual(String key, Comparable value) {
return new DBPredicate(" (%s >= %s) ".formatted(replaced(key), value.toString()));
return new DBPredicate(" (%s >= %s) ".formatted(replaceKey(key), replaceValue(value)));
}
@Override
public ImdgPredicate lessEqual(String key, Comparable value) {
return new DBPredicate(" (%s <= %s) ".formatted(replaced(key), value.toString()));
return new DBPredicate(" (%s <= %s) ".formatted(replaceKey(key), replaceValue(value)));
}
@Override
public ImdgPredicate greater(String key, Comparable value) {
return new DBPredicate(" (%s > %s) ".formatted(replaced(key), value.toString()));
return new DBPredicate(" (%s > %s) ".formatted(replaceKey(key), replaceValue(value)));
}
@Override
public ImdgPredicate less(String key, Comparable value) {
return new DBPredicate(" (%s < %s) ".formatted(replaced(key), value.toString()));
return new DBPredicate(" (%s < %s) ".formatted(replaceKey(key), replaceValue(value)));
}
@Override
public ImdgPredicate notNull(String key) {
return new DBPredicate(" (%s is not null) ".formatted(replaced(key)));
return new DBPredicate(" (%s is not null) ".formatted(replaceKey(key)));
}
@Override
public ImdgPredicate isNull(String key) {
return new DBPredicate(" (%s is null) ".formatted(replaced(key)));
return new DBPredicate(" (%s is null) ".formatted(replaceKey(key)));
}
@Override
public ImdgPredicate in(String key, Comparable... values) {
return new DBPredicate(
" (%s in (%s) ".formatted(
replaced(key),
" (%s in (%s)) ".formatted(
replaceKey(key),
Arrays.stream(values)
.map(" '%s' "::formatted)
.map(this::replaceValue)
.collect(Collectors.joining(","))
)
);

View file

@ -24,28 +24,14 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.imdg.api.ImdgTransaction;
public class DBProvider implements ImdgProvider {
private final Map<Class<?>, Map<String, String>> fieldsMatcherForTable;
private final Map<Class<?>, String> tableNameForClass;
private final JdbcTemplate jdbcTemplate;
private final Map<Class<?>, Map<String, String>> fieldsMatcherForTable = new HashMap<>();
private final Map<Class<?>, String> tableNameForClass = new HashMap<>();
public DBProvider(Map<Class<?>, Map<String, String>> fieldsMatcherForTable, JdbcTemplate jdbcTemplate) {
this.fieldsMatcherForTable = fieldsMatcherForTable;
public DBProvider(JdbcTemplate jdbcTemplate) {
initFieldsMatcherForTable();
initTableNames();
this.jdbcTemplate = jdbcTemplate;
this.tableNameForClass = new HashMap<>();
this.tableNameForClass.put(Account.class, "ACCOUNT");
this.tableNameForClass.put(ExecutionFond.class, "EXECUTION_FOND");
this.tableNameForClass.put(ExecutionDeposit.class, "EXECUTION_DEPOSIT");
this.tableNameForClass.put(Company.class, "COMPANY");
this.tableNameForClass.put(Registry.class, "REGISTRY");
this.tableNameForClass.put(Session.class, "SESSION");
this.tableNameForClass.put(CurrencyPairDictionary.class, "CURRENCY_PAIR_DICTIONARY");
this.tableNameForClass.put(CurrencyPairSecurity.class, "CURRENCY_PAIR_SECURITY");
this.tableNameForClass.put(RegistryCodeDictionary.class, "REGISTRY_CODE_DICTIONARY");
this.tableNameForClass.put(ClearingMemberCategory.class, "CLEARING_MEMBER_CATEGORY");
this.tableNameForClass.put(AccountSymbols.class, "ACCOUNT_SYMBOLS");
this.tableNameForClass.put(ProfileDocument.class, "PROFILE_DOCUMENT");
this.tableNameForClass.put(ExecutionCurrency.class, "EXECUTION_CURRENCY");
this.tableNameForClass.put(TradingClearingRegistry.class, "TRADING_CLEARING_REGISTRY");
}
@Override
@ -65,4 +51,286 @@ public class DBProvider implements ImdgProvider {
throw new UnsupportedOperationException("not implemented for direct DB provider");
}
private void initFieldsMatcherForTable() {
Map<String, String> accountMatcher = new HashMap<>();
accountMatcher.put("id", "id");
accountMatcher.put("updated", "updated_at");
accountMatcher.put("created", "created_at");
accountMatcher.put("account", "account");
accountMatcher.put("accountType", "account_type");
accountMatcher.put("relationId", "relation_id");
accountMatcher.put("status", "status");
accountMatcher.put("processingSign", "processing_sign");
accountMatcher.put("companyId", "companyId");
accountMatcher.put("currency", "currency");
this.fieldsMatcherForTable.put(Account.class, accountMatcher);
Map<String, String> executionDepositMatcher = new HashMap<>();
executionDepositMatcher.put("id", "id");
executionDepositMatcher.put("updated", "updated_at");
executionDepositMatcher.put("created", "created_at");
executionDepositMatcher.put("exchangeExecutionId", "exchange_execution_id");
executionDepositMatcher.put("side", "side");
executionDepositMatcher.put("market", "market");
executionDepositMatcher.put("tradingDate", "trading_date");
executionDepositMatcher.put("securitySymbol", "security_symbol");
executionDepositMatcher.put("securityId", "security_id");
executionDepositMatcher.put("interestAmount", "interest_amount");
executionDepositMatcher.put("exchangeOrderId", "exchange_order_id");
executionDepositMatcher.put("price", "price");
executionDepositMatcher.put("lots", "lots");
executionDepositMatcher.put("quantity", "quantity");
executionDepositMatcher.put("exchangeExecutionTime", "exchange_execution_time");
executionDepositMatcher.put("duration", "duration");
executionDepositMatcher.put("tradingClearingRegistryId", "trading_clearing_registry_id");
executionDepositMatcher.put("companyId", "company_id");
executionDepositMatcher.put("counterPartyId", "counter_party_id");
executionDepositMatcher.put("securityFullName", "security_full_name");
executionDepositMatcher.put("settlementCurrency", "settlement_currency");
executionDepositMatcher.put("coverageStatus", "coverage_status");
executionDepositMatcher.put("sessionId", "session_id");
executionDepositMatcher.put("counterPartyTradingClearingRegistryId", "counter_party_trading_clearing_registry_id");
executionDepositMatcher.put("partyTradingClearingRegistry", "party_trading_clearing_registry");
executionDepositMatcher.put("counterPartyTradingClearingRegistry", "counter_party_trading_clearing_registry");
executionDepositMatcher.put("secondLegSettlementDate", "second_leg_settlement_date");
executionDepositMatcher.put("secondLegSettlementCode", "second_leg_settlement_code");
executionDepositMatcher.put("firstLegSettlementCode", "first_leg_settlement_code");
executionDepositMatcher.put("contract", "contract");
executionDepositMatcher.put("firstLegAmount", "first_leg_amount");
executionDepositMatcher.put("firstLegSettlementDate", "first_leg_settlement_date");
executionDepositMatcher.put("secondLegAmount", "second_leg_amount");
executionDepositMatcher.put("securityCode", "security_code");
this.fieldsMatcherForTable.put(ExecutionDeposit.class, executionDepositMatcher);
Map<String, String> executionFondMatcher = new HashMap<>();
executionFondMatcher.put("id", "id");
executionFondMatcher.put("updated", "updated_at");
executionFondMatcher.put("created", "created_at");
executionFondMatcher.put("exchangeExecutionId", "exchange_execution_id");
executionFondMatcher.put("side", "side");
executionFondMatcher.put("market", "market");
executionFondMatcher.put("tradingDate", "trading_date");
executionFondMatcher.put("securitySymbol", "security_symbol");
executionFondMatcher.put("securityId", "security_id");
executionFondMatcher.put("interestAmount", "interest_amount");
executionFondMatcher.put("exchangeOrderId", "exchange_order_id");
executionFondMatcher.put("price", "price");
executionFondMatcher.put("settlementAmount", "settlement_amount");
executionFondMatcher.put("lots", "lots");
executionFondMatcher.put("quantity", "quantity");
executionFondMatcher.put("exchangeExecutionTime", "exchange_execution_time");
executionFondMatcher.put("duration", "duration");
executionFondMatcher.put("tradingClearingRegistryId", "trading_clearing_registry_id");
executionFondMatcher.put("comment", "comment");
executionFondMatcher.put("clientCodeId", "client_code_id");
executionFondMatcher.put("settlementCode", "settlement_code");
executionFondMatcher.put("companyId", "company_id");
executionFondMatcher.put("counterPartyId", "counter_party_id");
executionFondMatcher.put("securityFullName", "security_full_name");
executionFondMatcher.put("settlementDate", "settlement_date");
executionFondMatcher.put("settlementCurrency", "settlement_currency");
executionFondMatcher.put("exchangeExecutionMicroseconds", "exchange_execution_microseconds");
executionFondMatcher.put("coverageStatus", "coverage_status");
executionFondMatcher.put("sessionId", "session_id");
executionFondMatcher.put("counterPartyTradingClearingRegistryId", "counter_party_trading_clearing_registry_id");
executionFondMatcher.put("partyTradingClearingRegistry", "party_trading_clearing_registry");
executionFondMatcher.put("counterPartyTradingClearingRegistry", "counter_party_trading_clearing_registry");
this.fieldsMatcherForTable.put(ExecutionDeposit.class, executionFondMatcher);
Map<String, String> companyMatcher = new HashMap<>();
companyMatcher.put("id", "id");
companyMatcher.put("updated", "updated_at");
companyMatcher.put("created", "created_at");
companyMatcher.put("shortName", "short_name");
companyMatcher.put("fullName", "full_name");
companyMatcher.put("tradingCode", "trading_code");
companyMatcher.put("clearingCode", "clearing_code");
companyMatcher.put("registrationCode", "registration_code");
companyMatcher.put("workflowStatus", "workflow_status");
this.fieldsMatcherForTable.put(Company.class, companyMatcher);
Map<String, String> registryMatcher = new HashMap<>();
registryMatcher.put("id", "id");
registryMatcher.put("updated", "updated_at");
registryMatcher.put("created", "created_at");
registryMatcher.put("companyId", "company_id");
registryMatcher.put("tradingCode", "trading_code");
registryMatcher.put("clearingCode", "clearing_code");
registryMatcher.put("shortName", "short_name");
registryMatcher.put("fullName", "full_name");
registryMatcher.put("accountId", "account_id");
registryMatcher.put("accountType", "account_type");
registryMatcher.put("account", "account");
registryMatcher.put("registryDesignation", "registry_designation");
registryMatcher.put("registryInstrumentType", "registry_instrument_type");
registryMatcher.put("registryCapacity", "registry_capacity");
registryMatcher.put("registryUnit", "registry_unit");
registryMatcher.put("registryCode", "registry_code");
registryMatcher.put("tradingClearingRegistryId", "trading_clearing_registry_id");
registryMatcher.put("tradingClearingRegistry", "trading_clearing_registry");
registryMatcher.put("registryStatus", "registry_status");
registryMatcher.put("securityId", "security_id");
registryMatcher.put("securitySymbol", "security_symbol");
registryMatcher.put("balance", "balance");
registryMatcher.put("openBalance", "open_balance");
registryMatcher.put("closeBalance", "close_balance");
registryMatcher.put("credit", "credit");
registryMatcher.put("debit", "debit");
registryMatcher.put("settledCredit", "settled_credit");
registryMatcher.put("settledDebit", "settled_debit");
registryMatcher.put("checkBalance", "check_balance");
registryMatcher.put("diffBalance", "diff_balance");
registryMatcher.put("planBalance", "plan_balance");
registryMatcher.put("balanceDimension", "balance_dimension");
registryMatcher.put("settlementDate", "settlement_date");
registryMatcher.put("settlementCode", "settlement_code");
registryMatcher.put("tradingDate", "trading_date");
registryMatcher.put("clearingDate", "clearing_date");
registryMatcher.put("refundDate", "refund_date");
registryMatcher.put("valueDate", "value_date");
registryMatcher.put("price", "price");
registryMatcher.put("contract", "contract");
registryMatcher.put("counterPartyId", "counter_party_id");
registryMatcher.put("comment", "comment");
registryMatcher.put("parentId", "parent_id");
registryMatcher.put("groupId", "group_id");
registryMatcher.put("sessionId", "session_id");
registryMatcher.put("sessionType", "session_type");
registryMatcher.put("paymentId", "payment_id");
this.fieldsMatcherForTable.put(Registry.class, registryMatcher);
Map<String, String> sessionMatcher = new HashMap<>();
sessionMatcher.put("id", "id");
sessionMatcher.put("updated", "updated_at");
sessionMatcher.put("created", "created_at");
sessionMatcher.put("clearingDate", "clearing_date");
sessionMatcher.put("sessionStatus", "session_status");
sessionMatcher.put("companyId", "company_id");
sessionMatcher.put("securityId", "security_id");
sessionMatcher.put("userId", "user_id");
sessionMatcher.put("section", "section");
sessionMatcher.put("sessionType", "session_type");
sessionMatcher.put("workflowStatus", "workflow_status");
this.fieldsMatcherForTable.put(Session.class, sessionMatcher);
Map<String, String> currencyPairDictionaryMatcher = new HashMap<>();
currencyPairDictionaryMatcher.put("id", "id");
currencyPairDictionaryMatcher.put("code", "code");
currencyPairDictionaryMatcher.put("baseCurrencyId", "base_currency_id");
currencyPairDictionaryMatcher.put("quoteCurrencyId", "quote_currency_id");
currencyPairDictionaryMatcher.put("majorSign", "major_sign");
this.fieldsMatcherForTable.put(CurrencyPairDictionary.class, currencyPairDictionaryMatcher);
Map<String, String> currencyPairSecurityMatcher = new HashMap<>();
currencyPairSecurityMatcher.put("id", "id");
currencyPairSecurityMatcher.put("updated", "updated_at");
currencyPairSecurityMatcher.put("created", "created_at");
currencyPairSecurityMatcher.put("baseUnitSize", "base_unit_size");
currencyPairSecurityMatcher.put("currencyPairId", "currency_pair_id");
currencyPairSecurityMatcher.put("code", "code");
currencyPairSecurityMatcher.put("settlementType", "settlement_type");
currencyPairSecurityMatcher.put("clearingOrganization", "clearing_organization");
currencyPairSecurityMatcher.put("settlementOrganization", "settlement_organization");
currencyPairSecurityMatcher.put("securityId", "security_id");
this.fieldsMatcherForTable.put(CurrencyPairSecurity.class, currencyPairSecurityMatcher);
Map<String, String> registryCodeDictionaryMatcher = new HashMap<>();
registryCodeDictionaryMatcher.put("id", "id");
registryCodeDictionaryMatcher.put("code", "code");
registryCodeDictionaryMatcher.put("name", "name");
this.fieldsMatcherForTable.put(RegistryCodeDictionary.class, registryCodeDictionaryMatcher);
Map<String, String> clearingMemberCategoryMatcher = new HashMap<>();
clearingMemberCategoryMatcher.put("company_id", "company_id");
clearingMemberCategoryMatcher.put("clearingMemberCategory", "clearing_member_category");
clearingMemberCategoryMatcher.put("id", "id");
this.fieldsMatcherForTable.put(ClearingMemberCategory.class, clearingMemberCategoryMatcher);
Map<String, String> accountSymbolsMatcher = new HashMap<>();
accountSymbolsMatcher.put("id", "id");
accountSymbolsMatcher.put("accountId", "account_id");
accountSymbolsMatcher.put("accountSymbolValue", "account_symbol_value");
this.fieldsMatcherForTable.put(AccountSymbols.class, accountSymbolsMatcher);
Map<String, String> profileDocumentMatcher = new HashMap<>();
profileDocumentMatcher.put("companyId", "company_id");
profileDocumentMatcher.put("documentType", "document_type");
profileDocumentMatcher.put("issueDate", "issue_date");
profileDocumentMatcher.put("issuePlace", "issue_place");
profileDocumentMatcher.put("issuer", "issuer");
profileDocumentMatcher.put("issuerCode", "issuer_code");
profileDocumentMatcher.put("name", "name");
profileDocumentMatcher.put("number", "number");
profileDocumentMatcher.put("place", "place");
profileDocumentMatcher.put("validFromDate", "valid_from_date");
profileDocumentMatcher.put("validToDate", "valid_to_date");
profileDocumentMatcher.put("link", "link");
profileDocumentMatcher.put("id", "id");
this.fieldsMatcherForTable.put(ProfileDocument.class, profileDocumentMatcher);
Map<String, String> executionCurrencyMatcher = new HashMap<>();
executionCurrencyMatcher.put("id", "id");
executionCurrencyMatcher.put("updated", "updated_at");
executionCurrencyMatcher.put("created", "created_at");
executionCurrencyMatcher.put("exchangeExecutionId", "exchange_execution_id");
executionCurrencyMatcher.put("exchangeExecutionTime", "exchange_execution_time");
executionCurrencyMatcher.put("exchangeExecutionMicroseconds", "exchange_execution_microseconds");
executionCurrencyMatcher.put("tradingDate", "trading_date");
executionCurrencyMatcher.put("settlementDate", "settlement_date");
executionCurrencyMatcher.put("settlementCode", "settlement_code");
executionCurrencyMatcher.put("securityId", "security_id");
executionCurrencyMatcher.put("securitySymbol", "security_symbol");
executionCurrencyMatcher.put("securityName", "security_name");
executionCurrencyMatcher.put("companyId", "company_id");
executionCurrencyMatcher.put("partyTradingClearingRegistryId", "party_trading_clearing_registry_id");
executionCurrencyMatcher.put("partyTradingClearingRegistry", "party_trading_clearing_registry");
executionCurrencyMatcher.put("counterPartyId", "counter_party_id");
executionCurrencyMatcher.put("counterPartyTradingClearingRegistryId", "counter_party_trading_clearing_registry_id");
executionCurrencyMatcher.put("counterPartyTradingClearingRegistry", "counter_party_trading_clearing_registry");
executionCurrencyMatcher.put("market", "market");
executionCurrencyMatcher.put("price", "price");
executionCurrencyMatcher.put("lots", "lots");
executionCurrencyMatcher.put("settlementAmount", "settlement_amount");
executionCurrencyMatcher.put("quantity", "quantity");
executionCurrencyMatcher.put("side", "side");
executionCurrencyMatcher.put("currencyCode", "_currency_code");
executionCurrencyMatcher.put("settlementOrganization", "settlement_organization");
executionCurrencyMatcher.put("coverageStatus", "coverage_status");
executionCurrencyMatcher.put("sessionId", "session_id");
executionCurrencyMatcher.put("clearingDate", "clearing_date");
this.fieldsMatcherForTable.put(ExecutionCurrency.class, executionCurrencyMatcher);
Map<String, String> tradingClearingRegistryMatcher = new HashMap<>();
tradingClearingRegistryMatcher.put("id", "id");
tradingClearingRegistryMatcher.put("updated", "updated_at");
tradingClearingRegistryMatcher.put("created", "created_at");
tradingClearingRegistryMatcher.put("companyId", "company_id");
tradingClearingRegistryMatcher.put("code", "code");
tradingClearingRegistryMatcher.put("moneyAccountId", "money_account_id");
tradingClearingRegistryMatcher.put("depoAccountId", "depo_account_id");
tradingClearingRegistryMatcher.put("tradingClearingRegistryType", "trading_clearing_registry_type");
tradingClearingRegistryMatcher.put("tradingClearingRegistryLevel", "trading_clearing_registry_level");
tradingClearingRegistryMatcher.put("tradingClearingRegistryPurpose", "trading_clearing_registry_purpose");
tradingClearingRegistryMatcher.put("status", "status");
this.fieldsMatcherForTable.put(TradingClearingRegistry.class, tradingClearingRegistryMatcher);
}
private void initTableNames() {
this.tableNameForClass.put(Account.class, "ACCOUNT");
this.tableNameForClass.put(ExecutionFond.class, "EXECUTION_FOND");
this.tableNameForClass.put(ExecutionDeposit.class, "EXECUTION_DEPOSIT");
this.tableNameForClass.put(Company.class, "COMPANY");
this.tableNameForClass.put(Registry.class, "REGISTRY");
this.tableNameForClass.put(Session.class, "SESSION");
this.tableNameForClass.put(CurrencyPairDictionary.class, "CURRENCY_PAIR_DICTIONARY");
this.tableNameForClass.put(CurrencyPairSecurity.class, "CURRENCY_PAIR_SECURITY");
this.tableNameForClass.put(RegistryCodeDictionary.class, "REGISTRY_CODE_DICTIONARY");
this.tableNameForClass.put(ClearingMemberCategory.class, "CLEARING_MEMBER_CATEGORY");
this.tableNameForClass.put(AccountSymbols.class, "ACCOUNT_SYMBOLS");
this.tableNameForClass.put(ProfileDocument.class, "PROFILE_DOCUMENT");
this.tableNameForClass.put(ExecutionCurrency.class, "EXECUTION_CURRENCY");
this.tableNameForClass.put(TradingClearingRegistry.class, "TRADING_CLEARING_REGISTRY");
}
}

View file

@ -1,2 +0,0 @@
package ru.spcex.clearing.reports.db_direct;public class DBRegistryParams {
}