From 03b694687dc351b02891550c43fbaa8f48a3f7d6 Mon Sep 17 00:00:00 2001
From: xuejiaming <326308290@qq.com>
Date: Thu, 13 Jun 2024 23:09:31 +0800
Subject: [PATCH] =?UTF-8?q?feat:=202.0.29=20[#232]=E4=BC=98=E5=8C=96naviga?=
=?UTF-8?q?te=E5=92=8CnavigateFlat=E7=9A=84=E9=94=99=E8=AF=AF=E7=94=A8?=
=?UTF-8?q?=E6=B3=95=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
samples/console-demo/pom.xml | 8 +-
samples/easy-query-solon-web/pom.xml | 6 +-
samples/multi-datasource-demo/pom.xml | 2 +-
samples/pom.xml | 4 +-
samples/solon-sharding-demo/pom.xml | 4 +-
samples/spring-sharding-demo/pom.xml | 4 +-
samples/springbootdemo/pom.xml | 6 +-
sql-core/pom.xml | 2 +-
.../query/core/annotation/NavigateFlat.java | 2 +
.../abstraction/AbstractClientQueryable.java | 35 ++--
.../include/EasyFlatIncludeProcessor.java | 4 +-
.../include/DefaultIncludeParserEngine.java | 7 +-
.../query/core/metadata/EntityMetadata.java | 2 +-
.../core/metadata/IncludeNavigateParams.java | 9 +
.../core/metadata/MappingPathTreeBuilder.java | 5 +-
.../core/metadata/NavigateFlatMetadata.java | 9 +-
sql-db-support/pom.xml | 2 +-
sql-db-support/sql-clickhouse/pom.xml | 2 +-
sql-db-support/sql-dameng/pom.xml | 2 +-
sql-db-support/sql-gauss-db/pom.xml | 2 +-
sql-db-support/sql-h2/pom.xml | 2 +-
sql-db-support/sql-kingbase-es/pom.xml | 2 +-
sql-db-support/sql-mssql/pom.xml | 2 +-
sql-db-support/sql-mysql/pom.xml | 2 +-
sql-db-support/sql-oracle/pom.xml | 2 +-
sql-db-support/sql-pgsql/pom.xml | 2 +-
sql-db-support/sql-sqlite/pom.xml | 2 +-
sql-extension/pom.xml | 2 +-
sql-extension/sql-cache/pom.xml | 2 +-
.../sql-kt-springboot-starter/pom.xml | 2 +-
sql-extension/sql-solon-plugin/pom.xml | 2 +-
sql-extension/sql-springboot-starter/pom.xml | 2 +-
sql-platform/pom.xml | 2 +-
sql-platform/sql-api-proxy/pom.xml | 2 +-
sql-platform/sql-api4j/pom.xml | 2 +-
sql-platform/sql-api4kt/pom.xml | 2 +-
sql-processor/pom.xml | 2 +-
sql-test/pom.xml | 4 +-
.../com/easy/query/test/RelationTest.java | 167 ++++++++++++------
.../test/dto/autodto/SchoolClassAOProp12.java | 40 +++++
.../test/dto/autodto/SchoolClassAOProp5.java | 14 +-
.../test/dto/autodto/SchoolStudentDTOxxx.java | 57 ++++++
.../entity/school/dto/SchoolClassDTO123.java | 43 +++++
44 files changed, 361 insertions(+), 117 deletions(-)
create mode 100644 sql-test/src/main/java/com/easy/query/test/dto/autodto/SchoolClassAOProp12.java
create mode 100644 sql-test/src/main/java/com/easy/query/test/dto/autodto/SchoolStudentDTOxxx.java
create mode 100644 sql-test/src/main/java/com/easy/query/test/entity/school/dto/SchoolClassDTO123.java
diff --git a/pom.xml b/pom.xml
index 614a2d2b2..0ef0b6fa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.easy-query
easy-query-all
pom
- 2.0.28
+ 2.0.29
easy-query
java object query distributed connector
https://github.com/xuejmnet/easy-query
diff --git a/samples/console-demo/pom.xml b/samples/console-demo/pom.xml
index 9fbc11231..60c4d2a31 100644
--- a/samples/console-demo/pom.xml
+++ b/samples/console-demo/pom.xml
@@ -6,7 +6,7 @@
com.easy-query
samples
- 2.0.28
+ 2.0.29
console-demo
@@ -22,21 +22,21 @@
com.easy-query
sql-mysql
- 2.0.28
+ 2.0.29
compile
com.easy-query
sql-processor
- 2.0.28
+ 2.0.29
compile
com.easy-query
sql-api-proxy
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/easy-query-solon-web/pom.xml b/samples/easy-query-solon-web/pom.xml
index 3fee29be8..1f72f9de1 100644
--- a/samples/easy-query-solon-web/pom.xml
+++ b/samples/easy-query-solon-web/pom.xml
@@ -6,7 +6,7 @@
com.easy-query
samples
- 2.0.28
+ 2.0.29
com.easy.query.solon
@@ -22,13 +22,13 @@
com.easy-query
sql-solon-plugin
- 2.0.28
+ 2.0.29
compile
com.easy-query
sql-processor
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/multi-datasource-demo/pom.xml b/samples/multi-datasource-demo/pom.xml
index f13699d90..fd50e5a5b 100644
--- a/samples/multi-datasource-demo/pom.xml
+++ b/samples/multi-datasource-demo/pom.xml
@@ -52,7 +52,7 @@
com.easy-query
sql-springboot-starter
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/pom.xml b/samples/pom.xml
index 8c7165e16..0503b12fd 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -5,7 +5,7 @@
easy-query-all
com.easy-query
- 2.0.28
+ 2.0.29
4.0.0
@@ -44,7 +44,7 @@
com.easy-query
sql-springboot-starter
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/solon-sharding-demo/pom.xml b/samples/solon-sharding-demo/pom.xml
index b9133e40a..a0df5d466 100644
--- a/samples/solon-sharding-demo/pom.xml
+++ b/samples/solon-sharding-demo/pom.xml
@@ -6,7 +6,7 @@
com.easy-query
samples
- 2.0.28
+ 2.0.29
com.easy.query
@@ -22,7 +22,7 @@
com.easy-query
sql-solon-plugin
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/spring-sharding-demo/pom.xml b/samples/spring-sharding-demo/pom.xml
index 651ed39e6..c7b8e67d1 100644
--- a/samples/spring-sharding-demo/pom.xml
+++ b/samples/spring-sharding-demo/pom.xml
@@ -55,13 +55,13 @@
com.easy-query
sql-processor
- 2.0.28
+ 2.0.29
compile
com.easy-query
sql-springboot-starter
- 2.0.28
+ 2.0.29
compile
diff --git a/samples/springbootdemo/pom.xml b/samples/springbootdemo/pom.xml
index e4bd0611d..fab397e53 100644
--- a/samples/springbootdemo/pom.xml
+++ b/samples/springbootdemo/pom.xml
@@ -62,13 +62,13 @@
com.easy-query
sql-processor
- 2.0.28
+ 2.0.29
compile
com.easy-query
sql-springboot-starter
- 2.0.28
+ 2.0.29
compile
@@ -90,7 +90,7 @@
com.easy-query
sql-cache
- 2.0.28
+ 2.0.29
compile
diff --git a/sql-core/pom.xml b/sql-core/pom.xml
index f53087426..bded610d0 100644
--- a/sql-core/pom.xml
+++ b/sql-core/pom.xml
@@ -5,7 +5,7 @@
easy-query-all
com.easy-query
- 2.0.28
+ 2.0.29
4.0.0
diff --git a/sql-core/src/main/java/com/easy/query/core/annotation/NavigateFlat.java b/sql-core/src/main/java/com/easy/query/core/annotation/NavigateFlat.java
index e79872008..3d4af30db 100644
--- a/sql-core/src/main/java/com/easy/query/core/annotation/NavigateFlat.java
+++ b/sql-core/src/main/java/com/easy/query/core/annotation/NavigateFlat.java
@@ -11,6 +11,8 @@
/**
* create time 2024/5/14 08:41
* entity对象表不会生效
+ * NavigateFlat支持获取穿透数据库对象到VO
+ * 如果NavigateFlat了一个VO又在同级对象下获取了这个VO的id那么将会报错
*
* @author xuejiaming
*/
diff --git a/sql-core/src/main/java/com/easy/query/core/basic/api/select/abstraction/AbstractClientQueryable.java b/sql-core/src/main/java/com/easy/query/core/basic/api/select/abstraction/AbstractClientQueryable.java
index 3bd7ee32c..e3164f9cc 100644
--- a/sql-core/src/main/java/com/easy/query/core/basic/api/select/abstraction/AbstractClientQueryable.java
+++ b/sql-core/src/main/java/com/easy/query/core/basic/api/select/abstraction/AbstractClientQueryable.java
@@ -675,7 +675,7 @@ protected void selectAutoInclude0(Class
resultClass, boolean replace) {
private void selectAutoIncludeFlat0(EntityMetadataManager entityMetadataManager, ClientQueryable> clientQueryable, EntityMetadata entityMetadata, EntityMetadata resultEntityMetadata) {
Collection navigateFlatMetadatas = resultEntityMetadata.getNavigateFlatMetadatas();
if (EasyCollectionUtil.isNotEmpty(navigateFlatMetadatas)) {
- MappingPathTreeNode mappingPathTreeRoot = getMappingPathTree(navigateFlatMetadatas);
+ MappingPathTreeNode mappingPathTreeRoot = getMappingPathTree(navigateFlatMetadatas, resultEntityMetadata);
selectAutoIncludeFlat0(entityMetadataManager, clientQueryable, entityMetadata, mappingPathTreeRoot, true);
// for (MappingPathTreeNode mappingPathTree : mappingPathTreeRoot.getChildren()) {
//
@@ -703,11 +703,16 @@ private void selectAutoIncludeJoin0(Class
resultClass, ClientQueryable<
}
}
- private MappingPathTreeNode getMappingPathTree(Collection navigateFlatMetadataCollection) {
+ private MappingPathTreeNode getMappingPathTree(Collection navigateFlatMetadataCollection, EntityMetadata navigateEntityMetadata) {
MappingPathTreeNode root = new MappingPathTreeNode("EASY-QUERY-ROOT");
for (NavigateFlatMetadata navigateFlatMetadata : navigateFlatMetadataCollection) {
String[] mappingPath = navigateFlatMetadata.getMappingPath();
- MappingPathTreeBuilder.insertPath(root, mappingPath, navigateFlatMetadata);
+ MappingPathTreeBuilder.insertPath(root, mappingPath, navigateFlatMetadata, path -> {
+ NavigateMetadata navigateOrNull = navigateEntityMetadata.getNavigateOrNull(path);
+ if (navigateOrNull != null) {
+ throw new EasyQueryInvalidOperationException(String.format("In the selectAutoInclude query, the relational propoerty [%s] of the class [%s] should appear in both @Navigate and @NavigateFlat.", path, EasyClassUtil.getSimpleName(navigateEntityMetadata.getEntityClass())));
+ }
+ });
}
return root;
// return EasyUtil.groupBy(navigateFlatMetadataCollection.stream(), o -> o.getMappingPath()[0])
@@ -784,7 +789,7 @@ private void selectAutoIncludeFlat0(EntityMetadataManager entityMetadataManager,
}
// List flatProperties = navigateFlatGroupProperty.values().collect(Collectors.toList());
//获取当前属性没有后续的属性了的 path最后一个是navigate那么就不可以是自定义dto只能是table
- boolean basicType = mappingPathTreeChild.getNavigateFlatMetadataList().stream().anyMatch(o -> !o.isBasicType()&&o.getMappingPath().length==mappingPathTreeChild.getDeep());
+ boolean basicType = mappingPathTreeChild.getNavigateFlatMetadataList().stream().anyMatch(o -> !o.isBasicType() && o.getMappingPath().length == mappingPathTreeChild.getDeep());
// List customPathTypes = mappingPathTreeChild.getChildren().stream().filter(o -> !o.getNavigateFlatMetadata().isBasicType() && !o.hasChildren()).collect(Collectors.toList());
// String navigatePropName = resultNavigateMetadata.isBasicType() ? resultNavigateMetadata.getMappingProp().split("//.")[0] : resultNavigateMetadata.getPropertyName();
@@ -796,6 +801,7 @@ private void selectAutoIncludeFlat0(EntityMetadataManager entityMetadataManager,
return o.anyBasicType() && o.allBasicType(size) && !o.hasChildren();
}).collect(Collectors.toList());
+
clientQueryable
.include(t -> {
if (first) {
@@ -812,18 +818,25 @@ private void selectAutoIncludeFlat0(EntityMetadataManager entityMetadataManager,
// }
selectAutoIncludeFlat0(entityMetadataManager, with, entityEntityMetadata, mappingPathTreeChild, false);
- if (basicType && mappingPathTreeChild.anyBasicType()) {
+ if (basicType) {
//检查是否存在自定义dto
- List navigateFlatMetadataList = mappingPathTreeChild.getNavigateFlatMetadataList().stream().filter(o -> !o.isBasicType()).collect(Collectors.toList());
- for (NavigateFlatMetadata navigateFlatMetadata : navigateFlatMetadataList) {
+ List navigateFlatMetadataList = mappingPathTreeChild.getNavigateFlatMetadataList().stream().filter(o -> !o.isBasicType() && o.getMappingPath().length == mappingPathTreeChild.getDeep() && Objects.equals(propertyName, o.getMappingPath()[o.getMappingPath().length - 1])).collect(Collectors.toList());
+ if (EasyCollectionUtil.isNotEmpty(navigateFlatMetadataList)) {
+ if (EasyCollectionUtil.isNotSingle(navigateFlatMetadataList)) {
+ throw new EasyQueryInvalidOperationException(String.format("In the class [%s], @NavigateFlat only allows one associated attribute: [%s] to exist.", EasyClassUtil.getSimpleName(entityMetadata.getEntityClass()), propertyName));
+ }
+ NavigateFlatMetadata navigateFlatMetadata = EasyCollectionUtil.first(navigateFlatMetadataList);
Class> navigatePropertyType = navigateFlatMetadata.getNavigatePropertyType();
- if (Objects.equals(propertyName, mappingPathTreeChild.getName()) && !Objects.equals(with.queryClass(), navigatePropertyType)) {
- throw new EasyQueryInvalidOperationException("NavigateFlat only supports basic types and database types");
+ //表示VO对象并不是最终的对象
+ if (mappingPathTreeChild.hasChildren()) {
+ if (EasyCollectionUtil.isEmpty(navigateFlatBasicProps) && !Objects.equals(with.queryClass(), navigatePropertyType)) {
+ throw new EasyQueryInvalidOperationException(String.format("@NavigateFlat cannot simultaneously include non-database related objects: [%s] and its object properties.", EasyClassUtil.getSimpleName(navigatePropertyType)));
+ }
}
+ t.getIncludeNavigateParams().setFlatClassType(navigatePropertyType);
}
- }
- if (!(basicType && mappingPathTreeChild.anyBasicType())) {
+ } else {
if (EasyCollectionUtil.isNotEmpty(navigateFlatBasicProps)) {
with = with.select(z -> {
for (MappingPathTreeNode navigateFlatBasicProp : navigateFlatBasicProps) {
diff --git a/sql-core/src/main/java/com/easy/query/core/expression/include/EasyFlatIncludeProcessor.java b/sql-core/src/main/java/com/easy/query/core/expression/include/EasyFlatIncludeProcessor.java
index 547e1dbad..d3f107b87 100644
--- a/sql-core/src/main/java/com/easy/query/core/expression/include/EasyFlatIncludeProcessor.java
+++ b/sql-core/src/main/java/com/easy/query/core/expression/include/EasyFlatIncludeProcessor.java
@@ -33,10 +33,10 @@ public EasyFlatIncludeProcessor(NavigateFlatMetadata navigateFlatMetadata, Inclu
super(includeParserResult, runtimeContext);
this.navigateFlatMetadata = navigateFlatMetadata;
//生成多个targetNaviaget在process的时候for调用
- initNavigateFlatGetter(includeParserResult.getFlatQueryEntityMetadata(),navigateFlatMetadata,runtimeContext);
+ initNavigateFlatGetter(includeParserResult,includeParserResult.getFlatQueryEntityMetadata(),navigateFlatMetadata,runtimeContext);
}
- public void initNavigateFlatGetter(EntityMetadata flatQueryEntityMetadata, NavigateFlatMetadata navigateFlatMetadata, QueryRuntimeContext runtimeContext){
+ public void initNavigateFlatGetter(IncludeParserResult includeParserResult,EntityMetadata flatQueryEntityMetadata, NavigateFlatMetadata navigateFlatMetadata, QueryRuntimeContext runtimeContext){
if(navigateFlatMetadata==null){
return;
}
diff --git a/sql-core/src/main/java/com/easy/query/core/expression/sql/include/DefaultIncludeParserEngine.java b/sql-core/src/main/java/com/easy/query/core/expression/sql/include/DefaultIncludeParserEngine.java
index bcd71518d..525784b1d 100644
--- a/sql-core/src/main/java/com/easy/query/core/expression/sql/include/DefaultIncludeParserEngine.java
+++ b/sql-core/src/main/java/com/easy/query/core/expression/sql/include/DefaultIncludeParserEngine.java
@@ -281,7 +281,8 @@ private void confirmNavigateProperty(boolean aliasEntity, ExpressionContext expr
includeParseContext.setIncludeQueryableExpression(() -> {
ClientQueryable> includeQueryable = includeQueryableExpression.apply();
EntityQueryExpressionBuilder sqlEntityExpressionBuilder = includeQueryable.getSQLEntityExpressionBuilder();
- includeQueryable.select(aliasNavigateMetadata.getNavigatePropertyType(), t -> {
+ Class> aliasClassType = includeParseContext.getIncludeNavigateParams().getFlatClassType() == null ? aliasNavigateMetadata.getNavigatePropertyType() : includeParseContext.getIncludeNavigateParams().getFlatClassType();
+ includeQueryable.select(aliasClassType, t -> {
t.columnAll();
EasySQLExpressionUtil.appendTargetExtraTargetProperty(selfNavigateMetadata, sqlEntityExpressionBuilder, t.getSQLNative(), t.getTable());
});
@@ -295,7 +296,9 @@ private void confirmNavigateProperty(boolean aliasEntity, ExpressionContext expr
includeParseContext.setIncludeQueryableExpression(() -> {
ClientQueryable> includeQueryable = includeQueryableExpression.apply();
EntityQueryExpressionBuilder sqlEntityExpressionBuilder = includeQueryable.getSQLEntityExpressionBuilder();
- return includeQueryable.select(aliasNavigateMetadata.getNavigatePropertyType(), t -> {
+ Class> aliasClassType = includeParseContext.getIncludeNavigateParams().getFlatClassType() == null ? aliasNavigateMetadata.getNavigatePropertyType() : includeParseContext.getIncludeNavigateParams().getFlatClassType();
+
+ return includeQueryable.select(aliasClassType, t -> {
columnIncludeExpression.getIncludeSelectorExpression().apply(t.getAsSelector());
EasySQLExpressionUtil.appendSelfExtraTargetProperty(sqlEntityExpressionBuilder, t.getSQLNative(), t.getTable());
EasySQLExpressionUtil.appendTargetExtraTargetProperty(selfNavigateMetadata, sqlEntityExpressionBuilder, t.getSQLNative(), t.getTable());
diff --git a/sql-core/src/main/java/com/easy/query/core/metadata/EntityMetadata.java b/sql-core/src/main/java/com/easy/query/core/metadata/EntityMetadata.java
index 3311a670d..6e50e93d3 100644
--- a/sql-core/src/main/java/com/easy/query/core/metadata/EntityMetadata.java
+++ b/sql-core/src/main/java/com/easy/query/core/metadata/EntityMetadata.java
@@ -376,7 +376,7 @@ private void createNavigateFlatMappingMetadata(NavigateFlat navigateFlat, Map beanGetter = fastBean.getBeanGetter(fastBeanProperty);
PropertySetterCaller