【发布时间】:2020-12-14 16:32:31
【问题描述】:
我有以下class IImporter 的代码,到目前为止工作正常。我每天都会收到许多 zip 文件,其中包含名称为 'EQUFULLFILE' 和 'NONEQUFULLFILE' 在一个目录中,我正在尝试从该目录中读取文件并相应地在数据库表 'EquData' 或 'NonEquData' 中处理它。在处理之前,我只是想从这个数据库表中删除所有数据。
但我在我的代码中发现了问题。有时当我在'EQUFULLFILE' or 'NONEQUFULLFILE' 目录中没有收到任何文件时,它只会从数据库表中删除数据。
我只需要稍微修改我的代码以适应逻辑,这样当我没有收到目录中的任何文件为'EQUFULLFILE' 时,它不应该从数据库表'EquData' 中删除任何数据。当我没有收到目录 as'NONEQUFULLFILE' 中的任何文件时,它不应该从数据库表 'NonEquData' 中删除任何数据。
有什么建议吗?
@Service
public class IImporter {
private final static Logger log = LoggerFactory.getLogger(IImporter.class);
private final static String EQU_FILE_TAG = "EQUFULLFILE";
private final static String NONEQU_FILE_TAG = "NONEQUFULLFILE";
private boolean isEquity;
@Autowired
private IFullreader IFullreader;
@Autowired
private ZipWalker zipWalker;
@Autowired
private SessionFactory sessionFactory;
@Transactional
public void importDir(Path indir) throws IOException {
log.info("Delete all table DATA");
//here the logic should be changed and based on file name table should be deleted
sessionFactory.getCurrentSession().createQuery("delete from EquData").executeUpdate();
sessionFactory.getCurrentSession().createQuery("delete from NonEquData").executeUpdate();
log.info("Process directory" + indir.toString());
Files.walk(indir, 1, FOLLOW_LINKS)
.filter(Files::isRegularFile)
.filter(f -> f.toString().endsWith(".zip"))
.sorted()
.forEach(f -> zipWalker.processZipFile(f, this::importFile));
}
private void importFile(Path path) {
this.isEquity = path.getFileName().toString().contains(EQU_FILE_TAG);
if (isEquity) {
//code for reading data from file EQUFULLFILE
}
else {
//code for reading data from file NONEQUFULLFILE
}
}
}
}
【问题讨论】:
标签: java oracle sql-delete file-handling file-read