private void findUsers(Handler<List<User>> handler, JsonObject query) { mongo.find( USER, query, result -> { if (result.failed()) { // error handling } List<User> lookupResults = JsonConverter.fromJsonList(result.result(), User.class); handler.handle(lookupResults); }); }
@Override public void addUser(Handler<String> handler, User user) { String json = new Gson().toJson(user); JsonObject document = new JsonObject(json); mongo.insert( USER, document, res -> { // TODO // Check if the username already exists if (res.succeeded()) { handler.handle(res.result()); } else { res.cause().printStackTrace(); } }); }
@Override public void start() { MongoClientProvider.setClient(MongoClient.createShared(vertx, new JsonObject())); registerServices(); createServer(); }