Support comments in SQL scripts in JdbcTestUtils

Prior to this commit, utility methods in JdbcTestUtils interpreted SQL
comments as separate statements, resulting in an exception when such a
script is executed.

This commit addresses this issue by introducing a
readScript(lineNumberReader, String) method that accepts a comment
prefix. Comment lines are therefore no longer returned in the parsed
script. Furthermore, the existing readScript(lineNumberReader) method
now delegates to this new readScript() method, supplying "--" as the
default comment prefix.

Issue: SPR-9593
This commit is contained in:
Sam Brannen
2012-10-22 00:52:01 -04:00
parent 7c538bd588
commit 4aaf014cc6
5 changed files with 147 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,17 +19,18 @@ package org.springframework.jdbc.datasource.init;
import org.springframework.core.io.support.EncodedResource;
/**
* Thrown by {@link ResourceDatabasePopulator} if one of its SQL scripts could
* not be read during population.
* Thrown by {@link ResourceDatabasePopulator} if one of its SQL scripts cannot
* be read during population.
*
* @author Keith Donald
* @since 3.0
*/
@SuppressWarnings("serial")
public class CannotReadScriptException extends RuntimeException {
/**
* Constructor a new CannotReadScriptException.
* @param resource the resource that could not be read from
* Construct a new {@code CannotReadScriptException}.
* @param resource the resource that cannot be read from
* @param cause the underlying cause of the resource access failure
*/
public CannotReadScriptException(EncodedResource resource, Throwable cause) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,16 +23,18 @@ import org.springframework.core.io.support.EncodedResource;
* failed when executing it against the target database.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.0.5
*/
@SuppressWarnings("serial")
public class ScriptStatementFailedException extends RuntimeException {
/**
* Constructor a new ScriptStatementFailedException.
* Construct a new {@code ScriptStatementFailedException}.
* @param statement the actual SQL statement that failed
* @param lineNumber the line number in the SQL script
* @param resource the resource that could not be read from
* @param cause the underlying cause of the resource access failure
* @param resource the resource from which the SQL statement was read
* @param cause the underlying cause of the failure
*/
public ScriptStatementFailedException(String statement, int lineNumber, EncodedResource resource, Throwable cause) {
super("Failed to execute SQL script statement at line " + lineNumber +