diff --git a/hsweb-easy-orm-rdb/pom.xml b/hsweb-easy-orm-rdb/pom.xml
index e2fac1fb..f2175f58 100644
--- a/hsweb-easy-orm-rdb/pom.xml
+++ b/hsweb-easy-orm-rdb/pom.xml
@@ -95,9 +95,9 @@
- dev.miku
+ io.asyncer
r2dbc-mysql
- 0.8.2.RELEASE
+ 0.9.7
true
diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/ReactiveQuery.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/ReactiveQuery.java
index 2f3ff741..79ce1967 100644
--- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/ReactiveQuery.java
+++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/ReactiveQuery.java
@@ -31,4 +31,14 @@ public interface ReactiveQuery extends DSLQuery> {
* @return 如果未查询到结果将返回{@link Mono#empty()}
*/
Mono fetchOne();
+
+ /**
+ * 复制当前查询对象,在需要多次设置查询条件时,可以使用此方法复制一个新的查询对象
+ *
+ * @return 新的查询对象
+ * @since 4.1.3
+ */
+ default ReactiveQuery copy() {
+ return this;
+ }
}
diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultReactiveQuery.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultReactiveQuery.java
index 3023bf39..32739278 100644
--- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultReactiveQuery.java
+++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/defaults/DefaultReactiveQuery.java
@@ -41,78 +41,86 @@ public DefaultReactiveQuery(TableOrViewMetadata tableMetadata,
this.context = context;
}
+ @Override
+ public ReactiveQuery copy() {
+ DefaultReactiveQuery copy = new DefaultReactiveQuery<>(
+ tableMetadata, columnMapping, operator, wrapper, context);
+ copy.param = param.clone();
+ return copy;
+ }
+
@Override
public Flux fetch() {
return this
- .doFetch(operator.query(tableMetadata),
- "fetch",
- (_queryOperator) -> _queryOperator
- .context(param.getContext())
- .select(getSelectColumn())
- .where(param.getTerms())
- .orderBy(getSortOrder())
- .when(param.isPaging(), query -> query.paging(param.getPageIndex(), param.getPageSize()))
- .when(param.isForUpdate(), QueryOperator::forUpdate)
- .fetch(eventWrapper(tableMetadata, wrapper, executorType("reactive"), type("fetch")))
- .reactive())
- .contextWrite(context);
+ .doFetch(operator.query(tableMetadata),
+ "fetch",
+ (_queryOperator) -> _queryOperator
+ .context(param.getContext())
+ .select(getSelectColumn())
+ .where(param.getTerms())
+ .orderBy(getSortOrder())
+ .when(param.isPaging(), query -> query.paging(param.getPageIndex(), param.getPageSize()))
+ .when(param.isForUpdate(), QueryOperator::forUpdate)
+ .fetch(eventWrapper(tableMetadata, wrapper, executorType("reactive"), type("fetch")))
+ .reactive())
+ .contextWrite(context);
}
@Override
public Mono fetchOne() {
return this
- .doFetch(operator.query(tableMetadata),
- "fetchOne",
- (_queryOperator) -> _queryOperator
- .context(param.getContext())
- .select(getSelectColumn())
- .where(param.getTerms())
- .orderBy(getSortOrder())
- //.paging(0, 1)
- .when(param.isForUpdate(), QueryOperator::forUpdate)
- .fetch(eventWrapper(tableMetadata, wrapper, executorType("reactive"), type("fetchOne")))
- .reactive()
- .take(1))
- .contextWrite(context)
- .singleOrEmpty();
+ .doFetch(operator.query(tableMetadata),
+ "fetchOne",
+ (_queryOperator) -> _queryOperator
+ .context(param.getContext())
+ .select(getSelectColumn())
+ .where(param.getTerms())
+ .orderBy(getSortOrder())
+ //.paging(0, 1)
+ .when(param.isForUpdate(), QueryOperator::forUpdate)
+ .fetch(eventWrapper(tableMetadata, wrapper, executorType("reactive"), type("fetchOne")))
+ .reactive()
+ .take(1))
+ .contextWrite(context)
+ .singleOrEmpty();
}
private Flux doFetch(QueryOperator queryOperator, String type, Function> executor) {
DefaultReactiveResultHolder holder = new DefaultReactiveResultHolder();
tableMetadata
- .fireEvent(MappingEventTypes.select_before, eventContext ->
- eventContext.set(
- source(DefaultReactiveQuery.this),
- query(queryOperator),
- dml(operator),
- tableMetadata(tableMetadata),
- columnMapping(columnMapping),
- reactiveResultHolder.value(holder),
- queryOaram.value(param),
- executorType("reactive"),
- type(type)
- ));
+ .fireEvent(MappingEventTypes.select_before, eventContext ->
+ eventContext.set(
+ source(DefaultReactiveQuery.this),
+ query(queryOperator),
+ dml(operator),
+ tableMetadata(tableMetadata),
+ columnMapping(columnMapping),
+ reactiveResultHolder.value(holder),
+ queryOaram.value(param),
+ executorType("reactive"),
+ type(type)
+ ));
return holder
- .doBefore()
- .thenMany(Flux.defer(() -> executor.apply(queryOperator.clone())));
+ .doBefore()
+ .thenMany(Flux.defer(() -> executor.apply(queryOperator.clone())));
}
@Override
public Mono count() {
QueryOperator queryOperator = operator
- .query(tableMetadata)
- .select(count1().as("_total"));
+ .query(tableMetadata)
+ .select(count1().as("_total"));
return this
- .doFetch(queryOperator, "count", _opt -> _opt
- .context(param.getContext())
- .where(param.getTerms())
- .fetch(column("_total", Number.class::cast))
- .reactive()
- .map(Number::intValue)
- .reduce(Math::addExact)
- .switchIfEmpty(Mono.just(0)))
- .contextWrite(context)
- .singleOrEmpty();
+ .doFetch(queryOperator, "count", _opt -> _opt
+ .context(param.getContext())
+ .where(param.getTerms())
+ .fetch(column("_total", Number.class::cast))
+ .reactive()
+ .map(Number::intValue)
+ .reduce(Math::addExact)
+ .switchIfEmpty(Mono.just(0)))
+ .contextWrite(context)
+ .singleOrEmpty();
}
}