final PostgresConnectionProvider postgres = new PostgresConnectionProvider("localhost", 5432, params.getDbName(), params.getUser(), params.getPass()) private static DSLContext sql = DSL.using(postgres, SQLDialect.POSTGRES, settings); //execute some statements here sql.execute(...); //and don't forget to commit or the connection will not be returned to the pool PostgresConnectionProvider p = (PostgresConnectionProvider) sql.configuration().connectionProvider(); p.commit();
@Override public Configuration configuration() { return delegate.configuration(); }
@Override public /* final */ int getSQLType() { return getSQLType(DSL.using(dialect).configuration()); }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSequence(String escapedSchemaName, String seqName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CALL " + TorodbSchema.TORODB_SCHEMA + ".create_sequence(?,?)"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.setString(1, escapedSchemaName); ps.setString(2, seqName); ps.execute(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@Override public final SQLDialect getDialect() { if (dialect == null) { dialect = create().configuration().dialect(); } return dialect; }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSchema(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE SCHEMA \"" + escapedSchemaName + "\""; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") private void createSchema(DSLContext dsl, DatabaseInterface databaseInterface) throws SQLException { Connection c = dsl.configuration().connectionProvider().acquire(); try (PreparedStatement ps = c.prepareStatement(databaseInterface.createSchemaStatement(TORODB_SCHEMA))) { ps.executeUpdate(); } try (PreparedStatement ps = c.prepareStatement(databaseInterface.getCollectionsTable().getSQLCreationStatement(databaseInterface))) { ps.execute(); } finally { dsl.configuration().connectionProvider().release(c); } }
public MyCursorConnectionProvider( CursorId cursorId, DSLContext dsl, CollectionSchema colSchema, Connection connection, Projection projection) { this.cursorId = cursorId; this.configuration = dsl.configuration(); this.colSchema = colSchema; this.connection = connection; this.projection = projection; assert configuration.connectionProvider().acquire() == connection; }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSchema(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE DATABASE IF NOT EXISTS `" + escapedSchemaName + "`"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
/** * 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; } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createRootTable(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE TABLE \""+ escapedSchemaName + "\".root(" + "did int PRIMARY KEY DEFAULT nextval('\"" + escapedSchemaName + "\".root_seq')," + "sid int NOT NULL" + ") DISTRIBUTED BY (did)"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSequence(String escapedSchemaName, String seqName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE SEQUENCE " + "\""+ escapedSchemaName +"\".\"" + seqName + "\" " + "MINVALUE 0 START 0"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSchema(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE SCHEMA IF NOT EXISTS \"" + escapedSchemaName + "\""; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createStructuresTable(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE TABLE \"" + escapedSchemaName + "\".structures(" + "sid int PRIMARY KEY," + "_structure text NOT NULL" + ")"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createStructuresTable(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE TABLE \"" + escapedSchemaName + "\".structures(" + "sid int PRIMARY KEY," + "_structure jsonb NOT NULL" + ")"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createRootTable(String escapedSchemaName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CREATE TABLE \""+ escapedSchemaName + "\".root(" + "did int PRIMARY KEY DEFAULT nextval('\"" + escapedSchemaName + "\".root_seq')," + "sid int NOT NULL" + ")"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.executeUpdate(); } finally { getDsl().configuration().connectionProvider().release(c); } }
boolean requireUnsupportedSyntax() { if (dsl.configuration().settings().getParseUnsupportedSyntax() == ParseUnsupportedSyntax.FAIL) throw exception("Syntax not supported"); return true; }
private static int executeDeleteRoots( DSLContext dsl, CollectionSchema colSchema, Collection<Integer> dids, @Nonnull DatabaseInterface databaseInterface ) throws SQLException, RetryTransactionException { ConnectionProvider connectionProvider = dsl.configuration().connectionProvider(); Connection connection = connectionProvider.acquire(); try { Table<Record> rootTable = DSL.tableByName(colSchema.getName(), "root"); return delete(connection, colSchema, rootTable, dids, databaseInterface); } finally { connectionProvider.release(connection); } }
@Override public Company findCompanyUsingSimpleStaticStatement(Integer pid) { Configuration configuration = create.configuration().derive(staticStatementSettings); return DSL.using(configuration) .selectFrom(COMPANY) .where(COMPANY.PID.eq(pid)) .fetchOneInto(Company.class); }
@Override public RegisterEmployeeOutput callRegisterEmployee(String name, String surname, String email, BigDecimal salary, String departmentName, String companyName) { // very easy way how to call a stored procedure. Notice that RegisterEmployee class is generated by jooq... RegisterEmployeeOutput result = new RegisterEmployeeOutput(); RegisterEmployee output = Routines.registerEmployee(create.configuration(), name, surname, email, salary, departmentName, companyName); result.setCompanyPid(output.getCompanyId()); result.setDepartmentPid(output.getDepartmentId()); result.setEmployeePid(output.getEmployeeId()); return result; }