public DefaultDSLContext(Connection connection, SQLDialect dialect, Settings settings) { this(new DefaultConfiguration(new DefaultConnectionProvider(connection), null, null, null, null, dialect, settings, null)); }
@Override public final void commit(TransactionContext ctx) { Deque<Savepoint> savepoints = savepoints(ctx.configuration()); Savepoint savepoint = savepoints.pop(); // [#3489] Explicitly release savepoints prior to commit if (savepoint != null && savepoint != UNSUPPORTED_SAVEPOINT && savepoint != IGNORED_SAVEPOINT) try { connection(ctx.configuration()).releaseSavepoint(savepoint); } // [#3537] Ignore those cases where the JDBC driver incompletely implements the API // See also http://stackoverflow.com/q/10667292/521799 catch (DataAccessException ignore) {} // This is the top-level transaction if (savepoints.isEmpty()) { connection(ctx.configuration()).commit(); brace(ctx.configuration(), false); } // Nested commits have no effect else { } }
/** * Return the SQL connection associated with a DSLContext * @param context * @return the connection, or null. */ public static Connection getConnection(DSLContext context) { ConnectionProvider provider = context.configuration().connectionProvider(); if (provider instanceof DefaultConnectionProvider) { return ((DefaultConnectionProvider) provider).acquire(); } else { return null; } }
private final boolean autoCommit(Configuration configuration) { Boolean autoCommit = (Boolean) configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_AUTOCOMMIT); if (autoCommit == null) { autoCommit = connection(configuration).getAutoCommit(); configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_AUTOCOMMIT, autoCommit); } return autoCommit; }
@Override public final void rollback(TransactionContext ctx) { Deque<Savepoint> savepoints = savepoints(ctx.configuration()); Savepoint savepoint = null; // [#3537] If something went wrong with the savepoints per se if (!savepoints.isEmpty()) savepoint = savepoints.pop(); try { if (savepoint == null || savepoint == UNSUPPORTED_SAVEPOINT) { connection(ctx.configuration()).rollback(); } // [#3955] ROLLBACK is only effective if an exception reaches the // top-level transaction. else if (savepoint == IGNORED_SAVEPOINT) { if (savepoints.isEmpty()) connection(ctx.configuration()).rollback(); } else { connection(ctx.configuration()).rollback(savepoint); } } finally { if (savepoints.isEmpty()) brace(ctx.configuration(), false); } }
public DefaultDSLContext(Connection connection, SQLDialect dialect, Settings settings) { this(new DefaultConfiguration(new DefaultConnectionProvider(connection), null, null, null, null, null, null, null, null, null, null, null, null, dialect, settings, null)); }
/** * Convenience method for {@link #set(ConnectionProvider)}, using a * {@link DefaultConnectionProvider}. */ public final Configuration set(Connection newConnection) { return set(new DefaultConnectionProvider(newConnection)); }
/** * Convenience method for {@link #derive(ConnectionProvider)}, using a * {@link DefaultConnectionProvider}. */ public final Configuration derive(Connection newConnection) { return derive(new DefaultConnectionProvider(newConnection)); }
@Override public final Configuration set(Connection newConnection) { return set(new DefaultConnectionProvider(newConnection)); }
public ConnectionOwnerDslContext(Connection connection, SQLDialect dialect) { this.connection = connection; this.delegate = DSL.using(new DefaultConnectionProvider(connection), dialect); }
@Override public final Configuration derive(Connection newConnection) { return derive(new DefaultConnectionProvider(newConnection)); }
public ConnectionOwnerDslContext(DataSource datasource, SQLDialect dialect) { try { this.connection = datasource.getConnection(); this.delegate = DSL.using(new DefaultConnectionProvider(connection), dialect); } catch (SQLException ex) { throw new UncheckedException(ex); } }
private final DefaultConnectionProvider connection(Configuration configuration) { DefaultConnectionProvider connectionWrapper = (DefaultConnectionProvider) configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION); if (connectionWrapper == null) { connectionWrapper = new DefaultConnectionProvider(connectionProvider.acquire()); configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION, connectionWrapper); } return connectionWrapper; }
/** * 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); } }
final ConnectionProvider connectionProvider = new DefaultConnectionProvider(connection); final SQLDialect sqlDialect = SQLDialect.valueOf(context.getString(CONF_SQL_DIALECT).toUpperCase(Locale.ENGLISH));
private static void initInternal(final Vertx vertx, final String name) { vertxRef = vertx; Fn.pool(CONFIGS, name, () -> Infix.init(Plugins.Infix.JOOQ, (config) -> { // Initialized client final Configuration configuration = new DefaultConfiguration(); configuration.set(SQLDialect.MYSQL_5_7); final ConnectionProvider provider = new DefaultConnectionProvider(HikariCpPool.getConnection( config.getJsonObject("provider") )); // Initialized default configuration configuration.set(provider); return configuration; }, JooqInfix.class)); }