Skip to content

Commit 966f6e2

Browse files
authored
Code formatting for MappedQueryImpl (#4935)
* Auto format mappedqueryimpl * Fix kafkasql stapshotting * Code formatting
1 parent 97692ec commit 966f6e2

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3320,7 +3320,8 @@ public String createSnapshot(String location) throws RegistryStorageException {
33203320
if (!StringUtil.isEmpty(location)) {
33213321
log.debug("Creating internal database snapshot to location {}.", location);
33223322
handles.withHandleNoException(handle -> {
3323-
handle.createQuery(sqlStatements.createDataSnapshot()).bind(0, location).mapTo(Integer.class);
3323+
handle.createQuery(sqlStatements.createDataSnapshot()).bind(0, location).mapTo(String.class)
3324+
.first();
33243325
});
33253326
return location;
33263327
} else {

app/src/main/java/io/apicurio/registry/storage/impl/sql/jdb/MappedQueryImpl.java

+29-48
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,12 @@ public T one() {
4242
if (resultSet.next()) {
4343
throw new RuntimeSqlException("SQL error: Expected only one result but got multiple.");
4444
}
45-
}
46-
else {
45+
} else {
4746
throw new RuntimeSqlException("SQL error: Expected only one result row but got none.");
4847
}
49-
}
50-
catch (SQLException e) {
48+
} catch (SQLException e) {
5149
throw new RuntimeSqlException(e);
52-
}
53-
finally {
50+
} finally {
5451
close();
5552
}
5653
return rval;
@@ -65,15 +62,12 @@ public T first() {
6562
try (ResultSet resultSet = statement.executeQuery()) {
6663
if (resultSet.next()) {
6764
rval = this.mapper.map(resultSet);
68-
}
69-
else {
65+
} else {
7066
throw new RuntimeSqlException("SQL error: Expected AT LEAST one result row but got none.");
7167
}
72-
}
73-
catch (SQLException e) {
68+
} catch (SQLException e) {
7469
throw new RuntimeSqlException(e);
75-
}
76-
finally {
70+
} finally {
7771
close();
7872
}
7973
return rval;
@@ -91,15 +85,12 @@ public Optional<T> findOne() {
9185
if (resultSet.next()) {
9286
throw new RuntimeSqlException("SQL error: Expected only one result but got multiple.");
9387
}
94-
}
95-
else {
88+
} else {
9689
rval = Optional.empty();
9790
}
98-
}
99-
catch (SQLException e) {
91+
} catch (SQLException e) {
10092
throw new RuntimeSqlException(e);
101-
}
102-
finally {
93+
} finally {
10394
close();
10495
}
10596
return rval;
@@ -114,15 +105,12 @@ public Optional<T> findFirst() {
114105
try (ResultSet resultSet = statement.executeQuery()) {
115106
if (resultSet.next()) {
116107
rval = Optional.of(this.mapper.map(resultSet));
117-
}
118-
else {
108+
} else {
119109
rval = Optional.empty();
120110
}
121-
}
122-
catch (SQLException e) {
111+
} catch (SQLException e) {
123112
throw new RuntimeSqlException(e);
124-
}
125-
finally {
113+
} finally {
126114
close();
127115
}
128116
return rval;
@@ -141,11 +129,9 @@ public Optional<T> findLast() {
141129
if (rval == null) {
142130
rval = Optional.empty();
143131
}
144-
}
145-
catch (SQLException e) {
132+
} catch (SQLException e) {
146133
throw new RuntimeSqlException(e);
147-
}
148-
finally {
134+
} finally {
149135
close();
150136
}
151137
return rval;
@@ -162,11 +148,9 @@ public List<T> list() {
162148
T t = this.mapper.map(resultSet);
163149
rval.add(t);
164150
}
165-
}
166-
catch (SQLException e) {
151+
} catch (SQLException e) {
167152
throw new RuntimeSqlException(e);
168-
}
169-
finally {
153+
} finally {
170154
close();
171155
}
172156
return rval;
@@ -179,8 +163,9 @@ public List<T> list() {
179163
public Stream<T> stream() {
180164
try {
181165
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) {
184169
@Override
185170
public boolean tryAdvance(Consumer<? super T> action) {
186171
try {
@@ -190,23 +175,20 @@ public boolean tryAdvance(Consumer<? super T> action) {
190175
T t = mapper.map(resultSet);
191176
action.accept(t);
192177
return true;
193-
}
194-
catch (SQLException e) {
178+
} catch (SQLException e) {
195179
throw new RuntimeSqlException(e);
196180
}
197181
}
198182

199183
}, 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) {
210192
throw new RuntimeException(e);
211193
}
212194
}
@@ -218,8 +200,7 @@ public boolean tryAdvance(Consumer<? super T> action) {
218200
public void close() {
219201
try {
220202
this.statement.close();
221-
}
222-
catch (SQLException e) {
203+
} catch (SQLException e) {
223204
throw new RuntimeSqlException(e);
224205
}
225206
}

0 commit comments

Comments
 (0)