@@ -42,15 +42,12 @@ public T one() {
42
42
if (resultSet .next ()) {
43
43
throw new RuntimeSqlException ("SQL error: Expected only one result but got multiple." );
44
44
}
45
- }
46
- else {
45
+ } else {
47
46
throw new RuntimeSqlException ("SQL error: Expected only one result row but got none." );
48
47
}
49
- }
50
- catch (SQLException e ) {
48
+ } catch (SQLException e ) {
51
49
throw new RuntimeSqlException (e );
52
- }
53
- finally {
50
+ } finally {
54
51
close ();
55
52
}
56
53
return rval ;
@@ -65,15 +62,12 @@ public T first() {
65
62
try (ResultSet resultSet = statement .executeQuery ()) {
66
63
if (resultSet .next ()) {
67
64
rval = this .mapper .map (resultSet );
68
- }
69
- else {
65
+ } else {
70
66
throw new RuntimeSqlException ("SQL error: Expected AT LEAST one result row but got none." );
71
67
}
72
- }
73
- catch (SQLException e ) {
68
+ } catch (SQLException e ) {
74
69
throw new RuntimeSqlException (e );
75
- }
76
- finally {
70
+ } finally {
77
71
close ();
78
72
}
79
73
return rval ;
@@ -91,15 +85,12 @@ public Optional<T> findOne() {
91
85
if (resultSet .next ()) {
92
86
throw new RuntimeSqlException ("SQL error: Expected only one result but got multiple." );
93
87
}
94
- }
95
- else {
88
+ } else {
96
89
rval = Optional .empty ();
97
90
}
98
- }
99
- catch (SQLException e ) {
91
+ } catch (SQLException e ) {
100
92
throw new RuntimeSqlException (e );
101
- }
102
- finally {
93
+ } finally {
103
94
close ();
104
95
}
105
96
return rval ;
@@ -114,15 +105,12 @@ public Optional<T> findFirst() {
114
105
try (ResultSet resultSet = statement .executeQuery ()) {
115
106
if (resultSet .next ()) {
116
107
rval = Optional .of (this .mapper .map (resultSet ));
117
- }
118
- else {
108
+ } else {
119
109
rval = Optional .empty ();
120
110
}
121
- }
122
- catch (SQLException e ) {
111
+ } catch (SQLException e ) {
123
112
throw new RuntimeSqlException (e );
124
- }
125
- finally {
113
+ } finally {
126
114
close ();
127
115
}
128
116
return rval ;
@@ -141,11 +129,9 @@ public Optional<T> findLast() {
141
129
if (rval == null ) {
142
130
rval = Optional .empty ();
143
131
}
144
- }
145
- catch (SQLException e ) {
132
+ } catch (SQLException e ) {
146
133
throw new RuntimeSqlException (e );
147
- }
148
- finally {
134
+ } finally {
149
135
close ();
150
136
}
151
137
return rval ;
@@ -162,11 +148,9 @@ public List<T> list() {
162
148
T t = this .mapper .map (resultSet );
163
149
rval .add (t );
164
150
}
165
- }
166
- catch (SQLException e ) {
151
+ } catch (SQLException e ) {
167
152
throw new RuntimeSqlException (e );
168
- }
169
- finally {
153
+ } finally {
170
154
close ();
171
155
}
172
156
return rval ;
@@ -179,8 +163,9 @@ public List<T> list() {
179
163
public Stream <T > stream () {
180
164
try {
181
165
ResultSet resultSet = statement .executeQuery ();
182
- return StreamSupport .stream (
183
- new Spliterators .AbstractSpliterator <T >(Long .MAX_VALUE , Spliterator .IMMUTABLE | Spliterator .ORDERED | Spliterator .DISTINCT | Spliterator .NONNULL ) {
166
+ return StreamSupport
167
+ .stream (new Spliterators .AbstractSpliterator <T >(Long .MAX_VALUE , Spliterator .IMMUTABLE
168
+ | Spliterator .ORDERED | Spliterator .DISTINCT | Spliterator .NONNULL ) {
184
169
@ Override
185
170
public boolean tryAdvance (Consumer <? super T > action ) {
186
171
try {
@@ -190,23 +175,20 @@ public boolean tryAdvance(Consumer<? super T> action) {
190
175
T t = mapper .map (resultSet );
191
176
action .accept (t );
192
177
return true ;
193
- }
194
- catch (SQLException e ) {
178
+ } catch (SQLException e ) {
195
179
throw new RuntimeSqlException (e );
196
180
}
197
181
}
198
182
199
183
}, false ).onClose (() -> {
200
- try {
201
- resultSet .close ();
202
- close ();
203
- }
204
- catch (SQLException e ) {
205
- throw new RuntimeException (e );
206
- }
207
- });
208
- }
209
- catch (SQLException e ) {
184
+ try {
185
+ resultSet .close ();
186
+ close ();
187
+ } catch (SQLException e ) {
188
+ throw new RuntimeException (e );
189
+ }
190
+ });
191
+ } catch (SQLException e ) {
210
192
throw new RuntimeException (e );
211
193
}
212
194
}
@@ -218,8 +200,7 @@ public boolean tryAdvance(Consumer<? super T> action) {
218
200
public void close () {
219
201
try {
220
202
this .statement .close ();
221
- }
222
- catch (SQLException e ) {
203
+ } catch (SQLException e ) {
223
204
throw new RuntimeSqlException (e );
224
205
}
225
206
}
0 commit comments