diff --git a/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java b/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java index 436d24a..478c2ad 100644 --- a/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java +++ b/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java @@ -19,7 +19,7 @@ @Slf4j public abstract class PostProcessor implements BeanPostProcessor { - private final Collection wanted; + private final Collection> wanted; private final Collection initialized = new HashSet<>(); private boolean processed; @@ -28,7 +28,7 @@ public PostProcessor() { Collections.addAll(wanted, getWanted()); } - public abstract Class[] getWanted(); + public abstract Class[] getWanted(); public abstract void process(Collection wantedBeans) throws Exception; @@ -53,7 +53,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) @Nullable @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - Collection toBeRemoved = new HashSet<>(); + Collection> toBeRemoved = new HashSet<>(); for (Class wantedBean : wanted) { if (wantedBean.isInstance(bean) && !initialized.contains(bean)) { initialized.add(bean); diff --git a/src/main/java/codes/thischwa/dyndrest/service/DatabaseRestoreHandler.java b/src/main/java/codes/thischwa/dyndrest/service/DatabaseRestoreHandler.java index f86a427..7257ca1 100644 --- a/src/main/java/codes/thischwa/dyndrest/service/DatabaseRestoreHandler.java +++ b/src/main/java/codes/thischwa/dyndrest/service/DatabaseRestoreHandler.java @@ -82,16 +82,21 @@ public void restore() throws Exception { assert restorePath != null; assert restorePathBak != null; populate(ds); - try { - Files.move(restorePath, restorePathBak, StandardCopyOption.REPLACE_EXISTING); - log.info("Database restored successful, restore dump has moved to: {}", restorePathBak); - } catch (IOException e) { - throw new RuntimeException(e); - } + renameDump(); } } else { log.info("Embedded database is empty, try restore it from the last dump!"); populate(ds); + renameDump(); + } + } + + private void renameDump() { + try { + Files.move(restorePath, restorePathBak, StandardCopyOption.REPLACE_EXISTING); + log.info("Database restored successful, restore dump has moved to: {}", restorePathBak); + } catch (IOException e) { + throw new RuntimeException(e); } } @@ -113,7 +118,7 @@ private void populate(DataSource ds) { } @Override - public Class[] getWanted() { - return new Class[] {AppConfig.class, DataSource.class}; + public Class[] getWanted() { + return new Class[] {AppConfig.class, DataSource.class}; } }