Skip to content

Commit 9bc73e3

Browse files
Improve formatting
1 parent 323e44d commit 9bc73e3

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

sample/src/main/java/oracle/r2dbc/samples/JdbcToR2dbc.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public final class JdbcToR2dbc {
140140
* @return {@code DataSource} configured to connect with a database
141141
*/
142142
static DataSource configureJdbc() throws SQLException {
143+
143144
OracleDataSource dataSource = new oracle.jdbc.pool.OracleDataSource();
144145
dataSource.setDriverType("thin");
145146
dataSource.setServerName(DatabaseConfig.HOST);
@@ -148,6 +149,7 @@ static DataSource configureJdbc() throws SQLException {
148149
dataSource.setUser(DatabaseConfig.USER);
149150
dataSource.setPassword(DatabaseConfig.PASSWORD);
150151
return dataSource;
152+
151153
}
152154

153155
/**
@@ -157,6 +159,7 @@ static DataSource configureJdbc() throws SQLException {
157159
* @return {@code ConnectionFactory} configured to connect with a database
158160
*/
159161
static ConnectionFactory configureR2dbc() {
162+
160163
return ConnectionFactories.get(ConnectionFactoryOptions.builder()
161164
.option(DRIVER, "oracle")
162165
.option(HOST, DatabaseConfig.HOST)
@@ -165,15 +168,15 @@ static ConnectionFactory configureR2dbc() {
165168
.option(USER, DatabaseConfig.USER)
166169
.option(PASSWORD, DatabaseConfig.PASSWORD)
167170
.build());
171+
168172
}
169173

170174
/**
171175
* Executes a SQL query with JDBC. This method performs the same database
172176
* interactions as {@link #queryR2dbc(io.r2dbc.spi.Connection)}.
173177
* @return Value returned by a SQL query
174178
*/
175-
static String queryJdbc(java.sql.Connection connection)
176-
throws SQLException {
179+
static String queryJdbc(java.sql.Connection connection) throws SQLException {
177180

178181
try (java.sql.Statement statement = connection.createStatement()) {
179182
ResultSet resultSet =
@@ -184,6 +187,7 @@ static String queryJdbc(java.sql.Connection connection)
184187
else
185188
throw new NoSuchElementException("Query returned zero rows");
186189
}
190+
187191
}
188192

189193
/**
@@ -192,73 +196,79 @@ static String queryJdbc(java.sql.Connection connection)
192196
* @return Value returned by a SQL query
193197
*/
194198
static Publisher<String> queryR2dbc(io.r2dbc.spi.Connection connection) {
199+
195200
return Flux.from(connection.createStatement(
196201
"SELECT 'Hello, R2DBC!' FROM sys.dual")
197202
.execute())
198203
.flatMap(result ->
199204
result.map(row -> row.get(0, String.class)))
200205
.switchIfEmpty(Flux.error(
201206
new NoSuchElementException("Query returned zero rows")));
207+
202208
}
203209

204210
/**
205211
* Executes an INSERT with JDBC. This method performs the same database
206212
* interactions as {@link #insertR2dbc(io.r2dbc.spi.Connection)}.
207213
* @return Count of inserted rows.
208214
*/
209-
static int insertJdbc(java.sql.Connection connection)
210-
throws SQLException {
215+
static int insertJdbc(java.sql.Connection connection) throws SQLException {
216+
211217
try (PreparedStatement preparedStatement = connection.prepareStatement(
212218
"INSERT INTO JdbcToR2dbcTable(id, value) VALUES (?, ?)")) {
213219
preparedStatement.setInt(1, 0);
214220
preparedStatement.setString(2, "JDBC");
215221
return preparedStatement.executeUpdate();
216222
}
223+
217224
}
218225

219226
/**
220227
* Executes an INSERT with R2DBC. This method performs the same database
221228
* interactions as {@link #insertJdbc(java.sql.Connection)}.
222229
* @return {@code Publisher} emitting the count of inserted rows.
223230
*/
224-
static Publisher<Integer> insertR2dbc(
225-
io.r2dbc.spi.Connection connection) {
231+
static Publisher<Integer> insertR2dbc(io.r2dbc.spi.Connection connection) {
232+
226233
return Flux.from(connection.createStatement(
227234
"INSERT INTO JdbcToR2dbcTable(id, value) VALUES (?, ?)")
228235
.bind(0, 0)
229236
.bind(1, "R2DBC")
230237
.execute())
231238
.flatMap(Result::getRowsUpdated);
239+
232240
}
233241

234242
/**
235243
* Executes an UPDATE with JDBC. This method performs the same database
236244
* interactions as {@link #updateR2dbc(io.r2dbc.spi.Connection)}.
237245
* @return Count of updated rows.
238246
*/
239-
static int updateJdbc(java.sql.Connection connection)
240-
throws SQLException {
247+
static int updateJdbc(java.sql.Connection connection) throws SQLException {
248+
241249
try (PreparedStatement preparedStatement = connection.prepareStatement(
242250
"UPDATE JdbcToR2dbcTable SET value = ? WHERE id = ?")) {
243251
preparedStatement.setString(1, "JDBC");
244252
preparedStatement.setInt(2, 0);
245253
return preparedStatement.executeUpdate();
246254
}
255+
247256
}
248257

249258
/**
250259
* Executes an UPDATE with R2DBC. This method performs the same database
251260
* interactions as {@link #updateJdbc(java.sql.Connection)}.
252261
* @return {@code Publisher} emitting the count of updated rows.
253262
*/
254-
static Publisher<Integer> updateR2dbc(
255-
io.r2dbc.spi.Connection connection) {
263+
static Publisher<Integer> updateR2dbc(io.r2dbc.spi.Connection connection) {
264+
256265
return Flux.from(connection.createStatement(
257266
"UPDATE JdbcToR2dbcTable SET value = ? WHERE id = ?")
258267
.bind(0, "R2DBC")
259268
.bind(1, 0)
260269
.execute())
261270
.flatMap(Result::getRowsUpdated);
271+
262272
}
263273

264274
/**
@@ -268,8 +278,7 @@ static Publisher<Integer> updateR2dbc(
268278
* @param connection Database connection
269279
* @return Count of updated rows
270280
*/
271-
static int tryUpdateJdbc(java.sql.Connection connection)
272-
throws SQLException {
281+
static int tryUpdateJdbc(java.sql.Connection connection) throws SQLException {
273282

274283
// Try to update the row
275284
int updateCount = updateJdbc(connection);
@@ -279,6 +288,7 @@ static int tryUpdateJdbc(java.sql.Connection connection)
279288
return insertJdbc(connection);
280289
else
281290
return updateCount;
291+
282292
}
283293

284294
/**
@@ -301,6 +311,7 @@ static Publisher<Integer> tryUpdateR2dbc(io.r2dbc.spi.Connection connection) {
301311
return Flux.just(updateCount);
302312

303313
});
314+
304315
}
305316

306317
/**
@@ -311,8 +322,7 @@ static Publisher<Integer> tryUpdateR2dbc(io.r2dbc.spi.Connection connection) {
311322
* @param connection Database connection
312323
* @return Count of updated rows
313324
*/
314-
static int tryInsertJdbc(java.sql.Connection connection)
315-
throws SQLException {
325+
static int tryInsertJdbc(java.sql.Connection connection) throws SQLException {
316326

317327
try {
318328
// Try to insert the row
@@ -327,6 +337,7 @@ static int tryInsertJdbc(java.sql.Connection connection)
327337
throw sqlException;
328338

329339
}
340+
330341
}
331342

332343
/**
@@ -336,8 +347,7 @@ static int tryInsertJdbc(java.sql.Connection connection)
336347
* @param connection Database connection
337348
* @return {@code Publisher} emitting the count of updated rows.
338349
*/
339-
static Publisher<Integer> tryInsertR2dbc(
340-
io.r2dbc.spi.Connection connection) {
350+
static Publisher<Integer> tryInsertR2dbc(io.r2dbc.spi.Connection connection) {
341351

342352
// Try to insert the row
343353
return Flux.from(insertR2dbc(connection))
@@ -350,6 +360,7 @@ static Publisher<Integer> tryInsertR2dbc(
350360
return Flux.error(r2dbcException);
351361

352362
});
363+
353364
}
354365

355366
/**
@@ -364,11 +375,9 @@ static Publisher<Integer> tryInsertR2dbc(
364375
* @throws SQLException If the database interaction fails with an
365376
* unexpected error.
366377
*/
367-
static int loopJdbc(java.sql.Connection connection)
368-
throws SQLException {
378+
static int loopJdbc(java.sql.Connection connection) throws SQLException {
369379

370380
do {
371-
372381
try {
373382
// Try to update the row, or insert it if it does not exist
374383
return tryUpdateJdbc(connection);
@@ -381,8 +390,8 @@ static int loopJdbc(java.sql.Connection connection)
381390
throw sqlException;
382391

383392
}
384-
385393
} while (true);
394+
386395
}
387396

388397
/**
@@ -427,6 +436,7 @@ static Publisher<Integer> loopR2dbc(io.r2dbc.spi.Connection connection) {
427436
return loopR2dbc(connection);
428437

429438
});
439+
430440
}
431441

432442
/**

0 commit comments

Comments
 (0)