Skip to content

Commit a8bfb31

Browse files
committed
SqlExcecutor code cleaning
1 parent 785a279 commit a8bfb31

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

utils/SqlExecutor.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ public SqlParamBuilder(Connection dbConnection) {
150150
}
151151

152152
/** Close statement (if any) and set a new SQL template */
153-
public SqlParamBuilder sql(String... sqlTemplates ) {
153+
public SqlParamBuilder sql(String... sqlLines) {
154154
close();
155155
this.params.clear();
156-
this.sqlTemplate = sqlTemplates.length == 1
157-
? sqlTemplates[0] : String.join("\n", sqlTemplates);
156+
this.sqlTemplate = sqlLines.length == 1 ? sqlLines[0] : String.join("\n", sqlLines);
158157
return this;
159158
}
160159

@@ -164,6 +163,10 @@ public SqlParamBuilder bind(String key, Object... value) {
164163
return this;
165164
}
166165

166+
public int execute() throws IllegalStateException, SQLException {
167+
return prepareStatement().executeUpdate();
168+
}
169+
167170
private ResultSet executeSelect() throws IllegalStateException {
168171
try (AutoCloseable rs = resultSet) {
169172
} catch (Exception e) {
@@ -177,7 +180,7 @@ private ResultSet executeSelect() throws IllegalStateException {
177180
}
178181
}
179182

180-
/** Use a {@link #streamMap(SqlFunction)} rather */
183+
/** Use the {@link #streamMap(SqlFunction)} or {@link #forEach(SqlConsumer)} methods rather */
181184
private Stream<ResultSet> stream() {
182185
final var resultSet = executeSelect();
183186
final var iterator = new Iterator<ResultSet>() {
@@ -206,10 +209,6 @@ public <R> Stream<R> streamMap(SqlFunction<ResultSet, ? extends R> mapper ) {
206209
return stream().map(mapper);
207210
}
208211

209-
public int execute() throws IllegalStateException, SQLException {
210-
return prepareStatement().executeUpdate();
211-
}
212-
213212
public Connection getConnection() {
214213
return dbConnection;
215214
}
@@ -227,7 +226,7 @@ public void close() {
227226
}
228227

229228
public PreparedStatement prepareStatement() throws SQLException {
230-
final var sqlValues = new ArrayList<>();
229+
final var sqlValues = new ArrayList<>(params.size());
231230
final var sql = buildSql(sqlValues, false);
232231
final var result = preparedStatement != null
233232
? preparedStatement

0 commit comments

Comments
 (0)