Skip to content

Commit 6577aab

Browse files
committed
Revert "Remove callback usage from examples"
This reverts commit dcef9e6.
1 parent e531268 commit 6577aab

File tree

13 files changed

+433
-676
lines changed

13 files changed

+433
-676
lines changed

vertx-db2-client/src/main/java/examples/DB2ClientExamples.java

Lines changed: 66 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public void gettingStarted() {
5757
// A simple query
5858
client
5959
.query("SELECT * FROM users WHERE id='julien'")
60-
.execute()
61-
.onComplete(ar -> {
60+
.execute(ar -> {
6261
if (ar.succeeded()) {
6362
RowSet<Row> result = ar.result();
6463
System.out.println("Got " + result.size() + " rows ");
@@ -87,10 +86,9 @@ public void configureFromDataObject(Vertx vertx) {
8786
// Create the pool from the data object
8887
DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions);
8988

90-
pool.getConnection()
91-
.onComplete(ar -> {
92-
// Handling your connection
93-
});
89+
pool.getConnection(ar -> {
90+
// Handling your connection
91+
});
9492
}
9593

9694
public void configureFromUri(Vertx vertx) {
@@ -102,10 +100,9 @@ public void configureFromUri(Vertx vertx) {
102100
DB2Pool pool = DB2Pool.pool(connectionUri);
103101

104102
// Create the connection from the connection URI
105-
DB2Connection.connect(vertx, connectionUri)
106-
.onComplete(res -> {
107-
// Handling your connection
108-
});
103+
DB2Connection.connect(vertx, connectionUri, res -> {
104+
// Handling your connection
105+
});
109106
}
110107

111108
public void connecting01() {
@@ -262,45 +259,44 @@ public void connectSsl(Vertx vertx) {
262259
.setPath("/path/to/keystore.p12")
263260
.setPassword("keystoreSecret"));
264261

265-
DB2Connection.connect(vertx, options)
266-
.onComplete(res -> {
267-
if (res.succeeded()) {
268-
// Connected with SSL
269-
} else {
270-
System.out.println("Could not connect " + res.cause());
271-
}
272-
});
262+
DB2Connection.connect(vertx, options, res -> {
263+
if (res.succeeded()) {
264+
// Connected with SSL
265+
} else {
266+
System.out.println("Could not connect " + res.cause());
267+
}
268+
});
273269
}
274270

275271
public void generatedKeys(SqlClient client) {
276272
client
277273
.preparedQuery("SELECT color_id FROM FINAL TABLE ( INSERT INTO color (color_name) VALUES (?), (?), (?) )")
278-
.execute(Tuple.of("white", "red", "blue"))
279-
.onComplete(ar -> {
280-
if (ar.succeeded()) {
281-
RowSet<Row> rows = ar.result();
282-
System.out.println("Inserted " + rows.rowCount() + " new rows.");
283-
for (Row row : rows) {
284-
System.out.println("generated key: " + row.getInteger("color_id"));
285-
}
286-
} else {
287-
System.out.println("Failure: " + ar.cause().getMessage());
274+
.execute(Tuple.of("white", "red", "blue"), ar -> {
275+
if (ar.succeeded()) {
276+
RowSet<Row> rows = ar.result();
277+
System.out.println("Inserted " + rows.rowCount() + " new rows.");
278+
for (Row row : rows) {
279+
System.out.println("generated key: " + row.getInteger("color_id"));
288280
}
289-
});
281+
} else {
282+
System.out.println("Failure: " + ar.cause().getMessage());
283+
}
284+
});
290285
}
291286

292287
public void typeMapping01(Pool pool) {
293288
pool
294289
.query("SELECT an_int_column FROM exampleTable")
295-
.execute().onSuccess(rowSet -> {
296-
Row row = rowSet.iterator().next();
290+
.execute(ar -> {
291+
RowSet<Row> rowSet = ar.result();
292+
Row row = rowSet.iterator().next();
297293

298-
// Stored as INTEGER column type and represented as java.lang.Integer
299-
Object value = row.getValue(0);
294+
// Stored as INTEGER column type and represented as java.lang.Integer
295+
Object value = row.getValue(0);
300296

301-
// Convert to java.lang.Long
302-
Long longValue = row.getLong(0);
303-
});
297+
// Convert to java.lang.Long
298+
Long longValue = row.getLong(0);
299+
});
304300
}
305301

306302
public void collector01Example(SqlClient client) {
@@ -313,18 +309,17 @@ public void collector01Example(SqlClient client) {
313309
// Run the query with the collector
314310
client.query("SELECT * FROM users")
315311
.collecting(collector)
316-
.execute()
317-
.onComplete(ar -> {
318-
if (ar.succeeded()) {
319-
SqlResult<Map<Long, String>> result = ar.result();
312+
.execute(ar -> {
313+
if (ar.succeeded()) {
314+
SqlResult<Map<Long, String>> result = ar.result();
320315

321-
// Get the map created by the collector
322-
Map<Long, String> map = result.value();
323-
System.out.println("Got " + map);
324-
} else {
325-
System.out.println("Failure: " + ar.cause().getMessage());
326-
}
327-
});
316+
// Get the map created by the collector
317+
Map<Long, String> map = result.value();
318+
System.out.println("Got " + map);
319+
} else {
320+
System.out.println("Failure: " + ar.cause().getMessage());
321+
}
322+
});
328323
}
329324

330325
public void collector02Example(SqlClient client) {
@@ -336,11 +331,7 @@ public void collector02Example(SqlClient client) {
336331
);
337332

338333
// Run the query with the collector
339-
client
340-
.query("SELECT * FROM users")
341-
.collecting(collector)
342-
.execute()
343-
.onComplete(ar -> {
334+
client.query("SELECT * FROM users").collecting(collector).execute(ar -> {
344335
if (ar.succeeded()) {
345336
SqlResult<String> result = ar.result();
346337

@@ -362,38 +353,36 @@ enum Days {
362353
* Using an enum as a string value in the Row and Tuple methods.
363354
*/
364355
public void enumStringValues(SqlClient client) {
365-
client.preparedQuery("SELECT day_name FROM FINAL TABLE ( INSERT INTO days (day_name) VALUES (?), (?), (?) )")
366-
.execute(Tuple.of(Days.FRIDAY, Days.SATURDAY, Days.SUNDAY))
367-
.onComplete(ar -> {
368-
if (ar.succeeded()) {
369-
RowSet<Row> rows = ar.result();
370-
System.out.println("Inserted " + rows.rowCount() + " new rows");
371-
for (Row row : rows) {
372-
System.out.println("Day: " + row.get(Days.class, "day_name"));
373-
}
374-
} else {
375-
System.out.println("Failure: " + ar.cause().getMessage());
376-
}
377-
});
356+
client.preparedQuery("SELECT day_name FROM FINAL TABLE ( INSERT INTO days (day_name) VALUES (?), (?), (?) )")
357+
.execute(Tuple.of(Days.FRIDAY, Days.SATURDAY, Days.SUNDAY), ar -> {
358+
if (ar.succeeded()) {
359+
RowSet<Row> rows = ar.result();
360+
System.out.println("Inserted " + rows.rowCount() + " new rows");
361+
for (Row row : rows) {
362+
System.out.println("Day: " + row.get(Days.class, "day_name"));
363+
}
364+
} else {
365+
System.out.println("Failure: " + ar.cause().getMessage());
366+
}
367+
});
378368
}
379369

380370
/**
381371
* Using an enum as an int value in the Row and Tuple methods.
382372
* The row.get() method returns the corresponding enum's name() value at the ordinal position of the integer value retrieved.
383373
*/
384374
public void enumIntValues(SqlClient client) {
385-
client.preparedQuery("SELECT day_num FROM FINAL TABLE ( INSERT INTO days (day_num) VALUES (?), (?), (?) )")
386-
.execute(Tuple.of(Days.FRIDAY.ordinal(), Days.SATURDAY.ordinal(), Days.SUNDAY.ordinal()))
387-
.onComplete(ar -> {
388-
if (ar.succeeded()) {
389-
RowSet<Row> rows = ar.result();
390-
System.out.println("Inserted " + rows.rowCount() + " new rows");
391-
for (Row row : rows) {
392-
System.out.println("Day: " + row.get(Days.class, "day_num"));
393-
}
394-
} else {
395-
System.out.println("Failure: " + ar.cause().getMessage());
396-
}
375+
client.preparedQuery("SELECT day_num FROM FINAL TABLE ( INSERT INTO days (day_num) VALUES (?), (?), (?) )")
376+
.execute(Tuple.of(Days.FRIDAY.ordinal(), Days.SATURDAY.ordinal(), Days.SUNDAY.ordinal()), ar -> {
377+
if (ar.succeeded()) {
378+
RowSet<Row> rows = ar.result();
379+
System.out.println("Inserted " + rows.rowCount() + " new rows");
380+
for (Row row : rows) {
381+
System.out.println("Day: " + row.get(Days.class, "day_num"));
382+
}
383+
} else {
384+
System.out.println("Failure: " + ar.cause().getMessage());
385+
}
397386
});
398387
}
399388

vertx-db2-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class SqlClientExamples {
4545
public void queries01(SqlClient client) {
4646
client
4747
.query("SELECT * FROM users WHERE id='andy'")
48-
.execute()
49-
.onComplete(ar -> {
48+
.execute(ar -> {
5049
if (ar.succeeded()) {
5150
RowSet<Row> result = ar.result();
5251
System.out.println("Got " + result.size() + " rows ");
@@ -60,8 +59,7 @@ public void queries01(SqlClient client) {
6059
public void queries02(SqlClient client) {
6160
client
6261
.preparedQuery("SELECT * FROM users WHERE id=?")
63-
.execute(Tuple.of("andy"))
64-
.onComplete(ar -> {
62+
.execute(Tuple.of("andy"), ar -> {
6563
if (ar.succeeded()) {
6664
RowSet<Row> rows = ar.result();
6765
System.out.println("Got " + rows.size() + " rows ");
@@ -74,8 +72,7 @@ public void queries02(SqlClient client) {
7472
public void queries03(SqlClient client) {
7573
client
7674
.preparedQuery("SELECT first_name, last_name FROM users")
77-
.execute()
78-
.onComplete(ar -> {
75+
.execute(ar -> {
7976
if (ar.succeeded()) {
8077
RowSet<Row> rows = ar.result();
8178
for (Row row : rows) {
@@ -90,8 +87,7 @@ public void queries03(SqlClient client) {
9087
public void queries04(SqlClient client) {
9188
client
9289
.preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)")
93-
.execute(Tuple.of("Andy", "Guibert"))
94-
.onComplete(ar -> {
90+
.execute(Tuple.of("Andy", "Guibert"), ar -> {
9591
if (ar.succeeded()) {
9692
RowSet<Row> rows = ar.result();
9793
System.out.println(rows.rowCount());
@@ -130,8 +126,7 @@ public void queries08(SqlClient client) {
130126
// Execute the prepared batch
131127
client
132128
.preparedQuery("INSERT INTO USERS (id, name) VALUES (?, ?)")
133-
.executeBatch(batch)
134-
.onComplete(res -> {
129+
.executeBatch(batch, res -> {
135130
if (res.succeeded()) {
136131

137132
// Process rows
@@ -148,8 +143,7 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) {
148143
connectOptions.setCachePreparedStatements(true);
149144
client
150145
.preparedQuery("SELECT * FROM users WHERE id = ?")
151-
.execute(Tuple.of("julien"))
152-
.onComplete(ar -> {
146+
.execute(Tuple.of("julien"), ar -> {
153147
if (ar.succeeded()) {
154148
RowSet<Row> rows = ar.result();
155149
System.out.println("Got " + rows.size() + " rows ");
@@ -161,13 +155,11 @@ public void queries09(SqlClient client, SqlConnectOptions connectOptions) {
161155

162156
public void queries10(SqlConnection sqlConnection) {
163157
sqlConnection
164-
.prepare("SELECT * FROM users WHERE id = ?")
165-
.onComplete(ar -> {
158+
.prepare("SELECT * FROM users WHERE id = ?", ar -> {
166159
if (ar.succeeded()) {
167160
PreparedStatement preparedStatement = ar.result();
168161
preparedStatement.query()
169-
.execute(Tuple.of("julien"))
170-
.onComplete(ar2 -> {
162+
.execute(Tuple.of("julien"), ar2 -> {
171163
if (ar2.succeeded()) {
172164
RowSet<Row> rows = ar2.result();
173165
System.out.println("Got " + rows.size() + " rows ");
@@ -280,26 +272,20 @@ public void transaction03(Pool pool) {
280272
}
281273

282274
public void usingCursors01(SqlConnection connection) {
283-
connection
284-
.prepare("SELECT * FROM users WHERE first_name LIKE ?")
285-
.onComplete(ar0 -> {
275+
connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", ar0 -> {
286276
if (ar0.succeeded()) {
287277
PreparedStatement pq = ar0.result();
288278

289279
// Cursors require to run within a transaction
290-
connection
291-
.begin()
292-
.onComplete(ar1 -> {
280+
connection.begin(ar1 -> {
293281
if (ar1.succeeded()) {
294282
Transaction tx = ar1.result();
295283

296284
// Create a cursor
297285
Cursor cursor = pq.cursor(Tuple.of("julien"));
298286

299287
// Read 50 rows
300-
cursor
301-
.read(50)
302-
.onComplete(ar2 -> {
288+
cursor.read(50, ar2 -> {
303289
if (ar2.succeeded()) {
304290
RowSet<Row> rows = ar2.result();
305291

@@ -319,9 +305,7 @@ public void usingCursors01(SqlConnection connection) {
319305
}
320306

321307
public void usingCursors02(Cursor cursor) {
322-
cursor
323-
.read(50)
324-
.onComplete(ar2 -> {
308+
cursor.read(50, ar2 -> {
325309
if (ar2.succeeded()) {
326310
// Close the cursor
327311
cursor.close();
@@ -330,16 +314,12 @@ public void usingCursors02(Cursor cursor) {
330314
}
331315

332316
public void usingCursors03(SqlConnection connection) {
333-
connection
334-
.prepare("SELECT * FROM users WHERE first_name LIKE ?")
335-
.onComplete(ar0 -> {
317+
connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", ar0 -> {
336318
if (ar0.succeeded()) {
337319
PreparedStatement pq = ar0.result();
338320

339321
// Streams require to run within a transaction
340-
connection
341-
.begin()
342-
.onComplete(ar1 -> {
322+
connection.begin(ar1 -> {
343323
if (ar1.succeeded()) {
344324
Transaction tx = ar1.result();
345325

0 commit comments

Comments
 (0)