@@ -82,45 +82,37 @@ DatabaseType getDatabaseType() {
8282 * @throws SQLException : Exception while executing the script.
8383 */
8484 public void executeScript (InputStream scriptInputStream ) throws SQLException {
85- try {
86- runWithinTransaction (
87- connection -> {
88- try (Statement statement = connection .createStatement ();
89- BufferedReader reader =
90- new BufferedReader (
91- new InputStreamReader (Objects .requireNonNull (scriptInputStream ), UTF_8 ))) {
92- StringBuilder sqlBuffer = new StringBuilder ();
93- String line ;
94- while ((line = reader .readLine ()) != null ) {
95- line = line .trim ();
96- if (!line .isEmpty () && !line .startsWith ("--" )) { // Ignore empty lines and comments
97- sqlBuffer .append (line ).append ("\n " );
98- if (line .endsWith (";" )) { // Execute statement when semicolon is found
99- String sql = sqlBuffer .toString ().trim ();
100- try {
101- // since SQL is directly read from the file, there is close to 0 possibility
102- // of this being injected plus this run via an Admin tool, if attacker can
103- // fiddle with this that means lot of other things are already compromised.
104- statement .execute (sql );
105- } catch (SQLException e ) {
106- throw new RuntimeException (e );
107- }
108- sqlBuffer .setLength (0 ); // Clear the buffer for the next statement
85+ runWithinTransaction (
86+ connection -> {
87+ try (Statement statement = connection .createStatement ();
88+ BufferedReader reader =
89+ new BufferedReader (
90+ new InputStreamReader (Objects .requireNonNull (scriptInputStream ), UTF_8 ))) {
91+ StringBuilder sqlBuffer = new StringBuilder ();
92+ String line ;
93+ while ((line = reader .readLine ()) != null ) {
94+ line = line .trim ();
95+ if (!line .isEmpty () && !line .startsWith ("--" )) { // Ignore empty lines and comments
96+ sqlBuffer .append (line ).append ("\n " );
97+ if (line .endsWith (";" )) { // Execute statement when semicolon is found
98+ String sql = sqlBuffer .toString ().trim ();
99+ try {
100+ // since SQL is directly read from the file, there is close to 0 possibility
101+ // of this being injected plus this run via an Admin tool, if attacker can
102+ // fiddle with this that means lot of other things are already compromised.
103+ statement .execute (sql );
104+ } catch (SQLException e ) {
105+ throw new RuntimeException (e );
109106 }
107+ sqlBuffer .setLength (0 ); // Clear the buffer for the next statement
110108 }
111109 }
112- return true ;
113- } catch (IOException e ) {
114- throw new RuntimeException (e );
115110 }
116- });
117- } finally {
118- try {
119- scriptInputStream .close ();
120- } catch (IOException e ) {
121- LOGGER .error ("Failed to close input stream: {}" , e .getMessage ());
122- }
123- }
111+ return true ;
112+ } catch (IOException e ) {
113+ throw new RuntimeException (e );
114+ }
115+ });
124116 }
125117
126118 /**
0 commit comments