unit of work refactoring

This commit is contained in:
Athou
2014-12-12 08:57:50 +01:00
parent ccf18758fb
commit 2e475c35cc
7 changed files with 67 additions and 124 deletions

View File

@@ -44,15 +44,10 @@ public class StartupService implements Managed {
@Override
public void start() throws Exception {
updateSchema();
new UnitOfWork<Void>(sessionFactory) {
@Override
protected Void runInSession() throws Exception {
if (userDAO.count() == 0) {
initialData();
}
return null;
}
}.run();
long count = UnitOfWork.run(sessionFactory, () -> userDAO.count());
if (count == 0) {
UnitOfWork.run(sessionFactory, () -> initialData());
}
}
private void updateSchema() {