use of com.github.jingshouyan.jdbc.data.init.action.VersionHandler in project j-jdbc by jingshouyan.
the class DataInitAutoConfiguration method run.
@Override
public void run(ApplicationArguments args) {
Map<String, VersionHandler> map = ctx.getBeansOfType(VersionHandler.class);
List<VersionHandler> handlers = Lists.newArrayList(map.values());
Collections.sort(handlers);
String latest = versionDao.latestVersion().map(DataInitVersion::getVersion).orElse("");
handlers.stream().filter(h -> isNew(h.version(), latest)).forEach(h -> {
DataInitVersion version = new DataInitVersion();
version.setVersion(h.version());
version.setClazz(h.getClass().getName());
versionDao.insert(version);
try {
h.action();
version.setSuccess(true);
versionDao.update(version);
} catch (Throwable e) {
version.setSuccess(false);
version.setMessage(e.getMessage());
version.forDelete();
versionDao.update(version);
throw e;
}
});
}
Aggregations