本文整理汇总了Java中org.jooq.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于org.jooq包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchOne
import org.jooq.Query; //导入依赖的package包/类
@Override
public <P> void fetchOne(Query query, Function<JsonObject, P> mapper, Handler<AsyncResult<P>> resultHandler) {
getConnection().setHandler(sqlConnectionResult->{
if(sqlConnectionResult.succeeded()){
log("Fetch one", ()-> query.getSQL(ParamType.INLINED));
sqlConnectionResult.result().queryWithParams(
query.getSQL(),
getBindValues(query),
executeAndClose(rs -> {
if(rs.getRows().size() > 1){
throw new TooManyRowsException(String.format("Got more than one row: %d",rs.getRows().size()));
}
Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
return (optional.orElseGet(() -> null));
},
sqlConnectionResult.result(),
resultHandler)
);
}else{
resultHandler.handle(Future.failedFuture(sqlConnectionResult.cause()));
}
});
}
示例2: execute
import org.jooq.Query; //导入依赖的package包/类
@Override
public void execute(Query query, Handler<AsyncResult<Integer>> resultHandler) {
getConnection().setHandler(sqlConnectionResult->{
if(sqlConnectionResult.succeeded()){
log("Execute", ()-> query.getSQL(ParamType.INLINED));
sqlConnectionResult.result().updateWithParams(
query.getSQL(),
getBindValues(query),
executeAndClose(UpdateResult::getUpdated,
sqlConnectionResult.result(),
resultHandler)
);
}else{
resultHandler.handle(Future.failedFuture(sqlConnectionResult.cause()));
}
});
}
示例3: insertReturning
import org.jooq.Query; //导入依赖的package包/类
@Override
public void insertReturning(Query query, Handler<AsyncResult<Long>> resultHandler) {
getConnection().setHandler(sqlConnectionResult->{
if(sqlConnectionResult.succeeded()){
log("Insert Returning", ()-> query.getSQL(ParamType.INLINED));
sqlConnectionResult.result().update(
query.getSQL(ParamType.INLINED),
executeAndClose(res -> res.getKeys().getLong(0),
sqlConnectionResult.result(),
resultHandler)
);
}else{
resultHandler.handle(Future.failedFuture(sqlConnectionResult.cause()));
}
});
}
示例4: Execute
import org.jooq.Query; //导入依赖的package包/类
private Execute(
Connection connection,
QueryBuilder<? extends Query> queryBuilder
) {
super(
subscriber -> {
try (Query query = queryBuilder.build(connection)) {
setupUnsubscription(subscriber, query);
log.debug("Execute {}", query);
int i = query.execute();
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(i);
subscriber.onCompleted();
}
} catch (Throwable t) {
handleException(t, subscriber);
}
}
);
}
示例5: updateRoles
import org.jooq.Query; //导入依赖的package包/类
public boolean updateRoles(String userName, List<Role> 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);
List<Query> inserts = map(newRoles, r -> batcher
.insertInto(USER_ROLE, USER_ROLE.USER_NAME, USER_ROLE.ROLE)
.values(userName, r.name()));
batcher.batch(inserts)
.execute();
});
return true;
} catch (Exception e) {
return false;
}
}
示例6: write
import org.jooq.Query; //导入依赖的package包/类
public int[] write(List<ChangeLog> changeLogs) {
checkNotNull(changeLogs, "changeLogs must not be null");
Query[] queries = changeLogs
.stream()
.map(changeLog -> DSL.insertInto(CHANGE_LOG)
.set(CHANGE_LOG.MESSAGE, changeLog.message())
.set(CHANGE_LOG.PARENT_ID, changeLog.parentReference().id())
.set(CHANGE_LOG.PARENT_KIND, changeLog.parentReference().kind().name())
.set(CHANGE_LOG.USER_ID, changeLog.userId())
.set(CHANGE_LOG.SEVERITY, changeLog.severity().name())
.set(CHANGE_LOG.CHILD_KIND, changeLog.childKind().map(ck -> ck.name()).orElse(null))
.set(CHANGE_LOG.OPERATION, changeLog.operation().name())
.set(CHANGE_LOG.CREATED_AT, Timestamp.valueOf(changeLog.createdAt())))
.toArray(Query[]::new);
return dsl.batch(queries).execute();
}
示例7: addPermission
import org.jooq.Query; //导入依赖的package包/类
@Override
public void addPermission(final String username, final PermissionView permissionView)
throws FormException {
final Query query =
jooq.insertInto(USERS_PERMISSIONS,
USERS_PERMISSIONS.USER_ID,
USERS_PERMISSIONS.PERMISSION_ID,
USERS_PERMISSIONS.GROUP_SCOPE)
.values(getUserId(username),
JooqDaoUtils.getPermissionId(permissionView.getName()),
permissionView.isGroupScoped()
? JooqDaoUtils.getContestId(permissionView.getScope())
: null);
try {
query.execute();
} catch (DataIntegrityViolationException ex) {
throw new FormException().addError("permission", "unique");
}
}
示例8: addPermissionGroup
import org.jooq.Query; //导入依赖的package包/类
@Override
public void addPermissionGroup(final String username,
final PermissionGroupView permissionGroupView)
throws FormException {
final Query query =
jooq.insertInto(USERS_PERMISSION_GROUPS,
USERS_PERMISSION_GROUPS.USER_ID,
USERS_PERMISSION_GROUPS.PERMISSION_GROUP_ID,
USERS_PERMISSION_GROUPS.GROUP_SCOPE)
.values(getUserId(username),
JooqDaoUtils.getPermissionGroupId(permissionGroupView.getCode()),
permissionGroupView.isGroupScoped()
? JooqDaoUtils.getContestId(permissionGroupView.getScope())
: null);
try {
query.execute();
} catch (DataIntegrityViolationException ex) {
throw new FormException().addError("permission", "unique");
}
}
示例9: createPermissionGroup
import org.jooq.Query; //导入依赖的package包/类
@Override
public PermissionGroupView createPermissionGroup(final PermissionGroupView permissionGroupView)
throws FormException {
final Query query =
jooq.insertInto(PERMISSION_GROUPS,
PERMISSION_GROUPS.CODE,
PERMISSION_GROUPS.NAME,
PERMISSION_GROUPS.GROUP_SCOPED)
.values(permissionGroupView.getCode(),
permissionGroupView.getName(),
permissionGroupView.isGroupScoped());
try {
query.execute();
} catch (DataIntegrityViolationException ex) {
throw new FormException().addError("code", "unique");
}
return permissionGroupView;
}
示例10: fetch
import org.jooq.Query; //导入依赖的package包/类
@Override
public <P> Single<List<P>> fetch(Query query, java.util.function.Function<JsonObject, P> mapper){
return getConnection().flatMap(executeAndClose(sqlConnection ->
sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs ->
rs.getRows().stream().map(mapper).collect(Collectors.toList())
)));
}
示例11: fetchOne
import org.jooq.Query; //导入依赖的package包/类
@Override
public <P> Single<P> fetchOne(Query query, Function<JsonObject, P> mapper){
return getConnection().flatMap(executeAndClose(sqlConnection ->
sqlConnection.rxQueryWithParams(query.getSQL(), getBindValues(query)).map(rs -> {
Optional<P> optional = rs.getRows().stream().findFirst().map(mapper);
return optional.orElseGet(() -> null);
})));
}
示例12: execute
import org.jooq.Query; //导入依赖的package包/类
@Override
public Single<Integer> execute(Query query){
return getConnection()
.flatMap(executeAndClose(sqlConnection ->
sqlConnection
.rxUpdateWithParams(query.getSQL(), getBindValues(query))
.map(UpdateResult::getUpdated))
);
}
示例13: insertReturning
import org.jooq.Query; //导入依赖的package包/类
@Override
public Single<Long> insertReturning(Query query) {
return getConnection()
.flatMap(executeAndClose(sqlConnection ->
sqlConnection
.rxUpdateWithParams(query.getSQL(), getBindValues(query))
.map(updateResult -> updateResult.getKeys().getLong(0)))
);
}
示例14: getBindValues
import org.jooq.Query; //导入依赖的package包/类
private JsonArray getBindValues(Query query) {
JsonArray bindValues = new JsonArray();
for (Param<?> param : query.getParams().values()) {
Object value = convertToDatabaseType(param);
if(value==null){
bindValues.addNull();
}else{
bindValues.add(value);
}
}
return bindValues;
}
示例15: fetch
import org.jooq.Query; //导入依赖的package包/类
@Override
public <P> void fetch(Query query, Function<JsonObject, P> mapper, Handler<AsyncResult<List<P>>> resultHandler) {
getConnection().setHandler(sqlConnectionResult->{
if(sqlConnectionResult.succeeded()){
log("Fetch", ()-> query.getSQL(ParamType.INLINED));
sqlConnectionResult.result().queryWithParams(
query.getSQL(),
getBindValues(query),
executeAndClose(rs -> rs.getRows().stream().map(mapper).collect(Collectors.toList()), sqlConnectionResult.result(), resultHandler)
);
}else{
resultHandler.handle(Future.failedFuture(sqlConnectionResult.cause()));
}
});
}