/** * Load script from classpath and apply it to the given database * * @param databaseDelegate database delegate for script execution * @param initScriptPath the resource to load the init script from */ public static void runInitScript(DatabaseDelegate databaseDelegate, String initScriptPath) { try { URL resource = ScriptUtils.class.getClassLoader().getResource(initScriptPath); if (resource == null) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found."); } String scripts = IOUtils.toString(resource, StandardCharsets.UTF_8); executeDatabaseScript(databaseDelegate, initScriptPath, scripts); } catch (IOException e) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath, e); } catch (ScriptException e) { LOGGER.error("Error while executing init script: {}", initScriptPath, e); throw new UncategorizedScriptException("Error while executing init script: " + initScriptPath, e); } }
/** * Load init script content and apply it to the database if initScriptPath is set */ private void runInitScriptIfRequired() { if (initScriptPath != null) { try { URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath); if (resource == null) { logger().warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found."); } String cql = IOUtils.toString(resource, StandardCharsets.UTF_8); DatabaseDelegate databaseDelegate = getDatabaseDelegate(); ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, cql); } catch (IOException e) { logger().warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath, e); } catch (ScriptException e) { logger().error("Error while executing init script: {}", initScriptPath, e); throw new ScriptUtils.UncategorizedScriptException("Error while executing init script: " + initScriptPath, e); } } }
/** * Load script from classpath and apply it to the given database * * @param databaseDelegate database delegate for script execution * @param initScriptPath the resource to load the init script from */ public static void runInitScript(DatabaseDelegate databaseDelegate, String initScriptPath) { try { URL resource = ScriptUtils.class.getClassLoader().getResource(initScriptPath); if (resource == null) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found."); } String scripts = IOUtils.toString(resource, StandardCharsets.UTF_8); executeDatabaseScript(databaseDelegate, initScriptPath, scripts); } catch (IOException e) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath, e); } catch (ScriptException e) { LOGGER.error("Error while executing init script: {}", initScriptPath, e); throw new UncategorizedScriptException("Error while executing init script: " + initScriptPath, e); } }