@Override public void configure(final Env env, final Config conf, final Binder binder) { Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name)); Supplier<NoSuchElementException> noSuchElement = () -> new NoSuchElementException( "DataSource missing: " + dskey); HikariDataSource ds = (HikariDataSource) env.get(dskey).orElseThrow(noSuchElement); Configuration jooqconf = new DefaultConfiguration(); ConnectionProvider dscp = new DataSourceConnectionProvider(ds); jooqconf.set(JDBCUtils.dialect(env.get(Key.get(String.class, Names.named(name + ".url"))) .orElseThrow(noSuchElement))); jooqconf.set(dscp); jooqconf.set(new DefaultTransactionProvider(dscp)); if (callback != null) { callback.accept(jooqconf, conf); } ServiceKey serviceKey = env.serviceKey(); serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(jooqconf)); Provider<DSLContext> dsl = () -> DSL.using(jooqconf); serviceKey.generate(DSLContext.class, name, k -> binder.bind(k).toProvider(dsl)); } }
/** * Safely close a result set and / or a statement. * <p> * This method will silently ignore if <code>resultSet</code> or * <code>statement</code> is <code>null</code>, or if * {@link ResultSet#close()} or {@link Statement#close()} throws an * exception. */ public static final void safeClose(ResultSet resultSet, PreparedStatement statement) { safeClose(resultSet); safeClose(statement); }
private static final SQLDialect dialect(String url, int majorVersion, int minorVersion) { SQLDialect dialect = dialect(url); // [#6814] If the driver can't report the version, fall back to the dialect family if (majorVersion == 0) return dialect; switch (dialect) { case POSTGRES: return postgresDialect(majorVersion, minorVersion); case MYSQL: return mysqlDialect(majorVersion); case FIREBIRD: return firebirdDialect(majorVersion); } return dialect; }
@Override final Byte get0(BindingGetResultSetContext<U> ctx) throws SQLException { return wasNull(ctx.resultSet(), Byte.valueOf(ctx.resultSet().getByte(ctx.index()))); }
/** * [#2534] Extract <code>byte[]</code> or <code>String</code> data from a * LOB, if the argument is a lob. */ private static final Object unlob(Object object) throws SQLException { if (object instanceof Blob) { Blob blob = (Blob) object; try { return blob.getBytes(1, (int) blob.length()); } finally { JDBCUtils.safeFree(blob); } } else if (object instanceof Clob) { Clob clob = (Clob) object; try { return clob.getSubString(1, (int) clob.length()); } finally { JDBCUtils.safeFree(clob); } } return object; } }
return (T) wasNull(stream, Boolean.valueOf(stream.readBoolean())); return (T) wasNull(stream, Byte.valueOf(stream.readByte())); safeFree(blob); return (T) wasNull(stream, Double.valueOf(stream.readDouble())); return (T) wasNull(stream, Float.valueOf(stream.readFloat())); return (T) wasNull(stream, Integer.valueOf(stream.readInt())); return (T) wasNull(stream, Long.valueOf(stream.readLong())); return (T) wasNull(stream, Short.valueOf(stream.readShort()));
private String driverClass(Jdbc j) { String result = j.getDriver(); if (result == null) { result = JDBCUtils.driver(j.getUrl()); log.info("Database", "Inferring driver " + result + " from URL " + j.getUrl()); } return result; }
@Override final Long get0(BindingGetResultSetContext<U> ctx) throws SQLException { return wasNull(ctx.resultSet(), Long.valueOf(ctx.resultSet().getLong(ctx.index()))); }
/** * Safely close a result set and / or a statement. * <p> * This method will silently ignore if <code>resultSet</code> or * <code>statement</code> is <code>null</code>, or if * {@link ResultSet#close()} or {@link Statement#close()} throws an * exception. */ public static final void safeClose(ResultSet resultSet, PreparedStatement statement) { safeClose(resultSet); safeClose(statement); }
@Override final Short get0(BindingGetResultSetContext<U> ctx) throws SQLException { return wasNull(ctx.resultSet(), Short.valueOf(ctx.resultSet().getShort(ctx.index()))); }
/** * Create an executor with a connection configured. * <p> * If you provide a JDBC connection to a jOOQ Configuration, jOOQ will use * that connection directly for creating statements. * <p> * This is a convenience constructor for * {@link #using(Connection, Settings)}, guessing the {@link SQLDialect} * using {@link JDBCUtils#dialect(Connection)} * * @param connection The connection to use with objects created from this * executor * @see DefaultConnectionProvider * @see JDBCUtils#dialect(Connection) */ public static DSLContext using(Connection connection) { return new DefaultDSLContext(connection, JDBCUtils.dialect(connection), null); }
@Override public final void close() { JDBCUtils.safeClose(rs); rs = null; isClosed = true; }
@Override final Boolean get0(BindingGetResultSetContext<U> ctx) throws SQLException { return wasNull(ctx.resultSet(), Boolean.valueOf(ctx.resultSet().getBoolean(ctx.index()))); }
@Override public final void get(BindingGetResultSetContext<String> ctx) throws SQLException { Clob clob = ctx.resultSet().getClob(ctx.index()); try { ctx.value(clob == null ? null : clob.getSubString(1, (int) clob.length())); } finally { JDBCUtils.safeFree(clob); } }
/** * Create an executor with a connection, a dialect and settings configured. * <p> * If you provide a JDBC connection to a jOOQ Configuration, jOOQ will use * that connection directly for creating statements. * <p> * This is a convenience constructor for * {@link #using(ConnectionProvider, SQLDialect, Settings)} using a * {@link DefaultConnectionProvider} and guessing the {@link SQLDialect} * using {@link JDBCUtils#dialect(Connection)} * * @param connection The connection to use with objects created from this * executor * @param settings The runtime settings to apply to objects created from * this executor * @see DefaultConnectionProvider * @see JDBCUtils#dialect(Connection) */ public static DSLContext using(Connection connection, Settings settings) { return new DefaultDSLContext(connection, JDBCUtils.dialect(connection), settings); }
@Override public final void close() { JDBCUtils.safeClose(rs); rs = null; isClosed = true; }