SimpleJdbcTestUtils executeSqlScript properly closes its LineNumberReader after use (SPR-8872)
This commit is contained in:
parent
d10f2258e8
commit
263dd559b7
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.core.io.support.EncodedResource;
|
import org.springframework.core.io.support.EncodedResource;
|
||||||
|
|
@ -134,9 +135,10 @@ public abstract class SimpleJdbcTestUtils {
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
List<String> statements = new LinkedList<String>();
|
List<String> statements = new LinkedList<String>();
|
||||||
|
LineNumberReader reader = null;
|
||||||
try {
|
try {
|
||||||
LineNumberReader lnr = new LineNumberReader(resource.getReader());
|
reader = new LineNumberReader(resource.getReader());
|
||||||
String script = JdbcTestUtils.readScript(lnr);
|
String script = JdbcTestUtils.readScript(reader);
|
||||||
char delimiter = ';';
|
char delimiter = ';';
|
||||||
if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) {
|
if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) {
|
||||||
delimiter = '\n';
|
delimiter = '\n';
|
||||||
|
|
@ -168,6 +170,17 @@ public abstract class SimpleJdbcTestUtils {
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new DataAccessResourceFailureException("Failed to open SQL script from " + resource, ex);
|
throw new DataAccessResourceFailureException("Failed to open SQL script from " + resource, ex);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue