use of org.jooq.impl.DefaultConnectionProvider in project jOOQ by jOOQ.
the class LicenseService method run.
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
/**
* This method encapsulates a transaction and initialises a jOOQ DSLcontext.
* This could also be achieved with Spring and DBCP for connection pooling.
*/
private String run(CtxRunnable runnable) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = getConnection("jdbc:postgresql:postgres", "postgres", System.getProperty("pw", "test"));
DSLContext ctx = DSL.using(new DefaultConfiguration().set(new DefaultConnectionProvider(c)).set(SQLDialect.POSTGRES).set(new Settings().withExecuteLogging(false)));
return runnable.run(ctx);
} catch (Exception e) {
e.printStackTrace();
Response.status(Status.SERVICE_UNAVAILABLE);
return "Service Unavailable - Please contact support@datageekery.com for help";
} finally {
JDBCUtils.safeClose(c);
}
}
use of org.jooq.impl.DefaultConnectionProvider in project jOOQ by jOOQ.
the class Example_4_4_ExecuteListener method run.
@Test
public void run() {
Tools.title("Displaying execution time using a custom ExecuteListener");
ExecuteListener listener = new CallbackExecuteListener().onStart(ctx -> {
ctx.data("time", System.nanoTime());
}).onEnd(ctx -> {
Long time = (Long) ctx.data("time");
System.out.println("Execution time : " + ((System.nanoTime() - time) / 1000 / 1000.0) + "ms. Query : " + ctx.sql());
});
DSL.using(new DefaultConfiguration().set(SQLDialect.H2).set(new DefaultConnectionProvider(connection())).set(new DefaultExecuteListenerProvider(listener))).select(AUTHOR.ID).from(AUTHOR).fetch();
}
Aggregations