importer done
This commit is contained in:
parent
7759391a15
commit
621a02ad9e
11 changed files with 11 additions and 132 deletions
|
|
@ -1,13 +1,11 @@
|
|||
package ru.spcex.clearing.dbf.importer.config;
|
||||
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.spcex.clearing.dbf.importer.logic.stages.ImportToDB;
|
||||
import ru.spcex.clearing.dbf.importer.logic.stages.LoadFileFromDisk;
|
||||
|
|
@ -15,8 +13,6 @@ import ru.spcex.clearing.dbf.importer.logic.stages.Stage;
|
|||
import ru.spcex.clearing.dbf.importer.logic.stages.ValidateFields;
|
||||
import ru.spcex.clearing.dbf.importer.properties.AProperties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -33,21 +29,6 @@ public class DBFImporterConfig {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
@Bean("dbfDataSource")
|
||||
public DataSource dataSource() throws PropertyVetoException {
|
||||
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
||||
dataSource.setDriverClass(properties.getDbDriver());
|
||||
dataSource.setJdbcUrl(properties.getJdbcUrl());
|
||||
dataSource.setUser(properties.getDbLogin());
|
||||
dataSource.setPassword(properties.getDbPassword());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean("dbfJdbcTemplate")
|
||||
public JdbcTemplate jdbcTemplate(@Qualifier("dbfDataSource") DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Bean("pipeline")
|
||||
public List<Stage> pipeline() {
|
||||
List<Stage> pipeline = new LinkedList<>();
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
package ru.spcex.clearing.dbf.importer.logic.data.tables;
|
||||
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
public abstract class AbstractTable<T extends SpcexObjectBase> {
|
||||
private final String prefix;
|
||||
private final Class<T> clazz;
|
||||
private final String nameOfMap;
|
||||
protected HazelcastService hazelcastService;
|
||||
protected ImdgHazelcast<T> map;
|
||||
private String prefix;
|
||||
private Class<T> clazz;
|
||||
private String nameOfMap;
|
||||
|
||||
protected AbstractTable(String prefix, Class<T> clazz, String nameOfMap) {
|
||||
this.prefix = prefix;
|
||||
|
|
@ -18,53 +17,17 @@ public abstract class AbstractTable<T extends SpcexObjectBase> {
|
|||
this.nameOfMap = nameOfMap;
|
||||
}
|
||||
|
||||
public HazelcastService getHazelcastService() {
|
||||
return hazelcastService;
|
||||
}
|
||||
|
||||
public void setHazelcastService(HazelcastService hazelcastService) {
|
||||
this.hazelcastService = hazelcastService;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public Class<? extends SpcexObjectBase> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public void setObject(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public String getNameOfMap() {
|
||||
return nameOfMap;
|
||||
}
|
||||
|
||||
public void setNameOfMap(String nameOfMap) {
|
||||
this.nameOfMap = nameOfMap;
|
||||
}
|
||||
|
||||
public ImdgHazelcast<T> getImdg() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public abstract T getEntity(Object[] entity);
|
||||
|
||||
public void injectEntity(T obj) {
|
||||
map.insert(obj);
|
||||
}
|
||||
|
||||
public ImdgHazelcast<T> getMap() {
|
||||
if (map == null) {
|
||||
bootMap();
|
||||
}
|
||||
return map;
|
||||
map.insert(obj);
|
||||
}
|
||||
|
||||
private void bootMap() {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ public class SDf01Table extends AbstractTable<SDf01> {
|
|||
public SDf01 getEntity(Object[] entity) {
|
||||
SDf01 result = new SDf01();
|
||||
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
result.setCurr_code((String) entity[0]);
|
||||
result.setAccount((String) entity[1]);
|
||||
result.setRemainder((String) entity[2]);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ public class SDf02Table extends AbstractTable<SDf02> {
|
|||
public SDf02 getEntity(Object[] entity) {
|
||||
SDf02 result = new SDf02();
|
||||
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
result.setCurr_code((String) entity[0]);
|
||||
result.setAccount((String) entity[1]);
|
||||
result.setRemainder((String) entity[2]);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class SDf08Table extends AbstractTable<SDf08> {
|
|||
@Override
|
||||
public SDf08 getEntity(Object[] entity) {
|
||||
SDf08 result = new SDf08();
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
|
||||
result.setNumber((BigDecimal) entity[0]);
|
||||
result.setDatetime(TimeUtil.strToInstant((String) entity[1]));
|
||||
result.setGenerationTime(TimeUtil.strToInstant((String) entity[2]));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class SDf12Table extends AbstractTable<SDf12> {
|
|||
public SDf12 getEntity(Object[] entity) {
|
||||
SDf12 result = new SDf12();
|
||||
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
|
||||
result.setAccount((String) entity[0]);
|
||||
result.setDeal((String) entity[1]);
|
||||
result.setStatus((BigDecimal) entity[2]);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class SDf16Table extends AbstractTable<SDf16> {
|
|||
public SDf16 getEntity(Object[] entity) {
|
||||
SDf16 result = new SDf16();
|
||||
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
|
||||
result.setDate(TimeUtil.strToInstant((String) entity[0]));
|
||||
result.setAccount((String) entity[1]);
|
||||
result.setSum((BigDecimal) entity[2]);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class SDf18Table extends AbstractTable<SDf18> {
|
|||
@Override
|
||||
public SDf18 getEntity(Object[] entity) {
|
||||
SDf18 result = new SDf18();
|
||||
result.setId(this.getMap().nextIDSequenceFor());
|
||||
|
||||
result.setAccount((String) entity[0]);
|
||||
result.setDeal((String) entity[1]);
|
||||
result.setStatus((BigDecimal) entity[2]);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class ImportToDB extends Stage {
|
|||
}
|
||||
} catch (IOException exception) {
|
||||
log.warn(exception.getMessage());
|
||||
return StageResult.ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class LoadFileFromDisk extends Stage {
|
|||
log.debug("uuid {}. Read all bytes from source file {}", taskUuid, resultContainer.getDbfFile().getName());
|
||||
fileBytes = Files.readAllBytes(Paths.get(dbfFile.getAbsolutePath()));
|
||||
if (fileBytes.length == 0) throw new IOException("Empty file");
|
||||
if (properties.deleteSrcFiles()) Files.delete(dbfFile.toPath());
|
||||
if (properties.isDeleteSrcFiles()) Files.delete(dbfFile.toPath());
|
||||
} catch (IOException e) {
|
||||
log.error(String.format("uuid %s. Can't read file %s", taskUuid, resultContainer.getDbfFile().getName()), e);
|
||||
return StageResult.ERROR;
|
||||
|
|
|
|||
|
|
@ -6,18 +6,6 @@ import org.springframework.stereotype.Component;
|
|||
@Component("dbfImporterProperties")
|
||||
public class AProperties {
|
||||
|
||||
@Value("${db.jdbc-url}")
|
||||
private String jdbcUrl;
|
||||
|
||||
@Value("${db.driver}")
|
||||
private String dbDriver;
|
||||
|
||||
@Value("${db.login}")
|
||||
private String dbLogin;
|
||||
|
||||
@Value("${db.password}")
|
||||
private String dbPassword;
|
||||
|
||||
@Value("${dbf.src-dir}")
|
||||
private String srcDir;
|
||||
|
||||
|
|
@ -33,75 +21,23 @@ public class AProperties {
|
|||
@Value("${dbf.threads-count}")
|
||||
private int threadsCount;
|
||||
|
||||
public String getJdbcUrl() {
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
public void setJdbcUrl(String jdbcUrl) {
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
}
|
||||
|
||||
public String getDbLogin() {
|
||||
return dbLogin;
|
||||
}
|
||||
|
||||
public void setDbLogin(String dbLogin) {
|
||||
this.dbLogin = dbLogin;
|
||||
}
|
||||
|
||||
public String getDbPassword() {
|
||||
return dbPassword;
|
||||
}
|
||||
|
||||
public void setDbPassword(String dbPassword) {
|
||||
this.dbPassword = dbPassword;
|
||||
}
|
||||
|
||||
public String getDbDriver() {
|
||||
return dbDriver;
|
||||
}
|
||||
|
||||
public void setDbDriver(String dbDriver) {
|
||||
this.dbDriver = dbDriver;
|
||||
}
|
||||
|
||||
public String getSrcDir() {
|
||||
return srcDir;
|
||||
}
|
||||
|
||||
public void setSrcDir(String srcDir) {
|
||||
this.srcDir = srcDir;
|
||||
}
|
||||
|
||||
public boolean deleteSrcFiles() {
|
||||
public boolean isDeleteSrcFiles() {
|
||||
return deleteSrcFiles;
|
||||
}
|
||||
|
||||
public void setDeleteSrcFiles(boolean deleteSrcFiles) {
|
||||
this.deleteSrcFiles = deleteSrcFiles;
|
||||
}
|
||||
|
||||
public String getDbfEncoding() {
|
||||
return dbfEncoding;
|
||||
}
|
||||
|
||||
public void setDbfEncoding(String dbfEncoding) {
|
||||
this.dbfEncoding = dbfEncoding;
|
||||
}
|
||||
|
||||
public int getInsertBatchSize() {
|
||||
return insertBatchSize;
|
||||
}
|
||||
|
||||
public void setInsertBatchSize(int insertBatchSize) {
|
||||
this.insertBatchSize = insertBatchSize;
|
||||
}
|
||||
|
||||
public int getThreadsCount() {
|
||||
return threadsCount;
|
||||
}
|
||||
|
||||
public void setThreadsCount(int threadsCount) {
|
||||
this.threadsCount = threadsCount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue