se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java Source code

Java tutorial

Introduction

Here is the source code for se.liquidbytes.jel.database.DatabaseConnectionVertxEBProxy.java

Source

/*
 * Copyright 2015 Henrik stman.
 *
 * Licensed 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 se.liquidbytes.jel.database;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/*
 Generated Proxy code - DO NOT EDIT
 @author Roger the Robot
 */
public class DatabaseConnectionVertxEBProxy implements DatabaseConnection {

    private Vertx _vertx;
    private String _address;
    private boolean closed;

    public DatabaseConnectionVertxEBProxy(Vertx vertx, String address) {
        this._vertx = vertx;
        this._address = address;
    }

    public DatabaseConnection getSite(String id, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("id", id);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "getSite");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection getSites(Handler<AsyncResult<JsonArray>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "getSites");
        _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
            if (res.failed()) {
                resultHandler.handle(Future.failedFuture(res.cause()));
            } else {
                resultHandler.handle(Future.succeededFuture(res.result().body()));
            }
        });
        return this;
    }

    public DatabaseConnection addSite(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("document", document);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "addSite");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection updateSite(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("document", document);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "updateSite");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection removeSite(String id, Handler<AsyncResult<Void>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("id", id);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "removeSite");
        _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
            if (res.failed()) {
                resultHandler.handle(Future.failedFuture(res.cause()));
            } else {
                resultHandler.handle(Future.succeededFuture(res.result().body()));
            }
        });
        return this;
    }

    public DatabaseConnection getUser(String id, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("id", id);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "getUser");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection getUserByUsername(String username, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("username", username);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "getUserByUsername");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection getUsers(Handler<AsyncResult<JsonArray>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "getUsers");
        _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
            if (res.failed()) {
                resultHandler.handle(Future.failedFuture(res.cause()));
            } else {
                resultHandler.handle(Future.succeededFuture(res.result().body()));
            }
        });
        return this;
    }

    public DatabaseConnection addUser(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("document", document);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "addUser");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection updateUser(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("document", document);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "updateUser");
        _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()));
            }
        });
        return this;
    }

    public DatabaseConnection removeUser(String id, Handler<AsyncResult<Void>> resultHandler) {
        if (closed) {
            resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
            return this;
        }
        JsonObject _json = new JsonObject();
        _json.put("id", id);
        DeliveryOptions _deliveryOptions = new DeliveryOptions();
        _deliveryOptions.addHeader("action", "removeUser");
        _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
            if (res.failed()) {
                resultHandler.handle(Future.failedFuture(res.cause()));
            } else {
                resultHandler.handle(Future.succeededFuture(res.result().body()));
            }
        });
        return this;
    }

    private List<Character> convertToListChar(JsonArray arr) {
        List<Character> list = new ArrayList<>();
        for (Object obj : arr) {
            Integer jobj = (Integer) obj;
            list.add((char) jobj.intValue());
        }
        return list;
    }

    private Set<Character> convertToSetChar(JsonArray arr) {
        Set<Character> set = new HashSet<>();
        for (Object obj : arr) {
            Integer jobj = (Integer) obj;
            set.add((char) jobj.intValue());
        }
        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);
    }
}