org.jooq.Query Java Examples
The following examples show how to use
org.jooq.Query.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserRoleDao.java From waltz with Apache License 2.0 | 6 votes |
public boolean updateRoles(String userName, Set<String> newRoles) { try { dsl.transaction(config -> { LOG.info("Removing existing roles for: " + userName); DSL.using(config) .delete(USER_ROLE) .where(USER_ROLE.USER_NAME.eq(userName)) .execute(); LOG.info("Inserting roles for " + userName + " / " + newRoles) ; DSLContext batcher = DSL.using(config); Set<Query> inserts = map(newRoles, r -> batcher .insertInto(USER_ROLE, USER_ROLE.USER_NAME, USER_ROLE.ROLE) .values(userName, r)); batcher.batch(inserts) .execute(); }); return true; } catch (Exception e) { return false; } }
Example #2
Source File: MetadataDao.java From fasten with Apache License 2.0 | 5 votes |
/** * Executes batch insert for 'edges' table. * * @param edges List of edges records to insert */ public void batchInsertEdges(List<EdgesRecord> edges) { Query batchQuery = context.insertInto(Edges.EDGES, Edges.EDGES.SOURCE_ID, Edges.EDGES.TARGET_ID, Edges.EDGES.METADATA) .values((Long) null, (Long) null, (JSONB) null) .onConflictOnConstraint(Keys.UNIQUE_SOURCE_TARGET).doUpdate() .set(Edges.EDGES.METADATA, JsonbDSL.concat(Edges.EDGES.METADATA, Edges.EDGES.as("excluded").METADATA)); var batchBind = context.batch(batchQuery); for (var edge : edges) { batchBind = batchBind.bind(edge.getSourceId(), edge.getTargetId(), edge.getMetadata()); } batchBind.execute(); }
Example #3
Source File: ReactiveRXGenericQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
protected Tuple rxGetBindValues(Query query) { ArrayList<Object> bindValues = new ArrayList<>(); for (Param<?> param : query.getParams().values()) { Object value = convertToDatabaseType(param); bindValues.add(value); } Tuple tuple = Tuple.tuple(); bindValues.forEach(tuple::addValue); return tuple; }
Example #4
Source File: AbstractReactiveQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
protected Tuple getBindValues(Query query) { ArrayTuple bindValues = new ArrayTuple(query.getParams().size()); for (Param<?> param : query.getParams().values()) { if (!param.isInline()) { Object value = convertToDatabaseType(param); bindValues.addValue(value); } } return bindValues; }
Example #5
Source File: AbstractReactiveQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
protected String toPreparedQuery(Query query) { if (SQLDialect.POSTGRES.supports(configuration().dialect())) { String namedQuery = query.getSQL(ParamType.NAMED); return namedQuery.replaceAll(pattern, "\\$"); } // mysql works with the standard string return query.getSQL(); }
Example #6
Source File: ReactiveClassicGenericQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
/** * Executes the given queryFunction and returns a <code>RowSet</code> * @param queryFunction the query to execute * @return the results, never null */ public Future<RowSet<Row>> executeAny(Function<DSLContext, ? extends Query> queryFunction) { Query query = createQuery(queryFunction); log(query); Promise<RowSet<Row>> rowPromise = Promise.promise(); delegate.preparedQuery(toPreparedQuery(query)).execute(getBindValues(query),rowPromise); return rowPromise.future(); }
Example #7
Source File: ReactiveCompletableFutureGenericQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
@Override public CompletableFuture<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) { Query query = createQuery(queryFunction); log(query); CompletableFuture<RowSet<Row>> rowFuture = new VertxCompletableFuture<>(vertx); delegate.preparedQuery(toPreparedQuery(query)).execute(getBindValues(query),createCompletionHandler(rowFuture)); return rowFuture.thenApply(SqlResult::rowCount); }
Example #8
Source File: ReactiveCompletableFutureGenericQueryExecutor.java From vertx-jooq with MIT License | 5 votes |
/** * Executes the given queryFunction and returns a <code>RowSet</code> * @param queryFunction the query to execute * @return the results, never null */ public CompletableFuture<RowSet<Row>> executeAny(Function<DSLContext, ? extends Query> queryFunction) { Query query = createQuery(queryFunction); log(query); CompletableFuture<RowSet<Row>> rowFuture = new VertxCompletableFuture<>(vertx); delegate.preparedQuery(toPreparedQuery(query)).execute(getBindValues(query),createCompletionHandler(rowFuture)); return rowFuture; }
Example #9
Source File: AppGroupEntryDao.java From waltz with Apache License 2.0 | 5 votes |
public int[] addApplications(long groupId, List<Long> applicationIds) { Query[] queries = applicationIds .stream() .map(id -> DSL.insertInto(APPLICATION_GROUP_ENTRY) .set(APPLICATION_GROUP_ENTRY.GROUP_ID, groupId) .set(APPLICATION_GROUP_ENTRY.APPLICATION_ID, id) .onDuplicateKeyIgnore()) .toArray(Query[]::new); return dsl.batch(queries).execute(); }
Example #10
Source File: AbstractQueryExecutor.java From vertx-jooq with MIT License | 4 votes |
protected <T extends Query> T createQuery(Function<DSLContext,T> queryFunction){ return queryFunction.apply(DSL.using(configuration())); }
Example #11
Source File: ReactiveRXGenericQueryExecutor.java From vertx-jooq with MIT License | 4 votes |
@Override public Single<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) { return executeAny(queryFunction).map(SqlResult::rowCount); }
Example #12
Source File: ReactiveRXGenericQueryExecutor.java From vertx-jooq with MIT License | 4 votes |
/** * Executes the given queryFunction and returns a <code>RowSet</code> * @param queryFunction the query to execute * @return the results, never null */ public Single<RowSet<io.vertx.reactivex.sqlclient.Row>> executeAny(Function<DSLContext, ? extends Query> queryFunction) { Query query = createQuery(queryFunction); log(query); return delegate.preparedQuery(toPreparedQuery(query)).rxExecute(rxGetBindValues(query)); }
Example #13
Source File: AbstractReactiveQueryExecutor.java From vertx-jooq with MIT License | 4 votes |
protected void log(Query query) { if (logger.isDebugEnabled()) { logger.debug("Executing {}", query.getSQL(ParamType.INLINED)); } }
Example #14
Source File: ReactiveClassicGenericQueryExecutor.java From vertx-jooq with MIT License | 4 votes |
@Override public Future<Integer> execute(Function<DSLContext, ? extends Query> queryFunction) { return executeAny(queryFunction).map(SqlResult::rowCount); }