Pg-async-driver is a non-blocking Java driver for PostgreSQL. The driver supports connection pooling, prepared statements, transactions and all standard SQL types.
Pg-async-driver is available on Maven Central.
<dependency>
<groupId>com.github.alaisi.pgasync</groupId>
<artifactId>pg-async-driver</artifactId>
<version>0.1</version>
</dependency>
ConnectionPool pool = ...;
pool.query("SELECT 'Hello world!' AS message", new ResultHandler() {
@Override
public void onResult(ResultSet result) {
System.out.println(result.get(0).getString("message"));
}
}, new ErrorHandler() {
@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});
Or with Java 8:
ConnectionPool pool = ...;
pool.query("SELECT 'Hello world!' AS message",
(result) -> System.out.println(result.get(0).getString("message")),
(error) -> error.printStackTrace() );
Connection pools are created with com.github.pgasync.ConnectionPoolBuilder
ConnectionPool pool = return new ConnectionPoolBuilder()
.database("db")
.username("user")
.password("pass")
.poolSize(20)
.build();
Each connection pool will start one IO thread used in communicating with PostgreSQL backend.
TODO
TODO