@@ -130,11 +130,11 @@ private <T> void assertEquals(T expected, T result) {
130
130
}
131
131
132
132
/**
133
- * Less than 180 lines long class to simplify work with JDBC.
133
+ * Less than 170 lines long class to simplify work with JDBC.
134
134
* Original source: <a href="https://github.com/pponec/DirectoryBookmarks/blob/development/utils/SqlExecutor.java">GitHub</a>
135
135
* Licence: Apache License, Version 2.0
136
136
* @author Pavel Ponec, https://github.com/pponec
137
- * @version 1.0.5
137
+ * @version 1.0.6
138
138
*/
139
139
static class SqlParamBuilder implements Closeable {
140
140
/** SQL parameter mark type of {@code :param} */
@@ -143,7 +143,6 @@ static class SqlParamBuilder implements Closeable {
143
143
private final Map <String , Object > params = new HashMap <>();
144
144
private String sqlTemplate = null ;
145
145
private PreparedStatement preparedStatement = null ;
146
- private ResultSet resultSet = null ;
147
146
148
147
public SqlParamBuilder (Connection dbConnection ) {
149
148
this .dbConnection = dbConnection ;
@@ -167,14 +166,11 @@ public int execute() throws IllegalStateException, SQLException {
167
166
return prepareStatement ().executeUpdate ();
168
167
}
169
168
169
+ /** A ResultSet object is automatically closed when the Statement object that generated it is closed,
170
+ * re-executed, or used to retrieve the next result from a sequence of multiple results. */
170
171
private ResultSet executeSelect () throws IllegalStateException {
171
- try (AutoCloseable rs = resultSet ) {
172
- } catch (Exception e ) {
173
- throw new IllegalStateException ("Closing fails" , e );
174
- }
175
172
try {
176
- resultSet = prepareStatement ().executeQuery ();
177
- return resultSet ;
173
+ return prepareStatement ().executeQuery ();
178
174
} catch (Exception ex ) {
179
175
throw (ex instanceof RuntimeException re ) ? re : new IllegalStateException (ex );
180
176
}
@@ -216,11 +212,10 @@ public Connection getConnection() {
216
212
/** The method closes a PreparedStatement object with related objects, not the database connection. */
217
213
@ Override
218
214
public void close () {
219
- try (AutoCloseable c1 = resultSet ; PreparedStatement c2 = preparedStatement ) {
215
+ try (AutoCloseable c2 = preparedStatement ) {
220
216
} catch (Exception e ) {
221
217
throw new IllegalStateException ("Closing fails" , e );
222
218
} finally {
223
- resultSet = null ;
224
219
preparedStatement = null ;
225
220
}
226
221
}
@@ -238,7 +233,7 @@ public PreparedStatement prepareStatement() throws SQLException {
238
233
return result ;
239
234
}
240
235
241
- protected String buildSql ( List <Object > sqlValues , boolean toLog ) {
236
+ private String buildSql (List <Object > sqlValues , boolean toLog ) {
242
237
final var result = new StringBuilder (256 );
243
238
final var matcher = SQL_MARK .matcher (sqlTemplate );
244
239
final var missingKeys = new HashSet <>();
@@ -256,7 +251,7 @@ protected String buildSql( List<Object> sqlValues, boolean toLog) {
256
251
sqlValues .add (values [i ]);
257
252
}
258
253
} else {
259
- matcher .appendReplacement (result , Matcher .quoteReplacement (":" + key ));
254
+ matcher .appendReplacement (result , Matcher .quoteReplacement (matcher . group () ));
260
255
missingKeys .add (key );
261
256
}
262
257
}
0 commit comments