public static void executeDatabaseScript(DatabaseDelegate databaseDelegate, String scriptPath, String script) throws ScriptException { executeDatabaseScript(databaseDelegate, scriptPath, script, false, false, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR, DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); }
/** * @see org.testcontainers.ext.ScriptUtils * @deprecated Needed only to keep binary compatibility for this internal API. Consider using database-agnostic ScriptUtils */ public static void executeSqlScript(Connection connection, String scriptPath, String script) throws ScriptException { org.testcontainers.ext.ScriptUtils.executeDatabaseScript(new ContainerLessJdbcDelegate(connection), scriptPath, script); }
/** * @see org.testcontainers.ext.ScriptUtils * @deprecated Needed only to keep binary compatibility for this internal API. Consider using database-agnostic ScriptUtils */ public static void executeSqlScript(Connection connection, String scriptPath, String script, boolean continueOnError, boolean ignoreFailedDrops, String commentPrefix, String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter) throws ScriptException { org.testcontainers.ext.ScriptUtils.executeDatabaseScript(new ContainerLessJdbcDelegate(connection), scriptPath, script, continueOnError, ignoreFailedDrops, commentPrefix, separator, blockCommentStartDelimiter, blockCommentEndDelimiter); } }
/** * Run an init script from the classpath. * * @param connectionUrl {@link ConnectionUrl} instance representing JDBC Url with init script. * @param databaseDelegate database delegate to apply init scripts to the database * @throws SQLException on script or DB error */ private void runInitScriptIfRequired(final ConnectionUrl connectionUrl, DatabaseDelegate databaseDelegate) throws SQLException { if (connectionUrl.getInitScriptPath().isPresent()) { String initScriptPath = connectionUrl.getInitScriptPath().get(); try { URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath); if (resource == null) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new SQLException("Could not load classpath init script: " + initScriptPath + ". Resource not found."); } String sql = IOUtils.toString(resource, StandardCharsets.UTF_8); ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, sql); } catch (IOException e) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new SQLException("Could not load classpath init script: " + initScriptPath, e); } catch (ScriptException e) { LOGGER.error("Error while executing init script: {}", initScriptPath, e); throw new SQLException("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); } }
/** * 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); } } }
public static void executeDatabaseScript(DatabaseDelegate databaseDelegate, String scriptPath, String script) throws ScriptException { executeDatabaseScript(databaseDelegate, scriptPath, script, false, false, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR, DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); }
/** * @see org.testcontainers.ext.ScriptUtils * @deprecated Needed only to keep binary compatibility for this internal API. Consider using database-agnostic ScriptUtils */ public static void executeSqlScript(Connection connection, String scriptPath, String script) throws ScriptException { org.testcontainers.ext.ScriptUtils.executeDatabaseScript(new ContainerLessJdbcDelegate(connection), scriptPath, script); }
/** * @see org.testcontainers.ext.ScriptUtils * @deprecated Needed only to keep binary compatibility for this internal API. Consider using database-agnostic ScriptUtils */ public static void executeSqlScript(Connection connection, String scriptPath, String script, boolean continueOnError, boolean ignoreFailedDrops, String commentPrefix, String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter) throws ScriptException { org.testcontainers.ext.ScriptUtils.executeDatabaseScript(new ContainerLessJdbcDelegate(connection), scriptPath, script, continueOnError, ignoreFailedDrops, commentPrefix, separator, blockCommentStartDelimiter, blockCommentEndDelimiter); } }
/** * Run an init script from the classpath. * * @param connectionUrl {@link ConnectionUrl} instance representing JDBC Url with init script. * @param databaseDelegate database delegate to apply init scripts to the database * @throws SQLException on script or DB error */ private void runInitScriptIfRequired(final ConnectionUrl connectionUrl, DatabaseDelegate databaseDelegate) throws SQLException { if (connectionUrl.getInitScriptPath().isPresent()) { String initScriptPath = connectionUrl.getInitScriptPath().get(); try { URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath); if (resource == null) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new SQLException("Could not load classpath init script: " + initScriptPath + ". Resource not found."); } String sql = IOUtils.toString(resource, StandardCharsets.UTF_8); ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, sql); } catch (IOException e) { LOGGER.warn("Could not load classpath init script: {}", initScriptPath); throw new SQLException("Could not load classpath init script: " + initScriptPath, e); } catch (ScriptException e) { LOGGER.error("Error while executing init script: {}", initScriptPath, e); throw new SQLException("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); } }