Method to restore database of H2 programmatically / in sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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