Skip to content

Commit 9584891

Browse files
committed
Futurized docs
1 parent a7657dc commit 9584891

File tree

4 files changed

+101
-139
lines changed

4 files changed

+101
-139
lines changed

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

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void configureFromDataObject(Vertx vertx) {
9393
}
9494

9595
public void configureFromUri(Vertx vertx) {
96-
96+
9797
// Connection URI
9898
String connectionUri = "db2://dbuser:secretpassword@database.server.com:50000/mydb";
9999

@@ -165,33 +165,26 @@ public void connecting04(Vertx vertx) {
165165
DB2Pool client = DB2Pool.pool(vertx, connectOptions, poolOptions);
166166

167167
// Get a connection from the pool
168-
client.getConnection(ar1 -> {
169-
170-
if (ar1.succeeded()) {
171-
172-
System.out.println("Connected");
173-
174-
// Obtain our connection
175-
SqlConnection conn = ar1.result();
176-
177-
// All operations execute on the same connection
178-
conn
179-
.query("SELECT * FROM users WHERE id='julien'")
180-
.execute(ar2 -> {
181-
if (ar2.succeeded()) {
182-
conn
183-
.query("SELECT * FROM users WHERE id='emad'")
184-
.execute(ar3 -> {
185-
// Release the connection to the pool
186-
conn.close();
187-
});
188-
} else {
189-
// Release the connection to the pool
190-
conn.close();
191-
}
168+
client.getConnection().compose(conn -> {
169+
System.out.println("Got a connection from the pool");
170+
171+
// All operations execute on the same connection
172+
return conn
173+
.query("SELECT * FROM users WHERE id='julien'")
174+
.execute()
175+
.compose(res -> conn
176+
.query("SELECT * FROM users WHERE id='emad'")
177+
.execute())
178+
.onComplete(ar -> {
179+
// Release the connection to the pool
180+
conn.close();
192181
});
182+
}).onComplete(ar -> {
183+
if (ar.succeeded()) {
184+
185+
System.out.println("Done");
193186
} else {
194-
System.out.println("Could not connect: " + ar1.cause().getMessage());
187+
System.out.println("Something went wrong " + ar.cause().getMessage());
195188
}
196189
});
197190
}
@@ -207,30 +200,25 @@ public void connecting05(Vertx vertx) {
207200
.setPassword("secret");
208201

209202
// Connect to Postgres
210-
DB2Connection.connect(vertx, options, res -> {
211-
if (res.succeeded()) {
212-
203+
DB2Connection.connect(vertx, options)
204+
.compose(conn -> {
213205
System.out.println("Connected");
214206

215-
// Obtain our connection
216-
DB2Connection conn = res.result();
217-
218207
// All operations execute on the same connection
219-
conn
208+
return conn
220209
.query("SELECT * FROM users WHERE id='julien'")
221-
.execute(ar2 -> {
222-
if (ar2.succeeded()) {
223-
conn
224-
.query("SELECT * FROM users WHERE id='emad'")
225-
.execute(ar3 -> {
226-
// Close the connection
227-
conn.close();
228-
});
229-
} else {
210+
.execute()
211+
.compose(res -> conn
212+
.query("SELECT * FROM users WHERE id='emad'")
213+
.execute()
214+
).onComplete(ar -> {
230215
// Close the connection
231216
conn.close();
232-
}
233-
});
217+
});
218+
}).onComplete(res -> {
219+
if (res.succeeded()) {
220+
221+
System.out.println("Done");
234222
} else {
235223
System.out.println("Could not connect: " + res.cause().getMessage());
236224
}

vertx-mssql-client/src/main/java/examples/MSSQLClientExamples.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,33 +137,26 @@ public void connecting04(Vertx vertx) {
137137
MSSQLPool client = MSSQLPool.pool(vertx, connectOptions, poolOptions);
138138

139139
// Get a connection from the pool
140-
client.getConnection(ar1 -> {
141-
142-
if (ar1.succeeded()) {
143-
144-
System.out.println("Connected");
145-
146-
// Obtain our connection
147-
SqlConnection conn = ar1.result();
148-
149-
// All operations execute on the same connection
150-
conn
151-
.query("SELECT * FROM users WHERE id='julien'")
152-
.execute(ar2 -> {
153-
if (ar2.succeeded()) {
154-
conn
155-
.query("SELECT * FROM users WHERE id='emad'")
156-
.execute(ar3 -> {
157-
// Release the connection to the pool
158-
conn.close();
159-
});
160-
} else {
161-
// Release the connection to the pool
162-
conn.close();
163-
}
140+
client.getConnection().compose(conn -> {
141+
System.out.println("Got a connection from the pool");
142+
143+
// All operations execute on the same connection
144+
return conn
145+
.query("SELECT * FROM users WHERE id='julien'")
146+
.execute()
147+
.compose(res -> conn
148+
.query("SELECT * FROM users WHERE id='emad'")
149+
.execute())
150+
.onComplete(ar -> {
151+
// Release the connection to the pool
152+
conn.close();
164153
});
154+
}).onComplete(ar -> {
155+
if (ar.succeeded()) {
156+
157+
System.out.println("Done");
165158
} else {
166-
System.out.println("Could not connect: " + ar1.cause().getMessage());
159+
System.out.println("Something went wrong " + ar.cause().getMessage());
167160
}
168161
});
169162
}

vertx-mysql-client/src/main/java/examples/MySQLClientExamples.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,33 +195,26 @@ public void connecting04(Vertx vertx) {
195195
MySQLPool client = MySQLPool.pool(vertx, connectOptions, poolOptions);
196196

197197
// Get a connection from the pool
198-
client.getConnection(ar1 -> {
199-
200-
if (ar1.succeeded()) {
201-
202-
System.out.println("Connected");
203-
204-
// Obtain our connection
205-
SqlConnection conn = ar1.result();
206-
207-
// All operations execute on the same connection
208-
conn
209-
.query("SELECT * FROM users WHERE id='julien'")
210-
.execute(ar2 -> {
211-
if (ar2.succeeded()) {
212-
conn
213-
.query("SELECT * FROM users WHERE id='emad'")
214-
.execute(ar3 -> {
215-
// Release the connection to the pool
216-
conn.close();
217-
});
218-
} else {
219-
// Release the connection to the pool
220-
conn.close();
221-
}
198+
client.getConnection().compose(conn -> {
199+
System.out.println("Got a connection from the pool");
200+
201+
// All operations execute on the same connection
202+
return conn
203+
.query("SELECT * FROM users WHERE id='julien'")
204+
.execute()
205+
.compose(res -> conn
206+
.query("SELECT * FROM users WHERE id='emad'")
207+
.execute())
208+
.onComplete(ar -> {
209+
// Release the connection to the pool
210+
conn.close();
222211
});
212+
}).onComplete(ar -> {
213+
if (ar.succeeded()) {
214+
215+
System.out.println("Done");
223216
} else {
224-
System.out.println("Could not connect: " + ar1.cause().getMessage());
217+
System.out.println("Something went wrong " + ar.cause().getMessage());
225218
}
226219
});
227220
}

vertx-pg-client/src/main/java/examples/PgClientExamples.java

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.vertx.sqlclient.RowSet;
2727
import io.vertx.sqlclient.Row;
2828
import io.vertx.sqlclient.SqlClient;
29-
import io.vertx.sqlclient.SqlConnection;
3029
import io.vertx.sqlclient.Tuple;
3130
import io.vertx.core.Vertx;
3231
import io.vertx.core.json.JsonObject;
@@ -162,6 +161,7 @@ public void connecting02(Vertx vertx) {
162161
// Pool options
163162
PoolOptions poolOptions = new PoolOptions()
164163
.setMaxSize(5);
164+
165165
// Create the pooled client
166166
PgPool client = PgPool.pool(vertx, connectOptions, poolOptions);
167167
}
@@ -190,33 +190,26 @@ public void connecting04(Vertx vertx) {
190190
PgPool client = PgPool.pool(vertx, connectOptions, poolOptions);
191191

192192
// Get a connection from the pool
193-
client.getConnection(ar1 -> {
194-
195-
if (ar1.succeeded()) {
196-
197-
System.out.println("Connected");
198-
199-
// Obtain our connection
200-
SqlConnection conn = ar1.result();
201-
202-
// All operations execute on the same connection
203-
conn
204-
.query("SELECT * FROM users WHERE id='julien'")
205-
.execute(ar2 -> {
206-
if (ar2.succeeded()) {
207-
conn
208-
.query("SELECT * FROM users WHERE id='emad'")
209-
.execute(ar3 -> {
210-
// Release the connection to the pool
211-
conn.close();
212-
});
213-
} else {
214-
// Release the connection to the pool
215-
conn.close();
216-
}
193+
client.getConnection().compose(conn -> {
194+
System.out.println("Got a connection from the pool");
195+
196+
// All operations execute on the same connection
197+
return conn
198+
.query("SELECT * FROM users WHERE id='julien'")
199+
.execute()
200+
.compose(res -> conn
201+
.query("SELECT * FROM users WHERE id='emad'")
202+
.execute())
203+
.onComplete(ar -> {
204+
// Release the connection to the pool
205+
conn.close();
217206
});
207+
}).onComplete(ar -> {
208+
if (ar.succeeded()) {
209+
210+
System.out.println("Done");
218211
} else {
219-
System.out.println("Could not connect: " + ar1.cause().getMessage());
212+
System.out.println("Something went wrong " + ar.cause().getMessage());
220213
}
221214
});
222215
}
@@ -232,30 +225,25 @@ public void connecting05(Vertx vertx) {
232225
.setPassword("secret");
233226

234227
// Connect to Postgres
235-
PgConnection.connect(vertx, options, res -> {
236-
if (res.succeeded()) {
237-
228+
PgConnection.connect(vertx, options)
229+
.compose(conn -> {
238230
System.out.println("Connected");
239231

240-
// Obtain our connection
241-
PgConnection conn = res.result();
242-
243232
// All operations execute on the same connection
244-
conn
233+
return conn
245234
.query("SELECT * FROM users WHERE id='julien'")
246-
.execute(ar2 -> {
247-
if (ar2.succeeded()) {
248-
conn
249-
.query("SELECT * FROM users WHERE id='emad'")
250-
.execute(ar3 -> {
251-
// Close the connection
252-
conn.close();
253-
});
254-
} else {
255-
// Close the connection
256-
conn.close();
257-
}
235+
.execute()
236+
.compose(res -> conn
237+
.query("SELECT * FROM users WHERE id='emad'")
238+
.execute()
239+
).onComplete(ar -> {
240+
// Close the connection
241+
conn.close();
258242
});
243+
}).onComplete(res -> {
244+
if (res.succeeded()) {
245+
246+
System.out.println("Done");
259247
} else {
260248
System.out.println("Could not connect: " + res.cause().getMessage());
261249
}

0 commit comments

Comments
 (0)