Java tutorial
/* * Copyright 2014 Red Hat, Inc. * * Red Hat licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package com.test.db; import com.test.db.DbService; import io.vertx.core.eventbus.DeliveryOptions; import io.vertx.core.Vertx; import io.vertx.core.Future; import io.vertx.core.json.JsonObject; import io.vertx.core.json.JsonArray; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import io.vertx.serviceproxy.ProxyHelper; import com.test.db.DbService; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; import io.vertx.core.AsyncResult; import io.vertx.core.Handler; /* Generated Proxy code - DO NOT EDIT @author Roger the Robot */ public class DbServiceVertxEBProxy implements DbService { private Vertx _vertx; private String _address; private DeliveryOptions _options; private boolean closed; public DbServiceVertxEBProxy(Vertx vertx, String address) { this(vertx, address, null); } public DbServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) { this._vertx = vertx; this._address = address; this._options = options; } public void storedProc(String procName, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("procName", procName); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "storedProc"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } public void createStm(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "createStm"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } public void update(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "update"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } public void delete(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "delete"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } public void read(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "read"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } public void nonSharedRead(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return; } JsonObject _json = new JsonObject(); _json.put("query", query); _json.put("databaseConfig", databaseConfig); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "nonSharedRead"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); } private List<Character> convertToListChar(JsonArray arr) { List<Character> list = new ArrayList<>(); for (Object obj : arr) { Integer jobj = (Integer) obj; list.add((char) (int) jobj); } return list; } private Set<Character> convertToSetChar(JsonArray arr) { Set<Character> set = new HashSet<>(); for (Object obj : arr) { Integer jobj = (Integer) obj; set.add((char) (int) jobj); } return set; } private <T> Map<String, T> convertMap(Map map) { return (Map<String, T>) map; } private <T> List<T> convertList(List list) { return (List<T>) list; } private <T> Set<T> convertSet(List list) { return new HashSet<T>((List<T>) list); } }