From 1f6644db0087580cdec2e4d6ec14aad6e3a6a61b Mon Sep 17 00:00:00 2001 From: "tao.chen1" Date: Tue, 18 Apr 2023 11:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EALL=E3=80=81ROOT=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E9=80=89=E5=8F=96=E5=99=A8=EF=BC=8C=E4=BE=9B=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=80=85=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dorive-api/pom.xml | 2 +- dorive-coating/pom.xml | 2 +- dorive-core/pom.xml | 2 +- .../dorive/core/api/constant/Select.java | 27 ++++++++++++ .../core/impl/executor/ChainExecutor.java | 20 ++++----- .../core/impl/selector/RootSelector.java | 41 +++++++++++++++++++ dorive-event/pom.xml | 2 +- dorive-injection/pom.xml | 2 +- dorive-proxy/pom.xml | 2 +- dorive-ref/pom.xml | 2 +- dorive-spring-boot-starter/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Select.java create mode 100644 dorive-core/src/main/java/com/gitee/dorive/core/impl/selector/RootSelector.java diff --git a/dorive-api/pom.xml b/dorive-api/pom.xml index 9fe8d72b..71548f1a 100644 --- a/dorive-api/pom.xml +++ b/dorive-api/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-api diff --git a/dorive-coating/pom.xml b/dorive-coating/pom.xml index 4ced627d..7ca5ef2f 100644 --- a/dorive-coating/pom.xml +++ b/dorive-coating/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-coating diff --git a/dorive-core/pom.xml b/dorive-core/pom.xml index f3692fe0..354dfcc7 100644 --- a/dorive-core/pom.xml +++ b/dorive-core/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-core diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Select.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Select.java new file mode 100644 index 00000000..2daf51e7 --- /dev/null +++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Select.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.gitee.dorive.core.api.constant; + +import com.gitee.dorive.core.api.context.Selector; +import com.gitee.dorive.core.impl.selector.NameSelector; +import com.gitee.dorive.core.impl.selector.RootSelector; + +public interface Select { + Selector ALL = new NameSelector("*"); + Selector ROOT = new RootSelector(); +} diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/ChainExecutor.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/ChainExecutor.java index c6d77aba..9315f01c 100644 --- a/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/ChainExecutor.java +++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/ChainExecutor.java @@ -88,13 +88,13 @@ public class ChainExecutor extends AbstractExecutor implements EntityHandler { public int execute(Context context, Operation operation) { int expectedType = operation.getType(); + boolean isIncludeRoot = (expectedType & OperationType.INCLUDE_ROOT) == OperationType.INCLUDE_ROOT; + boolean isIgnoreRoot = (expectedType & OperationType.IGNORE_ROOT) == OperationType.IGNORE_ROOT; int realExpectedType = expectedType & OperationType.INSERT_OR_UPDATE_OR_DELETE; - int expectedIgnoreRoot = expectedType | OperationType.IGNORE_ROOT; - int expectedIncludeRoot = expectedType | OperationType.INCLUDE_ROOT; - boolean isInsertContext = (expectedType & OperationType.INSERT) == OperationType.INSERT; - boolean isIgnoreRoot = (expectedType & OperationType.IGNORE_ROOT) == OperationType.IGNORE_ROOT; - boolean isIncludeRoot = (expectedType & OperationType.INCLUDE_ROOT) == OperationType.INCLUDE_ROOT; + boolean isInsertContext = (realExpectedType & OperationType.INSERT) == OperationType.INSERT; + int expectedIncludeRoot = realExpectedType | OperationType.INCLUDE_ROOT; + int expectedIgnoreRoot = realExpectedType | OperationType.IGNORE_ROOT; Object rootEntity = operation.getEntity(); Assert.notNull(rootEntity, "The rootEntity cannot be null!"); @@ -106,19 +106,19 @@ public class ChainExecutor extends AbstractExecutor implements EntityHandler { Selector selector = context.getSelector(); int totalCount = 0; for (CommonRepository repository : delegateRepository.getOrderedRepositories()) { - boolean root = repository.isRoot(); - if (isIgnoreRoot && root) { + boolean isRoot = repository.isRoot(); + if (isIgnoreRoot && isRoot) { continue; } - boolean isMatch = selector.matches(context, repository) || (isIncludeRoot && root); + boolean isMatch = selector.matches(context, repository) || (isIncludeRoot && isRoot); boolean isAggregated = repository.isAggregated(); if (!isMatch && !isAggregated) { continue; } PropChain anchorPoint = repository.getAnchorPoint(); - Object targetEntity = root ? rootEntity : anchorPoint.getValue(rootEntity); + Object targetEntity = isRoot ? rootEntity : anchorPoint.getValue(rootEntity); if (targetEntity != null) { Collection collection; if (targetEntity instanceof Collection) { @@ -142,7 +142,7 @@ public class ChainExecutor extends AbstractExecutor implements EntityHandler { totalCount += repository.execute(context, newOperation); } else if (operable) { - if (root && realExpectedType == operationType) { + if (isRoot && realExpectedType == operationType) { totalCount += repository.execute(context, operation); } else { totalCount += doExecute(operationType, repository, context, entity); diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/selector/RootSelector.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/selector/RootSelector.java new file mode 100644 index 00000000..7252c2d3 --- /dev/null +++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/selector/RootSelector.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.gitee.dorive.core.impl.selector; + +import com.gitee.dorive.core.api.context.Context; +import com.gitee.dorive.core.repository.CommonRepository; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = false) +public class RootSelector extends AbstractSelector { + + @Override + public boolean matches(Context context, CommonRepository repository) { + return repository.isRoot(); + } + + @Override + public List selectColumns(Context context, CommonRepository repository) { + return null; + } + +} diff --git a/dorive-event/pom.xml b/dorive-event/pom.xml index d21af2c5..9c015120 100644 --- a/dorive-event/pom.xml +++ b/dorive-event/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-event diff --git a/dorive-injection/pom.xml b/dorive-injection/pom.xml index 0652a57e..24f2c76d 100644 --- a/dorive-injection/pom.xml +++ b/dorive-injection/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-injection diff --git a/dorive-proxy/pom.xml b/dorive-proxy/pom.xml index 1dd33e7b..ab21722e 100644 --- a/dorive-proxy/pom.xml +++ b/dorive-proxy/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-proxy diff --git a/dorive-ref/pom.xml b/dorive-ref/pom.xml index 59abf3a0..6c61fdfd 100644 --- a/dorive-ref/pom.xml +++ b/dorive-ref/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-ref diff --git a/dorive-spring-boot-starter/pom.xml b/dorive-spring-boot-starter/pom.xml index 57015d37..2ef45530 100644 --- a/dorive-spring-boot-starter/pom.xml +++ b/dorive-spring-boot-starter/pom.xml @@ -6,7 +6,7 @@ com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 dorive-spring-boot-starter diff --git a/pom.xml b/pom.xml index 39f7d1bc..cb448d0a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.digital-engine dorive - 3.3.2 + 3.3.3 pom -- Gitee