This provides an asynchronous interface around a JDBC datasource to:
-
JPAClient [like vertx official JDBCClient]
JPAClient jpaClient = JPAClient.createShared(vertx, config);
-
create table [the sql definition of table]
jpaClient.create("create table whiskies (uuid varchar(255), name varchar(255) ", result -> {});
-
find [to find by key]
jpaClient.find(TABLE, new JsonObject().put(TABLE_KEY, whiskyU.uuid), result_m -> {});
-
delete [to delete by key]
jpaClient.delete(TABLE, new JsonObject().put(TABLE_KEY, whiskyP.uuid), result_d -> {});
-
merge [to merge a json object]
jpaClient.merge(TABLE, whiskyU.toJson(), new JsonObject().put(TABLE_KEY, whiskyU.uuid), result_m -> {});
-
persist [to persist a json object]
jpaClient.persist(TABLE, whiskyP.toJson(), result_p -> {});
-
query with named parameter
jpaClient.query("selct * from " + TABLE + " where name = :NAME ", new JsonObject().put("NAME", whiskyU.name), result_q-> {});
-
query with dynamic restrictions handler
RestrinctionHandler<JsonObject, String, StringBuffer> rh = new RestrinctionHandler<JsonObject, String, StringBuffer>() { String alias = "a"; String separator = " WHERE "; @Override public void handle(JsonObject params, String table, StringBuffer toSql) { toSql.append("select * from " + table + " " + alias + " "); if (params.getString("name") != null) { toSql.append(separator).append(alias).append(".name LIKE :name "); params.put("name", "%" + params.getString("name") + "%"); separator = " and "; } if (params.getString("collection_name") != null) { toSql.append(separator).append(alias).append(".collection_name LIKE :collection_name "); params.put("collection_name", "%" + params.getString("collection_name") + "%"); separator = " and "; } if (params.getString("uuid") != null) { toSql.append(separator).append(alias).append(".uuid = :uuid "); separator = " and "; } } }; jpaClient.query(TABLE_NAME, params, rh, handler);
It’s a vertx-jdbc clone with new Actions and some different methods:
-
JPACreate
-
JPADelete
-
JPAFind
-
JPAHandlerQuery
-
JPAMerge
-
JPAPersist
-
JPAQuery
-
JPAStatementHelper
Also with rxActions inside:
-
Single<Void> rxCreate(String sql);
-
Single<UpdateResult> rxPersist(String table, JsonObject params);
-
Single<UpdateResult> rxMerge(String table, JsonObject params, JsonObject key);
-
Single<UpdateResult> rxDelete(String table, JsonObject key);
-
Single<ResultSet> rxQuery(String sql, JsonObject params);
-
Single<ResultSet> rxQuery(String sql, JsonObject params,RestrinctionHandler<JsonObject, String, StringBuffer> restictionHandler);
-
Single<ResultSet> rxFind(String table, JsonObject key);