@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)); } }
/** * 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); }
/** * 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); }
/** * "Guess" the JDBC driver from a connection URL. * * @return The appropriate JDBC driver class or * <code>"java.sql.Driver"</code> if no driver class could be * derived from the URL. Never <code>null</code>. */ public static final String driver(String url) { switch (dialect(url).family()) { case CUBRID: return "cubrid.jdbc.driver.CUBRIDDriver"; case DERBY: return "org.apache.derby.jdbc.ClientDriver"; case FIREBIRD: return "org.firebirdsql.jdbc.FBDriver"; case H2: return "org.h2.Driver"; case HSQLDB: return "org.hsqldb.jdbcDriver"; case MARIADB: return "org.mariadb.jdbc.Driver"; case MYSQL: return "com.mysql.jdbc.Driver"; case POSTGRES: return "org.postgresql.Driver"; case SQLITE: return "org.sqlite.JDBC"; } return "java.sql.Driver"; }
result = dialect(url, majorVersion, minorVersion);
/** * 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) */ @Transition( name = "USING", args = "Connection" ) public static DSLContext using(Connection connection) { return new DefaultDSLContext(connection, JDBCUtils.dialect(connection), null); }
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; }
private Class<? extends Database> databaseClass(String url) { if (isBlank(url)) throw new GeneratorException("No JDBC URL configured."); Class<? extends Database> result = Databases.databaseClass(JDBCUtils.dialect(url)); log.info("Database", "Inferring database " + result.getName() + " from URL " + url); return result; }
/** * 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) */ @Transition( name = "USING", args = { "Connection", "Settings" } ) public static DSLContext using(Connection connection, Settings settings) { return new DefaultDSLContext(connection, JDBCUtils.dialect(connection), settings); }
protected DSLContext createDSLContext() { return DSL.using(store.getConnection(), JDBCUtils.dialect(store.getDatabaseUrl())); }
/** * Create an executor from a JDBC connection URL. * <p> * Clients must ensure connections are closed properly by calling * {@link DSLContext#close()} on the resulting {@link DSLContext}. For * example: * <p> * <code><pre> * // Auto-closing DSLContext instance to free resources * try (DSLContext ctx = DSL.using("jdbc:h2:~/test")) { * * // ... * } * </pre></code> * * @param url The connection URL. * @see DefaultConnectionProvider * @see JDBCUtils#dialect(String) */ public static DSLContext using(String url) { try { Connection connection = DriverManager.getConnection(url); return using(new DefaultConnectionProvider(connection, true), JDBCUtils.dialect(connection)); } catch (SQLException e) { throw Tools.translate("Error when initialising Connection", e); } }
/** * Create an executor from a JDBC connection URL. * <p> * Clients must ensure connections are closed properly by calling * {@link DSLContext#close()} on the resulting {@link DSLContext}. For * example: * <p> * <code><pre> * // Auto-closing DSLContext instance to free resources * try (DSLContext ctx = DSL.using("jdbc:h2:~/test", "sa", "")) { * * // ... * } * </pre></code> * * @param url The connection URL. * @param username The connection user name. * @param password The connection password. * @see DefaultConnectionProvider * @see JDBCUtils#dialect(String) */ public static DSLContext using(String url, String username, String password) { try { Connection connection = DriverManager.getConnection(url, username, password); return using(new DefaultConnectionProvider(connection, true), JDBCUtils.dialect(connection)); } catch (SQLException e) { throw Tools.translate("Error when initialising Connection", e); } }
/** * Create an executor from a JDBC connection URL. * <p> * Clients must ensure connections are closed properly by calling * {@link DSLContext#close()} on the resulting {@link DSLContext}. For * example: * <p> * <code><pre> * // Auto-closing DSLContext instance to free resources * try (DSLContext ctx = DSL.using("jdbc:h2:~/test", properties)) { * * // ... * } * </pre></code> * * @param url The connection URL. * @param properties The connection properties. * @see DefaultConnectionProvider * @see JDBCUtils#dialect(String) */ public static DSLContext using(String url, Properties properties) { try { Connection connection = DriverManager.getConnection(url, properties); return using(new DefaultConnectionProvider(connection, true), JDBCUtils.dialect(connection)); } catch (SQLException e) { throw Tools.translate("Error when initialising Connection", e); } }
DSLContext get(Connection conn) { return DSL.using(new DefaultConfiguration() .set(conn) .set(JDBCUtils.dialect(conn)) .set(settings) .set(listenerProvider)); } }
DSLContext get(Connection conn) { return DSL.using(new DefaultConfiguration() .set(conn) .set(JDBCUtils.dialect(conn)) .set(settings) .set(listenerProvider)); } }
DSLContext context(Connection conn) { return DSL.using(new DefaultConfiguration() .set(conn) .set(JDBCUtils.dialect(conn)) .set(settings) .set(listenerProvider)); }
final org.jooq.util.Database database = Databases.databaseClass(JDBCUtils.dialect(databaseConfig.getUrl())).newInstance();