Source:
<code>private void upgradePageStore(String propertyPrefix) { String dbUrl = Common.envProps.getString(propertyPrefix + "db.url"); Path dbPath = getDbPathFromUrl(dbUrl); Path legacy = dbPath.getParent().resolve(dbPath.getFileName().toString() + ".h2.db"); if(legacy.toFile().exists()) { LOG.info("Converting legacy h2 database..."); String dumpFileName = "mah2.h2.196.sql.zip"; Path dumpPath = Common.MA_HOME_PATH.resolve("backup").resolve(dumpFileName); try { LOG.info("Dumping legacy database to file " + dumpPath.toString()); dump(legacy, dumpPath); Files.delete(legacy); String user = Common.envProps.getString(propertyPrefix + "db.username", null); String password = Common.envProps.getString(propertyPrefix + "db.password", null); String url = getUrl(propertyPrefix); <START> LOG.info("Importing exisiting H2 database..."); <END> String runScript = url + ";init=RUNSCRIPT FROM '" + dumpPath.toString() + "' COMPRESSION ZIP"; try(Connection conn = DriverManager.getConnection(runScript, user, password);){ Statement stat = conn.createStatement(); stat.execute("shutdown compact"); stat.close(); } try { LOG.info("Cleaning up H2 initializataion tests..."); Files.deleteIfExists(dumpPath); } catch (IOException e) { LOG.warn("Unable to delete un-necessary H2 dump file " + dumpPath.toString(), e); } } catch(Exception e) { throw new ShouldNeverHappenException(e); } } }</code><technical_language>this "exisiting" typo is in retained log messages</technical_language>

Target:
private void upgradePageStore(String propertyPrefix) { String dbUrl = Common.envProps.getString(propertyPrefix + "db.url"); Path dbPath = getDbPathFromUrl(dbUrl); Path legacy = dbPath.getParent().resolve(dbPath.getFileName().toString() + ".h2.db"); if(legacy.toFile().exists()) { LOG.info("Converting legacy h2 database..."); String dumpFileName = "mah2.h2.196.sql.zip"; Path dumpPath = Common.MA_HOME_PATH.resolve("backup").resolve(dumpFileName); if(dumpPath.toFile().exists()) throw new ShouldNeverHappenException("Found upgrade database backup, aborting startup. Likely corrupt database, replace with contents from " + dumpPath.toString()); try { LOG.info("Dumping legacy database to file " + dumpPath.toString()); dump(legacy, dumpPath); Files.delete(legacy); String user = Common.envProps.getString(propertyPrefix + "db.username", null); String password = Common.envProps.getString(propertyPrefix + "db.password", null); String url = getUrl(propertyPrefix); LOG.info("Importing existing H2 database..."); String runScript = url + ";init=RUNSCRIPT FROM '" + dumpPath.toString().replaceAll("\\\\", "/") + "' COMPRESSION ZIP"; try(Connection conn = DriverManager.getConnection(runScript, user, password);){ Statement stat = conn.createStatement(); stat.execute("SHUTDOWN COMPACT"); stat.close(); } try { LOG.info("Cleaning up H2 initializataion tests..."); Files.deleteIfExists(dumpPath); } catch (IOException e) { LOG.warn("Unable to delete un-necessary H2 dump file " + dumpPath.toString(), e); } } catch(Exception e) { if(e.getCause() instanceof JdbcSQLIntegrityConstraintViolationException) { throw new ShouldNeverHappenException("H2 Failed to start, likely corrupt database replace with contents of backup at: " + dumpPath.toString()); }else throw new ShouldNeverHappenException(e); } } }