- > query(SQLConnection connection) {
126 | Future
- > future = Future.future();
127 | connection.query("SELECT * FROM articles", result -> {
128 | connection.close();
129 | future.handle(
130 | result.map(rs -> rs.getRows().stream().map(Article::new).collect(Collectors.toList()))
131 | );
132 | }
133 | );
134 | return future;
135 | }
136 |
137 | private Future
My Reading List
15 | 16 |Just an example of simple CRUD application developed using Eclipse Vert.x and Vertx Web.
17 |Articles
22 | 26 || # | 30 |Title | 31 |URL | 32 |Actions | 33 |
|---|
Hello from my first Vert.x 3 application
"); 43 | }); 44 | 45 | // Serve static resources from the /assets directory 46 | router.route("/assets/*").handler(StaticHandler.create("assets")); 47 | router.get("/api/articles").handler(this::getAll); 48 | router.get("/api/articles/:id").handler(this::getOne); 49 | router.route("/api/articles*").handler(BodyHandler.create()); 50 | router.post("/api/articles").handler(this::addOne); 51 | router.delete("/api/articles/:id").handler(this::deleteOne); 52 | router.put("/api/articles/:id").handler(this::updateOne); 53 | 54 | ConfigRetriever retriever = ConfigRetriever.create(vertx); 55 | 56 | // Start sequence: 57 | // 1 - Retrieve the configuration 58 | // |- 2 - Create the JDBC client 59 | // |- 3 - Connect to the database (retrieve a connection) 60 | // |- 4 - Create table if needed 61 | // |- 5 - Add some data if needed 62 | // |- 6 - Close connection when done 63 | // |- 7 - Start HTTP server 64 | // |- 9 - we are done! 65 | 66 | retriever.rxGetConfig() 67 | .doOnSuccess(config -> 68 | jdbc = JDBCClient.createShared(vertx, config, "My-Reading-List")) 69 | .flatMap(config -> 70 | connect() 71 | .flatMap(connection -> 72 | this.createTableIfNeeded(connection) 73 | .flatMap(this::createSomeDataIfNone) 74 | .doAfterTerminate(connection::close) 75 | ) 76 | .map(x -> config) 77 | ) 78 | .flatMapCompletable(config -> createHttpServer(config, router)) 79 | .subscribe(CompletableHelper.toObserver(fut)); 80 | 81 | } 82 | 83 | private Completable createHttpServer(JsonObject config, Router router) { 84 | return vertx 85 | .createHttpServer() 86 | .requestHandler(router::accept) 87 | .rxListen(config.getInteger("HTTP_PORT", 8080)) 88 | .toCompletable(); 89 | } 90 | 91 | private Single- > query(SQLConnection connection) {
109 | return connection.rxQuery("SELECT * FROM articles")
110 | .map(rs -> rs.getRows().stream().map(Article::new).collect(Collectors.toList()))
111 | .doFinally(connection::close);
112 | }
113 |
114 | private Single
My Reading List
15 | 16 |Just an example of simple CRUD application developed using Eclipse Vert.x and Vertx Web.
17 |Articles
22 | 26 || # | 30 |Title | 31 |URL | 32 |Actions | 33 |
|---|