@Override public void compactInternally(final TableReference tableRef) { if (sqlDialect.family() == SQLDialect.POSTGRES) { run((Function<DSLContext, Void>) ctx -> { ctx.execute("VACUUM ANALYZE " + tableName(tableRef)); return null; }); } }
partialSql.substring(endIndex); try { ctx.execute(fullSql); } catch (DataAccessException e) { handleTableCreationException(e);
@Override public int execute(String sql, Object... bindings) throws DataAccessException { return delegate.execute(sql, bindings); }
@Override public int execute(String sql, QueryPart... parts) throws DataAccessException { return delegate.execute(sql, parts); }
@Override public int execute(SQL sql) throws DataAccessException { return delegate.execute(sql); }
DSLContext ctx = DSL.using(configuration); // As before, manually inlining arguments: ctx.execute("alter login \""+UserId+"\" with password='"+NewPassword+"'"); // Better, letting jOOQ do the string escaping for you, preventing // syntax errors and SQL injection vulnerabilities: ctx.execute("alter login {0} with password = {1}", DSL.name(UserId), // org.jooq.Name is rendered with quotes in most DBs DSL.inline(NewPassword) // org.jooq.Param is inlined as a (string) literal );
DSLContext ctx = DSL.using(...); ctx.execute("CREATE OR REPLACE VIEW my_view AS {0};", select(a, b).from(my_table).where(...) );
@Override public int execute(Query query) throws DataAccessException { return delegate.execute(query); }
@Override public int execute(String sql) throws DataAccessException { return delegate.execute(sql); }
partialSql.substring(endIndex); try { ctx.execute(fullSql); } catch (DataAccessException e) { kvs.handleTableCreationException(e);
public static JdbcTimestampBoundStore create(final JdbcKeyValueService kvs) { final JdbcTimestampBoundStore store = new JdbcTimestampBoundStore(kvs); kvs.run((Function<DSLContext, Void>) ctx -> { String partialSql = ctx.createTable(store.TABLE) .column(DUMMY_COLUMN, INTEGER.nullable(false)) .column(LATEST_TIMESTAMP, BIGINT.nullable(false)) .getSQL(); int endIndex = partialSql.lastIndexOf(')'); String fullSql = partialSql.substring(0, endIndex) + "," + " CONSTRAINT " + kvs.primaryKey(TIMESTAMP_TABLE) + " PRIMARY KEY (" + DUMMY_COLUMN.getName() + ")" + partialSql.substring(endIndex); try { ctx.execute(fullSql); } catch (DataAccessException e) { kvs.handleTableCreationException(e); } ctx.insertInto(store.TABLE, DUMMY_COLUMN, LATEST_TIMESTAMP) .select(ctx.select(DUMMY_COLUMN, LATEST_TIMESTAMP) .from(kvs.values(ctx, new RowN[] {(RowN) DSL.row(0, 10000L)}, "t", DUMMY_COLUMN.getName(), LATEST_TIMESTAMP.getName())) .whereNotExists(ctx.selectOne() .from(store.TABLE) .where(DUMMY_COLUMN.eq(0)))) .execute(); return null; }); return store; }
@Override public void createView(CreateViewFinalStep view) { LOGGER.info("Creating "+ view); // view.execute(); //See https://github.com/jOOQ/jOOQ/issues/4806 String sql = view.getSQL(ParamType.INLINED); dsl.execute(sql); }
/** * Execute insert statement * @param query to be executed * @return number of inserted records */ public int executeInsertStatement(InsertQuery query) { try (Connection connection = DbPool.getConnection()) { return PostgresDSL.using(connection, SQL_DIALECT).execute(query); } catch (Exception e) { return -1; } }
/** * Execute insert statement * @param query to be executed * @return number of inserted records */ public int executeInsertStatement(InsertQuery query) { try (Connection connection = DbPool.getConnection()) { return PostgresDSL.using(connection, SQL_DIALECT).execute(query); } catch (Exception e) { return -1; } }
/** * Execute insert statement * @param query to be executed * @return number of inserted records */ public int executeInsertStatement(InsertQuery query) { try (Connection connection = DbPool.getConnection()) { return PostgresDSL.using(connection, SQL_DIALECT).execute(query); } catch (Exception e) { return -1; } }
public int execute(String query) { try { return context.execute(query); } catch (Exception e) { context.close(); } try { reloadContexts(); } catch (IOException e) { e.printStackTrace(); } return execute(query); }
public int execute(Query query) { try { return context.execute(query); } catch (Exception e) { context.close(); } try { reloadContexts(); } catch (IOException e) { e.printStackTrace(); } return execute(query); }
@Override public final Results fetchMany() { ResultsImpl results = new ResultsImpl(configuration()); DSLContext ctx = configuration().dsl(); for (Query query : this) if (query instanceof ResultQuery) results.resultsOrRows.addAll(ctx.fetchMany((ResultQuery<?>) query).resultsOrRows()); else results.resultsOrRows.add(new ResultOrRowsImpl(ctx.execute(query))); return results; }
@Override public void createSubDocTypeTable(String collection, SubDocType type) throws ImplementationDbException { try { CollectionSchema collectionSchema = meta.getCollectionSchema(collection); if (!collectionSchema.existsSubDocTable(type)) { SubDocTable subDocTable = meta.getCollectionSchema(collection).prepareSubDocTable(type); getDsl().execute(getCreateSubDocTypeTableQuery(subDocTable, jooqConf)); getDsl().execute(getCreateIndexQuery(subDocTable, subDocTable.getDidColumn(), jooqConf)); } } catch (DataAccessException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
private void createIndexTableIfNotExists(DSLContext dsl) { boolean tableExists = dsl.select(DSL.count()) .from("information_schema.tables") .where( DSL.field("table_schema").eq(colSchema.getName()) .and(DSL.field("table_name").eq(toroIndexTable.getName())) ) .fetchOne(0, int.class) > 0; if (!tableExists) { Name tableName = DSL.name(colSchema.getName(), toroIndexTable.getName()); dsl.execute( databaseInterface.createIndexesTableStatement( dsl.render(tableName), toroIndexTable.nameColumn.getName(), toroIndexTable.indexColumn.getName() ) ); } }