Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Method to restore database of H2 programmatically / in sql
@Transactional
public Boolean restore(String filename, TimeUnit timeUnit, Integer during) {
Path restoreFile = backup.getLocation().resolve(filename);
if (!Files.exists(restoreFile))
return Boolean.FALSE;
log.info("Full database reset");
em.createNativeQuery("DROP ALL OBJECTS;").executeUpdate();
Try.run(() -> timeUnit.sleep(during));
log.info("Full database restore");
em.createNativeQuery("RUNSCRIPT FROM '"+ restoreFile.toAbsolutePath().toString() +"'").executeUpdate();
return Boolean.TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment