withRelations() {
+ return new RelationsBuilder<>(this);
+ }
+
+}
From f5c04c4bf7c7d3c2d2df8b781e9739269f364bdd Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:27:06 +0800
Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=E6=8A=BD=E8=B1=A1=E5=85=B3?=
=?UTF-8?q?=E8=81=94=E6=9F=A5=E8=AF=A2=E6=9E=84=E5=BB=BA=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../core/query/AbstractQueryBuilder.java | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/query/AbstractQueryBuilder.java
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/AbstractQueryBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/AbstractQueryBuilder.java
new file mode 100644
index 00000000..eacfc83a
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/AbstractQueryBuilder.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.query;
+
+import com.mybatisflex.core.BaseMapper;
+
+/**
+ * 抽象关联查询。
+ *
+ * @author 王帅
+ * @since 2023-08-08
+ */
+public abstract class AbstractQueryBuilder implements ChainQuery {
+
+ protected final MapperQueryChain delegate;
+
+ protected AbstractQueryBuilder(MapperQueryChain delegate) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * @return BaseMapper
+ */
+ protected BaseMapper baseMapper() {
+ return delegate.baseMapper();
+ }
+
+ /**
+ * @return QueryWrapper
+ */
+ protected QueryWrapper queryWrapper() {
+ return delegate.toQueryWrapper();
+ }
+
+}
From f91baac5cae25ff3e474f61ddb5dd3ae2a90f649 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:27:55 +0800
Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=E5=B1=9E=E6=80=A7=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2=E6=9E=84=E5=BB=BA=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mybatisflex/core/query/FieldsBuilder.java | 141 ++++++++++++++++++
1 file changed, 141 insertions(+)
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FieldsBuilder.java
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FieldsBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FieldsBuilder.java
new file mode 100644
index 00000000..1eb980da
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/FieldsBuilder.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.query;
+
+import com.mybatisflex.core.field.FieldQuery;
+import com.mybatisflex.core.field.FieldQueryManager;
+import com.mybatisflex.core.field.QueryBuilder;
+import com.mybatisflex.core.paginate.Page;
+import com.mybatisflex.core.util.FieldWrapper;
+import com.mybatisflex.core.util.LambdaGetter;
+import com.mybatisflex.core.util.LambdaUtil;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 使用 {@code Fields Query} 的方式进行关联查询。
+ *
+ * @author 王帅
+ * @since 2023-08-08
+ */
+public class FieldsBuilder extends AbstractQueryBuilder {
+
+ protected final Map fieldQueryMap;
+
+ public FieldsBuilder(MapperQueryChain delegate) {
+ super(delegate);
+ this.fieldQueryMap = new HashMap<>();
+ }
+
+ /**
+ * 设置属性对应的 {@code QueryWrapper} 查询。
+ *
+ * @param field 属性
+ * @param builder {@code QueryWrapper} 构建
+ * @param 属性类型
+ * @return 属性查询构建
+ */
+ public FieldsBuilder fieldMapping(LambdaGetter field, QueryBuilder builder) {
+ return fieldMapping(field, false, builder);
+ }
+
+ /**
+ * 设置属性对应的 {@code QueryWrapper} 查询。
+ *
+ * @param field 属性
+ * @param prevent 阻止对嵌套类属性的查询
+ * @param builder {@code QueryWrapper} 构建
+ * @param 属性类型
+ * @return 属性查询构建
+ */
+ public FieldsBuilder fieldMapping(LambdaGetter field, boolean prevent, QueryBuilder builder) {
+ String fieldName = LambdaUtil.getFieldName(field);
+ Class> entityClass = LambdaUtil.getImplClass(field);
+ FieldQuery fieldQuery = new FieldQuery();
+ fieldQuery.setPrevent(prevent);
+ fieldQuery.setFieldName(fieldName);
+ fieldQuery.setQueryBuilder(builder);
+ fieldQuery.setEntityClass(entityClass);
+ fieldQuery.setFieldWrapper(FieldWrapper.of(entityClass, fieldName));
+ this.fieldQueryMap.put(entityClass.getName() + '#' + fieldName, fieldQuery);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T one() {
+ List entities = Collections.singletonList(baseMapper().selectOneByQuery(queryWrapper()));
+ FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
+ return entities.get(0);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public R oneAs(Class asType) {
+ List entities = Collections.singletonList(baseMapper().selectOneByQueryAs(queryWrapper(), asType));
+ FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
+ return entities.get(0);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List list() {
+ List entities = baseMapper().selectListByQuery(queryWrapper());
+ FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
+ return entities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List listAs(Class asType) {
+ List entities = baseMapper().selectListByQueryAs(queryWrapper(), asType);
+ FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
+ return entities;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Page page(Page page) {
+ baseMapper().paginate(page, queryWrapper());
+ FieldQueryManager.queryFields(baseMapper(), page.getRecords(), fieldQueryMap);
+ return page;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Page pageAs(Page page, Class asType) {
+ baseMapper().paginateAs(page, queryWrapper(), asType);
+ FieldQueryManager.queryFields(baseMapper(), page.getRecords(), fieldQueryMap);
+ return page;
+ }
+
+}
From b6f3553c3faf79667c658247d61425c3f6fdc026 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:28:06 +0800
Subject: [PATCH 05/15] =?UTF-8?q?feat:=20Relation=20=E6=B3=A8=E8=A7=A3?=
=?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9E=84=E5=BB=BA=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../core/query/RelationsBuilder.java | 118 ++++++++++++++++++
1 file changed, 118 insertions(+)
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RelationsBuilder.java
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RelationsBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RelationsBuilder.java
new file mode 100644
index 00000000..50b00275
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/RelationsBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.query;
+
+import com.mybatisflex.core.paginate.Page;
+import com.mybatisflex.core.relation.RelationManager;
+
+import java.util.List;
+
+/**
+ * 使用 {@code Relations Query} 的方式进行关联查询。
+ *
+ * @author 王帅
+ * @since 2023-08-08
+ */
+public class RelationsBuilder extends AbstractQueryBuilder {
+
+ public RelationsBuilder(MapperQueryChain delegate) {
+ super(delegate);
+ }
+
+ /**
+ * 忽略查询部分 {@code Relations} 注解标记的属性。
+ *
+ * @param fields 属性
+ * @return {@code Relations} 查询构建
+ */
+ public RelationsBuilder ignoreRelations(String... fields) {
+ RelationManager.addIgnoreRelations(fields);
+ return this;
+ }
+
+ /**
+ * 设置父子关系查询中,默认的递归查询深度。
+ *
+ * @param maxDepth 查询深度
+ * @return {@code Relations} 查询构建
+ */
+ public RelationsBuilder maxDepth(int maxDepth) {
+ RelationManager.setMaxDepth(maxDepth);
+ return this;
+ }
+
+ /**
+ * 添加额外的 {@code Relations} 查询条件。
+ *
+ * @param key 键
+ * @param value 值
+ * @return {@code Relations} 查询构建
+ */
+ public RelationsBuilder extraConditionParam(String key, Object value) {
+ RelationManager.addExtraConditionParam(key, value);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T one() {
+ return baseMapper().selectOneWithRelationsByQuery(queryWrapper());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public R oneAs(Class asType) {
+ return baseMapper().selectOneWithRelationsByQueryAs(queryWrapper(), asType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List list() {
+ return baseMapper().selectListWithRelationsByQuery(queryWrapper());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List listAs(Class asType) {
+ return baseMapper().selectListWithRelationsByQueryAs(queryWrapper(), asType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Page page(Page page) {
+ return baseMapper().paginateWithRelations(page, queryWrapper());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Page pageAs(Page page, Class asType) {
+ return baseMapper().paginateWithRelationsAs(page, queryWrapper(), asType);
+ }
+
+}
From d7131f48e7f78c1e24c7cbc934e28d1cb49a37af Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:28:42 +0800
Subject: [PATCH 06/15] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20Relation?=
=?UTF-8?q?=20=E6=B3=A8=E8=A7=A3=E6=9F=A5=E8=AF=A2=E6=9E=84=E5=BB=BA?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../activerecord/query/RelationsQuery.java | 116 +++++-------------
1 file changed, 32 insertions(+), 84 deletions(-)
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/RelationsQuery.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/RelationsQuery.java
index fe11e913..86254ef6 100644
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/RelationsQuery.java
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/RelationsQuery.java
@@ -17,10 +17,7 @@
package com.mybatisflex.core.activerecord.query;
import com.mybatisflex.core.activerecord.Model;
-import com.mybatisflex.core.paginate.Page;
-import com.mybatisflex.core.relation.RelationManager;
-
-import java.util.List;
+import com.mybatisflex.core.query.RelationsBuilder;
/**
* 使用 {@code Relations Query} 的方式进行关联查询。
@@ -28,102 +25,53 @@ import java.util.List;
* @author 王帅
* @since 2023-07-30
*/
-public class RelationsQuery> extends AbstractQuery {
+public class RelationsQuery> extends RelationsBuilder {
public RelationsQuery(Model model) {
super(model);
}
- /**
- * 忽略查询部分 {@code Relations} 注解标记的属性。
- *
- * @param fields 属性
- * @return {@code Relations} 查询构建
- */
+ @Override
public RelationsQuery ignoreRelations(String... fields) {
- RelationManager.addIgnoreRelations(fields);
- return this;
- }
-
- /**
- * 设置父子关系查询中,默认的递归查询深度。
- *
- * @param maxDepth 查询深度
- * @return {@code Relations} 查询构建
- */
- public RelationsQuery maxDepth(int maxDepth) {
- RelationManager.setMaxDepth(maxDepth);
- return this;
- }
-
- /**
- * 添加额外的 {@code Relations} 查询条件。
- *
- * @param key 键
- * @param value 值
- * @return {@code Relations} 查询构建
- */
- public RelationsQuery extraConditionParam(String key, Object value) {
- RelationManager.addExtraConditionParam(key, value);
+ super.ignoreRelations(fields);
return this;
}
@Override
+ public RelationsQuery maxDepth(int maxDepth) {
+ super.maxDepth(maxDepth);
+ return this;
+ }
+
+ @Override
+ public RelationsQuery extraConditionParam(String key, Object value) {
+ super.extraConditionParam(key, value);
+ return this;
+ }
+
+ protected Object[] pkValues() {
+ // 懒加载,实际用到的时候才会生成 主键值
+ return ((Model) delegate).pkValues();
+ }
+
+ /**
+ * 根据主键查询一条数据。
+ *
+ * @return 一条数据
+ */
public T oneById() {
return baseMapper().selectOneWithRelationsById(pkValues());
}
- @Override
+ /**
+ * 根据主键查询一条数据,返回的数据为 asType 类型。
+ *
+ * @param asType 接收数据类型
+ * @param 接收数据类型
+ * @return 一条数据
+ */
public R oneByIdAs(Class asType) {
return baseMapper().selectOneWithRelationsByIdAs(pkValues(), asType);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public T one() {
- return baseMapper().selectOneWithRelationsByQuery(queryWrapper());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public R oneAs(Class asType) {
- return baseMapper().selectOneWithRelationsByQueryAs(queryWrapper(), asType);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List list() {
- return baseMapper().selectListWithRelationsByQuery(queryWrapper());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List listAs(Class asType) {
- return baseMapper().selectListWithRelationsByQueryAs(queryWrapper(), asType);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Page page(Page page) {
- return baseMapper().paginateWithRelations(page, queryWrapper());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Page pageAs(Page page, Class asType) {
- return baseMapper().paginateWithRelationsAs(page, queryWrapper(), asType);
- }
-
}
From d22d9498bfe8b2101c8d90a07631f8f08d1a03d4 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:28:56 +0800
Subject: [PATCH 07/15] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=B1=9E?=
=?UTF-8?q?=E6=80=A7=E6=9F=A5=E8=AF=A2=E6=9E=84=E5=BB=BA=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../core/activerecord/query/FieldsQuery.java | 129 ++++--------------
1 file changed, 24 insertions(+), 105 deletions(-)
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/FieldsQuery.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/FieldsQuery.java
index 0958d3af..3bc69815 100644
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/FieldsQuery.java
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/FieldsQuery.java
@@ -17,19 +17,14 @@
package com.mybatisflex.core.activerecord.query;
import com.mybatisflex.core.activerecord.Model;
-import com.mybatisflex.core.field.FieldQuery;
import com.mybatisflex.core.field.FieldQueryManager;
import com.mybatisflex.core.field.QueryBuilder;
import com.mybatisflex.core.mybatis.MappedStatementTypes;
-import com.mybatisflex.core.paginate.Page;
-import com.mybatisflex.core.util.FieldWrapper;
+import com.mybatisflex.core.query.FieldsBuilder;
import com.mybatisflex.core.util.LambdaGetter;
-import com.mybatisflex.core.util.LambdaUtil;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* 使用 {@code Fields Query} 的方式进行关联查询。
@@ -37,53 +32,34 @@ import java.util.Map;
* @author 王帅
* @since 2023-07-30
*/
-public class FieldsQuery> extends AbstractQuery {
-
- private final Map fieldQueryMap;
+public class FieldsQuery> extends FieldsBuilder {
public FieldsQuery(Model model) {
super(model);
- this.fieldQueryMap = new HashMap<>();
}
- /**
- * 设置属性对应的 {@code QueryWrapper} 查询。
- *
- * @param field 属性
- * @param builder {@code QueryWrapper} 构建
- * @param 属性类型
- * @return 属性查询构建
- */
+ @Override
public FieldsQuery fieldMapping(LambdaGetter field, QueryBuilder builder) {
- return fieldMapping(field, false, builder);
- }
-
- /**
- * 设置属性对应的 {@code QueryWrapper} 查询。
- *
- * @param field 属性
- * @param prevent 阻止对嵌套类属性的查询
- * @param builder {@code QueryWrapper} 构建
- * @param 属性类型
- * @return 属性查询构建
- */
- public FieldsQuery fieldMapping(LambdaGetter field, boolean prevent, QueryBuilder builder) {
- String fieldName = LambdaUtil.getFieldName(field);
- Class> entityClass = LambdaUtil.getImplClass(field);
- FieldQuery fieldQuery = new FieldQuery();
- fieldQuery.setPrevent(prevent);
- fieldQuery.setFieldName(fieldName);
- fieldQuery.setQueryBuilder(builder);
- fieldQuery.setEntityClass(entityClass);
- fieldQuery.setFieldWrapper(FieldWrapper.of(entityClass, fieldName));
- this.fieldQueryMap.put(entityClass.getName() + '#' + fieldName, fieldQuery);
+ super.fieldMapping(field, builder);
return this;
}
- /**
- * {@inheritDoc}
- */
@Override
+ public FieldsBuilder fieldMapping(LambdaGetter field, boolean prevent, QueryBuilder builder) {
+ super.fieldMapping(field, prevent, builder);
+ return this;
+ }
+
+ protected Object[] pkValues() {
+ // 懒加载,实际用到的时候才会生成 主键值
+ return ((Model) delegate).pkValues();
+ }
+
+ /**
+ * 根据主键查询一条数据。
+ *
+ * @return 一条数据
+ */
public T oneById() {
List entities = Collections.singletonList(baseMapper().selectOneById(pkValues()));
FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
@@ -91,9 +67,12 @@ public class FieldsQuery> extends AbstractQuery {
}
/**
- * {@inheritDoc}
+ * 根据主键查询一条数据,返回的数据为 asType 类型。
+ *
+ * @param asType 接收数据类型
+ * @param 接收数据类型
+ * @return 一条数据
*/
- @Override
@SuppressWarnings("unchecked")
public R oneByIdAs(Class asType) {
try {
@@ -106,64 +85,4 @@ public class FieldsQuery> extends AbstractQuery {
}
}
- /**
- * {@inheritDoc}
- */
- @Override
- public T one() {
- List entities = Collections.singletonList(baseMapper().selectOneByQuery(queryWrapper()));
- FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
- return entities.get(0);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public R oneAs(Class asType) {
- List entities = Collections.singletonList(baseMapper().selectOneByQueryAs(queryWrapper(), asType));
- FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
- return entities.get(0);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List list() {
- List entities = baseMapper().selectListByQuery(queryWrapper());
- FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
- return entities;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List listAs(Class asType) {
- List entities = baseMapper().selectListByQueryAs(queryWrapper(), asType);
- FieldQueryManager.queryFields(baseMapper(), entities, fieldQueryMap);
- return entities;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Page page(Page page) {
- baseMapper().paginate(page, queryWrapper());
- FieldQueryManager.queryFields(baseMapper(), page.getRecords(), fieldQueryMap);
- return page;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Page pageAs(Page page, Class asType) {
- baseMapper().paginateAs(page, queryWrapper(), asType);
- FieldQueryManager.queryFields(baseMapper(), page.getRecords(), fieldQueryMap);
- return page;
- }
-
}
From fc00f8e120945bdf6b55a07f3992a0a8726891f5 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:29:27 +0800
Subject: [PATCH 08/15] =?UTF-8?q?remove:=20=E5=88=A0=E9=99=A4=E5=BA=9F?=
=?UTF-8?q?=E5=BC=83=E7=9A=84=E7=B1=BB=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../activerecord/query/AbstractQuery.java | 160 ------------------
1 file changed, 160 deletions(-)
delete mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/AbstractQuery.java
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/AbstractQuery.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/AbstractQuery.java
deleted file mode 100644
index 3610dc87..00000000
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/activerecord/query/AbstractQuery.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mybatisflex.core.activerecord.query;
-
-import com.mybatisflex.core.BaseMapper;
-import com.mybatisflex.core.activerecord.Model;
-import com.mybatisflex.core.paginate.Page;
-import com.mybatisflex.core.query.QueryWrapper;
-
-import java.util.List;
-import java.util.Optional;
-
-/**
- * 抽象关联查询。
- *
- * @author 王帅
- * @since 2023-07-30
- */
-public abstract class AbstractQuery> {
-
- protected final Model model;
-
- protected AbstractQuery(Model model) {
- this.model = model;
- }
-
- /**
- * @return 主键
- */
- protected Object[] pkValues() {
- return model.pkValues();
- }
-
- /**
- * @return BaseMapper
- */
- protected BaseMapper baseMapper() {
- return model.baseMapper();
- }
-
- /**
- * @return QueryWrapper
- */
- protected QueryWrapper queryWrapper() {
- return model.queryWrapper();
- }
-
- /**
- * 根据实体类主键获取一条数据。
- *
- * @return 数据
- */
- public abstract T oneById();
-
- /**
- * 根据实体类主键获取一条数据,并封装为 {@link Optional} 返回。
- *
- * @return 数据
- */
- public Optional oneByIdOpt() {
- return Optional.ofNullable(oneById());
- }
-
- /**
- * 根据实体类主键获取一条数据。
- *
- * @return 数据
- */
- public abstract R oneByIdAs(Class asType);
-
- /**
- * 根据实体类主键获取一条数据,并封装为 {@link Optional} 返回。
- *
- * @return 数据
- */
- public Optional oneByIdAsOpt(Class asType) {
- return Optional.ofNullable(oneByIdAs(asType));
- }
-
- /**
- * 根据实体类构建的条件获取一条数据。
- *
- * @return 数据
- */
- public abstract T one();
-
- /**
- * 根据实体类构建的条件获取一条数据,返回的数据为 asType 类型。
- *
- * @param asType 接收数据类型
- * @return 数据
- */
- public abstract R oneAs(Class asType);
-
- /**
- * 根据实体类构建的条件获取一条数据,并封装为 {@link Optional} 返回。
- *
- * @return 数据
- */
- public Optional oneOpt() {
- return Optional.ofNullable(one());
- }
-
- /**
- * 根据实体类构建的条件获取一条数据,返回的数据为 asType 类型,并封装为 {@link Optional} 返回。
- *
- * @param asType 接收数据类型
- * @return 数据
- */
- public Optional oneOptAs(Class asType) {
- return Optional.ofNullable(oneAs(asType));
- }
-
- /**
- * 根据实体类构建的条件获取多条数据。
- *
- * @return 数据列表
- */
- public abstract List list();
-
- /**
- * 根据实体类构建的条件获取多条数据,返回的数据为 asType 类型。
- *
- * @param asType 接收数据类型
- * @return 数据列表
- */
- public abstract List listAs(Class asType);
-
- /**
- * 根据实体类构建的条件获取分页数据。
- *
- * @param page 分页对象
- * @return 分页数据
- */
- public abstract Page page(Page page);
-
- /**
- * 根据实体类构建的条件获取分页数据,返回的数据为 asType 类型。
- *
- * @param page 分页对象
- * @param asType 接收数据类型
- * @return 分页数据
- */
- public abstract Page pageAs(Page page, Class asType);
-
-}
From 6efad5d3cde24af346ae9a5a06ca19530c63901a Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 8 Aug 2023 16:29:47 +0800
Subject: [PATCH 09/15] =?UTF-8?q?style:=20=E6=A0=87=E8=AE=B0=E5=BA=9F?=
=?UTF-8?q?=E5=BC=83=E6=96=B9=E6=B3=95=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mybatisflex/core/query/QueryChain.java | 104 +++++++-----------
1 file changed, 41 insertions(+), 63 deletions(-)
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryChain.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryChain.java
index ded14920..5b14a0ee 100644
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryChain.java
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryChain.java
@@ -20,18 +20,17 @@ import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.table.TableInfo;
import com.mybatisflex.core.table.TableInfoFactory;
-import com.mybatisflex.core.util.SqlUtil;
import java.util.List;
import java.util.Optional;
/**
- * {@link QueryWrapper}链式调用。
+ * {@link QueryWrapper} 链式调用。
*
* @author 王帅
* @since 2023-07-22
*/
-public class QueryChain extends QueryWrapperAdapter> {
+public class QueryChain extends QueryWrapperAdapter> implements MapperQueryChain {
private final BaseMapper baseMapper;
@@ -43,98 +42,76 @@ public class QueryChain extends QueryWrapperAdapter> {
return new QueryChain<>(baseMapper);
}
- public long count() {
- return baseMapper.selectCountByQuery(this);
+ @Override
+ public BaseMapper baseMapper() {
+ return baseMapper;
}
- public boolean exists() {
- return SqlUtil.toBool(count());
- }
-
- public T one() {
- return baseMapper.selectOneByQuery(this);
- }
-
- public R oneAs(Class asType) {
- return baseMapper.selectOneByQueryAs(this, asType);
+ @Override
+ public QueryWrapper toQueryWrapper() {
+ return this;
}
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public T oneWithRelations() {
return baseMapper.selectOneWithRelationsByQuery(this);
}
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public R oneWithRelationsAs(Class asType) {
return baseMapper.selectOneWithRelationsByQueryAs(this, asType);
}
- public Optional oneOpt() {
- return Optional.ofNullable(baseMapper.selectOneByQuery(this));
- }
-
- public Optional oneAsOpt(Class asType) {
- return Optional.ofNullable(baseMapper.selectOneByQueryAs(this, asType));
- }
-
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public Optional oneWithRelationsOpt() {
return Optional.ofNullable(baseMapper.selectOneWithRelationsByQuery(this));
}
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public Optional oneWithRelationsAsOpt(Class asType) {
return Optional.ofNullable(baseMapper.selectOneWithRelationsByQueryAs(this, asType));
}
- public Object obj() {
- return baseMapper.selectObjectByQuery(this);
- }
-
- public R objAs(Class asType) {
- return baseMapper.selectObjectByQueryAs(this, asType);
- }
-
- public Optional objOpt() {
- return Optional.ofNullable(baseMapper.selectObjectByQuery(this));
- }
-
- public Optional objAsOpt(Class asType) {
- return Optional.ofNullable(baseMapper.selectObjectByQueryAs(this, asType));
- }
-
- public List objList() {
- return baseMapper.selectObjectListByQuery(this);
- }
-
- public List objListAs(Class asType) {
- return baseMapper.selectObjectListByQueryAs(this, asType);
- }
-
- public List list() {
- return baseMapper.selectListByQuery(this);
- }
-
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public List listWithRelations() {
return baseMapper.selectListWithRelationsByQuery(this);
}
- public List listAs(Class asType) {
- return baseMapper.selectListByQueryAs(this, asType);
- }
-
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public List listWithRelationsAs(Class asType) {
return baseMapper.selectListWithRelationsByQueryAs(this, asType);
}
- public Page page(Page page) {
- return baseMapper.paginate(page, this);
- }
-
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public Page pageWithRelations(Page page) {
return baseMapper.paginateWithRelations(page, this);
}
- public Page pageAs(Page page, Class asType) {
- return baseMapper.paginateAs(page, this, asType);
- }
-
+ /**
+ * @deprecated 该方法将在 1.6.0 版本移除
+ */
+ @Deprecated
public Page