Skip to content

Instantly share code, notes, and snippets.

View vietj's full-sized avatar
🤖
Coding the Future

Julien Viet vietj

🤖
Coding the Future
View GitHub Profile

SQL Client Templates

Table of Contents

SQL Client Templates is a small library designed to facilitate the execution of SQL queries.

Usage

To use SQL Client Templates add the following dependency to the dependencies section of your build descriptor:

  • Maven (in your pom.xml):

@Test
public void testResolveAbsoluteFile() throws Exception {
File folder = File.createTempFile("test", ".txt");
assertTrue(folder.delete());
assertTrue(folder.mkdirs());
folder.deleteOnExit(); // Cleanup
File f = new File(folder, "child.txt");
Files.write(f.toPath(), "the_child".getBytes());
File notFound = new File(folder, "not_found");
Thread thread = Thread.currentThread();
pool.begin(res -> {
if (res.succeeded()) {
// Get the transaction
Transaction tx = res.result();
// Various statements
tx.query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')")
.execute(ar1 -> {
if (ar1.succeeded()) {
@VertxGen
public interface SqlTemplate<R> {
static SqlTemplate<RowSet<Row>> forQuery(SqlClient client, String template) {
Collector<Row, ?, SqlResult<Row>> collector = null;
Function<SqlResult<Row>, RowSet<Row>> bilto = null;
return new SqlTemplateImpl<SqlResult<Row>, RowSet<Row>>(client, collector, bilto, template);
}
public void customKeyManagerFactory() {
Vertx vertx = Vertx.vertx();
vertx.createHttpServer(new HttpServerOptions().setKeyCertOptions(new KeyCertOptions() {
@Override
public KeyManagerFactory getKeyManagerFactory(Vertx vertx) throws Exception {
throw new UnsupportedOperationException("Implement me");
}
@Override
public KeyCertOptions clone() {
throw new UnsupportedOperationException("Implement me");
public class JDBCTxOp extends AbstractJDBCAction<Void> {
private final TxCommand op;
public JDBCTxOp(JDBCStatementHelper helper, TxCommand op, SQLOptions options) {
super(helper, options);
this.op = op;
}
@Override
private <T> void executeDirect(ContextInternal ctx, AbstractJDBCAction<T> action, Handler<AsyncResult<T>> handler) {
getConnection(ctx, ar1 -> {
Future<T> fut = Future.future();
fut.setHandler(ar2 -> ctx.runOnContext(v -> handler.handle(ar2)));
if (ar1.succeeded()) {
JDBCConnectionImpl conn = (JDBCConnectionImpl) ar1.result();
Tracer tracer = ctx.owner().tracer();
Object trace;
if (tracer != null) {
trace = tracer.sendRequest(ctx.localContextData(), action);
@vietj
vietj / StatementBenchmarks.java
Created November 8, 2019 18:14 — forked from mp911de/StatementBenchmarks.java
R2DBC Postgres benchmarks
/*
* Copyright 2019 the original author or authors.
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Dear Committer:
The Eclipse Board of Directors approved changes to the Eclipse Intellectual
Property Policy on October 21, 2019. The most significant change relates to
how we will perform due diligence of leveraged Third Party Content (Section IV
B).
Motivation and Background:
The Eclipse IP Policy and Procedures date back to 2004. While we have made
Vertx vertx = Vertx.vertx();
HttpClient client = vertx.createHttpClient();
HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
Trace trace = Trace.create(req);
HttpClientRequest clientReq = client.get("some-uri", ar -> {
trace.close();
});
trace.propagateTo(clientReq);
clientReq.end();