Skip to content

Instantly share code, notes, and snippets.

@davinkevin
Created June 24, 2016 05:15
Show Gist options
  • Save davinkevin/3008a224228c8a1f0a71235a3313b63a to your computer and use it in GitHub Desktop.
Save davinkevin/3008a224228c8a1f0a71235a3313b63a to your computer and use it in GitHub Desktop.
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