Search in sources :

Example 1 with StatementBuilder

use of org.jdbi.v3.core.statement.StatementBuilder in project jdbi by jdbi.

the class Jdbi method open.

/**
 * Obtain a Handle to the data source wrapped by this Jdbi instance.
 * You own this expensive resource and are required to close it or
 * risk leaks.  Using a {@code try-with-resources} block is recommended.
 *
 * @return an open Handle instance
 * @see #useHandle(HandleConsumer)
 * @see #withHandle(HandleCallback)
 */
public Handle open() {
    try {
        final long start = System.nanoTime();
        Connection conn = connectionFactory.openConnection();
        final long stop = System.nanoTime();
        for (JdbiPlugin p : plugins) {
            conn = p.customizeConnection(conn);
        }
        StatementBuilder cache = statementBuilderFactory.get().createStatementBuilder(conn);
        Handle h = new Handle(config.createCopy(), transactionhandler.get(), cache, conn);
        for (JdbiPlugin p : plugins) {
            h = p.customizeHandle(h);
        }
        LOG.trace("Jdbi [{}] obtain handle [{}] in {}ms", this, h, (stop - start) / 1000000L);
        return h;
    } catch (SQLException e) {
        throw new ConnectionException(e);
    }
}
Also used : SQLException(java.sql.SQLException) JdbiPlugin(org.jdbi.v3.core.spi.JdbiPlugin) DefaultStatementBuilder(org.jdbi.v3.core.statement.DefaultStatementBuilder) StatementBuilder(org.jdbi.v3.core.statement.StatementBuilder) Connection(java.sql.Connection)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 JdbiPlugin (org.jdbi.v3.core.spi.JdbiPlugin)1 DefaultStatementBuilder (org.jdbi.v3.core.statement.DefaultStatementBuilder)1 StatementBuilder (org.jdbi.v3.core.statement.StatementBuilder)1