changing inherited class from ObjectBaseMapStore to TemplateMapStore for ContactMapStore and ProfileDocumentMapStore. refactor CompanySymbolsMapStore
This commit is contained in:
parent
b10c22b888
commit
2acc0fa402
3 changed files with 78 additions and 92 deletions
|
|
@ -21,16 +21,6 @@ public class CompanySymbolsMapStore extends TemplateMapStore<CompanySymbols> {
|
|||
return IMDGDistributedNames.Map_CompanySymbols;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompanySymbols objectReader(ResultSet resultSet) throws SQLException {
|
||||
CompanySymbols object = new CompanySymbols();
|
||||
object.setId(resultSet.getObject("id", Long.class));
|
||||
object.setCompanyId(resultSet.getObject("companyid", Long.class));
|
||||
object.setCompanySymbol(resultSet.getObject("companysymbol", String.class));
|
||||
object.setCompanySymbolValue(resultSet.getObject("companysymbolvalue", String.class));
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "COMPANY_SYMBOLS";
|
||||
|
|
@ -43,6 +33,16 @@ public class CompanySymbolsMapStore extends TemplateMapStore<CompanySymbols> {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompanySymbols objectReader(ResultSet resultSet) throws SQLException {
|
||||
CompanySymbols object = new CompanySymbols();
|
||||
object.setId(resultSet.getObject("id", Long.class));
|
||||
object.setCompanyId(resultSet.getObject("companyid", Long.class));
|
||||
object.setCompanySymbol(resultSet.getObject("companysymbol", String.class));
|
||||
object.setCompanySymbolValue(resultSet.getObject("companysymbolvalue", String.class));
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object[] objectToField(CompanySymbols resultSet) {
|
||||
Object[] args = new Object[]{
|
||||
|
|
|
|||
|
|
@ -3,17 +3,24 @@ package ru.spcex.clearing.imdg.object;
|
|||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.profile.Contact;
|
||||
import ru.spcex.clearing.imdg.base.ObjectBaseMapStore;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.imdg.base.TemplateMapStore;
|
||||
|
||||
import java.util.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Component
|
||||
public class ContactMapStore extends ObjectBaseMapStore<Contact> {
|
||||
public class ContactMapStore extends TemplateMapStore<Contact> {
|
||||
|
||||
public ContactMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMapName() {
|
||||
return IMDGDistributedNames.Map_Contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "CONTACT";
|
||||
|
|
@ -26,38 +33,24 @@ public class ContactMapStore extends ObjectBaseMapStore<Contact> {
|
|||
};
|
||||
}
|
||||
|
||||
protected final String insertStatement = makeInsertSql(getTableName(), getFields(), "id");
|
||||
|
||||
@Override
|
||||
public Collection<Contact> load(Collection<Long> keys) {
|
||||
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
|
||||
return namedParameterJdbcTemplate.query("select * from " + getTableName() + " where id in (:ids)", paramMap,
|
||||
(resultSet, i) -> {
|
||||
Contact contact = new Contact();
|
||||
contact.setId(resultSet.getObject("id", Long.class));
|
||||
contact.setCompanyId(resultSet.getObject("company_id", Long.class));
|
||||
contact.setContactType(resultSet.getObject("contact_type", String.class));
|
||||
contact.setContactValue(resultSet.getObject("contact_value", String.class));
|
||||
return contact;
|
||||
});
|
||||
protected Contact objectReader(ResultSet resultSet) throws SQLException {
|
||||
Contact object = new Contact();
|
||||
object.setId(resultSet.getObject("id", Long.class));
|
||||
object.setCompanyId(resultSet.getObject("company_id", Long.class));
|
||||
object.setContactType(resultSet.getObject("contact_type", String.class));
|
||||
object.setContactValue(resultSet.getObject("contact_value", String.class));
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, Contact> map) {
|
||||
List<Object[]> batchArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, Contact> entry : map.entrySet()) {
|
||||
Contact contact = entry.getValue();
|
||||
|
||||
Object[] args = new Object[]{
|
||||
contact.getId(),
|
||||
contact.getCompanyId(),
|
||||
contact.getContactType(),
|
||||
contact.getContactValue()
|
||||
};
|
||||
batchArgs.add(args);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, batchArgs);
|
||||
protected Object[] objectToField(Contact resultSet) {
|
||||
Object[] args = new Object[]{
|
||||
resultSet.getId(),
|
||||
resultSet.getCompanyId(),
|
||||
resultSet.getContactType(),
|
||||
resultSet.getContactValue()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,25 @@ package ru.spcex.clearing.imdg.object;
|
|||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.profile.ProfileDocument;
|
||||
import ru.spcex.clearing.imdg.base.ObjectBaseMapStore;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.imdg.base.TemplateMapStore;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Component
|
||||
public class ProfileDocumentMapStore extends ObjectBaseMapStore<ProfileDocument> {
|
||||
public class ProfileDocumentMapStore extends TemplateMapStore<ProfileDocument> {
|
||||
|
||||
public ProfileDocumentMapStore(JdbcTemplate jdbcTemplate) {
|
||||
super(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMapName() {
|
||||
return IMDGDistributedNames.Map_ProfileDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "PROFILE_DOCUMENT";
|
||||
|
|
@ -28,56 +35,42 @@ public class ProfileDocumentMapStore extends ObjectBaseMapStore<ProfileDocument>
|
|||
};
|
||||
}
|
||||
|
||||
protected final String insertStatement = makeInsertSql(getTableName(), getFields(), "id");
|
||||
|
||||
@Override
|
||||
public Collection<ProfileDocument> load(Collection<Long> keys) {
|
||||
Map<String, Collection<Long>> paramMap = Collections.singletonMap("ids", keys);
|
||||
return namedParameterJdbcTemplate.query("select * from " + getTableName() + " where id in (:ids)", paramMap,
|
||||
(resultSet, i) -> {
|
||||
ProfileDocument profileDocument = new ProfileDocument();
|
||||
profileDocument.setId(resultSet.getObject("id", Long.class));
|
||||
profileDocument.setCompanyId(resultSet.getObject("company_id", Long.class));
|
||||
profileDocument.setDocumentType(resultSet.getObject("document_type", String.class));
|
||||
profileDocument.setIssueDate(getInstantFromTimestamp(resultSet,"issue_date"));
|
||||
profileDocument.setIssuePlace(resultSet.getObject("issue_place", String.class));
|
||||
profileDocument.setIssuer(resultSet.getObject("issuer", String.class));
|
||||
profileDocument.setIssuerCode(resultSet.getObject("issuer_code", String.class));
|
||||
profileDocument.setName(resultSet.getObject("name", String.class));
|
||||
profileDocument.setNumber(resultSet.getObject("number", String.class));
|
||||
profileDocument.setPlace(resultSet.getObject("place", String.class));
|
||||
profileDocument.setValidFromDate(getInstantFromTimestamp(resultSet,"valid_from_date"));
|
||||
profileDocument.setValidToDate(getInstantFromTimestamp(resultSet,"valid_to_date"));
|
||||
profileDocument.setLink(resultSet.getObject("LINK", String.class));
|
||||
return profileDocument;
|
||||
});
|
||||
protected ProfileDocument objectReader(ResultSet resultSet) throws SQLException {
|
||||
ProfileDocument object = new ProfileDocument();
|
||||
object.setId(resultSet.getObject("id", Long.class));
|
||||
object.setCompanyId(resultSet.getObject("company_id", Long.class));
|
||||
object.setDocumentType(resultSet.getObject("document_type", String.class));
|
||||
object.setIssueDate(getInstantFromTimestamp(resultSet, "issue_date"));
|
||||
object.setIssuePlace(resultSet.getObject("issue_place", String.class));
|
||||
object.setIssuer(resultSet.getObject("issuer", String.class));
|
||||
object.setIssuerCode(resultSet.getObject("issuer_code", String.class));
|
||||
object.setName(resultSet.getObject("name", String.class));
|
||||
object.setNumber(resultSet.getObject("number", String.class));
|
||||
object.setPlace(resultSet.getObject("place", String.class));
|
||||
object.setValidFromDate(getInstantFromTimestamp(resultSet, "valid_from_date"));
|
||||
object.setValidToDate(getInstantFromTimestamp(resultSet, "valid_to_date"));
|
||||
object.setLink(resultSet.getObject("LINK", String.class));
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Map<Long, ProfileDocument> map) {
|
||||
List<Object[]> batchArgs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Long, ProfileDocument> entry : map.entrySet()) {
|
||||
ProfileDocument profileDocument = entry.getValue();
|
||||
|
||||
Object[] args = new Object[]{
|
||||
profileDocument.getId(),
|
||||
profileDocument.getCompanyId(),
|
||||
profileDocument.getDocumentType(),
|
||||
TimeUtil.toDateFromInstant(profileDocument.getIssueDate()),
|
||||
profileDocument.getIssuePlace(),
|
||||
profileDocument.getIssuer(),
|
||||
profileDocument.getIssuerCode(),
|
||||
profileDocument.getName(),
|
||||
profileDocument.getNumber(),
|
||||
profileDocument.getPlace(),
|
||||
TimeUtil.toDateFromInstant(profileDocument.getValidFromDate()),
|
||||
TimeUtil.toDateFromInstant(profileDocument.getValidToDate()),
|
||||
profileDocument.getLink()
|
||||
};
|
||||
batchArgs.add(args);
|
||||
}
|
||||
batchInsertUpdate(insertStatement, batchArgs);
|
||||
protected Object[] objectToField(ProfileDocument resultSet) {
|
||||
Object[] args = new Object[]{
|
||||
resultSet.getId(),
|
||||
resultSet.getCompanyId(),
|
||||
resultSet.getDocumentType(),
|
||||
TimeUtil.toDateFromInstant(resultSet.getIssueDate()),
|
||||
resultSet.getIssuePlace(),
|
||||
resultSet.getIssuer(),
|
||||
resultSet.getIssuerCode(),
|
||||
resultSet.getName(),
|
||||
resultSet.getNumber(),
|
||||
resultSet.getPlace(),
|
||||
TimeUtil.toDateFromInstant(resultSet.getValidFromDate()),
|
||||
TimeUtil.toDateFromInstant(resultSet.getValidToDate()),
|
||||
resultSet.getLink()
|
||||
};
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue