diff --git a/README.md b/README.md
index 7d4a7110dfb4768da10a8c12ca118932df31ed80..8f8d930e18e6ffe63b81b7bf3950059eec4de736 100644
--- a/README.md
+++ b/README.md
@@ -1,48 +1,64 @@
## Spring Domain
- 轻量级领域驱动框架。
+轻量级领域驱动框架。
-- **支持实体和数据库表联动,同步增、删、改。**
-- **支持通过简单对象查询实体,而无需考虑字段所属表结构。**
-- **支持实体继承,并根据类型进行动态级联查询。**
+- **实现以关系数据库为基础的仓储(Repository)**
+
+- **实现领域事件通知机制**
+
+- **实现通过防腐对象查询数据聚合**
-## 什么是领域驱动?
+## SmartUI模式
- 在讨论什么是领域驱动之前,让我们思考一下什么是需求驱动。
+**以UI界面驱动数据库设计,再以数据库设计驱动代码开发的模式,称为“SmartUI模式”。**
-## 需求驱动
+**优点:**
- 从字面来理解,就是产品经理提需求,开发工程师按照需求,开展设计与编码工作。开发工程师一般先设计表结构,再通过逆向工程生成映射对象。映射对象只包含业务字段,不包含业务方法,业务逻辑都统一放在Service层。这是典型的”失血模式“。
+- 效率高,能在短时间内实现简单的应用程序。
- 需求驱动的特点:
+- 对开发人员的要求低,几乎不需要培训。
-- 基本不需要复杂的设计,开发简单,可以做到快速开发和上线。
-- 设计、编码与需求耦合度高,无法应对更复杂的业务场景。
+- 有时可以克服需求分析上的不足,只需要满足原型即可。
+- 程序之间独立性高,可以相对准确地安排小的交付周期。
-## 领域驱动
+- 能够便捷地在关系数据库上构建应用。
+
+- 通过UI界面,能够大致了解后台的逻辑。
+
+**缺点:**
+
+- 应用开发,无法脱离数据库。
- 同样是产品经理提需求,开发工程师按照需求,开展设计与编码工作。不过,在设计之前,开发工程师需要思考以下几个问题:
+- 没有对业务行为的提炼与复用,每次遇到相似的业务需求时,都必须重新开发。
-- 需求所属的业务领域是什么?
-- 该业务领域是否存在通用的数据模型?
-- 该数据模型是否存在具体的业务行为?
-- 该业务领域是否存在细分的子业务领域?
-- 该子业务领域中,数据模型的业务行为是否会发生变化?
+- 功能迭代有一定局限性,难以拓展与重构。
+
+- 面对复杂的功能,无所适从,只能做简单地修改,无法实现更加丰富的功能。
+
+
+## 领域驱动
- 从以上几个问题,隐约能够嗅到“面向对象编程”的味道。在领域驱动设计理念中,上述数据模型被称为“领域模型”。
+**以业务核心驱动模型设计,再以模型设计驱动代码开发的方式,称为领域驱动。**
- 开发工程师一般先设计实体类(Java对象),再配置实体类和数据库表的映射关系。实体类包含业务字段,也包含业务方法,业务方法可以被子类重写。这是典型的“充血模式”。
+**优点:**
- 领域模型的优势:
+- 领域模型是业务知识的高度概括,容易在产品、开发、测试人员之间进行传播。
+
+- 不强依赖于数据库,容易与不同的存储引擎进行集成。
+
+- 领域模型通用性强,容易在不同的业务场景中复用。
+
+- 实现复杂的功能比较容易,可拓展性强。
+
+- 在战略层面,能借用领域模型,进行业务架构的顶层设计。
-- 与现实世界中的概念相似,容易被产品经理、前端工程师、后端工程师、测试工程师所理解。
+**缺点:**
-- 允许多层嵌套,数据结构高度内聚。
+- 要求开发人员掌握一定的业务知识。
-- 具有面向对象编程的特性,支持在不同的业务领域,发生不同的业务行为。
+- 要求开发人员能够与业务人员进行充分的交流。
- 领域模型的劣势:
+- 要求开发人员能够将业务知识融入到模型的开发当中。
-- 要求开发工程师对业务十分熟悉,最好是领域专家。
-- 要求开发工程师理解面向对象编程,并掌握常见的设计模式。
\ No newline at end of file
+- 初期的领域模型,可能需要在后续迭代中,不断演进。
diff --git a/spring-domain-event/pom.xml b/dorive-coating/pom.xml
similarity index 75%
rename from spring-domain-event/pom.xml
rename to dorive-coating/pom.xml
index 81398f6b49251ebef7f51d04c3e03b8fcb3146dc..f78022c26efc37f3fa1a76139024879d00ff42a9 100644
--- a/spring-domain-event/pom.xml
+++ b/dorive-coating/pom.xml
@@ -5,15 +5,14 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-domain-event
-
+ dorive-coating
com.gitee.digital-engine
- spring-domain-core
+ dorive-event
${project.version}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Coating.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Coating.java
new file mode 100644
index 0000000000000000000000000000000000000000..49ab4ae92cbe5a35f3a3e6ff08e616074901b255
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Coating.java
@@ -0,0 +1,32 @@
+/*
+ * 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.coating.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Coating {
+ Class> qualifier() default Object.class;
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/CoatingScan.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/CoatingScan.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5b6e65da97fb0f97d4beab51a3759101dcd2e2e
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/CoatingScan.java
@@ -0,0 +1,32 @@
+/*
+ * 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.coating.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface CoatingScan {
+ String[] value() default {};
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Property.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Property.java
new file mode 100644
index 0000000000000000000000000000000000000000..d10a956ed14c713781b53309635009375b8991a1
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/annotation/Property.java
@@ -0,0 +1,40 @@
+/*
+ * 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.coating.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Property {
+
+ String accessPath() default "";
+
+ String alias() default "";
+
+ String operator() default "=";
+
+ boolean ignore() default false;
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/api/CoatingRepository.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/api/CoatingRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..b640e49c9a318912b40eec4e025f06e56daedcdd
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/api/CoatingRepository.java
@@ -0,0 +1,30 @@
+/*
+ * 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.coating.api;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Page;
+
+import java.util.List;
+
+public interface CoatingRepository {
+
+ List selectByCoating(BoundedContext boundedContext, Object coatingObject);
+
+ Page selectPageByCoating(BoundedContext boundedContext, Object coatingObject);
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/api/ExampleBuilder.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/api/ExampleBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..67cbd3db80e77ca591d00baf1250d3680ed037e6
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/api/ExampleBuilder.java
@@ -0,0 +1,26 @@
+/*
+ * 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.coating.api;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Example;
+
+public interface ExampleBuilder {
+
+ Example buildExample(BoundedContext boundedContext, Object coatingObject);
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/CoatingWrapper.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/CoatingWrapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..1610f686d38fb724f4d82862e8cfd9ff0cd8114f
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/CoatingWrapper.java
@@ -0,0 +1,32 @@
+/*
+ * 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.coating.entity;
+
+import com.gitee.dorive.coating.entity.definition.CoatingDefinition;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+public class CoatingWrapper {
+ private CoatingDefinition coatingDefinition;
+ private List repositoryWrappers;
+ private List reversedRepositoryWrappers;
+ private SpecificProperties specificProperties;
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/MergedRepository.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/MergedRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..01fcf19422785049c24ac0b965fc7a77fd9fd763
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/MergedRepository.java
@@ -0,0 +1,31 @@
+/*
+ * 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.coating.entity;
+
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class MergedRepository {
+ private String lastAccessPath;
+ private String absoluteAccessPath;
+ private boolean merged;
+ private ConfiguredRepository definedRepository;
+ private ConfiguredRepository configuredRepository;
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/PropertyWrapper.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/PropertyWrapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..2254e0c129ecdf8d8d4e7e0a2706c676aa57d0e7
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/PropertyWrapper.java
@@ -0,0 +1,29 @@
+/*
+ * 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.coating.entity;
+
+import com.gitee.dorive.coating.entity.definition.PropertyDefinition;
+import com.gitee.dorive.core.entity.Property;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class PropertyWrapper {
+ private Property property;
+ private PropertyDefinition propertyDefinition;
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/RepositoryWrapper.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/RepositoryWrapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..8e1d0c6b2231e0566ea3c9e5ceae5a0300409b94
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/RepositoryWrapper.java
@@ -0,0 +1,65 @@
+/*
+ * 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.coating.entity;
+
+import com.gitee.dorive.coating.entity.definition.PropertyDefinition;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.Property;
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.entity.executor.Criterion;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.impl.binder.ContextBinder;
+import com.gitee.dorive.core.impl.resolver.BinderResolver;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+public class RepositoryWrapper {
+
+ private MergedRepository mergedRepository;
+ private List collectedPropertyWrappers;
+
+ public Example newExampleByCoating(BoundedContext boundedContext, Object coatingObject) {
+ Example example = new Example();
+ for (PropertyWrapper propertyWrapper : collectedPropertyWrappers) {
+ Property property = propertyWrapper.getProperty();
+ Object fieldValue = property.getFieldValue(coatingObject);
+ if (fieldValue != null) {
+ PropertyDefinition propertyDefinition = propertyWrapper.getPropertyDefinition();
+ String alias = propertyDefinition.getAlias();
+ String operator = propertyDefinition.getOperator();
+ example.addCriterion(new Criterion(alias, operator, fieldValue));
+ }
+ }
+ ConfiguredRepository definedRepository = mergedRepository.getDefinedRepository();
+ BinderResolver binderResolver = definedRepository.getBinderResolver();
+ for (ContextBinder contextBinder : binderResolver.getContextBinders()) {
+ Object boundValue = contextBinder.getBoundValue(boundedContext, null);
+ if (boundValue != null) {
+ BindingDefinition bindingDefinition = contextBinder.getBindingDefinition();
+ String alias = bindingDefinition.getAlias();
+ example.eq(alias, boundValue);
+ }
+ }
+ return example;
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/SpecificProperties.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/SpecificProperties.java
new file mode 100644
index 0000000000000000000000000000000000000000..93256c7afbaa8612ef9d43c8dc354f64a52e9256
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/SpecificProperties.java
@@ -0,0 +1,89 @@
+/*
+ * 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.coating.entity;
+
+import cn.hutool.core.convert.Convert;
+import com.gitee.dorive.core.api.constant.Order;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.util.StringUtils;
+import lombok.Data;
+
+@Data
+public class SpecificProperties {
+
+ private PropertyWrapper orderByAscProperty;
+ private PropertyWrapper orderByDescProperty;
+ private PropertyWrapper pageNumProperty;
+ private PropertyWrapper pageSizeProperty;
+
+ public boolean addProperty(String fieldName, PropertyWrapper propertyWrapper) {
+ if ("orderByAsc".equals(fieldName)) {
+ orderByAscProperty = propertyWrapper;
+ return true;
+
+ } else if ("orderByDesc".equals(fieldName)) {
+ orderByDescProperty = propertyWrapper;
+ return true;
+
+ } else if ("pageNum".equals(fieldName)) {
+ pageNumProperty = propertyWrapper;
+ return true;
+
+ } else if ("pageSize".equals(fieldName)) {
+ pageSizeProperty = propertyWrapper;
+ return true;
+ }
+ return false;
+ }
+
+ public OrderBy getOrderBy(Object coatingObject) {
+ if (orderByAscProperty != null) {
+ Object orderByAsc = orderByAscProperty.getProperty().getFieldValue(coatingObject);
+ if (orderByAsc != null) {
+ String[] columns = StringUtils.toStringArray(orderByAsc);
+ if (columns != null && columns.length > 0) {
+ return new OrderBy(columns, Order.ASC);
+ }
+ }
+ }
+ if (orderByDescProperty != null) {
+ Object orderByDesc = orderByDescProperty.getProperty().getFieldValue(coatingObject);
+ if (orderByDesc != null) {
+ String[] columns = StringUtils.toStringArray(orderByDesc);
+ if (columns != null && columns.length > 0) {
+ return new OrderBy(columns, Order.DESC);
+ }
+ }
+ }
+ return null;
+ }
+
+ public Page getPage(Object coatingObject) {
+ if (pageNumProperty != null && pageSizeProperty != null) {
+ Object pageNum = pageNumProperty.getProperty().getFieldValue(coatingObject);
+ Object pageSize = pageSizeProperty.getProperty().getFieldValue(coatingObject);
+ if (pageNum != null && pageSize != null) {
+ return new Page<>(Convert.convert(Long.class, pageNum), Convert.convert(Long.class, pageSize));
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/CoatingDefinition.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/CoatingDefinition.java
new file mode 100644
index 0000000000000000000000000000000000000000..9b7709bbe6f19a3da9fd6a4df35ab0606936f730
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/CoatingDefinition.java
@@ -0,0 +1,33 @@
+/*
+ * 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.coating.entity.definition;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.gitee.dorive.coating.annotation.Coating;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Map;
+
+public class CoatingDefinition {
+
+ public static CoatingDefinition newCoatingDefinition(AnnotatedElement annotatedElement) {
+ Map annotationAttributes = AnnotatedElementUtils.getMergedAnnotationAttributes(annotatedElement, Coating.class);
+ return BeanUtil.copyProperties(annotationAttributes, CoatingDefinition.class);
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/PropertyDefinition.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/PropertyDefinition.java
new file mode 100644
index 0000000000000000000000000000000000000000..364726bbe75d315f25f42299f36268e0a5266f3c
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/entity/definition/PropertyDefinition.java
@@ -0,0 +1,54 @@
+/*
+ * 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.coating.entity.definition;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.gitee.dorive.coating.annotation.Property;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Map;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class PropertyDefinition {
+
+ private String accessPath;
+ private String alias;
+ private String operator;
+ private boolean ignore;
+
+ public static PropertyDefinition newPropertyDefinition(AnnotatedElement annotatedElement) {
+ Map annotationAttributes = AnnotatedElementUtils.getMergedAnnotationAttributes(annotatedElement, Property.class);
+ if (annotationAttributes == null) {
+ return new PropertyDefinition("", "", "=", false);
+ }
+ return BeanUtil.copyProperties(annotationAttributes, PropertyDefinition.class);
+ }
+
+ public static void renewPropertyDefinition(String fieldName, PropertyDefinition propertyDefinition) {
+ if (StringUtils.isBlank(propertyDefinition.getAlias())) {
+ propertyDefinition.setAlias(fieldName);
+ }
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/DefaultExampleBuilder.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/DefaultExampleBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..22e969e8bf01ea79b176b02530eb98055bfbadb5
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/DefaultExampleBuilder.java
@@ -0,0 +1,151 @@
+/*
+ * 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.coating.impl;
+
+import cn.hutool.core.lang.Assert;
+import com.gitee.dorive.coating.api.ExampleBuilder;
+import com.gitee.dorive.coating.entity.CoatingWrapper;
+import com.gitee.dorive.coating.entity.MergedRepository;
+import com.gitee.dorive.coating.entity.RepositoryWrapper;
+import com.gitee.dorive.coating.impl.resolver.CoatingWrapperResolver;
+import com.gitee.dorive.coating.repository.AbstractCoatingRepository;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.impl.binder.PropertyBinder;
+import com.gitee.dorive.core.impl.resolver.BinderResolver;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.*;
+
+public class DefaultExampleBuilder implements ExampleBuilder {
+
+ private final AbstractCoatingRepository, ?> repository;
+
+ public DefaultExampleBuilder(AbstractCoatingRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public Example buildExample(BoundedContext boundedContext, Object coatingObject) {
+ CoatingWrapperResolver coatingWrapperResolver = repository.getCoatingWrapperResolver();
+ Map, CoatingWrapper> coatingWrapperMap = coatingWrapperResolver.getCoatingWrapperMap();
+
+ CoatingWrapper coatingWrapper = coatingWrapperMap.get(coatingObject.getClass());
+ Assert.notNull(coatingWrapper, "No coating wrapper exists!");
+
+ Map repoCriterionMap = new LinkedHashMap<>();
+ for (RepositoryWrapper repositoryWrapper : coatingWrapper.getReversedRepositoryWrappers()) {
+ Example example = repositoryWrapper.newExampleByCoating(boundedContext, coatingObject);
+ RepoCriterion repoCriterion = new RepoCriterion(repositoryWrapper, example);
+
+ MergedRepository mergedRepository = repositoryWrapper.getMergedRepository();
+ String absoluteAccessPath = mergedRepository.getAbsoluteAccessPath();
+ String relativeAccessPath = mergedRepository.isMerged() ? absoluteAccessPath + "/" : absoluteAccessPath;
+ repoCriterionMap.put(relativeAccessPath, repoCriterion);
+ }
+
+ executeChainQuery(boundedContext, repoCriterionMap);
+
+ RepoCriterion repoCriterion = repoCriterionMap.get("/");
+ Assert.notNull(repoCriterion, "The criterion cannot be null!");
+ return repoCriterion.getExample();
+ }
+
+ private void executeChainQuery(BoundedContext boundedContext, Map repoCriterionMap) {
+ repoCriterionMap.forEach((accessPath, repoCriterion) -> {
+ if ("/".equals(accessPath)) return;
+
+ RepositoryWrapper repositoryWrapper = repoCriterion.getRepositoryWrapper();
+ Example example = repoCriterion.getExample();
+
+ MergedRepository mergedRepository = repositoryWrapper.getMergedRepository();
+ String lastAccessPath = mergedRepository.getLastAccessPath();
+ ConfiguredRepository definedRepository = mergedRepository.getDefinedRepository();
+ ConfiguredRepository configuredRepository = mergedRepository.getConfiguredRepository();
+
+ BinderResolver binderResolver = definedRepository.getBinderResolver();
+
+ for (PropertyBinder propertyBinder : binderResolver.getPropertyBinders()) {
+ String absoluteAccessPath = lastAccessPath + propertyBinder.getBelongAccessPath();
+ RepoCriterion targetRepoCriterion = repoCriterionMap.get(absoluteAccessPath);
+ if (targetRepoCriterion != null) {
+ Example targetExample = targetRepoCriterion.getExample();
+ if (targetExample.isEmptyQuery()) {
+ example.setEmptyQuery(true);
+ break;
+ }
+ }
+ }
+
+ if (example.isQueryAll()) {
+ return;
+ }
+
+ List entities = Collections.emptyList();
+ if (!example.isEmptyQuery() && example.isDirtyQuery()) {
+ example.setSelectColumns(binderResolver.getBoundColumns());
+ entities = configuredRepository.selectByExample(boundedContext, example);
+ }
+
+ for (PropertyBinder propertyBinder : binderResolver.getPropertyBinders()) {
+ String absoluteAccessPath = lastAccessPath + propertyBinder.getBelongAccessPath();
+ RepoCriterion targetRepoCriterion = repoCriterionMap.get(absoluteAccessPath);
+ if (targetRepoCriterion != null) {
+ Example targetExample = targetRepoCriterion.getExample();
+ if (entities.isEmpty()) {
+ targetExample.setEmptyQuery(true);
+ continue;
+ }
+
+ List fieldValues = collectFieldValues(boundedContext, entities, propertyBinder);
+ if (fieldValues.isEmpty()) {
+ targetExample.setEmptyQuery(true);
+ continue;
+ }
+
+ BindingDefinition bindingDefinition = propertyBinder.getBindingDefinition();
+ String bindAlias = bindingDefinition.getBindAlias();
+ Object fieldValue = fieldValues.size() == 1 ? fieldValues.get(0) : fieldValues;
+ fieldValue = propertyBinder.output(boundedContext, fieldValue);
+ targetExample.eq(bindAlias, fieldValue);
+ }
+ }
+ });
+ }
+
+ private List collectFieldValues(BoundedContext boundedContext, List entities, PropertyBinder propertyBinder) {
+ List fieldValues = new ArrayList<>();
+ for (Object entity : entities) {
+ Object fieldValue = propertyBinder.getFieldValue(boundedContext, entity);
+ if (fieldValue != null) {
+ fieldValues.add(fieldValue);
+ }
+ }
+ return fieldValues;
+ }
+
+ @Data
+ @AllArgsConstructor
+ public static class RepoCriterion {
+ private RepositoryWrapper repositoryWrapper;
+ private Example example;
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/CoatingWrapperResolver.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/CoatingWrapperResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..19d4cdc24855e8f8ba042f091f737d9dd2c9968a
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/CoatingWrapperResolver.java
@@ -0,0 +1,163 @@
+/*
+ * 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.coating.impl.resolver;
+
+import com.gitee.dorive.coating.annotation.Coating;
+import com.gitee.dorive.coating.entity.CoatingWrapper;
+import com.gitee.dorive.coating.entity.MergedRepository;
+import com.gitee.dorive.coating.entity.PropertyWrapper;
+import com.gitee.dorive.coating.entity.RepositoryWrapper;
+import com.gitee.dorive.coating.entity.SpecificProperties;
+import com.gitee.dorive.coating.repository.AbstractCoatingRepository;
+import com.gitee.dorive.coating.entity.definition.CoatingDefinition;
+import com.gitee.dorive.coating.entity.definition.PropertyDefinition;
+import com.gitee.dorive.coating.util.ResourceUtils;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.Property;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.util.ReflectionUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Data
+public class CoatingWrapperResolver {
+
+ private AbstractCoatingRepository, ?> repository;
+
+ private Map, CoatingWrapper> coatingWrapperMap = new ConcurrentHashMap<>();
+
+ public CoatingWrapperResolver(AbstractCoatingRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ public void resolveCoatingWrapperMap(String... scanPackages) throws Exception {
+ for (String scanPackage : scanPackages) {
+ List> classes = ResourceUtils.resolveClasses(scanPackage);
+ for (Class> coatingClass : classes) {
+
+ Coating coatingAnnotation = AnnotationUtils.getAnnotation(coatingClass, Coating.class);
+ if (coatingAnnotation == null) {
+ continue;
+ }
+ if (coatingAnnotation.qualifier() != Object.class && coatingAnnotation.qualifier() != repository.getEntityClass()) {
+ continue;
+ }
+
+ Set fieldNames = new LinkedHashSet<>();
+ Map> accessPathPropertyWrappersMap = new LinkedHashMap<>();
+ Map fieldPropertyWrapperMap = new LinkedHashMap<>();
+ SpecificProperties specificProperties = new SpecificProperties();
+
+ ReflectionUtils.doWithLocalFields(coatingClass, declaredField -> {
+ Property property = new Property(declaredField);
+ String fieldName = property.getFieldName();
+
+ PropertyDefinition propertyDefinition = PropertyDefinition.newPropertyDefinition(declaredField);
+ PropertyDefinition.renewPropertyDefinition(fieldName, propertyDefinition);
+ if (propertyDefinition.isIgnore()) {
+ return;
+ }
+
+ PropertyWrapper propertyWrapper = new PropertyWrapper(property, propertyDefinition);
+ if (specificProperties.addProperty(fieldName, propertyWrapper)) {
+ return;
+ }
+
+ fieldNames.add(fieldName);
+
+ String accessPath = propertyDefinition.getAccessPath();
+ if (StringUtils.isNotBlank(accessPath) && accessPath.startsWith("/")) {
+ List existPropertyWrappers = accessPathPropertyWrappersMap.computeIfAbsent(accessPath, key -> new ArrayList<>());
+ existPropertyWrappers.add(propertyWrapper);
+ } else {
+ fieldPropertyWrapperMap.put(fieldName, propertyWrapper);
+ }
+ });
+
+ List repositoryWrappers = collectRepositoryWrappers(accessPathPropertyWrappersMap, fieldPropertyWrapperMap);
+ checkFieldNames(coatingClass, fieldNames, repositoryWrappers);
+
+ List reversedRepositoryWrappers = new ArrayList<>(repositoryWrappers);
+ Collections.reverse(reversedRepositoryWrappers);
+
+ CoatingDefinition coatingDefinition = CoatingDefinition.newCoatingDefinition(coatingClass);
+ CoatingWrapper coatingWrapper = new CoatingWrapper(coatingDefinition, repositoryWrappers, reversedRepositoryWrappers, specificProperties);
+ coatingWrapperMap.put(coatingClass, coatingWrapper);
+ }
+ }
+ }
+
+ private List collectRepositoryWrappers(Map> accessPathPropertyWrappersMap,
+ Map fieldPropertyWrapperMap) {
+ MergedRepositoryResolver mergedRepositoryResolver = repository.getMergedRepositoryResolver();
+ Map mergedRepositoryMap = mergedRepositoryResolver.getMergedRepositoryMap();
+
+ List repositoryWrappers = new ArrayList<>();
+
+ for (MergedRepository mergedRepository : mergedRepositoryMap.values()) {
+ String absoluteAccessPath = mergedRepository.getAbsoluteAccessPath();
+ ConfiguredRepository repository = mergedRepository.getConfiguredRepository();
+ EntityElement entityElement = repository.getEntityElement();
+
+ List propertyWrappers = new ArrayList<>();
+
+ List accessPathPropertyWrappers = accessPathPropertyWrappersMap.get(absoluteAccessPath);
+ if (accessPathPropertyWrappers != null) {
+ propertyWrappers.addAll(accessPathPropertyWrappers);
+ }
+
+ for (String fieldName : entityElement.getProperties()) {
+ PropertyWrapper propertyWrapper = fieldPropertyWrapperMap.get(fieldName);
+ if (propertyWrapper != null) {
+ propertyWrappers.add(propertyWrapper);
+ }
+ }
+
+ if (!propertyWrappers.isEmpty() || repository.isBoundEntity()) {
+ RepositoryWrapper repositoryWrapper = new RepositoryWrapper(mergedRepository, propertyWrappers);
+ repositoryWrappers.add(repositoryWrapper);
+ }
+ }
+
+ return repositoryWrappers;
+ }
+
+ private void checkFieldNames(Class> coatingClass, Set fieldNames, List repositoryWrappers) {
+ Set remainFieldNames = new LinkedHashSet<>(fieldNames);
+ for (RepositoryWrapper repositoryWrapper : repositoryWrappers) {
+ for (PropertyWrapper propertyWrapper : repositoryWrapper.getCollectedPropertyWrappers()) {
+ remainFieldNames.remove(propertyWrapper.getProperty().getFieldName());
+ }
+ }
+ if (!remainFieldNames.isEmpty()) {
+ String errorMessage = String.format("The field does not exist in the aggregate root! entity: %s, coating: %s, fieldNames: %s",
+ repository.getEntityClass(), coatingClass, remainFieldNames);
+ throw new RuntimeException(errorMessage);
+ }
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/MergedRepositoryResolver.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/MergedRepositoryResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..195bb350e7af50b803f4671de8c8bed677b133ac
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/impl/resolver/MergedRepositoryResolver.java
@@ -0,0 +1,90 @@
+/*
+ * 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.coating.impl.resolver;
+
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.coating.entity.MergedRepository;
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import com.gitee.dorive.core.repository.AbstractRepository;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class MergedRepositoryResolver {
+
+ private AbstractContextRepository, ?> repository;
+
+ private Map mergedRepositoryMap = new LinkedHashMap<>();
+
+ public MergedRepositoryResolver(AbstractContextRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ public void resolveMergedRepositoryMap() {
+ ConfiguredRepository rootRepository = repository.getRootRepository();
+ MergedRepository mergedRepository = new MergedRepository(
+ "",
+ "/",
+ false,
+ rootRepository,
+ rootRepository);
+ mergedRepositoryMap.put("/", mergedRepository);
+ resolveMergedRepositoryMap(new ArrayList<>(), repository);
+ }
+
+ private void resolveMergedRepositoryMap(List multiAccessPath, AbstractContextRepository, ?> lastRepository) {
+ String lastAccessPath = StrUtil.join("", multiAccessPath);
+
+ for (ConfiguredRepository repository : lastRepository.getSubRepositories()) {
+ String accessPath = repository.getAccessPath();
+ String absoluteAccessPath = lastAccessPath + accessPath;
+ AbstractRepository abstractRepository = repository.getProxyRepository();
+
+ if (abstractRepository instanceof AbstractContextRepository) {
+ AbstractContextRepository, ?> abstractContextRepository = (AbstractContextRepository, ?>) abstractRepository;
+ ConfiguredRepository rootRepository = abstractContextRepository.getRootRepository();
+
+ MergedRepository mergedRepository = new MergedRepository(
+ lastAccessPath,
+ absoluteAccessPath,
+ true,
+ repository,
+ rootRepository);
+ mergedRepositoryMap.put(absoluteAccessPath, mergedRepository);
+
+ List newMultiAccessPath = new ArrayList<>(multiAccessPath);
+ newMultiAccessPath.add(accessPath);
+ resolveMergedRepositoryMap(newMultiAccessPath, abstractContextRepository);
+
+ } else {
+ MergedRepository mergedRepository = new MergedRepository(
+ lastAccessPath,
+ absoluteAccessPath,
+ false,
+ repository,
+ repository);
+ mergedRepositoryMap.put(absoluteAccessPath, mergedRepository);
+ }
+ }
+ }
+
+}
diff --git a/dorive-coating/src/main/java/com/gitee/dorive/coating/repository/AbstractCoatingRepository.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/repository/AbstractCoatingRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..46d46cfec734ddc43cd506c8d758508897bba169
--- /dev/null
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/repository/AbstractCoatingRepository.java
@@ -0,0 +1,70 @@
+/*
+ * 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.coating.repository;
+
+import com.gitee.dorive.coating.annotation.CoatingScan;
+import com.gitee.dorive.coating.api.CoatingRepository;
+import com.gitee.dorive.coating.api.ExampleBuilder;
+import com.gitee.dorive.coating.impl.resolver.CoatingWrapperResolver;
+import com.gitee.dorive.coating.impl.DefaultExampleBuilder;
+import com.gitee.dorive.coating.impl.resolver.MergedRepositoryResolver;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.event.repository.AbstractEventRepository;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public abstract class AbstractCoatingRepository extends AbstractEventRepository implements ExampleBuilder, CoatingRepository {
+
+ protected MergedRepositoryResolver mergedRepositoryResolver = new MergedRepositoryResolver(this);
+ protected CoatingWrapperResolver coatingWrapperResolver = new CoatingWrapperResolver(this);
+ protected ExampleBuilder exampleBuilder = new DefaultExampleBuilder(this);
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ super.afterPropertiesSet();
+ CoatingScan coatingScan = AnnotatedElementUtils.getMergedAnnotation(this.getClass(), CoatingScan.class);
+ if (coatingScan != null) {
+ mergedRepositoryResolver.resolveMergedRepositoryMap();
+ coatingWrapperResolver.resolveCoatingWrapperMap(coatingScan.value());
+ }
+ }
+
+ @Override
+ public Example buildExample(BoundedContext boundedContext, Object coatingObject) {
+ return exampleBuilder.buildExample(boundedContext, coatingObject);
+ }
+
+ @Override
+ public List selectByCoating(BoundedContext boundedContext, Object coatingObject) {
+ Example example = buildExample(boundedContext, coatingObject);
+ return selectByExample(boundedContext, example);
+ }
+
+ @Override
+ public Page selectPageByCoating(BoundedContext boundedContext, Object coatingObject) {
+ Example example = buildExample(boundedContext, coatingObject);
+ return selectPageByExample(boundedContext, example);
+ }
+
+}
diff --git a/spring-domain-coating/src/main/java/com/gitee/spring/domain/coating/utils/ResourceUtils.java b/dorive-coating/src/main/java/com/gitee/dorive/coating/util/ResourceUtils.java
similarity index 64%
rename from spring-domain-coating/src/main/java/com/gitee/spring/domain/coating/utils/ResourceUtils.java
rename to dorive-coating/src/main/java/com/gitee/dorive/coating/util/ResourceUtils.java
index df02a950adcd8f25a5de6093fcc483f4386706bc..2011070a4c53302afe6e7c063817fbed24eff111 100644
--- a/spring-domain-coating/src/main/java/com/gitee/spring/domain/coating/utils/ResourceUtils.java
+++ b/dorive-coating/src/main/java/com/gitee/dorive/coating/util/ResourceUtils.java
@@ -1,4 +1,20 @@
-package com.gitee.spring.domain.coating.utils;
+/*
+ * 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.coating.util;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
diff --git a/spring-domain-core/pom.xml b/dorive-core/pom.xml
similarity index 71%
rename from spring-domain-core/pom.xml
rename to dorive-core/pom.xml
index c8aa135485452fb24d2e3c4bb134b0f476c6fbb4..5d481184e435437453c49c9940844aa05c998448 100644
--- a/spring-domain-core/pom.xml
+++ b/dorive-core/pom.xml
@@ -5,12 +5,16 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-domain-core
-
+ dorive-core
+
+ com.gitee.digital-engine
+ dorive-proxy
+ ${project.version}
+
org.springframework.boot
spring-boot-starter-web
@@ -19,17 +23,9 @@
org.projectlombok
lombok
-
- org.apache.commons
- commons-lang3
-
cn.hutool
hutool-all
-
- org.javassist
- javassist
-
\ No newline at end of file
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Binding.java b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Binding.java
new file mode 100644
index 0000000000000000000000000000000000000000..6054689284c2ce04debe57eea4ec8b399cebbe70
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Binding.java
@@ -0,0 +1,50 @@
+/*
+ * 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.annotation;
+
+import com.gitee.dorive.core.impl.processor.DefaultProcessor;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Repeatable(Bindings.class)
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.FIELD})
+public @interface Binding {
+
+ String field();
+
+ String bindProp() default "";
+
+ String property() default "";
+
+ Class> processor() default DefaultProcessor.class;
+
+ String bindCtx() default "";
+
+ String alias() default "";
+
+ String bindAlias() default "";
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Bindings.java b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Bindings.java
new file mode 100644
index 0000000000000000000000000000000000000000..9ae8e3afcce23779b0ed0799ada33f9e7c88942b
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Bindings.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.annotation;
+
+import java.lang.annotation.*;
+
+@Inherited
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.FIELD})
+public @interface Bindings {
+ Binding[] value();
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Entity.java b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Entity.java
new file mode 100644
index 0000000000000000000000000000000000000000..5923273d41308f089b007af7ceaa6164837352f8
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Entity.java
@@ -0,0 +1,49 @@
+/*
+ * 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.annotation;
+
+import com.gitee.dorive.core.repository.DefaultRepository;
+import com.gitee.dorive.core.impl.DefaultEntityFactory;
+
+import java.lang.annotation.*;
+
+@Inherited
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.FIELD})
+public @interface Entity {
+
+ String[] matchKeys() default {};
+
+ int order() default 0;
+
+ Class> mapper() default Object.class;
+
+ Class> factory() default DefaultEntityFactory.class;
+
+ Class> repository() default DefaultRepository.class;
+
+ String orderByAsc() default "";
+
+ String orderByDesc() default "";
+
+ String builderKey() default "";
+
+ String commandKey() default "";
+
+}
+
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Repository.java b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Repository.java
new file mode 100644
index 0000000000000000000000000000000000000000..0f093853d5c70cd7a1d6a4f51f3089ed6ebc8dc2
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/annotation/Repository.java
@@ -0,0 +1,34 @@
+/*
+ * 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.annotation;
+
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.stereotype.Component;
+
+import java.lang.annotation.*;
+
+@Component
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Repository {
+
+ @AliasFor(annotation = Component.class)
+ String value() default "";
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/Binder.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/Binder.java
new file mode 100644
index 0000000000000000000000000000000000000000..8fe93b25fe1203abc2ef4c5c164aae85e4d753b7
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/Binder.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+
+public interface Binder {
+
+ BindingDefinition getBindingDefinition();
+
+ Object getFieldValue(BoundedContext boundedContext, Object entity);
+
+ void setFieldValue(BoundedContext boundedContext, Object entity, Object property);
+
+ Object getBoundValue(BoundedContext boundedContext, Object rootEntity);
+
+ void setBoundValue(BoundedContext boundedContext, Object rootEntity, Object property);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityFactory.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..59425b7a939b3d1eb5dd4812ee24d9e76785196a
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityFactory.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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+
+public interface EntityFactory {
+
+ Object reconstitute(BoundedContext boundedContext, Object persistentObject);
+
+ Object deconstruct(BoundedContext boundedContext, Object entity);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityHandler.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..26fa3a01bbeadbffe98de8b8ac534b13557b3bf0
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityHandler.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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+
+import java.util.List;
+
+public interface EntityHandler {
+
+ void handleEntities(BoundedContext boundedContext, List rootEntities);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityIndex.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityIndex.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb0ad328ce8a79baebe3e97e2659112cfca6bd3d
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/EntityIndex.java
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+import java.util.List;
+
+public interface EntityIndex {
+
+ List selectList(Object rootEntity, Object primaryKey);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/ExampleBuilder.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/ExampleBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..1fd1a007716b7f3e18d4b99d91d1d37be4ff6773
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/ExampleBuilder.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Example;
+
+public interface ExampleBuilder {
+
+ Example buildExample(BoundedContext boundedContext, Object rootEntity, Example example);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/Executor.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/Executor.java
new file mode 100644
index 0000000000000000000000000000000000000000..8f0aa584e9c00c386fa338820892a728fcb48122
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/Executor.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.operation.Delete;
+import com.gitee.dorive.core.entity.operation.Insert;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Query;
+import com.gitee.dorive.core.entity.operation.Update;
+
+public interface Executor {
+
+ Query buildQueryByPK(BoundedContext boundedContext, Object primaryKey);
+
+ Query buildQuery(BoundedContext boundedContext, Example example);
+
+ Result executeQuery(BoundedContext boundedContext, Query query);
+
+ Insert buildInsert(BoundedContext boundedContext, Object entity);
+
+ Update buildUpdate(BoundedContext boundedContext, Object entity);
+
+ Update buildUpdate(BoundedContext boundedContext, Object entity, Example example);
+
+ Operation buildInsertOrUpdate(BoundedContext boundedContext, Object entity);
+
+ Delete buildDelete(BoundedContext boundedContext, Object entity);
+
+ Delete buildDeleteByPK(BoundedContext boundedContext, Object primaryKey);
+
+ Delete buildDelete(BoundedContext boundedContext, Example example);
+
+ int execute(BoundedContext boundedContext, Operation operation);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/ListableRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/ListableRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..111a4f65bc0011717a63616184af2c3d1d0ec607
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/ListableRepository.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+
+import java.util.List;
+
+public interface ListableRepository extends Repository {
+
+ int insertList(BoundedContext boundedContext, List entities);
+
+ int updateList(BoundedContext boundedContext, List entities);
+
+ int insertOrUpdateList(BoundedContext boundedContext, List entities);
+
+ int deleteList(BoundedContext boundedContext, List entities);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/MetadataHolder.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/MetadataHolder.java
new file mode 100644
index 0000000000000000000000000000000000000000..390c408b154fa9eb403c5a530f47f4e98b15e30e
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/MetadataHolder.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public interface MetadataHolder {
+
+ Object getMetadata();
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/Processor.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/Processor.java
new file mode 100644
index 0000000000000000000000000000000000000000..5303647756d31275094201521b48d4d3e34ba7fe
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/Processor.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;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+
+public interface Processor {
+
+ Object input(BoundedContext boundedContext, Object valueObject);
+
+ Object output(BoundedContext boundedContext, Object valueObject);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/PropertyProxy.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/PropertyProxy.java
new file mode 100644
index 0000000000000000000000000000000000000000..382926bfef9fd91590038ffd7199514771a4f924
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/PropertyProxy.java
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+public interface PropertyProxy {
+
+ Object getValue(Object entity);
+
+ void setValue(Object entity, Object value);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/Repository.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/Repository.java
new file mode 100644
index 0000000000000000000000000000000000000000..df1d74d3252856f41ddb5a3a1d7eba91cf2e7d42
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/Repository.java
@@ -0,0 +1,135 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.BoundedContext;
+
+import java.util.List;
+
+/**
+ * 仓储接口
+ *
+ * @param 实体类型
+ * @param 主键类型
+ */
+public interface Repository {
+
+ /**
+ * 根据主键查询实体
+ *
+ * @param boundedContext 边界上下文
+ * @param primaryKey 主键
+ * @return 实体
+ */
+ E selectByPrimaryKey(BoundedContext boundedContext, PK primaryKey);
+
+ /**
+ * 根据条件查询实体
+ *
+ * @param boundedContext 边界上下文
+ * @param example 条件
+ * @return 实体
+ */
+ List selectByExample(BoundedContext boundedContext, Example example);
+
+ /**
+ * 根据条件查询分页
+ *
+ * @param boundedContext 边界上下文
+ * @param example 条件
+ * @return 分页
+ */
+ Page selectPageByExample(BoundedContext boundedContext, Example example);
+
+ /**
+ * 根据条件查询结果集
+ *
+ * @param boundedContext 边界上下文
+ * @param example 条件
+ * @return 结果集
+ */
+ Result selectResultByExample(BoundedContext boundedContext, Example example);
+
+ /**
+ * 插入一个实体
+ *
+ * @param boundedContext 边界上下文
+ * @param entity 实体
+ * @return 操作数
+ */
+ int insert(BoundedContext boundedContext, E entity);
+
+ /**
+ * 根据实体的主键,修改一个实体
+ *
+ * @param boundedContext 边界上下文
+ * @param entity 实体
+ * @return 操作数
+ */
+ int update(BoundedContext boundedContext, E entity);
+
+ /**
+ * 根据实体和条件,修改聚合内的所有实体
+ *
+ * @param boundedContext 边界上下文
+ * @param entity 实体
+ * @param example 条件
+ * @return 操作数
+ */
+ int updateByExample(BoundedContext boundedContext, Object entity, Example example);
+
+ /**
+ * 根据实体的主键,插入或者修改一个实体。
+ * 主键为空则插入,主键不为空则修改。
+ *
+ * @param boundedContext 边界上下文
+ * @param entity 实体
+ * @return 操作数
+ */
+ int insertOrUpdate(BoundedContext boundedContext, E entity);
+
+ /**
+ * 根据实体的主键,删除一个实体
+ *
+ * @param boundedContext 边界上下文
+ * @param entity 实体
+ * @return 操作数
+ */
+ int delete(BoundedContext boundedContext, E entity);
+
+ /**
+ * 根据主键,删除一个实体
+ *
+ * @param boundedContext 边界上下文
+ * @param primaryKey 主键
+ * @return 操作数
+ */
+ int deleteByPrimaryKey(BoundedContext boundedContext, PK primaryKey);
+
+ /**
+ * 根据条件,删除聚合内的所有实体
+ *
+ * @param boundedContext 边界上下文
+ * @param example 条件
+ * @return 操作数
+ */
+ int deleteByExample(BoundedContext boundedContext, Example example);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Operator.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Operator.java
new file mode 100644
index 0000000000000000000000000000000000000000..4fbc6dc12f3c18c216208098c675696b269476c2
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Operator.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+public interface Operator {
+ String EQ = "=";
+ String NE = "<>";
+ String IN = "IN";
+ String NOT_IN = "NOT IN";
+ String IS = "IS";
+ String IS_NOT = "IS NOT";
+ String LIKE = "LIKE";
+ String NOT_LIKE = "NOT LIKE";
+ String GT = ">";
+ String GE = ">=";
+ String LT = "<";
+ String LE = "<=";
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Order.java b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Order.java
new file mode 100644
index 0000000000000000000000000000000000000000..d94ddd77c0e75d11aa7e79024c62db64b3666814
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/api/constant/Order.java
@@ -0,0 +1,22 @@
+/*
+ * 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;
+
+public interface Order {
+ String ASC = "ASC";
+ String DESC = "DESC";
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/config/DomainCoreConfiguration.java b/dorive-core/src/main/java/com/gitee/dorive/core/config/DomainCoreConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..fec5500861acadcfcff44ba74933f1bf430c9b9f
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/config/DomainCoreConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * 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.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+@Order(-100)
+@Configuration
+public class DomainCoreConfiguration {
+
+ @Bean
+ public RepositoryContext repositoryContext() {
+ return new RepositoryContext();
+ }
+
+}
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/config/RepositoryContext.java b/dorive-core/src/main/java/com/gitee/dorive/core/config/RepositoryContext.java
similarity index 40%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/config/RepositoryContext.java
rename to dorive-core/src/main/java/com/gitee/dorive/core/config/RepositoryContext.java
index 29a513cf7ab7812d1b8581a48176960cbb7c375f..fc2793605fa76c25004e43eb649850e6c7f409ec 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/config/RepositoryContext.java
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/config/RepositoryContext.java
@@ -1,6 +1,22 @@
-package com.gitee.spring.domain.core.config;
-
-import com.gitee.spring.domain.core.repository.AbstractGenericRepository;
+/*
+ * 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.config;
+
+import com.gitee.dorive.core.repository.AbstractContextRepository;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
@@ -11,9 +27,10 @@ import java.util.concurrent.ConcurrentHashMap;
public class RepositoryContext implements ApplicationContextAware, InitializingBean {
- private static final Map, AbstractGenericRepository, ?>> CLASS_REPOSITORY_MAP = new ConcurrentHashMap<>();
private ApplicationContext applicationContext;
+ private static final Map, AbstractContextRepository, ?>> CLASS_REPOSITORY_MAP = new ConcurrentHashMap<>();
+
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
@@ -22,14 +39,14 @@ public class RepositoryContext implements ApplicationContextAware, InitializingB
@Override
@SuppressWarnings("rawtypes")
public void afterPropertiesSet() {
- Map beansOfType = applicationContext.getBeansOfType(AbstractGenericRepository.class);
- for (AbstractGenericRepository, ?> abstractGenericRepository : beansOfType.values()) {
- CLASS_REPOSITORY_MAP.put(abstractGenericRepository.getEntityClass(), abstractGenericRepository);
+ Map beansOfType = applicationContext.getBeansOfType(AbstractContextRepository.class);
+ for (AbstractContextRepository, ?> repository : beansOfType.values()) {
+ CLASS_REPOSITORY_MAP.put(repository.getEntityClass(), repository);
}
}
@SuppressWarnings("unchecked")
- public static , E> R getRepository(Class entityClass) {
+ public static , E> R getRepository(Class entityClass) {
return (R) CLASS_REPOSITORY_MAP.get(entityClass);
}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/BoundedContext.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/BoundedContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..48a151d70c88bfe54601b42a66462a911856c5ef
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/BoundedContext.java
@@ -0,0 +1,45 @@
+/*
+ * 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.entity;
+
+import com.gitee.dorive.core.api.ExampleBuilder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+import java.util.LinkedHashMap;
+
+@Data
+@NoArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class BoundedContext extends LinkedHashMap {
+
+ public BoundedContext(String... keys) {
+ putKeys(keys);
+ }
+
+ public void putKeys(String... keys) {
+ for (String key : keys) {
+ put(key, true);
+ }
+ }
+
+ public void putBuilder(String key, ExampleBuilder builder) {
+ put(key, builder);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/Command.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/Command.java
new file mode 100644
index 0000000000000000000000000000000000000000..7fce8303a480e84c869ccf809af811fba869eae6
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/Command.java
@@ -0,0 +1,28 @@
+/*
+ * 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.entity;
+
+import lombok.Data;
+
+import java.util.Set;
+
+@Data
+public class Command {
+ private boolean forceIgnore;
+ private boolean forceInsert;
+ private Set nullableProperties;
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/EntityElement.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/EntityElement.java
new file mode 100644
index 0000000000000000000000000000000000000000..be9d213a85ebcf5c8a1a94bc028987cbd08d109d
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/EntityElement.java
@@ -0,0 +1,83 @@
+/*
+ * 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.entity;
+
+import cn.hutool.core.lang.Assert;
+import com.gitee.dorive.core.annotation.Binding;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.impl.PropertyProxyFactory;
+import com.gitee.dorive.core.util.ReflectUtils;
+import com.gitee.dorive.core.annotation.Entity;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.util.Set;
+
+@Data
+@AllArgsConstructor
+public class EntityElement {
+
+ private Entity entityAnnotation;
+ private Set bindingAnnotations;
+ private AnnotatedElement annotatedElement;
+ private Class> entityClass;
+ private boolean collection;
+ private Class> genericEntityClass;
+ private String fieldName;
+ private Set properties;
+ private PropertyProxy primaryKeyProxy;
+
+ public static EntityElement newEntityElement(AnnotatedElement annotatedElement) {
+ Entity entityAnnotation = AnnotatedElementUtils.getMergedAnnotation(annotatedElement, Entity.class);
+ Assert.notNull(entityAnnotation, "The annotation @Entity cannot be null!");
+ Set bindingAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(annotatedElement, Binding.class);
+
+ if (annotatedElement instanceof Class) {
+ Class> entityClass = (Class>) annotatedElement;
+ return new EntityElement(
+ entityAnnotation,
+ bindingAnnotations,
+ annotatedElement,
+ entityClass,
+ false,
+ entityClass,
+ null,
+ ReflectUtils.getFieldNames(entityClass),
+ PropertyProxyFactory.newPropertyProxy(entityClass, "id"));
+
+ } else if (annotatedElement instanceof Field) {
+ Property property = new Property((Field) annotatedElement);
+ return new EntityElement(
+ entityAnnotation,
+ bindingAnnotations,
+ annotatedElement,
+ property.getFieldClass(),
+ property.isCollection(),
+ property.getGenericFieldClass(),
+ property.getFieldName(),
+ ReflectUtils.getFieldNames(property.getGenericFieldClass()),
+ PropertyProxyFactory.newPropertyProxy(property.getGenericFieldClass(), "id"));
+
+ } else {
+ throw new RuntimeException("Unknown type!");
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/Property.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/Property.java
new file mode 100644
index 0000000000000000000000000000000000000000..0372caea2a01e5f1256d14ec679ba742f3efecfd
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/Property.java
@@ -0,0 +1,64 @@
+/*
+ * 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.entity;
+
+import cn.hutool.core.util.ReflectUtil;
+import lombok.Data;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+@Data
+public class Property {
+
+ private Field declaredField;
+ private Class> fieldClass;
+ private boolean collection;
+ private Class> genericFieldClass;
+ private String fieldName;
+
+ public Property(Field declaredField) {
+ Class> fieldClass = declaredField.getType();
+ boolean isCollection = false;
+ Class> fieldGenericClass = fieldClass;
+ String fieldName = declaredField.getName();
+
+ if (Collection.class.isAssignableFrom(fieldClass)) {
+ isCollection = true;
+ ParameterizedType parameterizedType = (ParameterizedType) declaredField.getGenericType();
+ Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0];
+ fieldGenericClass = (Class>) actualTypeArgument;
+ }
+
+ this.declaredField = declaredField;
+ this.fieldClass = fieldClass;
+ this.collection = isCollection;
+ this.genericFieldClass = fieldGenericClass;
+ this.fieldName = fieldName;
+ }
+
+ public boolean isSameType(Property property) {
+ return fieldClass == property.getFieldClass() && genericFieldClass == property.getGenericFieldClass();
+ }
+
+ public Object getFieldValue(Object object) {
+ return ReflectUtil.getFieldValue(object, declaredField);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/PropertyChain.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/PropertyChain.java
new file mode 100644
index 0000000000000000000000000000000000000000..9dfec7332aba8a71b8444a4f8648f6f2b7e3b107
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/PropertyChain.java
@@ -0,0 +1,64 @@
+/*
+ * 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.entity;
+
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.impl.PropertyProxyFactory;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@AllArgsConstructor
+@ToString(exclude = "lastPropertyChain")
+public class PropertyChain implements PropertyProxy {
+
+ private PropertyChain lastPropertyChain;
+ private Class> entityClass;
+ private String accessPath;
+ private boolean annotatedEntity;
+ private Property property;
+ private PropertyProxy propertyProxy;
+
+ public void initialize() {
+ if (propertyProxy == null) {
+ propertyProxy = PropertyProxyFactory.newPropertyProxy(entityClass, property.getDeclaredField());
+ if (lastPropertyChain != null) {
+ lastPropertyChain.initialize();
+ }
+ }
+ }
+
+ @Override
+ public Object getValue(Object entity) {
+ if (lastPropertyChain != null) {
+ entity = lastPropertyChain.getValue(entity);
+ }
+ return entity != null ? propertyProxy.getValue(entity) : null;
+ }
+
+ @Override
+ public void setValue(Object entity, Object value) {
+ if (lastPropertyChain != null) {
+ entity = lastPropertyChain.getValue(entity);
+ }
+ if (entity != null) {
+ propertyProxy.setValue(entity, value);
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/BindingDefinition.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/BindingDefinition.java
new file mode 100644
index 0000000000000000000000000000000000000000..31f1940d8d03ba40b87e9a20d76029f25b16afad
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/BindingDefinition.java
@@ -0,0 +1,51 @@
+/*
+ * 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.entity.definition;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.gitee.dorive.core.annotation.Binding;
+import com.gitee.dorive.core.entity.EntityElement;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.springframework.core.annotation.AnnotationUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Data
+@AllArgsConstructor
+public class BindingDefinition {
+
+ private String field;
+ private String bindProp;
+ private String property;
+ private Class> processor;
+ private String bindCtx;
+ private String alias;
+ private String bindAlias;
+
+ public static List newBindingDefinitions(EntityElement entityElement) {
+ List bindingDefinitions = new ArrayList<>();
+ for (Binding bindingAnnotation : entityElement.getBindingAnnotations()) {
+ Map annotationAttributes = AnnotationUtils.getAnnotationAttributes(bindingAnnotation);
+ bindingDefinitions.add(BeanUtil.copyProperties(annotationAttributes, BindingDefinition.class));
+ }
+ return bindingDefinitions;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/EntityDefinition.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/EntityDefinition.java
new file mode 100644
index 0000000000000000000000000000000000000000..e7ff3b1589356aa81e2ecc266d1890c238330636
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/definition/EntityDefinition.java
@@ -0,0 +1,68 @@
+/*
+ * 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.entity.definition;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.annotation.Entity;
+import com.gitee.dorive.core.api.constant.Order;
+import com.gitee.dorive.core.entity.EntityElement;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.core.annotation.AnnotationUtils;
+
+import java.util.Map;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class EntityDefinition {
+
+ private String[] matchKeys;
+ private int order;
+ private Class> mapper;
+ private Class> factory;
+ private Class> repository;
+ private String orderByAsc;
+ private String orderByDesc;
+ private String builderKey;
+ private String commandKey;
+
+ public static EntityDefinition newEntityDefinition(EntityElement entityElement) {
+ Entity entityAnnotation = entityElement.getEntityAnnotation();
+ Map annotationAttributes = AnnotationUtils.getAnnotationAttributes(entityAnnotation);
+ return BeanUtil.copyProperties(annotationAttributes, EntityDefinition.class);
+ }
+
+ public OrderBy getDefaultOrderBy() {
+ if (StringUtils.isNotBlank(this.orderByAsc)) {
+ String orderByAsc = StrUtil.toUnderlineCase(this.orderByAsc);
+ String[] columns = StrUtil.splitTrim(orderByAsc, ",").toArray(new String[0]);
+ return new OrderBy(columns, Order.ASC);
+ }
+ if (StringUtils.isNotBlank(this.orderByDesc)) {
+ String orderByDesc = StrUtil.toUnderlineCase(this.orderByDesc);
+ String[] columns = StrUtil.splitTrim(orderByDesc, ",").toArray(new String[0]);
+ return new OrderBy(columns, Order.DESC);
+ }
+ return null;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Criterion.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Criterion.java
new file mode 100644
index 0000000000000000000000000000000000000000..582fe9f8b0e6d2a8dceb4a56107b797d7881979c
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Criterion.java
@@ -0,0 +1,84 @@
+/*
+ * 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.entity.executor;
+
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.core.api.constant.Operator;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Data
+@AllArgsConstructor
+public class Criterion {
+
+ private static final SimpleDateFormat SQL_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ private String property;
+ private String operator;
+ private Object value;
+
+ @Override
+ public String toString() {
+ String property = StrUtil.toUnderlineCase(this.property);
+ String operator = this.operator;
+ if (this.value instanceof Collection) {
+ if (Operator.EQ.equals(operator)) {
+ operator = Operator.IN;
+
+ } else if (Operator.NE.equals(operator)) {
+ operator = Operator.NOT_IN;
+ }
+ }
+ String value = convert(this.value);
+ return property + " " + operator + " " + value;
+ }
+
+ private String convert(Object value) {
+ if (value instanceof Collection) {
+ Collection> collection = (Collection>) value;
+ List values = new ArrayList<>(collection.size());
+ for (Object item : collection) {
+ values.add(doConvert(item));
+ }
+ return "(" + StrUtil.join(", ", values) + ")";
+
+ } else if (operator.endsWith(Operator.IN)) {
+ return "(" + doConvert(value) + ")";
+ }
+ return doConvert(value);
+ }
+
+ private String doConvert(Object value) {
+ if (value instanceof Number) {
+ return String.valueOf(value);
+
+ } else if (value instanceof String) {
+ return "'" + value + "'";
+
+ } else if (value instanceof Date) {
+ return "'" + SQL_DATE_FORMAT.format((Date) value) + "'";
+
+ } else if (value == null || operator.startsWith(Operator.IS)) {
+ return "NULL";
+ }
+ return value.toString();
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Example.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Example.java
new file mode 100644
index 0000000000000000000000000000000000000000..5189a91f7bc23bd957e6efebb0ef831654afb902
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Example.java
@@ -0,0 +1,140 @@
+/*
+ * 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.entity.executor;
+
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.core.api.constant.Operator;
+import com.gitee.dorive.core.api.constant.Order;
+import com.gitee.dorive.core.util.StringUtils;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+public class Example {
+
+ private boolean emptyQuery = false;
+ private String[] selectColumns;
+ private List criteria = new ArrayList<>(4);
+ private OrderBy orderBy;
+ private Page page;
+
+ public boolean isDirtyQuery() {
+ return !criteria.isEmpty();
+ }
+
+ public boolean isQueryAll() {
+ return !emptyQuery && !isDirtyQuery();
+ }
+
+ public void selectColumns(String... columns) {
+ selectColumns = selectColumns == null ? columns : ArrayUtil.addAll(selectColumns, columns);
+ }
+
+ public void addCriterion(Criterion criterion) {
+ criteria.add(criterion);
+ }
+
+ public String buildCriteria() {
+ return StrUtil.join(" AND ", criteria);
+ }
+
+ public Example eq(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.EQ, value));
+ return this;
+ }
+
+ public Example ne(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.NE, value));
+ return this;
+ }
+
+ public Example in(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.IN, value));
+ return this;
+ }
+
+ public Example notIn(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.NOT_IN, value));
+ return this;
+ }
+
+ public Example isNull(String property) {
+ criteria.add(new Criterion(property, Operator.IS, null));
+ return this;
+ }
+
+ public Example isNotNull(String property) {
+ criteria.add(new Criterion(property, Operator.IS_NOT, null));
+ return this;
+ }
+
+ public Example like(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.LIKE, value));
+ return this;
+ }
+
+ public Example notLike(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.NOT_LIKE, value));
+ return this;
+ }
+
+ public Example gt(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.GT, value));
+ return this;
+ }
+
+ public Example ge(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.GE, value));
+ return this;
+ }
+
+ public Example lt(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.LT, value));
+ return this;
+ }
+
+ public Example le(String property, Object value) {
+ criteria.add(new Criterion(property, Operator.LE, value));
+ return this;
+ }
+
+ public Example orderByAsc(String... columns) {
+ orderBy = new OrderBy(StringUtils.toUnderlineCase(columns), Order.ASC);
+ return this;
+ }
+
+ public Example orderByDesc(String... columns) {
+ orderBy = new OrderBy(StringUtils.toUnderlineCase(columns), Order.DESC);
+ return this;
+ }
+
+ public Example startPage(long pageNum, long pageSize) {
+ page = new Page<>(pageNum, pageSize);
+ return this;
+ }
+
+ public Example startPage() {
+ page = new Page<>();
+ return this;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/OrderBy.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/OrderBy.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd961b519f9a0e2e9705c427ec81de6d976a2775
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/OrderBy.java
@@ -0,0 +1,37 @@
+/*
+ * 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.entity.executor;
+
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.core.util.StringUtils;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class OrderBy {
+
+ private String[] columns;
+ private String order;
+
+ @Override
+ public String toString() {
+ String[] columns = StringUtils.toUnderlineCase(this.columns);
+ return "ORDER BY " + StrUtil.join(", ", (Object) columns) + " " + order.toUpperCase();
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Page.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Page.java
new file mode 100644
index 0000000000000000000000000000000000000000..52ec53f5295991a6f260f54ef32eccbfc9db64de
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Page.java
@@ -0,0 +1,46 @@
+/*
+ * 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.entity.executor;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Collections;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Page {
+
+ private long total = 0;
+ private long current = 1;
+ private long size = 10;
+ private List records = Collections.emptyList();
+
+ public Page(long current, long size) {
+ this.current = current;
+ this.size = size;
+ }
+
+ @Override
+ public String toString() {
+ return "LIMIT " + (current - 1) * size + ", " + size;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Result.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Result.java
new file mode 100644
index 0000000000000000000000000000000000000000..6618c5078c18e4bbaa654ec169e9bc6fa46662f9
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/Result.java
@@ -0,0 +1,48 @@
+/*
+ * 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.entity.executor;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Collections;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+public class Result {
+
+ private E record;
+ private List records = Collections.emptyList();
+ private Page page;
+
+ public Result(E record) {
+ this.record = record;
+ }
+
+ public Result(List records) {
+ this.records = records;
+ this.record = !records.isEmpty() ? records.get(0) : null;
+ }
+
+ public Result(Page page) {
+ this.page = page;
+ this.records = page.getRecords();
+ this.record = !records.isEmpty() ? records.get(0) : null;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/UnionExample.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/UnionExample.java
new file mode 100644
index 0000000000000000000000000000000000000000..5ba102e75e8b69ee721bfd7d574be4453a09a00c
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/executor/UnionExample.java
@@ -0,0 +1,42 @@
+/*
+ * 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.entity.executor;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class UnionExample extends Example {
+
+ private List examples = new ArrayList<>();
+
+ @Override
+ public boolean isDirtyQuery() {
+ return !examples.isEmpty();
+ }
+
+ public void addExample(Example example) {
+ examples.add(example);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Condition.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Condition.java
new file mode 100644
index 0000000000000000000000000000000000000000..1736220bd8f97a0234a194e439c2d7e8ec38b702
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Condition.java
@@ -0,0 +1,34 @@
+/*
+ * 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.entity.operation;
+
+import com.gitee.dorive.core.entity.executor.Example;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class Condition extends Operation {
+
+ protected Object primaryKey;
+ protected Example example;
+
+ public Condition(int type, Object entity) {
+ super(type, entity);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Delete.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Delete.java
new file mode 100644
index 0000000000000000000000000000000000000000..844a6bb7027b2a591feaaaeec914ff3184a271b3
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Delete.java
@@ -0,0 +1,25 @@
+/*
+ * 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.entity.operation;
+
+public class Delete extends Condition {
+
+ public Delete(int type, Object entity) {
+ super(type, entity);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Insert.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Insert.java
new file mode 100644
index 0000000000000000000000000000000000000000..243cd3ba8df413be0321487cf5a849cf3a50ef88
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Insert.java
@@ -0,0 +1,25 @@
+/*
+ * 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.entity.operation;
+
+public class Insert extends Operation {
+
+ public Insert(int type, Object entity) {
+ super(type, entity);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Operation.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Operation.java
new file mode 100644
index 0000000000000000000000000000000000000000..960af73e692664984084f4949cbae216a84af04d
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Operation.java
@@ -0,0 +1,39 @@
+/*
+ * 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.entity.operation;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Operation {
+
+ public static final int NONE = 0x00000000;
+ public static final int SELECT = 0x00000001;
+ public static final int INSERT = 0x00000002;
+ public static final int UPDATE = 0x00000004;
+ public static final int DELETE = 0x00000008;
+ public static final int INSERT_OR_UPDATE = INSERT | UPDATE;
+ public static final int UPDATE_OR_DELETE = UPDATE | DELETE;
+ public static final int FORCE_IGNORE = 0x00000010;
+ public static final int FORCE_INSERT = 0x00000010 | INSERT;
+
+ protected int type;
+ protected Object entity;
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Query.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Query.java
new file mode 100644
index 0000000000000000000000000000000000000000..47d793808e5254cee6c13fe1cc45553978522b15
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Query.java
@@ -0,0 +1,29 @@
+/*
+ * 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.entity.operation;
+
+public class Query extends Condition {
+
+ public Query(int type, Object entity) {
+ super(type, entity);
+ }
+
+ public boolean withoutPage() {
+ return example.getPage() == null;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Update.java b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Update.java
new file mode 100644
index 0000000000000000000000000000000000000000..cb121bfe80cc3a3a578d4c692fcf55b34923ea7a
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/entity/operation/Update.java
@@ -0,0 +1,25 @@
+/*
+ * 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.entity.operation;
+
+public class Update extends Condition {
+
+ public Update(int type, Object entity) {
+ super(type, entity);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/DefaultEntityFactory.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/DefaultEntityFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..dca8926bd9c5399ec2ab16da85972ffddf996102
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/DefaultEntityFactory.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.api.EntityFactory;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class DefaultEntityFactory implements EntityFactory {
+
+ private EntityElement entityElement;
+ private Class> pojoClass;
+
+ @Override
+ public Object reconstitute(BoundedContext boundedContext, Object persistentObject) {
+ if (persistentObject instanceof Map) {
+ return BeanUtil.mapToBean((Map, ?>) persistentObject, entityElement.getGenericEntityClass(), true, CopyOptions.create().ignoreNullValue());
+ } else {
+ return BeanUtil.copyProperties(persistentObject, entityElement.getGenericEntityClass());
+ }
+ }
+
+ @Override
+ public Object deconstruct(BoundedContext boundedContext, Object entity) {
+ return BeanUtil.copyProperties(entity, pojoClass);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/OperationTypeResolver.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/OperationTypeResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..0544b909e9f4f141423300df278052a83350c254
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/OperationTypeResolver.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import com.gitee.dorive.core.entity.definition.EntityDefinition;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.Command;
+import org.apache.commons.lang3.StringUtils;
+
+public class OperationTypeResolver {
+
+ public int resolveOperationType(BoundedContext boundedContext, ConfiguredRepository repository) {
+ EntityDefinition entityDefinition = repository.getEntityDefinition();
+ String commandKey = entityDefinition.getCommandKey();
+ if (StringUtils.isNotBlank(commandKey) && boundedContext.containsKey(commandKey)) {
+ Command command = (Command) boundedContext.get(commandKey);
+ if (command.isForceIgnore()) {
+ return Operation.FORCE_IGNORE;
+
+ } else if (command.isForceInsert()) {
+ return Operation.FORCE_INSERT;
+ }
+ }
+ return Operation.NONE;
+ }
+
+ public int mergeOperationType(int expectedOperationType, int contextOperationType, Object primaryKey) {
+ if (contextOperationType == Operation.FORCE_IGNORE) {
+ return Operation.FORCE_IGNORE;
+
+ } else if (contextOperationType == Operation.FORCE_INSERT) {
+ return expectedOperationType & Operation.INSERT;
+
+ } else if (expectedOperationType == Operation.INSERT_OR_UPDATE) {
+ return Operation.INSERT_OR_UPDATE;
+
+ } else {
+ contextOperationType = primaryKey == null ? Operation.INSERT : Operation.UPDATE_OR_DELETE;
+ return expectedOperationType & contextOperationType;
+ }
+ }
+
+}
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/impl/EntityPropertyFactory.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/PropertyProxyFactory.java
similarity index 43%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/impl/EntityPropertyFactory.java
rename to dorive-core/src/main/java/com/gitee/dorive/core/impl/PropertyProxyFactory.java
index f25d3beb007f114b5d15c1740a18b3c40fb0c278..8d791153e66c7f077299cfdad7e0b11e651549eb 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/impl/EntityPropertyFactory.java
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/PropertyProxyFactory.java
@@ -1,31 +1,64 @@
-package com.gitee.spring.domain.core.impl;
+/*
+ * 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;
+import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
-import com.gitee.spring.domain.core.api.EntityProperty;
-import com.gitee.spring.domain.core.api.ProxyCompiler;
-import com.gitee.spring.domain.core.compile.JavassistCompiler;
-import com.gitee.spring.domain.core.utils.ReflectUtils;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.proxy.ProxyCompiler;
+import com.gitee.dorive.proxy.JavassistCompiler;
+import com.gitee.dorive.core.util.ReflectUtils;
+import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-public class EntityPropertyFactory {
+public class PropertyProxyFactory {
private static final AtomicInteger COUNT = new AtomicInteger(0);
private static final ProxyCompiler PROXY_COMPILER = new JavassistCompiler();
- private static final Map GENERATED_PROXY_CACHE = new ConcurrentHashMap<>();
+ private static final Map GENERATED_PROXY_CACHE = new ConcurrentHashMap<>();
- public static EntityProperty newEntityProperty(Class> lastEntityClass, Class> entityClass, String fieldName) {
- String cacheKey = lastEntityClass.getTypeName() + ":" + entityClass.getTypeName() + ":" + fieldName;
+ public static PropertyProxy newPropertyProxy(Class> entityClass, Field declaredField) {
+ return newPropertyProxy(entityClass, declaredField.getType(), declaredField.getName());
+ }
+
+ public static PropertyProxy newPropertyProxy(Class> entityClass, String fieldName) {
+ try {
+ Field field = ReflectUtil.getField(entityClass, fieldName);
+ Class> fieldClass = field.getType();
+ return newPropertyProxy(entityClass, fieldClass, fieldName);
+
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to generate class!", e);
+ }
+ }
+
+ public static PropertyProxy newPropertyProxy(Class> entityClass, Class> fieldClass, String fieldName) {
+ String cacheKey = entityClass.getTypeName() + ":" + fieldClass.getTypeName() + ":" + fieldName;
if (!GENERATED_PROXY_CACHE.containsKey(cacheKey)) {
synchronized (GENERATED_PROXY_CACHE) {
if (!GENERATED_PROXY_CACHE.containsKey(cacheKey)) {
try {
- String generatedCode = generateCode(lastEntityClass, entityClass, fieldName);
+ String generatedCode = generateCode(entityClass, fieldClass, fieldName);
Class> generatedClass = PROXY_COMPILER.compile(generatedCode, null);
- EntityProperty entityProperty = (EntityProperty) ReflectUtils.newInstance(generatedClass);
- GENERATED_PROXY_CACHE.put(cacheKey, entityProperty);
+ PropertyProxy propertyProxy = (PropertyProxy) ReflectUtils.newInstance(generatedClass);
+ GENERATED_PROXY_CACHE.put(cacheKey, propertyProxy);
} catch (Exception e) {
throw new RuntimeException("Failed to generate class!", e);
@@ -36,21 +69,21 @@ public class EntityPropertyFactory {
return GENERATED_PROXY_CACHE.get(cacheKey);
}
- private static String generateCode(Class> lastEntityClass, Class> entityClass, String fieldName) {
- Class> interfaceClass = EntityProperty.class;
+ private static String generateCode(Class> entityClass, Class> fieldClass, String fieldName) {
+ Class> interfaceClass = PropertyProxy.class;
StringBuilder builder = new StringBuilder();
String simpleName = interfaceClass.getSimpleName() + "$Proxy" + COUNT.getAndIncrement();
builder.append(String.format("package %s;\n", interfaceClass.getPackage().getName()));
builder.append(String.format("public class %s implements %s {\n", simpleName, interfaceClass.getName()));
builder.append("\t").append(String.format("public %s getValue(%s arg0) {\n", Object.class.getTypeName(), Object.class.getTypeName()));
- builder.append("\t\t").append(String.format("%s arg1 = (%s)arg0;\n", lastEntityClass.getTypeName(), lastEntityClass.getTypeName()));
+ builder.append("\t\t").append(String.format("%s arg1 = (%s)arg0;\n", entityClass.getTypeName(), entityClass.getTypeName()));
builder.append("\t\t").append(String.format("return arg1.get%s();\n", StrUtil.upperFirst(fieldName)));
builder.append("\t").append("}\n");
builder.append("\t").append(String.format("public void setValue(%s arg0, %s arg1) {\n", Object.class.getTypeName(), Object.class.getTypeName()));
- builder.append("\t\t").append(String.format("%s arg2 = (%s)arg0;\n", lastEntityClass.getTypeName(), lastEntityClass.getTypeName()));
- builder.append("\t\t").append(String.format("%s arg3 = (%s)arg1;\n", entityClass.getTypeName(), entityClass.getTypeName()));
+ builder.append("\t\t").append(String.format("%s arg2 = (%s)arg0;\n", entityClass.getTypeName(), entityClass.getTypeName()));
+ builder.append("\t\t").append(String.format("%s arg3 = (%s)arg1;\n", fieldClass.getTypeName(), fieldClass.getTypeName()));
builder.append("\t\t").append(String.format("arg2.set%s(arg3);\n", StrUtil.upperFirst(fieldName)));
builder.append("\t").append("}\n");
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/AbstractBinder.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/AbstractBinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..ba140812e1c7f7ce47d7e7c42f4252678c6ca41d
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/AbstractBinder.java
@@ -0,0 +1,60 @@
+/*
+ * 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.binder;
+
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.api.Binder;
+import com.gitee.dorive.core.api.Processor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.PropertyChain;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public abstract class AbstractBinder implements Binder, Processor {
+
+ protected BindingDefinition bindingDefinition;
+ protected PropertyChain fieldPropertyChain;
+ protected Processor processor;
+
+ @Override
+ public BindingDefinition getBindingDefinition() {
+ return bindingDefinition;
+ }
+
+ @Override
+ public Object getFieldValue(BoundedContext boundedContext, Object entity) {
+ return fieldPropertyChain.getValue(entity);
+ }
+
+ @Override
+ public void setFieldValue(BoundedContext boundedContext, Object entity, Object property) {
+ fieldPropertyChain.setValue(entity, property);
+ }
+
+ @Override
+ public Object input(BoundedContext boundedContext, Object valueObject) {
+ return processor.input(boundedContext, valueObject);
+ }
+
+ @Override
+ public Object output(BoundedContext boundedContext, Object valueObject) {
+ return processor.output(boundedContext, valueObject);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/ContextBinder.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/ContextBinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..125d2afb6b05353d30e583897edaa543ec238882
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/ContextBinder.java
@@ -0,0 +1,43 @@
+/*
+ * 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.binder;
+
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.api.Processor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.PropertyChain;
+
+public class ContextBinder extends AbstractBinder {
+
+ public ContextBinder(BindingDefinition bindingDefinition,
+ PropertyChain fieldPropertyChain,
+ Processor processor) {
+ super(bindingDefinition, fieldPropertyChain, processor);
+ }
+
+ @Override
+ public Object getBoundValue(BoundedContext boundedContext, Object rootEntity) {
+ String bindCtx = bindingDefinition.getBindCtx();
+ return boundedContext.get(bindCtx);
+ }
+
+ @Override
+ public void setBoundValue(BoundedContext boundedContext, Object rootEntity, Object property) {
+ // ignore
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/PropertyBinder.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/PropertyBinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..6e7c06bbe8ab9218ff119297390d89c9244d57ed
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/binder/PropertyBinder.java
@@ -0,0 +1,61 @@
+/*
+ * 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.binder;
+
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.api.Processor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class PropertyBinder extends AbstractBinder {
+
+ protected String belongAccessPath;
+ protected ConfiguredRepository belongRepository;
+ protected PropertyChain boundPropertyChain;
+
+ public PropertyBinder(BindingDefinition bindingDefinition,
+ PropertyChain fieldPropertyChain,
+ Processor processor,
+ String belongAccessPath,
+ ConfiguredRepository belongRepository,
+ PropertyChain boundPropertyChain) {
+ super(bindingDefinition, fieldPropertyChain, processor);
+ this.belongAccessPath = belongAccessPath;
+ this.belongRepository = belongRepository;
+ this.boundPropertyChain = boundPropertyChain;
+ }
+
+ public boolean isSameType() {
+ return fieldPropertyChain.getProperty().isSameType(boundPropertyChain.getProperty());
+ }
+
+ @Override
+ public Object getBoundValue(BoundedContext boundedContext, Object rootEntity) {
+ return boundPropertyChain.getValue(rootEntity);
+ }
+
+ @Override
+ public void setBoundValue(BoundedContext boundedContext, Object rootEntity, Object property) {
+ boundPropertyChain.setValue(rootEntity, property);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/AbstractExecutor.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/AbstractExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..d55aaf85572c96590046a76ca050ecf9c12aa61d
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/AbstractExecutor.java
@@ -0,0 +1,105 @@
+/*
+ * 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.executor;
+
+import com.gitee.dorive.core.entity.operation.Delete;
+import com.gitee.dorive.core.entity.operation.Insert;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Query;
+import com.gitee.dorive.core.entity.operation.Update;
+import com.gitee.dorive.core.api.Executor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.executor.Example;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public abstract class AbstractExecutor implements Executor {
+
+ protected EntityElement entityElement;
+
+ @Override
+ public Query buildQueryByPK(BoundedContext boundedContext, Object primaryKey) {
+ Query query = new Query(Operation.SELECT, null);
+ query.setPrimaryKey(primaryKey);
+ return query;
+ }
+
+ @Override
+ public Query buildQuery(BoundedContext boundedContext, Example example) {
+ Query query = new Query(Operation.SELECT, null);
+ query.setExample(example);
+ return query;
+ }
+
+ @Override
+ public Insert buildInsert(BoundedContext boundedContext, Object entity) {
+ return new Insert(Operation.INSERT, entity);
+ }
+
+ @Override
+ public Update buildUpdate(BoundedContext boundedContext, Object entity) {
+ Update update = new Update(Operation.UPDATE, entity);
+ Object primaryKey = entityElement.getPrimaryKeyProxy().getValue(entity);
+ update.setPrimaryKey(primaryKey);
+ return update;
+ }
+
+ @Override
+ public Update buildUpdate(BoundedContext boundedContext, Object entity, Example example) {
+ Update update = new Update(Operation.UPDATE, entity);
+ update.setExample(example);
+ return update;
+ }
+
+ @Override
+ public Operation buildInsertOrUpdate(BoundedContext boundedContext, Object entity) {
+ Object primaryKey = entityElement.getPrimaryKeyProxy().getValue(entity);
+ if (primaryKey == null) {
+ return new Insert(Operation.INSERT, entity);
+ } else {
+ Update update = new Update(Operation.UPDATE, entity);
+ update.setPrimaryKey(primaryKey);
+ return update;
+ }
+ }
+
+ @Override
+ public Delete buildDelete(BoundedContext boundedContext, Object entity) {
+ Delete delete = new Delete(Operation.DELETE, entity);
+ Object primaryKey = entityElement.getPrimaryKeyProxy().getValue(entity);
+ delete.setPrimaryKey(primaryKey);
+ return delete;
+ }
+
+ @Override
+ public Delete buildDeleteByPK(BoundedContext boundedContext, Object primaryKey) {
+ Delete delete = new Delete(Operation.DELETE, null);
+ delete.setPrimaryKey(primaryKey);
+ return delete;
+ }
+
+ @Override
+ public Delete buildDelete(BoundedContext boundedContext, Example example) {
+ Delete delete = new Delete(Operation.DELETE, null);
+ delete.setExample(example);
+ return delete;
+ }
+
+}
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
new file mode 100644
index 0000000000000000000000000000000000000000..ec471fc0cfdfe84917f0d0ea57d7f5fd8a6b473e
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/executor/ChainExecutor.java
@@ -0,0 +1,176 @@
+/*
+ * 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.executor;
+
+import cn.hutool.core.lang.Assert;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Query;
+import com.gitee.dorive.core.api.Binder;
+import com.gitee.dorive.core.api.EntityHandler;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.impl.OperationTypeResolver;
+import com.gitee.dorive.core.impl.resolver.DelegateResolver;
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+@Getter
+@Setter
+@ToString
+public class ChainExecutor extends AbstractExecutor implements EntityHandler {
+
+ private final AbstractContextRepository, ?> repository;
+ private final EntityHandler entityHandler;
+
+ private final OperationTypeResolver operationTypeResolver = new OperationTypeResolver();
+
+ public ChainExecutor(AbstractContextRepository, ?> repository, EntityHandler entityHandler) {
+ super(repository.getEntityElement());
+ this.repository = repository;
+ this.entityHandler = entityHandler;
+ }
+
+ @Override
+ public Result executeQuery(BoundedContext boundedContext, Query query) {
+ ConfiguredRepository rootRepository = repository.getRootRepository();
+ if (query.getPrimaryKey() != null) {
+ Object rootEntity = rootRepository.selectByPrimaryKey(boundedContext, query.getPrimaryKey());
+ if (rootEntity != null) {
+ handleEntities(boundedContext, Collections.singletonList(rootEntity));
+ }
+ return new Result<>(rootEntity);
+
+ } else if (query.getExample() != null) {
+ Result result = rootRepository.selectResultByExample(boundedContext, query.getExample());
+ List rootEntities = result.getRecords();
+ if (!rootEntities.isEmpty()) {
+ handleEntities(boundedContext, rootEntities);
+ }
+ return result;
+
+ } else {
+ throw new RuntimeException("Unsupported query method!");
+ }
+ }
+
+ @Override
+ public void handleEntities(BoundedContext boundedContext, List rootEntities) {
+ entityHandler.handleEntities(boundedContext, rootEntities);
+ }
+
+ @Override
+ public Operation buildInsertOrUpdate(BoundedContext boundedContext, Object entity) {
+ return new Operation(Operation.INSERT_OR_UPDATE, entity);
+ }
+
+ @Override
+ public int execute(BoundedContext boundedContext, Operation operation) {
+ int expectedOperationType = operation.getType();
+ boolean isInsertContext = (expectedOperationType & Operation.INSERT) == Operation.INSERT;
+
+ Object rootEntity = operation.getEntity();
+ Assert.notNull(rootEntity, "The rootEntity cannot be null!");
+
+ DelegateResolver delegateResolver = repository.getDelegateResolver();
+ AbstractContextRepository, ?> delegateRepository = delegateResolver.delegateRepository(rootEntity);
+ delegateRepository = delegateRepository == null ? repository : delegateRepository;
+
+ int totalCount = 0;
+ for (ConfiguredRepository repository : delegateRepository.getOrderedRepositories()) {
+ PropertyChain anchorPoint = repository.getAnchorPoint();
+ Object targetEntity = anchorPoint == null ? rootEntity : anchorPoint.getValue(rootEntity);
+
+ if (targetEntity != null && repository.matchKeys(boundedContext)) {
+ int contextOperationType = operationTypeResolver.resolveOperationType(boundedContext, repository);
+
+ Collection> collection;
+ Object boundIdEntity = null;
+ if (targetEntity instanceof Collection) {
+ collection = (Collection>) targetEntity;
+ } else {
+ collection = Collections.singletonList(targetEntity);
+ boundIdEntity = targetEntity;
+ }
+
+ for (Object entity : collection) {
+ Object primaryKey = repository.getPrimaryKey(entity);
+ int operationType = operationTypeResolver.mergeOperationType(expectedOperationType, contextOperationType, primaryKey);
+ if ((operationType & Operation.INSERT) == Operation.INSERT) {
+ getBoundValueFromContext(boundedContext, rootEntity, repository, entity);
+ }
+ operationType = repository.isAggregated() ? expectedOperationType : operationType;
+ totalCount += doExecute(boundedContext, repository, entity, operationType);
+ }
+
+ if (isInsertContext && boundIdEntity != null) {
+ setBoundIdForBoundEntity(boundedContext, rootEntity, repository, boundIdEntity);
+ }
+ }
+ }
+ return totalCount;
+ }
+
+ private int doExecute(BoundedContext boundedContext, ConfiguredRepository repository, Object entity, int operationType) {
+ if (operationType == Operation.INSERT) {
+ return repository.insert(boundedContext, entity);
+
+ } else if (operationType == Operation.UPDATE) {
+ return repository.update(boundedContext, entity);
+
+ } else if (operationType == Operation.INSERT_OR_UPDATE) {
+ return repository.insertOrUpdate(boundedContext, entity);
+
+ } else if (operationType == Operation.DELETE) {
+ return repository.delete(boundedContext, entity);
+ }
+ return 0;
+ }
+
+ private void getBoundValueFromContext(BoundedContext boundedContext, Object rootEntity, ConfiguredRepository repository, Object entity) {
+ for (Binder binder : repository.getBinderResolver().getBoundValueBinders()) {
+ Object fieldValue = binder.getFieldValue(boundedContext, entity);
+ if (fieldValue == null) {
+ Object boundValue = binder.getBoundValue(boundedContext, rootEntity);
+ if (boundValue != null) {
+ binder.setFieldValue(boundedContext, entity, boundValue);
+ }
+ }
+ }
+ }
+
+ private void setBoundIdForBoundEntity(BoundedContext boundedContext, Object rootEntity, ConfiguredRepository repository, Object entity) {
+ Binder binder = repository.getBinderResolver().getBoundIdBinder();
+ if (binder != null) {
+ Object boundValue = binder.getBoundValue(boundedContext, rootEntity);
+ if (boundValue == null) {
+ Object primaryKey = binder.getFieldValue(boundedContext, entity);
+ if (primaryKey != null) {
+ binder.setBoundValue(boundedContext, rootEntity, primaryKey);
+ }
+ }
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/AdaptiveEntityHandler.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/AdaptiveEntityHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..2784fe53d0231f941af87fbcc9355ce442cf2044
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/AdaptiveEntityHandler.java
@@ -0,0 +1,73 @@
+/*
+ * 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.handler;
+
+import com.gitee.dorive.core.api.EntityHandler;
+import com.gitee.dorive.core.api.Executor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.impl.resolver.DelegateResolver;
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class AdaptiveEntityHandler implements EntityHandler {
+
+ private final AbstractContextRepository, ?> repository;
+ private final EntityHandler entityHandler;
+
+ public AdaptiveEntityHandler(AbstractContextRepository, ?> repository, EntityHandler entityHandler) {
+ this.repository = repository;
+ this.entityHandler = entityHandler;
+ }
+
+ @Override
+ public void handleEntities(BoundedContext boundedContext, List rootEntities) {
+ List newRootEntities = new ArrayList<>(rootEntities.size());
+ int delegateCount = repository.getDelegateResolver().getDelegateCount();
+ Map, List> repositoryEntitiesMap = new LinkedHashMap<>(delegateCount * 4 / 3 + 1);
+ filterRootEntities(rootEntities, newRootEntities, repositoryEntitiesMap);
+ if (!newRootEntities.isEmpty()) {
+ entityHandler.handleEntities(boundedContext, newRootEntities);
+ }
+ repositoryEntitiesMap.forEach((repository, entities) -> {
+ Executor executor = repository.getExecutor();
+ if (executor instanceof EntityHandler) {
+ ((EntityHandler) executor).handleEntities(boundedContext, entities);
+ }
+ });
+ }
+
+ private void filterRootEntities(List rootEntities, List newRootEntities,
+ Map, List> repositoryEntitiesMap) {
+ DelegateResolver delegateResolver = repository.getDelegateResolver();
+ for (Object rootEntity : rootEntities) {
+ AbstractContextRepository, ?> repository = delegateResolver.delegateRepository(rootEntity);
+ if (repository == null) {
+ newRootEntities.add(rootEntity);
+ } else {
+ List existRootEntities = repositoryEntitiesMap.computeIfAbsent(repository, key -> new ArrayList<>(rootEntities.size()));
+ existRootEntities.add(rootEntity);
+ }
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/BatchEntityHandler.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/BatchEntityHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..480dce5ebbba3b3d54b5212172d9e77ff40466a6
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/handler/BatchEntityHandler.java
@@ -0,0 +1,106 @@
+/*
+ * 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.handler;
+
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.executor.UnionExample;
+import com.gitee.dorive.core.api.EntityHandler;
+import com.gitee.dorive.core.api.EntityIndex;
+import com.gitee.dorive.core.api.ExampleBuilder;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+
+public class BatchEntityHandler implements EntityHandler {
+
+ private final AbstractContextRepository, ?> repository;
+
+ public BatchEntityHandler(AbstractContextRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public void handleEntities(BoundedContext boundedContext, List rootEntities) {
+ for (ConfiguredRepository repository : this.repository.getSubRepositories()) {
+ if (repository.matchKeys(boundedContext)) {
+ UnionExample unionExample = newUnionExample(repository, boundedContext, rootEntities);
+ if (!unionExample.isDirtyQuery()) {
+ continue;
+ }
+ Result result = repository.selectResultByExample(boundedContext, unionExample);
+ if (!(result instanceof EntityIndex)) {
+ continue;
+ }
+ setValueForRootEntities(repository, rootEntities, (EntityIndex) result);
+ }
+ }
+ }
+
+ private UnionExample newUnionExample(ConfiguredRepository repository, BoundedContext boundedContext, List rootEntities) {
+ ConfiguredRepository rootRepository = this.repository.getRootRepository();
+
+ PropertyChain anchorPoint = repository.getAnchorPoint();
+ PropertyChain lastPropertyChain = anchorPoint.getLastPropertyChain();
+
+ String builderKey = repository.getEntityDefinition().getBuilderKey();
+ ExampleBuilder exampleBuilder = StringUtils.isNotBlank(builderKey) ? (ExampleBuilder) boundedContext.get(builderKey) : null;
+
+ UnionExample unionExample = new UnionExample();
+ for (Object rootEntity : rootEntities) {
+ Object lastEntity = lastPropertyChain == null ? rootEntity : lastPropertyChain.getValue(rootEntity);
+ if (lastEntity != null) {
+ Example example = repository.newExampleByContext(boundedContext, rootEntity);
+ if (exampleBuilder != null) {
+ example = exampleBuilder.buildExample(boundedContext, rootEntity, example);
+ }
+ if (example.isDirtyQuery()) {
+ Object primaryKey = rootRepository.getPrimaryKey(rootEntity);
+ example.selectColumns(primaryKey + " as $id");
+ unionExample.addExample(example);
+ }
+ }
+ }
+ return unionExample;
+ }
+
+ private void setValueForRootEntities(ConfiguredRepository repository, List rootEntities, EntityIndex entityIndex) {
+ ConfiguredRepository rootRepository = this.repository.getRootRepository();
+
+ PropertyChain anchorPoint = repository.getAnchorPoint();
+ PropertyChain lastPropertyChain = anchorPoint.getLastPropertyChain();
+ PropertyProxy propertyProxy = anchorPoint.getPropertyProxy();
+
+ for (Object rootEntity : rootEntities) {
+ Object lastEntity = lastPropertyChain == null ? rootEntity : lastPropertyChain.getValue(rootEntity);
+ if (lastEntity != null) {
+ Object primaryKey = rootRepository.getPrimaryKey(rootEntity);
+ List entities = entityIndex.selectList(rootEntity, primaryKey);
+ Object entity = repository.convertManyToOne(entities);
+ if (entity != null) {
+ propertyProxy.setValue(lastEntity, entity);
+ }
+ }
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/DefaultProcessor.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/DefaultProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..2fd3d9627f4b3207949e2dfc497cb2fb13e17934
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/DefaultProcessor.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.processor;
+
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.api.Processor;
+import com.gitee.dorive.core.entity.BoundedContext;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class DefaultProcessor implements Processor {
+
+ protected BindingDefinition bindingDefinition;
+
+ @Override
+ public Object input(BoundedContext boundedContext, Object valueObject) {
+ return valueObject;
+ }
+
+ @Override
+ public Object output(BoundedContext boundedContext, Object valueObject) {
+ return valueObject;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/PropertyProcessor.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/PropertyProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..f6493a3ae8d78a1dff8ffe3c89cb0b34b18e18e0
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/processor/PropertyProcessor.java
@@ -0,0 +1,43 @@
+/*
+ * 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.processor;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import com.gitee.dorive.core.entity.BoundedContext;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Collection;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class PropertyProcessor extends DefaultProcessor {
+
+ @Override
+ public Object input(BoundedContext boundedContext, Object valueObject) {
+ String property = bindingDefinition.getProperty();
+ if (valueObject instanceof Collection) {
+ return CollUtil.map((Collection>) valueObject, item -> BeanUtil.getFieldValue(item, property), true);
+ } else {
+ return BeanUtil.getFieldValue(valueObject, property);
+ }
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/BinderResolver.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/BinderResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..6e90b7384199991425e0a9d9e8eda1f6bc31b8c2
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/BinderResolver.java
@@ -0,0 +1,190 @@
+/*
+ * 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.resolver;
+
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.StrUtil;
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.entity.definition.EntityDefinition;
+import com.gitee.dorive.core.impl.binder.ContextBinder;
+import com.gitee.dorive.core.impl.binder.PropertyBinder;
+import com.gitee.dorive.core.impl.processor.DefaultProcessor;
+import com.gitee.dorive.core.impl.processor.PropertyProcessor;
+import com.gitee.dorive.core.api.Binder;
+import com.gitee.dorive.core.api.Processor;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+import com.gitee.dorive.core.util.PathUtils;
+import com.gitee.dorive.core.util.ReflectUtils;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.ApplicationContext;
+
+import java.util.*;
+
+@Data
+public class BinderResolver {
+
+ private AbstractContextRepository, ?> repository;
+
+ private List allBinders;
+ private List propertyBinders;
+ private String[] boundColumns;
+ private List contextBinders;
+ private List boundValueBinders;
+ private PropertyBinder boundIdBinder;
+
+ public BinderResolver(AbstractContextRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ public void resolveAllBinders(String accessPath, EntityElement entityElement, EntityDefinition entityDefinition,
+ String fieldPrefix, PropertyResolver propertyResolver) {
+
+ List bindingDefinitions = BindingDefinition.newBindingDefinitions(entityElement);
+ Map allPropertyChainMap = propertyResolver.getAllPropertyChainMap();
+
+ allBinders = new ArrayList<>(bindingDefinitions.size());
+ propertyBinders = new ArrayList<>(bindingDefinitions.size());
+ Set boundColumns = new LinkedHashSet<>(bindingDefinitions.size() * 4 / 3 + 1);
+ contextBinders = new ArrayList<>(bindingDefinitions.size());
+ boundValueBinders = new ArrayList<>(bindingDefinitions.size());
+ boundIdBinder = null;
+
+ for (BindingDefinition bindingDefinition : bindingDefinitions) {
+ renewBindingDefinition(accessPath, bindingDefinition);
+
+ String field = bindingDefinition.getField();
+ PropertyChain fieldPropertyChain = allPropertyChainMap.get(fieldPrefix + field);
+ Assert.notNull(fieldPropertyChain, "The field property chain cannot be null! entity: {}, field: {}",
+ entityElement.getGenericEntityClass().getSimpleName(), field);
+ fieldPropertyChain.initialize();
+
+ Processor processor = newProcessor(bindingDefinition);
+
+ if (StringUtils.isNotBlank(bindingDefinition.getBindProp())) {
+ PropertyBinder propertyBinder = newPropertyBinder(bindingDefinition, fieldPropertyChain, processor);
+ allBinders.add(propertyBinder);
+ propertyBinders.add(propertyBinder);
+ boundColumns.add(StrUtil.toUnderlineCase(bindingDefinition.getAlias()));
+
+ if (propertyBinder.isSameType()) {
+ if (!"id".equals(field)) {
+ boundValueBinders.add(propertyBinder);
+ } else {
+ if (entityDefinition.getOrder() == 0) {
+ entityDefinition.setOrder(-1);
+ }
+ boundIdBinder = propertyBinder;
+ }
+ }
+
+ } else {
+ ContextBinder contextBinder = new ContextBinder(bindingDefinition, fieldPropertyChain, processor);
+ allBinders.add(contextBinder);
+ contextBinders.add(contextBinder);
+ boundValueBinders.add(contextBinder);
+ }
+ }
+
+ this.boundColumns = boundColumns.toArray(new String[0]);
+ }
+
+ private void renewBindingDefinition(String accessPath, BindingDefinition bindingDefinition) {
+ String field = bindingDefinition.getField();
+ String bindProp = bindingDefinition.getBindProp();
+ String property = bindingDefinition.getProperty();
+ Class> processor = bindingDefinition.getProcessor();
+ String bindCtx = bindingDefinition.getBindCtx();
+ String alias = bindingDefinition.getAlias();
+ String bindAlias = bindingDefinition.getBindAlias();
+
+ Assert.notBlank(bindProp + bindCtx, "The bindProp and bindCtx cannot be blank at the same time!");
+
+ if (StringUtils.isBlank(alias)) {
+ alias = field;
+ }
+ if (StringUtils.isBlank(bindAlias)) {
+ bindAlias = property;
+ }
+
+ if (StringUtils.isNotBlank(bindProp)) {
+ Assert.isTrue(bindProp.startsWith("/") || bindProp.startsWith("."), "The bindProp must be a path!");
+ if (bindProp.startsWith(".")) {
+ bindProp = PathUtils.getAbsolutePath(accessPath, bindProp);
+ }
+ if (StringUtils.isBlank(bindAlias)) {
+ bindAlias = PathUtils.getFieldName(bindProp);
+ }
+ }
+
+ bindingDefinition.setField(field);
+ bindingDefinition.setBindProp(bindProp);
+ bindingDefinition.setProperty(property);
+ bindingDefinition.setProcessor(processor);
+ bindingDefinition.setBindCtx(bindCtx);
+ bindingDefinition.setAlias(alias);
+ bindingDefinition.setBindAlias(bindAlias);
+ }
+
+ private Processor newProcessor(BindingDefinition bindingDefinition) {
+ Class> processorClass = bindingDefinition.getProcessor();
+ Processor processor = null;
+ if (processorClass == DefaultProcessor.class) {
+ if (StringUtils.isBlank(bindingDefinition.getProperty())) {
+ processor = new DefaultProcessor();
+ } else {
+ processor = new PropertyProcessor();
+ }
+ } else {
+ ApplicationContext applicationContext = repository.getApplicationContext();
+ String[] beanNamesForType = applicationContext.getBeanNamesForType(processorClass);
+ if (beanNamesForType.length > 0) {
+ processor = (Processor) applicationContext.getBean(beanNamesForType[0]);
+ }
+ if (processor == null) {
+ processor = (Processor) ReflectUtils.newInstance(processorClass);
+ }
+ }
+ if (processor instanceof DefaultProcessor) {
+ DefaultProcessor defaultProcessor = (DefaultProcessor) processor;
+ defaultProcessor.setBindingDefinition(bindingDefinition);
+ }
+ if (processor instanceof PropertyProcessor) {
+ Assert.notBlank(bindingDefinition.getProperty(), "The property of PropertyProcessor cannot be blank!");
+ }
+ return processor;
+ }
+
+ private PropertyBinder newPropertyBinder(BindingDefinition bindingDefinition, PropertyChain fieldPropertyChain, Processor processor) {
+ Map allRepositoryMap = repository.getAllRepositoryMap();
+ String belongAccessPath = PathUtils.getBelongPath(allRepositoryMap.keySet(), bindingDefinition.getBindProp());
+ ConfiguredRepository belongRepository = allRepositoryMap.get(belongAccessPath);
+ Assert.notNull(belongRepository, "The belong repository cannot be null!");
+ belongRepository.setBoundEntity(true);
+
+ Map allPropertyChainMap = repository.getPropertyResolver().getAllPropertyChainMap();
+ PropertyChain boundPropertyChain = allPropertyChainMap.get(bindingDefinition.getBindProp());
+ Assert.notNull(boundPropertyChain, "The bound property chain cannot be null!");
+ boundPropertyChain.initialize();
+
+ return new PropertyBinder(bindingDefinition, fieldPropertyChain, processor, belongAccessPath, belongRepository, boundPropertyChain);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/DelegateResolver.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/DelegateResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..831d2cea5ebe6d5599db9d0ee7e574e0781fd4ee
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/DelegateResolver.java
@@ -0,0 +1,65 @@
+/*
+ * 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.resolver;
+
+import com.gitee.dorive.core.repository.AbstractContextRepository;
+import lombok.Data;
+import org.springframework.context.ApplicationContext;
+import org.springframework.util.ReflectionUtils;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Data
+public class DelegateResolver {
+
+ private AbstractContextRepository, ?> repository;
+
+ private Map, AbstractContextRepository, ?>> delegateRepositoryMap = new LinkedHashMap<>(3 * 4 / 3 + 1);
+
+ public DelegateResolver(AbstractContextRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ public void resolveDelegateRepositoryMap() {
+ ReflectionUtils.doWithLocalFields(repository.getClass(), declaredField -> {
+ Class> fieldClass = declaredField.getType();
+ if (AbstractContextRepository.class.isAssignableFrom(fieldClass)) {
+ ApplicationContext applicationContext = repository.getApplicationContext();
+ Object beanInstance = applicationContext.getBean(fieldClass);
+ AbstractContextRepository, ?> abstractContextRepository = (AbstractContextRepository, ?>) beanInstance;
+ Class> fieldEntityClass = abstractContextRepository.getEntityClass();
+ if (repository.getEntityClass().isAssignableFrom(fieldEntityClass)) {
+ delegateRepositoryMap.put(fieldEntityClass, abstractContextRepository);
+ }
+ }
+ });
+ }
+
+ public boolean isDelegated() {
+ return !delegateRepositoryMap.isEmpty();
+ }
+
+ public int getDelegateCount() {
+ return delegateRepositoryMap.size();
+ }
+
+ public AbstractContextRepository, ?> delegateRepository(Object rootEntity) {
+ return delegateRepositoryMap.get(rootEntity.getClass());
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/PropertyResolver.java b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/PropertyResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..bf8b9e0ae11c66c32c7fde33340709ed995c7954
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/impl/resolver/PropertyResolver.java
@@ -0,0 +1,80 @@
+/*
+ * 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.resolver;
+
+import com.gitee.dorive.core.annotation.Entity;
+import com.gitee.dorive.core.entity.Property;
+import com.gitee.dorive.core.entity.PropertyChain;
+import lombok.Data;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+import org.springframework.util.ReflectionUtils;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Data
+public class PropertyResolver {
+
+ private boolean ignoreAnnotated;
+ private Map allPropertyChainMap = new LinkedHashMap<>();
+
+ public PropertyResolver(boolean ignoreAnnotated) {
+ this.ignoreAnnotated = ignoreAnnotated;
+ }
+
+ public void resolveProperties(Class> entityClass) {
+ resolveProperties("", entityClass);
+ }
+
+ public void resolveProperties(String lastAccessPath, Class> entityClass) {
+ PropertyChain lastPropertyChain = allPropertyChainMap.get(lastAccessPath);
+ ReflectionUtils.doWithLocalFields(entityClass, declaredField -> {
+ String accessPath = lastAccessPath + "/" + declaredField.getName();
+ boolean isAnnotatedEntity = AnnotatedElementUtils.isAnnotated(declaredField, Entity.class);
+ Property property = new Property(declaredField);
+
+ PropertyChain propertyChain = new PropertyChain(
+ lastPropertyChain,
+ entityClass,
+ accessPath,
+ isAnnotatedEntity,
+ property,
+ null);
+
+ if (isAnnotatedEntity) {
+ propertyChain.initialize();
+ }
+
+ allPropertyChainMap.put(accessPath, propertyChain);
+
+ if (ignoreAnnotated && isAnnotatedEntity) {
+ return;
+ }
+
+ Class> fieldClass = property.getFieldClass();
+ if (!filterEntityClass(fieldClass)) {
+ resolveProperties(accessPath, fieldClass);
+ }
+ });
+ }
+
+ private boolean filterEntityClass(Class> entityClass) {
+ String className = entityClass.getName();
+ return className.startsWith("java.lang.") || className.startsWith("java.util.") || entityClass.isEnum();
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractContextRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractContextRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..66c331069211dc8718771ddaac05f605e28ec246
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractContextRepository.java
@@ -0,0 +1,155 @@
+/*
+ * 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.repository;
+
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.entity.definition.EntityDefinition;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.impl.executor.ChainExecutor;
+import com.gitee.dorive.core.impl.handler.AdaptiveEntityHandler;
+import com.gitee.dorive.core.impl.handler.BatchEntityHandler;
+import com.gitee.dorive.core.impl.resolver.BinderResolver;
+import com.gitee.dorive.core.impl.resolver.DelegateResolver;
+import com.gitee.dorive.core.impl.resolver.PropertyResolver;
+import com.gitee.dorive.core.api.EntityHandler;
+import com.gitee.dorive.core.api.Executor;
+import com.gitee.dorive.core.util.ReflectUtils;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.*;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public abstract class AbstractContextRepository extends AbstractRepository implements ApplicationContextAware, InitializingBean {
+
+ protected ApplicationContext applicationContext;
+
+ protected Class> entityClass;
+
+ protected DelegateResolver delegateResolver = new DelegateResolver(this);
+ protected PropertyResolver propertyResolver = new PropertyResolver(false);
+
+ protected Map allRepositoryMap = new LinkedHashMap<>();
+ protected ConfiguredRepository rootRepository;
+ protected List subRepositories = new ArrayList<>();
+ protected List orderedRepositories = new ArrayList<>();
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ entityClass = ReflectUtils.getFirstArgumentType(this.getClass());
+ delegateResolver.resolveDelegateRepositoryMap();
+
+ List> allClasses = ReflectUtils.getAllSuperclasses(entityClass, Object.class);
+ allClasses.add(entityClass);
+ allClasses.forEach(clazz -> propertyResolver.resolveProperties(clazz));
+
+ ConfiguredRepository rootRepository = newRepository("/", entityClass);
+ allRepositoryMap.put("/", rootRepository);
+ this.rootRepository = rootRepository;
+ orderedRepositories.add(rootRepository);
+
+ Map allPropertyChainMap = propertyResolver.getAllPropertyChainMap();
+ allPropertyChainMap.forEach((accessPath, propertyChain) -> {
+ if (propertyChain.isAnnotatedEntity()) {
+ ConfiguredRepository subRepository = newRepository(accessPath, propertyChain.getProperty().getDeclaredField());
+ allRepositoryMap.put(accessPath, subRepository);
+ subRepositories.add(subRepository);
+ orderedRepositories.add(subRepository);
+ }
+ });
+
+ orderedRepositories.sort(Comparator.comparingInt(repository -> repository.getEntityDefinition().getOrder()));
+
+ setEntityElement(rootRepository.getEntityElement());
+ setEntityDefinition(rootRepository.getEntityDefinition());
+
+ EntityHandler entityHandler = new BatchEntityHandler(this);
+ if (delegateResolver.isDelegated()) {
+ entityHandler = new AdaptiveEntityHandler(this, entityHandler);
+ }
+ setExecutor(new ChainExecutor(this, entityHandler));
+ }
+
+ @SuppressWarnings("unchecked")
+ private ConfiguredRepository newRepository(String accessPath, AnnotatedElement annotatedElement) {
+ EntityElement entityElement = EntityElement.newEntityElement(annotatedElement);
+ EntityDefinition entityDefinition = EntityDefinition.newEntityDefinition(entityElement);
+
+ Class> repositoryClass = entityDefinition.getRepository();
+ Object repository;
+ if (repositoryClass == DefaultRepository.class) {
+ repository = new DefaultRepository();
+ } else {
+ repository = applicationContext.getBean(repositoryClass);
+ }
+ if (repository instanceof DefaultRepository) {
+ DefaultRepository defaultRepository = (DefaultRepository) repository;
+ defaultRepository.setEntityElement(entityElement);
+ defaultRepository.setEntityDefinition(entityDefinition);
+ defaultRepository.setExecutor(newExecutor(entityElement, entityDefinition));
+ }
+
+ boolean aggregateRoot = "/".equals(accessPath);
+ boolean aggregated = !(repository instanceof DefaultRepository);
+ repository = postProcessRepository((AbstractRepository) repository);
+
+ Map allPropertyChainMap = propertyResolver.getAllPropertyChainMap();
+ PropertyChain anchorPoint = allPropertyChainMap.get(accessPath);
+
+ PropertyResolver propertyResolver = new PropertyResolver(true);
+ String lastAccessPath = aggregateRoot || entityElement.isCollection() ? "" : accessPath;
+ propertyResolver.resolveProperties(lastAccessPath, entityElement.getGenericEntityClass());
+
+ OrderBy defaultOrderBy = entityDefinition.getDefaultOrderBy();
+
+ BinderResolver binderResolver = new BinderResolver(this);
+ String fieldPrefix = lastAccessPath + "/";
+ binderResolver.resolveAllBinders(accessPath, entityElement, entityDefinition, fieldPrefix, propertyResolver);
+
+ ConfiguredRepository configuredRepository = new ConfiguredRepository();
+ configuredRepository.setEntityElement(entityElement);
+ configuredRepository.setEntityDefinition(entityDefinition);
+ configuredRepository.setProxyRepository((AbstractRepository) repository);
+ configuredRepository.setAccessPath(accessPath);
+ configuredRepository.setAggregateRoot(aggregateRoot);
+ configuredRepository.setAggregated(aggregated);
+ configuredRepository.setAnchorPoint(anchorPoint);
+ configuredRepository.setPropertyResolver(propertyResolver);
+ configuredRepository.setDefaultOrderBy(defaultOrderBy);
+ configuredRepository.setFieldPrefix(fieldPrefix);
+ configuredRepository.setBinderResolver(binderResolver);
+ configuredRepository.setBoundEntity(false);
+ return configuredRepository;
+ }
+
+ protected abstract Executor newExecutor(EntityElement entityElement, EntityDefinition entityDefinition);
+
+ protected abstract AbstractRepository postProcessRepository(AbstractRepository repository);
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractGenericRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractGenericRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..2fe08b853dabe15ddbce3594e292146671d2d064
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractGenericRepository.java
@@ -0,0 +1,91 @@
+/*
+ * 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.repository;
+
+import cn.hutool.core.lang.Assert;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.api.ListableRepository;
+import com.gitee.dorive.core.api.MetadataHolder;
+import com.gitee.dorive.core.entity.BoundedContext;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public abstract class AbstractGenericRepository extends AbstractContextRepository
+ implements ListableRepository, MetadataHolder {
+
+ @Override
+ public int updateByExample(BoundedContext boundedContext, Object entity, Example example) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Assert.notNull(example, "The example cannot be null!");
+ int totalCount = 0;
+ for (ConfiguredRepository repository : getOrderedRepositories()) {
+ if (repository.matchKeys(boundedContext)) {
+ totalCount += repository.updateByExample(boundedContext, entity, example);
+ }
+ }
+ return totalCount;
+ }
+
+ @Override
+ public int deleteByPrimaryKey(BoundedContext boundedContext, PK primaryKey) {
+ Assert.notNull(primaryKey, "The primaryKey cannot be null!");
+ E entity = selectByPrimaryKey(boundedContext, primaryKey);
+ return delete(boundedContext, entity);
+ }
+
+ @Override
+ public int deleteByExample(BoundedContext boundedContext, Example example) {
+ Assert.notNull(example, "The example cannot be null!");
+ int totalCount = 0;
+ for (ConfiguredRepository repository : getOrderedRepositories()) {
+ if (repository.matchKeys(boundedContext)) {
+ totalCount += repository.deleteByExample(boundedContext, example);
+ }
+ }
+ return totalCount;
+ }
+
+ @Override
+ public int insertList(BoundedContext boundedContext, List entities) {
+ return entities.stream().mapToInt(entity -> insert(boundedContext, entity)).sum();
+ }
+
+ @Override
+ public int updateList(BoundedContext boundedContext, List entities) {
+ return entities.stream().mapToInt(entity -> update(boundedContext, entity)).sum();
+ }
+
+ @Override
+ public int insertOrUpdateList(BoundedContext boundedContext, List entities) {
+ return entities.stream().mapToInt(entity -> insertOrUpdate(boundedContext, entity)).sum();
+ }
+
+ @Override
+ public int deleteList(BoundedContext boundedContext, List entities) {
+ return entities.stream().mapToInt(entity -> delete(boundedContext, entity)).sum();
+ }
+
+ @Override
+ public Object getMetadata() {
+ return rootRepository.getMetadata();
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..13fa62929a4fd4dc2ecce138ad959b24d536b142
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/AbstractRepository.java
@@ -0,0 +1,130 @@
+/*
+ * 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.repository;
+
+import cn.hutool.core.lang.Assert;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.definition.EntityDefinition;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.operation.Delete;
+import com.gitee.dorive.core.entity.operation.Insert;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Query;
+import com.gitee.dorive.core.entity.operation.Update;
+import com.gitee.dorive.core.api.Executor;
+import com.gitee.dorive.core.api.Repository;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public abstract class AbstractRepository implements Repository {
+
+ protected EntityElement entityElement;
+ protected EntityDefinition entityDefinition;
+ protected Executor executor;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public E selectByPrimaryKey(BoundedContext boundedContext, PK primaryKey) {
+ Assert.notNull(primaryKey, "The primaryKey cannot be null!");
+ Query query = executor.buildQueryByPK(boundedContext, primaryKey);
+ Result result = executor.executeQuery(boundedContext, query);
+ return (E) result.getRecord();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List selectByExample(BoundedContext boundedContext, Example example) {
+ Assert.notNull(example, "The example cannot be null!");
+ Query query = executor.buildQuery(boundedContext, example);
+ Result result = executor.executeQuery(boundedContext, query);
+ return (List) result.getRecords();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Page selectPageByExample(BoundedContext boundedContext, Example example) {
+ Assert.notNull(example, "The example cannot be null!");
+ Assert.notNull(example.getPage(), "The page cannot be null!");
+ Query query = executor.buildQuery(boundedContext, example);
+ Result result = executor.executeQuery(boundedContext, query);
+ return (Page) result.getPage();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Result selectResultByExample(BoundedContext boundedContext, Example example) {
+ Assert.notNull(example, "The example cannot be null!");
+ Query query = executor.buildQuery(boundedContext, example);
+ return (Result) executor.executeQuery(boundedContext, query);
+ }
+
+ @Override
+ public int insert(BoundedContext boundedContext, E entity) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Insert insert = executor.buildInsert(boundedContext, entity);
+ return executor.execute(boundedContext, insert);
+ }
+
+ @Override
+ public int update(BoundedContext boundedContext, E entity) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Update update = executor.buildUpdate(boundedContext, entity);
+ return executor.execute(boundedContext, update);
+ }
+
+ @Override
+ public int updateByExample(BoundedContext boundedContext, Object entity, Example example) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Assert.notNull(example, "The example cannot be null!");
+ Update update = executor.buildUpdate(boundedContext, entity, example);
+ return executor.execute(boundedContext, update);
+ }
+
+ @Override
+ public int insertOrUpdate(BoundedContext boundedContext, E entity) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Operation operation = executor.buildInsertOrUpdate(boundedContext, entity);
+ return executor.execute(boundedContext, operation);
+ }
+
+ @Override
+ public int delete(BoundedContext boundedContext, E entity) {
+ Assert.notNull(entity, "The entity cannot be null!");
+ Delete delete = executor.buildDelete(boundedContext, entity);
+ return executor.execute(boundedContext, delete);
+ }
+
+ @Override
+ public int deleteByPrimaryKey(BoundedContext boundedContext, PK primaryKey) {
+ Assert.notNull(primaryKey, "The primaryKey cannot be null!");
+ Delete delete = executor.buildDeleteByPK(boundedContext, primaryKey);
+ return executor.execute(boundedContext, delete);
+ }
+
+ @Override
+ public int deleteByExample(BoundedContext boundedContext, Example example) {
+ Assert.notNull(example, "The example cannot be null!");
+ Delete delete = executor.buildDelete(boundedContext, example);
+ return executor.execute(boundedContext, delete);
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/repository/ConfiguredRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/ConfiguredRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..dca90ea6e07b5f38f951b69226fb942f2df469c3
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/ConfiguredRepository.java
@@ -0,0 +1,167 @@
+/*
+ * 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.repository;
+
+import com.gitee.dorive.core.entity.PropertyChain;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.impl.binder.ContextBinder;
+import com.gitee.dorive.core.impl.binder.PropertyBinder;
+import com.gitee.dorive.core.impl.resolver.BinderResolver;
+import com.gitee.dorive.core.impl.resolver.PropertyResolver;
+import com.gitee.dorive.core.api.MetadataHolder;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.entity.BoundedContext;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ConfiguredRepository extends ProxyRepository implements MetadataHolder {
+
+ protected String accessPath;
+ protected boolean aggregateRoot;
+ protected boolean aggregated;
+ protected PropertyChain anchorPoint;
+ protected PropertyResolver propertyResolver;
+ protected OrderBy defaultOrderBy;
+ protected String fieldPrefix;
+ protected BinderResolver binderResolver;
+ protected boolean boundEntity;
+
+ @Override
+ public List selectByExample(BoundedContext boundedContext, Example example) {
+ if (example.isEmptyQuery()) {
+ return Collections.emptyList();
+ }
+ if (example.getOrderBy() == null) {
+ example.setOrderBy(defaultOrderBy);
+ }
+ return super.selectByExample(boundedContext, example);
+ }
+
+ @Override
+ public Page selectPageByExample(BoundedContext boundedContext, Example example) {
+ if (example.isEmptyQuery()) {
+ Page page = example.getPage();
+ return page != null ? page : new Page<>();
+ }
+ if (example.getOrderBy() == null) {
+ example.setOrderBy(defaultOrderBy);
+ }
+ return super.selectPageByExample(boundedContext, example);
+ }
+
+ @Override
+ public Result selectResultByExample(BoundedContext boundedContext, Example example) {
+ if (example.isEmptyQuery()) {
+ Page page = example.getPage();
+ return page != null ? new Result<>(page) : new Result<>();
+ }
+ if (example.getOrderBy() == null) {
+ example.setOrderBy(defaultOrderBy);
+ }
+ return super.selectResultByExample(boundedContext, example);
+ }
+
+ @Override
+ public int updateByExample(BoundedContext boundedContext, Object entity, Example example) {
+ if (example.isEmptyQuery()) {
+ return 0;
+ }
+ return super.updateByExample(boundedContext, entity, example);
+ }
+
+ @Override
+ public int deleteByExample(BoundedContext boundedContext, Example example) {
+ if (example.isEmptyQuery()) {
+ return 0;
+ }
+ return super.deleteByExample(boundedContext, example);
+ }
+
+ @Override
+ public Object getMetadata() {
+ AbstractRepository proxyRepository = getProxyRepository();
+ if (proxyRepository instanceof MetadataHolder) {
+ return ((MetadataHolder) proxyRepository).getMetadata();
+ }
+ return null;
+ }
+
+ public boolean matchKeys(BoundedContext boundedContext) {
+ String[] matchKeys = entityDefinition.getMatchKeys();
+ if (matchKeys == null || matchKeys.length == 0) {
+ return true;
+ }
+ for (String matchKey : matchKeys) {
+ if (boundedContext.containsKey(matchKey)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Example newExampleByContext(BoundedContext boundedContext, Object rootEntity) {
+ Example example = new Example();
+ for (PropertyBinder propertyBinder : binderResolver.getPropertyBinders()) {
+ String alias = propertyBinder.getBindingDefinition().getAlias();
+ Object boundValue = propertyBinder.getBoundValue(boundedContext, rootEntity);
+ if (boundValue instanceof Collection) {
+ boundValue = !((Collection>) boundValue).isEmpty() ? boundValue : null;
+ }
+ if (boundValue != null) {
+ boundValue = propertyBinder.input(boundedContext, boundValue);
+ example.eq(alias, boundValue);
+ } else {
+ example.getCriteria().clear();
+ break;
+ }
+ }
+ if (example.isDirtyQuery()) {
+ for (ContextBinder contextBinder : binderResolver.getContextBinders()) {
+ String alias = contextBinder.getBindingDefinition().getAlias();
+ Object boundValue = contextBinder.getBoundValue(boundedContext, rootEntity);
+ if (boundValue != null) {
+ example.eq(alias, boundValue);
+ }
+ }
+ }
+ return example;
+ }
+
+ public Object getPrimaryKey(Object entity) {
+ PropertyProxy primaryKeyProxy = entityElement.getPrimaryKeyProxy();
+ return primaryKeyProxy.getValue(entity);
+ }
+
+ public Object convertManyToOne(List> entities) {
+ if (entityElement.isCollection()) {
+ return entities;
+ } else if (!entities.isEmpty()) {
+ return entities.get(0);
+ }
+ return null;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/repository/DefaultRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/DefaultRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..66d63417624688974993921b701326dfb61737a3
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/DefaultRepository.java
@@ -0,0 +1,35 @@
+/*
+ * 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.repository;
+
+import com.gitee.dorive.core.api.MetadataHolder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class DefaultRepository extends AbstractRepository implements MetadataHolder {
+
+ @Override
+ public Object getMetadata() {
+ if (executor instanceof MetadataHolder) {
+ return ((MetadataHolder) executor).getMetadata();
+ }
+ return null;
+ }
+
+}
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/repository/ProxyRepository.java b/dorive-core/src/main/java/com/gitee/dorive/core/repository/ProxyRepository.java
similarity index 48%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/repository/ProxyRepository.java
rename to dorive-core/src/main/java/com/gitee/dorive/core/repository/ProxyRepository.java
index 7cba7484b539e9f8afc7bbcfce6a73f100499de0..942a7acc2221d99ae9773eabc7d6a7f942b81b89 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/repository/ProxyRepository.java
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/repository/ProxyRepository.java
@@ -1,6 +1,25 @@
-package com.gitee.spring.domain.core.repository;
-
-import com.gitee.spring.domain.core.entity.BoundedContext;
+/*
+ * 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.repository;
+
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.BoundedContext;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -16,29 +35,43 @@ public class ProxyRepository extends AbstractRepository {
protected AbstractRepository proxyRepository;
+ public AbstractRepository getProxyRepository() {
+ if (proxyRepository instanceof ProxyRepository) {
+ return ((ProxyRepository) proxyRepository).getProxyRepository();
+ }
+ return proxyRepository;
+ }
+
+ public void setProxyRepository(AbstractRepository proxyRepository) {
+ if (this.proxyRepository instanceof ProxyRepository) {
+ ((ProxyRepository) this.proxyRepository).setProxyRepository(proxyRepository);
+ }
+ this.proxyRepository = proxyRepository;
+ }
+
@Override
public Object selectByPrimaryKey(BoundedContext boundedContext, Object primaryKey) {
return proxyRepository.selectByPrimaryKey(boundedContext, primaryKey);
}
@Override
- public List selectByExample(BoundedContext boundedContext, Object example) {
+ public List selectByExample(BoundedContext boundedContext, Example example) {
return proxyRepository.selectByExample(boundedContext, example);
}
@Override
- public T selectPageByExample(BoundedContext boundedContext, Object example, Object page) {
- return proxyRepository.selectPageByExample(boundedContext, example, page);
+ public Page selectPageByExample(BoundedContext boundedContext, Example example) {
+ return proxyRepository.selectPageByExample(boundedContext, example);
}
@Override
- public int insert(BoundedContext boundedContext, Object entity) {
- return proxyRepository.insert(boundedContext, entity);
+ public Result selectResultByExample(BoundedContext boundedContext, Example example) {
+ return proxyRepository.selectResultByExample(boundedContext, example);
}
@Override
- public int updateSelective(BoundedContext boundedContext, Object entity) {
- return proxyRepository.updateSelective(boundedContext, entity);
+ public int insert(BoundedContext boundedContext, Object entity) {
+ return proxyRepository.insert(boundedContext, entity);
}
@Override
@@ -47,7 +80,7 @@ public class ProxyRepository extends AbstractRepository {
}
@Override
- public int updateByExample(BoundedContext boundedContext, Object entity, Object example) {
+ public int updateByExample(BoundedContext boundedContext, Object entity, Example example) {
return proxyRepository.updateByExample(boundedContext, entity, example);
}
@@ -67,7 +100,7 @@ public class ProxyRepository extends AbstractRepository {
}
@Override
- public int deleteByExample(BoundedContext boundedContext, Object example) {
+ public int deleteByExample(BoundedContext boundedContext, Example example) {
return proxyRepository.deleteByExample(boundedContext, example);
}
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/utils/PathUtils.java b/dorive-core/src/main/java/com/gitee/dorive/core/util/PathUtils.java
similarity index 48%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/utils/PathUtils.java
rename to dorive-core/src/main/java/com/gitee/dorive/core/util/PathUtils.java
index 4b4443ae2d8512830af2cf1507f139cb12dc9232..e6e9b17cb0e32cf2d509cd38322c045e7ad1f280 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/utils/PathUtils.java
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/util/PathUtils.java
@@ -1,4 +1,20 @@
-package com.gitee.spring.domain.core.utils;
+/*
+ * 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.util;
import cn.hutool.core.util.URLUtil;
@@ -15,9 +31,9 @@ public class PathUtils {
}
public static String getAbsolutePath(String accessPath, String relativePath) {
- accessPath = "https://spring-domain" + accessPath;
+ accessPath = "https://dorive" + accessPath;
accessPath = URLUtil.completeUrl(accessPath, relativePath);
- return accessPath.replace("https://spring-domain", "");
+ return accessPath.replace("https://dorive", "");
}
public static String getBelongPath(Set allAccessPath, String accessPath) {
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/util/ReflectUtils.java b/dorive-core/src/main/java/com/gitee/dorive/core/util/ReflectUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..2296f1fb75c3cc9b862e2350dd4b665d0d67cf89
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/util/ReflectUtils.java
@@ -0,0 +1,58 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.*;
+
+public class ReflectUtils {
+
+ public static Class> getFirstArgumentType(Class> type) {
+ Type genericSuperclass = type.getGenericSuperclass();
+ ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
+ Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0];
+ return (Class>) actualTypeArgument;
+ }
+
+ public static Object newInstance(Class> type) {
+ return org.springframework.cglib.core.ReflectUtils.newInstance(type);
+ }
+
+ public static List> getAllSuperclasses(Class> type, Class> ignoredType) {
+ List> superclasses = new ArrayList<>();
+ Class> superclass = type.getSuperclass();
+ while (superclass != null) {
+ if (superclass != ignoredType) {
+ superclasses.add(superclass);
+ }
+ superclass = superclass.getSuperclass();
+ }
+ Collections.reverse(superclasses);
+ return superclasses;
+ }
+
+ public static Set getFieldNames(Class> type) {
+ Set fieldNames = new LinkedHashSet<>();
+ for (Field field : type.getDeclaredFields()) {
+ fieldNames.add(field.getName());
+ }
+ return fieldNames;
+ }
+
+}
diff --git a/dorive-core/src/main/java/com/gitee/dorive/core/util/StringUtils.java b/dorive-core/src/main/java/com/gitee/dorive/core/util/StringUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..f4fd48610f24d0cc255cc88cba3f267c24828c5a
--- /dev/null
+++ b/dorive-core/src/main/java/com/gitee/dorive/core/util/StringUtils.java
@@ -0,0 +1,52 @@
+/*
+ * 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.util;
+
+import cn.hutool.core.util.StrUtil;
+
+import java.util.Collection;
+
+public class StringUtils {
+
+ public static String[] toUnderlineCase(String... columns) {
+ String[] newColumns = new String[columns.length];
+ for (int index = 0; index < columns.length; index++) {
+ newColumns[index] = StrUtil.toUnderlineCase(columns[index]);
+ }
+ return newColumns;
+ }
+
+ public static String[] toStringArray(Object object) {
+ if (object instanceof String) {
+ return new String[]{(String) object};
+
+ } else if (object instanceof String[]) {
+ return (String[]) object;
+
+ } else if (object instanceof Collection) {
+ Collection> collection = (Collection>) object;
+ String[] stringArray = new String[collection.size()];
+ int index = 0;
+ for (Object item : collection) {
+ stringArray[index++] = item.toString();
+ }
+ return stringArray;
+ }
+ return null;
+ }
+
+}
diff --git a/spring-domain-core/src/main/resources/META-INF/spring.factories b/dorive-core/src/main/resources/META-INF/spring.factories
similarity index 52%
rename from spring-domain-core/src/main/resources/META-INF/spring.factories
rename to dorive-core/src/main/resources/META-INF/spring.factories
index 8165946b32e78157ad79d14cf752b196acf283cf..54e414f0ab1098acb830f1c75e6b92f043cb68a2 100644
--- a/spring-domain-core/src/main/resources/META-INF/spring.factories
+++ b/dorive-core/src/main/resources/META-INF/spring.factories
@@ -1 +1 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.spring.domain.core.config.DomainCoreConfiguration
\ No newline at end of file
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.dorive.core.config.DomainCoreConfiguration
\ No newline at end of file
diff --git a/spring-domain-coating/pom.xml b/dorive-event/pom.xml
similarity index 75%
rename from spring-domain-coating/pom.xml
rename to dorive-event/pom.xml
index b2b60f7023fbbdaf0bf4346305a52e3926c55e71..f3b58fe435efa7bb902ed365cfe29cf99af02ad3 100644
--- a/spring-domain-coating/pom.xml
+++ b/dorive-event/pom.xml
@@ -5,15 +5,14 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-domain-coating
-
+ dorive-event
com.gitee.digital-engine
- spring-domain-event
+ dorive-core
${project.version}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/annotation/EnableEvent.java b/dorive-event/src/main/java/com/gitee/dorive/event/annotation/EnableEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..02037fa87364b87e44474c48ea89c19dd9a62965
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/annotation/EnableEvent.java
@@ -0,0 +1,31 @@
+/*
+ * 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.event.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnableEvent {
+}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/annotation/Listener.java b/dorive-event/src/main/java/com/gitee/dorive/event/annotation/Listener.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb41431e46fc1738d8c7f4b5fdf2a94ad54ca98e
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/annotation/Listener.java
@@ -0,0 +1,32 @@
+/*
+ * 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.event.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Listener {
+ Class> value();
+}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/api/EntityListener.java b/dorive-event/src/main/java/com/gitee/dorive/event/api/EntityListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..80f277a6fcb41ddea0ade45f74e5016fec7760e4
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/api/EntityListener.java
@@ -0,0 +1,25 @@
+/*
+ * 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.event.api;
+
+import com.gitee.dorive.event.entity.RepositoryEvent;
+
+public interface EntityListener {
+
+ void onApplicationEvent(RepositoryEvent repositoryEvent);
+
+}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/config/DomainEventConfiguration.java b/dorive-event/src/main/java/com/gitee/dorive/event/config/DomainEventConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..a9de69173f3d1aac2cef1712a36f34fc2d23ff99
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/config/DomainEventConfiguration.java
@@ -0,0 +1,33 @@
+/*
+ * 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.event.config;
+
+import com.gitee.dorive.event.impl.RepositoryListener;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+@Order(-100)
+@Configuration
+public class DomainEventConfiguration {
+
+ @Bean
+ public RepositoryListener repositoryListener() {
+ return new RepositoryListener();
+ }
+
+}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/entity/RepositoryEvent.java b/dorive-event/src/main/java/com/gitee/dorive/event/entity/RepositoryEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..9864d185eb14979e96af80e153268ab64128e8db
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/entity/RepositoryEvent.java
@@ -0,0 +1,38 @@
+/*
+ * 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.event.entity;
+
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.event.repository.EventRepository;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.context.ApplicationEvent;
+
+@Getter
+@Setter
+public class RepositoryEvent extends ApplicationEvent {
+
+ private String methodName;
+ private BoundedContext boundedContext;
+ private Operation operation;
+
+ public RepositoryEvent(EventRepository eventRepository) {
+ super(eventRepository);
+ }
+
+}
diff --git a/spring-domain-event/src/main/java/com/gitee/spring/domain/event/listener/RepositoryListener.java b/dorive-event/src/main/java/com/gitee/dorive/event/impl/RepositoryListener.java
similarity index 35%
rename from spring-domain-event/src/main/java/com/gitee/spring/domain/event/listener/RepositoryListener.java
rename to dorive-event/src/main/java/com/gitee/dorive/event/impl/RepositoryListener.java
index 354f67c420fd62b7f2813b30e5e89b9bc79ae63b..f0e260a01571318304fb34adcd08869d9c0c34c1 100644
--- a/spring-domain-event/src/main/java/com/gitee/spring/domain/event/listener/RepositoryListener.java
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/impl/RepositoryListener.java
@@ -1,10 +1,26 @@
-package com.gitee.spring.domain.event.listener;
+/*
+ * 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.event.impl;
-import com.gitee.spring.domain.event.annotation.EntityListener;
-import com.gitee.spring.domain.event.api.EventListener;
-import com.gitee.spring.domain.core.entity.EntityDefinition;
-import com.gitee.spring.domain.event.entity.RepositoryEvent;
-import com.gitee.spring.domain.event.repository.EventRepository;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.event.annotation.Listener;
+import com.gitee.dorive.event.api.EntityListener;
+import com.gitee.dorive.event.entity.RepositoryEvent;
+import com.gitee.dorive.event.repository.EventRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
@@ -22,8 +38,8 @@ import java.util.Map;
@Slf4j
public class RepositoryListener implements ApplicationListener, ApplicationContextAware, InitializingBean {
- protected ApplicationContext applicationContext;
- protected Map, List> classEventListenersMap = new LinkedHashMap<>();
+ private ApplicationContext applicationContext;
+ private final Map, List> classEventListenersMap = new LinkedHashMap<>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -32,15 +48,15 @@ public class RepositoryListener implements ApplicationListener,
@Override
public void afterPropertiesSet() {
- Map entityListenerMap = applicationContext.getBeansOfType(EventListener.class);
- List orderedEventListeners = new ArrayList<>(entityListenerMap.values());
- orderedEventListeners.sort(new AnnotationAwareOrderComparator());
- for (EventListener eventListener : orderedEventListeners) {
- EntityListener entityListener = AnnotationUtils.getAnnotation(eventListener.getClass(), EntityListener.class);
- if (entityListener != null) {
- Class> entityClass = entityListener.value();
- List eventListeners = classEventListenersMap.computeIfAbsent(entityClass, key -> new ArrayList<>());
- eventListeners.add(eventListener);
+ Map entityListenerMap = applicationContext.getBeansOfType(EntityListener.class);
+ List entityListeners = new ArrayList<>(entityListenerMap.values());
+ entityListeners.sort(new AnnotationAwareOrderComparator());
+ for (EntityListener entityListener : entityListeners) {
+ Listener listener = AnnotationUtils.getAnnotation(entityListener.getClass(), Listener.class);
+ if (listener != null) {
+ Class> entityClass = listener.value();
+ List existEntityListeners = classEventListenersMap.computeIfAbsent(entityClass, key -> new ArrayList<>());
+ existEntityListeners.add(entityListener);
}
}
}
@@ -48,13 +64,13 @@ public class RepositoryListener implements ApplicationListener,
@Override
public void onApplicationEvent(RepositoryEvent event) {
EventRepository eventRepository = (EventRepository) event.getSource();
- EntityDefinition entityDefinition = eventRepository.getEntityDefinition();
- Class> entityClass = entityDefinition.getGenericEntityClass();
- List eventListeners = classEventListenersMap.get(entityClass);
- if (eventListeners != null && !eventListeners.isEmpty()) {
- for (EventListener eventListener : eventListeners) {
+ EntityElement entityElement = eventRepository.getEntityElement();
+ Class> entityClass = entityElement.getGenericEntityClass();
+ List entityListeners = classEventListenersMap.get(entityClass);
+ if (entityListeners != null && !entityListeners.isEmpty()) {
+ for (EntityListener entityListener : entityListeners) {
try {
- eventListener.onApplicationEvent(event);
+ entityListener.onApplicationEvent(event);
} catch (Exception e) {
log.error("Exception occurred in event listening!", e);
}
diff --git a/dorive-event/src/main/java/com/gitee/dorive/event/repository/AbstractEventRepository.java b/dorive-event/src/main/java/com/gitee/dorive/event/repository/AbstractEventRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ec6ab0167a48a8e175a6de2a195186a00f590af
--- /dev/null
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/repository/AbstractEventRepository.java
@@ -0,0 +1,49 @@
+/*
+ * 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.event.repository;
+
+import com.gitee.dorive.core.repository.AbstractGenericRepository;
+import com.gitee.dorive.core.repository.AbstractRepository;
+import com.gitee.dorive.core.repository.DefaultRepository;
+import com.gitee.dorive.event.annotation.EnableEvent;
+import org.springframework.core.annotation.AnnotationUtils;
+
+public abstract class AbstractEventRepository extends AbstractGenericRepository {
+
+ protected boolean enableEvent;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ EnableEvent enableEvent = AnnotationUtils.getAnnotation(this.getClass(), EnableEvent.class);
+ this.enableEvent = enableEvent != null;
+ super.afterPropertiesSet();
+ }
+
+ @Override
+ protected AbstractRepository postProcessRepository(AbstractRepository repository) {
+ if (enableEvent && (repository instanceof DefaultRepository)) {
+ DefaultRepository defaultRepository = (DefaultRepository) repository;
+ EventRepository eventRepository = new EventRepository(applicationContext);
+ eventRepository.setEntityElement(defaultRepository.getEntityElement());
+ eventRepository.setEntityDefinition(defaultRepository.getEntityDefinition());
+ eventRepository.setProxyRepository(repository);
+ return eventRepository;
+ }
+ return repository;
+ }
+
+}
diff --git a/spring-domain-event/src/main/java/com/gitee/spring/domain/event/repository/EventRepository.java b/dorive-event/src/main/java/com/gitee/dorive/event/repository/EventRepository.java
similarity index 50%
rename from spring-domain-event/src/main/java/com/gitee/spring/domain/event/repository/EventRepository.java
rename to dorive-event/src/main/java/com/gitee/dorive/event/repository/EventRepository.java
index d81078182511c46024643a346eab47be8553a6eb..65b74f69e59a7d9090441eeddc47bb0d27106806 100644
--- a/spring-domain-event/src/main/java/com/gitee/spring/domain/event/repository/EventRepository.java
+++ b/dorive-event/src/main/java/com/gitee/dorive/event/repository/EventRepository.java
@@ -1,33 +1,49 @@
-package com.gitee.spring.domain.event.repository;
+/*
+ * 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.event.repository;
-import com.gitee.spring.domain.core.entity.*;
-import com.gitee.spring.domain.core.repository.ConfiguredRepository;
-import com.gitee.spring.domain.event.entity.OperationType;
-import com.gitee.spring.domain.event.entity.RepositoryEvent;
-import lombok.Getter;
-import lombok.Setter;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.operation.Delete;
+import com.gitee.dorive.core.entity.operation.Insert;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Update;
+import com.gitee.dorive.core.repository.ProxyRepository;
+import com.gitee.dorive.event.entity.RepositoryEvent;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.springframework.context.ApplicationContext;
-@Getter
-@Setter
-public class EventRepository extends ConfiguredRepository {
+@Data
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class EventRepository extends ProxyRepository {
protected ApplicationContext applicationContext;
- public EventRepository(ConfiguredRepository configuredRepository, ApplicationContext applicationContext) {
- super(configuredRepository);
- this.applicationContext = applicationContext;
- }
-
@Override
public int insert(BoundedContext boundedContext, Object entity) {
int count = super.insert(boundedContext, entity);
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("insert");
- repositoryEvent.setOperationType(OperationType.INSERT);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setEntity(entity);
+ repositoryEvent.setOperation(new Insert(Operation.INSERT, entity));
applicationContext.publishEvent(repositoryEvent);
}
return count;
@@ -39,24 +55,36 @@ public class EventRepository extends ConfiguredRepository {
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("update");
- repositoryEvent.setOperationType(OperationType.UPDATE);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setEntity(entity);
+ repositoryEvent.setOperation(new Update(Operation.UPDATE, entity));
applicationContext.publishEvent(repositoryEvent);
}
return count;
}
@Override
- public int updateByExample(BoundedContext boundedContext, Object entity, Object example) {
+ public int updateByExample(BoundedContext boundedContext, Object entity, Example example) {
int count = super.updateByExample(boundedContext, entity, example);
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("updateByExample");
- repositoryEvent.setOperationType(OperationType.UPDATE);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setEntity(entity);
- repositoryEvent.setExample(example);
+ Update update = new Update(Operation.UPDATE, entity);
+ update.setExample(example);
+ repositoryEvent.setOperation(update);
+ applicationContext.publishEvent(repositoryEvent);
+ }
+ return count;
+ }
+
+ @Override
+ public int insertOrUpdate(BoundedContext boundedContext, Object entity) {
+ int count = super.insertOrUpdate(boundedContext, entity);
+ if (count != 0) {
+ RepositoryEvent repositoryEvent = new RepositoryEvent(this);
+ repositoryEvent.setMethodName("insertOrUpdate");
+ repositoryEvent.setBoundedContext(boundedContext);
+ repositoryEvent.setOperation(new Operation(Operation.INSERT_OR_UPDATE, entity));
applicationContext.publishEvent(repositoryEvent);
}
return count;
@@ -68,9 +96,8 @@ public class EventRepository extends ConfiguredRepository {
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("delete");
- repositoryEvent.setOperationType(OperationType.DELETE);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setEntity(entity);
+ repositoryEvent.setOperation(new Delete(Operation.DELETE, entity));
applicationContext.publishEvent(repositoryEvent);
}
return count;
@@ -82,23 +109,25 @@ public class EventRepository extends ConfiguredRepository {
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("deleteByPrimaryKey");
- repositoryEvent.setOperationType(OperationType.DELETE);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setPrimaryKey(primaryKey);
+ Delete delete = new Delete(Operation.DELETE, null);
+ delete.setPrimaryKey(primaryKey);
+ repositoryEvent.setOperation(delete);
applicationContext.publishEvent(repositoryEvent);
}
return count;
}
@Override
- public int deleteByExample(BoundedContext boundedContext, Object example) {
+ public int deleteByExample(BoundedContext boundedContext, Example example) {
int count = super.deleteByExample(boundedContext, example);
if (count != 0) {
RepositoryEvent repositoryEvent = new RepositoryEvent(this);
repositoryEvent.setMethodName("deleteByExample");
- repositoryEvent.setOperationType(OperationType.DELETE);
repositoryEvent.setBoundedContext(boundedContext);
- repositoryEvent.setExample(example);
+ Delete delete = new Delete(Operation.DELETE, null);
+ delete.setExample(example);
+ repositoryEvent.setOperation(delete);
applicationContext.publishEvent(repositoryEvent);
}
return count;
diff --git a/spring-domain-event/src/main/resources/META-INF/spring.factories b/dorive-event/src/main/resources/META-INF/spring.factories
similarity index 51%
rename from spring-domain-event/src/main/resources/META-INF/spring.factories
rename to dorive-event/src/main/resources/META-INF/spring.factories
index 8745411b983547ed865d8c32d138e04c0aa6de79..0ae90702cdf029edb2ac74475b28c5c36fbd706a 100644
--- a/spring-domain-event/src/main/resources/META-INF/spring.factories
+++ b/dorive-event/src/main/resources/META-INF/spring.factories
@@ -1 +1 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.spring.domain.event.config.DomainEventConfiguration
\ No newline at end of file
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.dorive.event.config.DomainEventConfiguration
\ No newline at end of file
diff --git a/spring-domain-injection/pom.xml b/dorive-injection/pom.xml
similarity index 88%
rename from spring-domain-injection/pom.xml
rename to dorive-injection/pom.xml
index 23f5b78866834c1cf0104883b412aec539e06971..251e134550e2d64363bdc97b3698362cc302afed 100644
--- a/spring-domain-injection/pom.xml
+++ b/dorive-injection/pom.xml
@@ -5,11 +5,10 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-domain-injection
-
+ dorive-injection
org.springframework.boot
diff --git a/dorive-injection/src/main/java/com/gitee/dorive/injection/annotation/Root.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/annotation/Root.java
new file mode 100644
index 0000000000000000000000000000000000000000..e33b7721e780776dd1c2ecc4d9ae8386a43ed166
--- /dev/null
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/annotation/Root.java
@@ -0,0 +1,26 @@
+/*
+ * 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.injection.annotation;
+
+import java.lang.annotation.*;
+
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Root {
+}
diff --git a/dorive-injection/src/main/java/com/gitee/dorive/injection/api/TypeDomainResolver.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/api/TypeDomainResolver.java
new file mode 100644
index 0000000000000000000000000000000000000000..81cae8b7a96c4fa2142d249652b4b1723832a69b
--- /dev/null
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/api/TypeDomainResolver.java
@@ -0,0 +1,31 @@
+/*
+ * 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.injection.api;
+
+import com.gitee.dorive.injection.entity.DomainDefinition;
+
+public interface TypeDomainResolver {
+
+ boolean isUnderScanPackage(Class> typeToMatch);
+
+ DomainDefinition matchDomainDefinition(Class> typeToMatch);
+
+ void checkDomain(Class> targetType, Class> injectedType);
+
+ void checkDomainProtection(Class> targetType);
+
+}
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/config/DomainInjectionConfiguration.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/config/DomainInjectionConfiguration.java
similarity index 67%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/config/DomainInjectionConfiguration.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/config/DomainInjectionConfiguration.java
index 2a253e0448460ccd85fd4b0b7be3d43682eeb098..533bdf1e2f93577a6d3ce2477515af444594b19c 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/config/DomainInjectionConfiguration.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/config/DomainInjectionConfiguration.java
@@ -1,12 +1,28 @@
-package com.gitee.spring.domain.injection.config;
+/*
+ * 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.injection.config;
import cn.hutool.core.lang.Assert;
-import com.gitee.spring.domain.injection.api.TypeDomainResolver;
-import com.gitee.spring.domain.injection.entity.DomainDefinition;
-import com.gitee.spring.domain.injection.impl.DefaultTypeDomainResolver;
-import com.gitee.spring.domain.injection.spring.LimitedAutowiredBeanPostProcessor;
-import com.gitee.spring.domain.injection.spring.LimitedCglibSubclassingInstantiationStrategy;
-import com.gitee.spring.domain.injection.spring.LimitedRootInitializingBean;
+import com.gitee.dorive.injection.impl.DefaultTypeDomainResolver;
+import com.gitee.dorive.injection.spring.LimitedAutowiredBeanPostProcessor;
+import com.gitee.dorive.injection.spring.LimitedCglibSubclassingInstantiationStrategy;
+import com.gitee.dorive.injection.spring.LimitedRootInitializingBean;
+import com.gitee.dorive.injection.api.TypeDomainResolver;
+import com.gitee.dorive.injection.entity.DomainDefinition;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
diff --git a/dorive-injection/src/main/java/com/gitee/dorive/injection/entity/DomainDefinition.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/entity/DomainDefinition.java
new file mode 100644
index 0000000000000000000000000000000000000000..7db4652f06d270b2b0808713ee9192d1d57852b3
--- /dev/null
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/entity/DomainDefinition.java
@@ -0,0 +1,28 @@
+/*
+ * 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.injection.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class DomainDefinition {
+ private String name;
+ private String pattern;
+ private String protect;
+}
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/impl/DefaultTypeDomainResolver.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/impl/DefaultTypeDomainResolver.java
similarity index 76%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/impl/DefaultTypeDomainResolver.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/impl/DefaultTypeDomainResolver.java
index f3c8f3e971f8bca77286a023a9eb76feb50ac807..39538969df5b7d1a1f1f149a905d8d0b1012334f 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/impl/DefaultTypeDomainResolver.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/impl/DefaultTypeDomainResolver.java
@@ -1,9 +1,25 @@
-package com.gitee.spring.domain.injection.impl;
+/*
+ * 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.injection.impl;
import cn.hutool.core.collection.CollUtil;
-import com.gitee.spring.domain.injection.annotation.Root;
-import com.gitee.spring.domain.injection.api.TypeDomainResolver;
-import com.gitee.spring.domain.injection.entity.DomainDefinition;
+import com.gitee.dorive.injection.annotation.Root;
+import com.gitee.dorive.injection.api.TypeDomainResolver;
+import com.gitee.dorive.injection.entity.DomainDefinition;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.core.annotation.AnnotationUtils;
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedAutowiredBeanPostProcessor.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedAutowiredBeanPostProcessor.java
similarity index 79%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedAutowiredBeanPostProcessor.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedAutowiredBeanPostProcessor.java
index f0b4a29bbac31d5a490723ffd246e313d4f31766..becd963ec69847e46c296ffbfd8e7131a4f573b1 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedAutowiredBeanPostProcessor.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedAutowiredBeanPostProcessor.java
@@ -1,6 +1,22 @@
-package com.gitee.spring.domain.injection.spring;
+/*
+ * 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.injection.spring;
-import com.gitee.spring.domain.injection.api.TypeDomainResolver;
+import com.gitee.dorive.injection.api.TypeDomainResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java
similarity index 65%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java
index c6a7f7c8c4b3cc09ca9b79d1d10e8e27d7594e44..2282142897dc883d1ed5b7ed70ba349e50e30e4c 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedCglibSubclassingInstantiationStrategy.java
@@ -1,6 +1,22 @@
-package com.gitee.spring.domain.injection.spring;
-
-import com.gitee.spring.domain.injection.api.TypeDomainResolver;
+/*
+ * 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.injection.spring;
+
+import com.gitee.dorive.injection.api.TypeDomainResolver;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy;
import org.springframework.beans.factory.support.RootBeanDefinition;
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedRootInitializingBean.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedRootInitializingBean.java
similarity index 53%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedRootInitializingBean.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedRootInitializingBean.java
index fed0758c85e88e40cd27816b25e8ce6bb4054fbe..cbaf6f3eca467c85007f97d67d4a558764599057 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/spring/LimitedRootInitializingBean.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/spring/LimitedRootInitializingBean.java
@@ -1,8 +1,24 @@
-package com.gitee.spring.domain.injection.spring;
-
-import com.gitee.spring.domain.injection.annotation.Root;
-import com.gitee.spring.domain.injection.api.TypeDomainResolver;
-import com.gitee.spring.domain.injection.utils.AopUtils;
+/*
+ * 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.injection.spring;
+
+import com.gitee.dorive.injection.annotation.Root;
+import com.gitee.dorive.injection.api.TypeDomainResolver;
+import com.gitee.dorive.injection.utils.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
diff --git a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/utils/AopUtils.java b/dorive-injection/src/main/java/com/gitee/dorive/injection/utils/AopUtils.java
similarity index 51%
rename from spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/utils/AopUtils.java
rename to dorive-injection/src/main/java/com/gitee/dorive/injection/utils/AopUtils.java
index fa3751530e1bb396ab38d6e48568b3dad102e56f..45b73c03a144516b5465e8d37a1d1694d269b19c 100644
--- a/spring-domain-injection/src/main/java/com/gitee/spring/domain/injection/utils/AopUtils.java
+++ b/dorive-injection/src/main/java/com/gitee/dorive/injection/utils/AopUtils.java
@@ -1,4 +1,20 @@
-package com.gitee.spring.domain.injection.utils;
+/*
+ * 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.injection.utils;
import java.lang.annotation.Annotation;
diff --git a/spring-domain-injection/src/main/resources/META-INF/spring.factories b/dorive-injection/src/main/resources/META-INF/spring.factories
similarity index 48%
rename from spring-domain-injection/src/main/resources/META-INF/spring.factories
rename to dorive-injection/src/main/resources/META-INF/spring.factories
index 3be8fa9800d96f78b8d0a80bc65d0f55829c6539..f95c7848bbdd1d6090ee490ba6837574a2d0aa75 100644
--- a/spring-domain-injection/src/main/resources/META-INF/spring.factories
+++ b/dorive-injection/src/main/resources/META-INF/spring.factories
@@ -1 +1 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.spring.domain.injection.config.DomainInjectionConfiguration
\ No newline at end of file
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.gitee.dorive.injection.config.DomainInjectionConfiguration
\ No newline at end of file
diff --git a/spring-domain-web/pom.xml b/dorive-proxy/pom.xml
similarity index 57%
rename from spring-domain-web/pom.xml
rename to dorive-proxy/pom.xml
index 3cb5e67abd50041700a39d055b6b3d2355f42581..8b113b6bfec937dda2d122c1e9f914c5146c28ff 100644
--- a/spring-domain-web/pom.xml
+++ b/dorive-proxy/pom.xml
@@ -5,16 +5,18 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-domain-web
-
+ dorive-proxy
- com.gitee.digital-engine
- spring-domain-coating
- ${project.version}
+ org.javassist
+ javassist
+
+
+ org.apache.commons
+ commons-lang3
\ No newline at end of file
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/AbstractCompiler.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/AbstractCompiler.java
similarity index 96%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/AbstractCompiler.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/AbstractCompiler.java
index fd9a90e3b6d13b9fa8ab9c628b5a276a97f5b6f9..15e3540dc1a98f413814ac5b0f9c77060acac23d 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/AbstractCompiler.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/AbstractCompiler.java
@@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
-
-import com.gitee.spring.domain.core.api.ProxyCompiler;
+package com.gitee.dorive.proxy;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassLoaderUtils.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassLoaderUtils.java
similarity index 99%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassLoaderUtils.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassLoaderUtils.java
index 9e22b52e65b47aa07415b07f58c5ffd952f6b558..a9afc3bb9ae541e968b44e5cedf01fb59ce4743c 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassLoaderUtils.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassLoaderUtils.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
+package com.gitee.dorive.proxy;
import java.lang.reflect.Array;
import java.util.*;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassUtils.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassUtils.java
similarity index 99%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassUtils.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassUtils.java
index 758fa38371f5fdddefb7941592a4be12117db15b..83881600410de0308221270658b583126a753676 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/ClassUtils.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ClassUtils.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
+package com.gitee.dorive.proxy;
import org.apache.commons.lang3.StringUtils;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/CtClassBuilder.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/CtClassBuilder.java
similarity index 99%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/CtClassBuilder.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/CtClassBuilder.java
index e8ec9bfb7cffd1c0dadd20034ad94848e6cfa2e7..534855e407f437ca7d9f54755040dd893967bfb1 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/CtClassBuilder.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/CtClassBuilder.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
+package com.gitee.dorive.proxy;
import javassist.*;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JavassistCompiler.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/JavassistCompiler.java
similarity index 98%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JavassistCompiler.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/JavassistCompiler.java
index 0b627aa6b967e2a23e74a595cc00cffb2e4ff070..827d40a6213cbea422036553f8a16c18b4712577 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JavassistCompiler.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/JavassistCompiler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
+package com.gitee.dorive.proxy;
import javassist.CtClass;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JdkCompiler.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/JdkCompiler.java
similarity index 99%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JdkCompiler.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/JdkCompiler.java
index ad8f6e1c34af930cefb3f5e94e5a7eec1abb508a..cc9ce6576beda1e1d8c1c4a70aa133a57dcbf030 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/compile/JdkCompiler.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/JdkCompiler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.compile;
+package com.gitee.dorive.proxy;
import javax.tools.*;
import javax.tools.JavaFileObject.Kind;
diff --git a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/api/ProxyCompiler.java b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ProxyCompiler.java
similarity index 96%
rename from spring-domain-core/src/main/java/com/gitee/spring/domain/core/api/ProxyCompiler.java
rename to dorive-proxy/src/main/java/com/gitee/dorive/proxy/ProxyCompiler.java
index 7d208ae68461e572e26daf5c0304014d51215cb0..f40ce6d8349beaf5f6364d4e1b13c15e327eba0c 100644
--- a/spring-domain-core/src/main/java/com/gitee/spring/domain/core/api/ProxyCompiler.java
+++ b/dorive-proxy/src/main/java/com/gitee/dorive/proxy/ProxyCompiler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitee.spring.domain.core.api;
+package com.gitee.dorive.proxy;
public interface ProxyCompiler {
diff --git a/pom.xml b/pom.xml
index 4e9aa006bb7ebfc92475f51599748da143c3943a..dad4509c64f5d66cd7aa87d408ea05a0f123bf70 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,17 +4,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
pom
- spring-domain-injection
- spring-domain-core
- spring-domain-event
- spring-domain-coating
- spring-domain-web
- spring-boot-starter-domain
+ dorive-injection
+ dorive-proxy
+ dorive-core
+ dorive-event
+ dorive-coating
+ spring-boot-starter-dorive
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/annotation/RootRepository.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/annotation/RootRepository.java
deleted file mode 100644
index 8e7a4c33e372fbbfae0bdf52cb3b9115f78f16d7..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/annotation/RootRepository.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.gitee.spring.boot.starter.domain.annotation;
-
-import com.gitee.spring.domain.coating.annotation.CoatingScan;
-import com.gitee.spring.domain.core.annotation.Repository;
-import com.gitee.spring.domain.event.annotation.EnableEvent;
-import com.gitee.spring.domain.injection.annotation.Root;
-import com.gitee.spring.domain.web.annotation.EnableWeb;
-import org.springframework.core.annotation.AliasFor;
-
-import java.lang.annotation.*;
-
-@Root
-@Repository
-@EnableEvent
-@CoatingScan
-@EnableWeb
-@Inherited
-@Documented
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface RootRepository {
-
- @AliasFor(annotation = Repository.class)
- String value() default "";
-
- @AliasFor(annotation = Repository.class)
- String name() default "";
-
- @AliasFor(annotation = CoatingScan.class, attribute = "value")
- String[] scanPackages() default {};
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/api/ExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/api/ExampleBuilder.java
deleted file mode 100644
index e906227bd3021adb76bccf0a3f592030c902027b..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/api/ExampleBuilder.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gitee.spring.boot.starter.domain.api;
-
-public interface ExampleBuilder {
-
- void appendCriterion(Object example, String fieldName, Object fieldValue);
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/EQExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/EQExampleBuilder.java
deleted file mode 100644
index a79147c46fd6dbb0a73d4b24ee15d5755daa34fa..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/EQExampleBuilder.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-import java.util.Collection;
-
-public class EQExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- if (fieldValue instanceof Collection) {
- queryWrapper.in(fieldName, (Collection>) fieldValue);
- } else {
- queryWrapper.eq(fieldName, fieldValue);
- }
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GEExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GEExampleBuilder.java
deleted file mode 100644
index 21ca12830e87ad7ca10e729321ccaf2d6af322af..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GEExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class GEExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.ge(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GTExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GTExampleBuilder.java
deleted file mode 100644
index a42a873c58349c4ba791f7e373324652f3ede5a4..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/GTExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class GTExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.gt(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/InExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/InExampleBuilder.java
deleted file mode 100644
index fe2df5503a6a459be91d8eae260577e327cdf7e9..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/InExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class InExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.in(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNotNullExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNotNullExampleBuilder.java
deleted file mode 100644
index 445372dc332a1ec3981ad92df58f03109faabf33..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNotNullExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class IsNotNullExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.isNotNull(fieldName);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNullExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNullExampleBuilder.java
deleted file mode 100644
index 449e109888e6e7a5337cf87b70f7f929e685aa7d..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/IsNullExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class IsNullExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.isNull(fieldName);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LEExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LEExampleBuilder.java
deleted file mode 100644
index cdcb5facbde052b4312e16346b8991f6467787a2..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LEExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class LEExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.le(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LTExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LTExampleBuilder.java
deleted file mode 100644
index 1779034d90f90278ffb3d867d35adb4980ffe3d8..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LTExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class LTExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.lt(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LikeExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LikeExampleBuilder.java
deleted file mode 100644
index 03cc5b3f3a70f6290bc18838875f689caa0b5572..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/LikeExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class LikeExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.like(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NEExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NEExampleBuilder.java
deleted file mode 100644
index 9415c5a127c8e993b4c5e32fa97ffafa34af7ec3..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NEExampleBuilder.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-import java.util.Collection;
-
-public class NEExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- if (fieldValue instanceof Collection) {
- queryWrapper.notIn(fieldName, (Collection>) fieldValue);
- } else {
- queryWrapper.ne(fieldName, fieldValue);
- }
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotInExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotInExampleBuilder.java
deleted file mode 100644
index 83fde885fc56c8563e6d7fad947ad23a578d9a6d..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotInExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class NotInExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.notIn(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotLikeExampleBuilder.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotLikeExampleBuilder.java
deleted file mode 100644
index 721dec2f93c456216fd5eb42782872b683addf54..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/builder/NotLikeExampleBuilder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gitee.spring.boot.starter.domain.builder;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-
-public class NotLikeExampleBuilder implements ExampleBuilder {
-
- @Override
- public void appendCriterion(Object example, String fieldName, Object fieldValue) {
- QueryWrapper> queryWrapper = (QueryWrapper>) example;
- queryWrapper.notLike(fieldName, fieldValue);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusEntityMapper.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusEntityMapper.java
deleted file mode 100644
index 6d79c52a9debeaaf32f1fd9d0ed957871f6d8486..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusEntityMapper.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.gitee.spring.boot.starter.domain.repository;
-
-import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.gitee.spring.boot.starter.domain.api.ExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.EQExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.GEExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.GTExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.InExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.IsNotNullExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.IsNullExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.LEExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.LTExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.LikeExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.NEExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.NotInExampleBuilder;
-import com.gitee.spring.boot.starter.domain.builder.NotLikeExampleBuilder;
-import com.gitee.spring.domain.core.api.EntityMapper;
-import com.gitee.spring.domain.core.constants.Operator;
-import com.gitee.spring.domain.core.entity.BoundedContext;
-import com.gitee.spring.domain.core.entity.EntityCriterion;
-import com.gitee.spring.domain.core.entity.EntityDefinition;
-import com.gitee.spring.domain.core.entity.EntityExample;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class MybatisPlusEntityMapper implements EntityMapper {
-
- public static Map operatorExampleBuilderMap = new ConcurrentHashMap<>();
- protected EntityDefinition entityDefinition;
-
- static {
- operatorExampleBuilderMap.put(Operator.EQ, new EQExampleBuilder());
- operatorExampleBuilderMap.put(Operator.NE, new NEExampleBuilder());
- operatorExampleBuilderMap.put(Operator.IN, new InExampleBuilder());
- operatorExampleBuilderMap.put(Operator.NOT_IN, new NotInExampleBuilder());
- operatorExampleBuilderMap.put(Operator.IS_NULL, new IsNullExampleBuilder());
- operatorExampleBuilderMap.put(Operator.IS_NOT_NULL, new IsNotNullExampleBuilder());
- operatorExampleBuilderMap.put(Operator.LIKE, new LikeExampleBuilder());
- operatorExampleBuilderMap.put(Operator.NOT_LIKE, new NotLikeExampleBuilder());
- operatorExampleBuilderMap.put(Operator.GT, new GTExampleBuilder());
- operatorExampleBuilderMap.put(Operator.GE, new GEExampleBuilder());
- operatorExampleBuilderMap.put(Operator.LT, new LTExampleBuilder());
- operatorExampleBuilderMap.put(Operator.LE, new LEExampleBuilder());
- }
-
- public MybatisPlusEntityMapper(EntityDefinition entityDefinition) {
- this.entityDefinition = entityDefinition;
- }
-
- @Override
- public Object newPage(Integer pageNum, Integer pageSize) {
- return new Page<>(pageNum, pageSize);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public List getDataFromPage(Object dataPage) {
- return ((IPage) dataPage).getRecords();
- }
-
- @Override
- public Object newPageOfEntities(Object dataPage, List entities) {
- IPage> page = (IPage>) dataPage;
- IPage newPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
- newPage.setRecords(entities);
- return newPage;
- }
-
- @Override
- public Object buildExample(BoundedContext boundedContext, EntityExample entityExample) {
- QueryWrapper> queryWrapper = new QueryWrapper<>();
- String[] selectColumns = entityExample.getSelectColumns();
- if (selectColumns != null) {
- queryWrapper.select(selectColumns);
- }
- for (EntityCriterion entityCriterion : entityExample.getEntityCriteria()) {
- String fieldName = entityCriterion.getFieldName();
- String operator = entityCriterion.getOperator();
- Object fieldValue = entityCriterion.getFieldValue();
- ExampleBuilder exampleBuilder = operatorExampleBuilderMap.get(operator);
- exampleBuilder.appendCriterion(queryWrapper, StrUtil.toUnderlineCase(fieldName), fieldValue);
- }
- String[] orderBy;
- if (entityExample.getOrderBy() != null) {
- orderBy = entityExample.getOrderBy();
- } else {
- orderBy = entityDefinition.getOrderBy();
- }
- String sort;
- if (entityExample.getSort() != null) {
- sort = entityExample.getSort();
- } else {
- sort = entityDefinition.getSort();
- }
- if (orderBy != null && sort != null) {
- if ("asc".equals(sort)) {
- queryWrapper.orderByAsc(orderBy);
- } else if ("desc".equals(sort)) {
- queryWrapper.orderByDesc(orderBy);
- }
- }
- return queryWrapper;
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusGenericRepository.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusGenericRepository.java
deleted file mode 100644
index 34d135604c215df8e2b184b0171d1cb41846ccb5..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusGenericRepository.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.gitee.spring.boot.starter.domain.repository;
-
-import com.gitee.spring.domain.core.api.EntityMapper;
-import com.gitee.spring.domain.core.entity.EntityDefinition;
-import com.gitee.spring.domain.core.repository.AbstractRepository;
-import com.gitee.spring.domain.web.repository.AbstractWebRepository;
-
-import java.io.Serializable;
-
-public class MybatisPlusGenericRepository extends AbstractWebRepository {
-
- @Override
- protected EntityMapper newEntityMapper(EntityDefinition entityDefinition) {
- return new MybatisPlusEntityMapper(entityDefinition);
- }
-
- @Override
- protected AbstractRepository newRepository(EntityDefinition entityDefinition) {
- return new MybatisPlusRepository(entityDefinition);
- }
-
-}
diff --git a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusRepository.java b/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusRepository.java
deleted file mode 100644
index 7920c1e8c0e0f68203fe257ea768d540758eef64..0000000000000000000000000000000000000000
--- a/spring-boot-starter-domain/src/main/java/com/gitee/spring/boot/starter/domain/repository/MybatisPlusRepository.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package com.gitee.spring.boot.starter.domain.repository;
-
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.lang.Pair;
-import cn.hutool.core.util.ReflectUtil;
-import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.gitee.spring.domain.core.entity.BoundedContext;
-import com.gitee.spring.domain.core.entity.EntityDefinition;
-import com.gitee.spring.domain.core.repository.AbstractRepository;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-@SuppressWarnings("unchecked")
-public class MybatisPlusRepository extends AbstractRepository {
-
- protected EntityDefinition entityDefinition;
- protected BaseMapper baseMapper;
- protected List> fieldColumnPairs;
-
- public MybatisPlusRepository(EntityDefinition entityDefinition) {
- this.entityDefinition = entityDefinition;
- this.baseMapper = (BaseMapper) entityDefinition.getMapper();
- Class> pojoClass = entityDefinition.getPojoClass();
- if (pojoClass != null) {
- this.fieldColumnPairs = new ArrayList<>();
- for (Field field : ReflectUtil.getFields(pojoClass)) {
- boolean isTableId = field.isAnnotationPresent(TableId.class);
- String fieldName = field.getName();
- if (isTableId || "id".equals(fieldName)) {
- continue;
- }
- TableField tableField = field.getAnnotation(TableField.class);
- String columnName = tableField != null ? tableField.value() : StrUtil.toUnderlineCase(fieldName);
- fieldColumnPairs.add(new Pair<>(fieldName, columnName));
- }
- }
- }
-
- @Override
- public Object selectByPrimaryKey(BoundedContext boundedContext, Object primaryKey) {
- return baseMapper.selectById((Serializable) primaryKey);
- }
-
- @Override
- public List selectByExample(BoundedContext boundedContext, Object example) {
- if (example instanceof Wrapper) {
- return baseMapper.selectList((Wrapper) example);
-
- } else if (example instanceof Map) {
- return baseMapper.selectByMap((Map) example);
- }
- return null;
- }
-
- @Override
- public T selectPageByExample(BoundedContext boundedContext, Object example, Object page) {
- return (T) baseMapper.selectPage((IPage) page, (Wrapper) example);
- }
-
- @Override
- public int insert(BoundedContext boundedContext, Object entity) {
- return baseMapper.insert(entity);
- }
-
- @Override
- public int updateSelective(BoundedContext boundedContext, Object entity) {
- return baseMapper.updateById(entity);
- }
-
- @Override
- public int update(BoundedContext boundedContext, Object entity) {
- Object primaryKey = BeanUtil.getFieldValue(entity, "id");
- if (primaryKey != null) {
- Set fieldNames = (Set) boundedContext.get("#forceUpdate");
- if (fieldNames != null && !fieldNames.isEmpty()) {
- UpdateWrapper updateWrapper = new UpdateWrapper<>();
- updateWrapper.eq("id", primaryKey);
- for (Pair fieldColumnPair : fieldColumnPairs) {
- String fieldName = fieldColumnPair.getKey();
- Object fieldValue = BeanUtil.getFieldValue(entity, fieldName);
- if (fieldValue != null || fieldNames.contains(fieldName)) {
- updateWrapper.set(true, fieldColumnPair.getValue(), fieldValue);
- }
- }
- return baseMapper.update(null, updateWrapper);
- } else {
- return baseMapper.updateById(entity);
- }
- }
- return 0;
- }
-
- @Override
- public int updateByExample(BoundedContext boundedContext, Object entity, Object example) {
- return baseMapper.update(entity, (Wrapper) example);
- }
-
- @Override
- public int insertOrUpdate(BoundedContext boundedContext, Object entity) {
- throw new RuntimeException("This method is not supported!");
- }
-
- @Override
- public int delete(BoundedContext boundedContext, Object entity) {
- Object primaryKey = BeanUtil.getFieldValue(entity, "id");
- return deleteByPrimaryKey(boundedContext, primaryKey);
- }
-
- @Override
- public int deleteByPrimaryKey(BoundedContext boundedContext, Object primaryKey) {
- return baseMapper.deleteById((Serializable) primaryKey);
- }
-
- @Override
- public int deleteByExample(BoundedContext boundedContext, Object example) {
- return baseMapper.delete((Wrapper) example);
- }
-
-}
diff --git a/spring-boot-starter-domain/pom.xml b/spring-boot-starter-dorive/pom.xml
similarity index 50%
rename from spring-boot-starter-domain/pom.xml
rename to spring-boot-starter-dorive/pom.xml
index 6fa424978d06b60fe7993b5ce7983e48ffc249ec..9febfaf70b461bd79f7cfd640dab45c2d6e7527e 100644
--- a/spring-boot-starter-domain/pom.xml
+++ b/spring-boot-starter-dorive/pom.xml
@@ -5,35 +5,19 @@
4.0.0
com.gitee.digital-engine
- spring-domain
- 2.8.3
+ dorive
+ 3.0.0
- spring-boot-starter-domain
-
+ spring-boot-starter-dorive
com.gitee.digital-engine
- spring-domain-injection
+ dorive-injection
${project.version}
com.gitee.digital-engine
- spring-domain-core
- ${project.version}
-
-
- com.gitee.digital-engine
- spring-domain-event
- ${project.version}
-
-
- com.gitee.digital-engine
- spring-domain-coating
- ${project.version}
-
-
- com.gitee.digital-engine
- spring-domain-web
+ dorive-coating
${project.version}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/annotation/RootRepository.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/annotation/RootRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..55f9e0b1015dcde1c9f2cb067782d6e3a8b3b639
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/annotation/RootRepository.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.spring.boot.starter.dorive.annotation;
+
+import com.gitee.dorive.core.annotation.Repository;
+import com.gitee.dorive.injection.annotation.Root;
+import org.springframework.core.annotation.AliasFor;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Root
+@Repository
+@Inherited
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface RootRepository {
+
+ @AliasFor(annotation = Repository.class)
+ String value() default "";
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/api/CriterionAppender.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/api/CriterionAppender.java
new file mode 100644
index 0000000000000000000000000000000000000000..584164fce3e74300239bdf1c56ff5baddb6944c2
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/api/CriterionAppender.java
@@ -0,0 +1,25 @@
+/*
+ * 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.spring.boot.starter.dorive.api;
+
+import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
+
+public interface CriterionAppender {
+
+ void appendCriterion(AbstractWrapper, String, ?> abstractWrapper, String property, Object value);
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/config/EnvironmentProcessor.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/config/EnvironmentProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..ded212338c51dca61406ea8dd1f2fd13ee1302b1
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/config/EnvironmentProcessor.java
@@ -0,0 +1,48 @@
+/*
+ * 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.spring.boot.starter.dorive.config;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.env.EnvironmentPostProcessor;
+import org.springframework.core.Ordered;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.PropertiesPropertySource;
+
+import java.util.Properties;
+
+public class EnvironmentProcessor implements EnvironmentPostProcessor, Ordered {
+
+ private static final String PROPERTY_KEY = "mybatis-plus.global-config.enable-sql-runner";
+
+ @Override
+ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
+ if (!environment.containsProperty(PROPERTY_KEY)) {
+ Properties properties = new Properties();
+ properties.setProperty(PROPERTY_KEY, "true");
+ PropertiesPropertySource propertySource = new PropertiesPropertySource(PROPERTY_KEY, properties);
+ environment.getPropertySources().addLast(propertySource);
+ }
+ }
+
+ @Override
+ public int getOrder() {
+ return Ordered.LOWEST_PRECEDENCE;
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/JoinSegment.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/JoinSegment.java
new file mode 100644
index 0000000000000000000000000000000000000000..46d5eb8ea6ce886da13dd1d2fdf4ea5ae0787877
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/JoinSegment.java
@@ -0,0 +1,35 @@
+/*
+ * 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.spring.boot.starter.dorive.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class JoinSegment {
+
+ private String joinTableName;
+ private String joinTableAlias;
+ private String sql;
+
+ @Override
+ public String toString() {
+ return sql;
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/Metadata.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/Metadata.java
new file mode 100644
index 0000000000000000000000000000000000000000..eec1966800a348581b5257a433345ce10df8c21e
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/Metadata.java
@@ -0,0 +1,26 @@
+/*
+ * 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.spring.boot.starter.dorive.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Metadata {
+ private Class> pojoClass;
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/SqlSegment.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/SqlSegment.java
new file mode 100644
index 0000000000000000000000000000000000000000..395df5e5506b3c810fec604b45904f855e237ee9
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/entity/SqlSegment.java
@@ -0,0 +1,43 @@
+/*
+ * 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.spring.boot.starter.dorive.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Set;
+
+@Data
+@AllArgsConstructor
+public class SqlSegment {
+
+ private String tableName;
+ private String tableAlias;
+ private String sql;
+ private List joinSegments;
+ private String sqlCriteria;
+ private boolean rootReachable;
+ private boolean dirtyQuery;
+ private Set joinTableNames;
+
+ @Override
+ public String toString() {
+ return sql;
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/AppenderContext.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/AppenderContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..6ba33c2b3956f7411b9c60d6f00cdcb856b233b4
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/AppenderContext.java
@@ -0,0 +1,58 @@
+/*
+ * 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.spring.boot.starter.dorive.impl;
+
+import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
+import com.gitee.spring.boot.starter.dorive.api.CriterionAppender;
+import com.gitee.dorive.core.api.constant.Operator;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class AppenderContext {
+
+ public final static Map OPERATOR_CRITERION_APPENDER_MAP = new ConcurrentHashMap<>();
+
+ static {
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.EQ, (abstractWrapper, property, value) -> {
+ if (value instanceof Collection) {
+ abstractWrapper.in(property, (Collection>) value);
+ } else {
+ abstractWrapper.eq(property, value);
+ }
+ });
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.NE, (abstractWrapper, property, value) -> {
+ if (value instanceof Collection) {
+ abstractWrapper.notIn(property, (Collection>) value);
+ } else {
+ abstractWrapper.ne(property, value);
+ }
+ });
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.IN, (abstractWrapper, property, value) -> abstractWrapper.in(property, (Collection>) value));
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.NOT_IN, (abstractWrapper, property, value) -> abstractWrapper.notIn(property, (Collection>) value));
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.IS, (abstractWrapper, property, value) -> abstractWrapper.isNull(property));
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.IS_NOT, (abstractWrapper, property, value) -> abstractWrapper.isNotNull(property));
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.LIKE, Compare::like);
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.NOT_LIKE, Compare::notLike);
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.GT, Compare::gt);
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.GE, Compare::ge);
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.LT, Compare::lt);
+ OPERATOR_CRITERION_APPENDER_MAP.put(Operator.LE, Compare::le);
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/EntityIndexResult.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/EntityIndexResult.java
new file mode 100644
index 0000000000000000000000000000000000000000..88ac1a7a82a1781ea7bfdcbd367abb87c3868acf
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/EntityIndexResult.java
@@ -0,0 +1,73 @@
+/*
+ * 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.spring.boot.starter.dorive.impl;
+
+import com.gitee.spring.boot.starter.dorive.util.NumberUtils;
+import com.gitee.dorive.core.api.EntityIndex;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.executor.UnionExample;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class EntityIndexResult extends Result implements EntityIndex {
+
+ private final Map> primaryKeyMapping;
+ private final Map primaryKeyEntityMap;
+
+ public EntityIndexResult(UnionExample unionExample, List> resultMaps, List entities, PropertyProxy primaryKeyProxy) {
+ super(entities);
+
+ int rootSize = unionExample.getExamples().size();
+ int entitySize = entities.size();
+ primaryKeyMapping = new HashMap<>(rootSize * 4 / 3 + 1);
+ primaryKeyEntityMap = new HashMap<>(entitySize * 4 / 3 + 1);
+
+ int averageSize = resultMaps.size() / rootSize + 1;
+ for (Map resultMap : resultMaps) {
+ Long rootPrimaryKey = NumberUtils.longValue(resultMap.get("$id"));
+ List existPrimaryKeys = primaryKeyMapping.computeIfAbsent(rootPrimaryKey, key -> new ArrayList<>(averageSize));
+ Long primaryKey = NumberUtils.longValue(resultMap.get("id"));
+ existPrimaryKeys.add(primaryKey);
+ }
+
+ for (Object entity : entities) {
+ Long primaryKey = NumberUtils.longValue(primaryKeyProxy.getValue(entity));
+ primaryKeyEntityMap.put(primaryKey, entity);
+ }
+ }
+
+ @Override
+ public List selectList(Object rootEntity, Object primaryKey) {
+ Long rootPrimaryKey = NumberUtils.longValue(primaryKey);
+ List existPrimaryKeys = primaryKeyMapping.get(rootPrimaryKey);
+ if (existPrimaryKeys != null && !existPrimaryKeys.isEmpty()) {
+ List entities = new ArrayList<>(existPrimaryKeys.size());
+ for (Long existPrimaryKey : existPrimaryKeys) {
+ Object entity = primaryKeyEntityMap.get(existPrimaryKey);
+ entities.add(entity);
+ }
+ return entities;
+ }
+ return Collections.emptyList();
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/SQLExampleBuilder.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/SQLExampleBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..f0f7db5a5718e2d169d00f2617fc74f711531236
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/impl/SQLExampleBuilder.java
@@ -0,0 +1,210 @@
+/*
+ * 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.spring.boot.starter.dorive.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
+import com.gitee.spring.boot.starter.dorive.entity.JoinSegment;
+import com.gitee.spring.boot.starter.dorive.entity.Metadata;
+import com.gitee.spring.boot.starter.dorive.entity.SqlSegment;
+import com.gitee.dorive.coating.api.ExampleBuilder;
+import com.gitee.dorive.coating.entity.CoatingWrapper;
+import com.gitee.dorive.coating.entity.RepositoryWrapper;
+import com.gitee.dorive.coating.entity.MergedRepository;
+import com.gitee.dorive.coating.entity.SpecificProperties;
+import com.gitee.dorive.coating.impl.resolver.CoatingWrapperResolver;
+import com.gitee.dorive.coating.repository.AbstractCoatingRepository;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.definition.BindingDefinition;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.entity.executor.Page;
+import com.gitee.dorive.core.impl.binder.PropertyBinder;
+import com.gitee.dorive.core.impl.resolver.BinderResolver;
+import com.gitee.dorive.core.repository.ConfiguredRepository;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class SQLExampleBuilder implements ExampleBuilder {
+
+ private final AbstractCoatingRepository, ?> repository;
+
+ public SQLExampleBuilder(AbstractCoatingRepository, ?> repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public Example buildExample(BoundedContext boundedContext, Object coatingObject) {
+ CoatingWrapperResolver coatingWrapperResolver = repository.getCoatingWrapperResolver();
+ Map, CoatingWrapper> coatingWrapperMap = coatingWrapperResolver.getCoatingWrapperMap();
+
+ CoatingWrapper coatingWrapper = coatingWrapperMap.get(coatingObject.getClass());
+ Assert.notNull(coatingWrapper, "No coating wrapper exists!");
+
+ List repositoryWrappers = coatingWrapper.getRepositoryWrappers();
+ SpecificProperties specificProperties = coatingWrapper.getSpecificProperties();
+ OrderBy orderByInfo = specificProperties.getOrderBy(coatingObject);
+ Page pageInfo = specificProperties.getPage(coatingObject);
+
+ Map sqlSegmentMap = new LinkedHashMap<>(repositoryWrappers.size() * 4 / 3 + 1);
+ SqlSegment rootSqlSegment = null;
+ char letter = 'a';
+
+ for (RepositoryWrapper repositoryWrapper : repositoryWrappers) {
+ MergedRepository mergedRepository = repositoryWrapper.getMergedRepository();
+ String absoluteAccessPath = mergedRepository.getAbsoluteAccessPath();
+ ConfiguredRepository definedRepository = mergedRepository.getDefinedRepository();
+ ConfiguredRepository configuredRepository = mergedRepository.getConfiguredRepository();
+
+ TableInfo tableInfo = getTableInfo(configuredRepository);
+ String tableName = tableInfo.getTableName();
+
+ String tableAlias = String.valueOf(letter);
+ letter = (char) (letter + 1);
+
+ List joinSegments = newJoinSegments(sqlSegmentMap, definedRepository.getBinderResolver(), tableName, tableAlias);
+
+ Example example = repositoryWrapper.newExampleByCoating(boundedContext, coatingObject);
+ String sqlCriteria = null;
+ if (example.isDirtyQuery()) {
+ sqlCriteria = CollUtil.join(example.getCriteria(), " AND ", tableAlias + ".", null);
+ }
+
+ if ("/".equals(absoluteAccessPath)) {
+ String sql = String.format("SELECT %s.id FROM %s %s ", tableAlias, tableName, tableAlias);
+ rootSqlSegment = new SqlSegment(tableName, tableAlias, sql, joinSegments, sqlCriteria, true, example.isDirtyQuery(), new HashSet<>(8));
+ sqlSegmentMap.put(tableName, rootSqlSegment);
+
+ } else {
+ String sql = String.format("LEFT JOIN %s %s ON ", tableName, tableAlias);
+ SqlSegment sqlSegment = new SqlSegment(tableName, tableAlias, sql, joinSegments, sqlCriteria, false, example.isDirtyQuery(), new HashSet<>(8));
+ sqlSegmentMap.put(tableName, sqlSegment);
+ }
+ }
+
+ Example example = new Example();
+ example.setOrderBy(orderByInfo);
+ example.setPage(pageInfo);
+
+ assert rootSqlSegment != null;
+ markReachableAndDirty(sqlSegmentMap, rootSqlSegment);
+ if (!rootSqlSegment.isDirtyQuery()) {
+ return example;
+ }
+
+ String sql = buildSQL(sqlSegmentMap, example);
+ List> resultMaps = SqlRunner.db().selectList(sql);
+ List primaryKeys = CollUtil.map(resultMaps, map -> map.get("id"), true);
+ if (!primaryKeys.isEmpty()) {
+ example.eq("id", primaryKeys);
+ } else {
+ example.setEmptyQuery(true);
+ }
+
+ return example;
+ }
+
+ private TableInfo getTableInfo(ConfiguredRepository repository) {
+ Metadata metadata = (Metadata) repository.getMetadata();
+ Class> pojoClass = metadata.getPojoClass();
+ return TableInfoHelper.getTableInfo(pojoClass);
+ }
+
+ private List newJoinSegments(Map sqlSegmentMap, BinderResolver binderResolver, String tableName, String tableAlias) {
+ List propertyBinders = binderResolver.getPropertyBinders();
+ List joinSegments = new ArrayList<>(propertyBinders.size());
+ for (PropertyBinder propertyBinder : propertyBinders) {
+ TableInfo joinTableInfo = getTableInfo(propertyBinder.getBelongRepository());
+ String joinTableName = joinTableInfo.getTableName();
+
+ SqlSegment sqlSegment = sqlSegmentMap.get(joinTableName);
+ if (sqlSegment != null) {
+ String joinTableAlias = sqlSegment.getTableAlias();
+ Set joinTableNames = sqlSegment.getJoinTableNames();
+ joinTableNames.add(tableName);
+
+ BindingDefinition bindingDefinition = propertyBinder.getBindingDefinition();
+ String alias = StrUtil.toUnderlineCase(bindingDefinition.getAlias());
+ String bindAlias = StrUtil.toUnderlineCase(bindingDefinition.getBindAlias());
+
+ String sqlCriteria = tableAlias + "." + alias + " = " + joinTableAlias + "." + bindAlias;
+ JoinSegment joinSegment = new JoinSegment(joinTableName, joinTableAlias, sqlCriteria);
+ joinSegments.add(joinSegment);
+ }
+ }
+ return joinSegments;
+ }
+
+ private void markReachableAndDirty(Map sqlSegmentMap, SqlSegment lastSqlSegment) {
+ Set joinTableNames = lastSqlSegment.getJoinTableNames();
+ for (String joinTableName : joinTableNames) {
+ SqlSegment joinSqlSegment = sqlSegmentMap.get(joinTableName);
+ if (joinSqlSegment != null) {
+ joinSqlSegment.setRootReachable(true);
+ markReachableAndDirty(sqlSegmentMap, joinSqlSegment);
+ if (joinSqlSegment.isDirtyQuery()) {
+ lastSqlSegment.setDirtyQuery(true);
+ }
+ }
+ }
+ }
+
+ private String buildSQL(Map sqlSegmentMap, Example example) {
+ StringBuilder sqlBuilder = new StringBuilder();
+ List sqlCriteria = new ArrayList<>(sqlSegmentMap.size());
+
+ for (SqlSegment sqlSegment : sqlSegmentMap.values()) {
+ if (sqlSegment.isRootReachable() && sqlSegment.isDirtyQuery()) {
+ sqlBuilder.append(sqlSegment);
+
+ List joinSegments = sqlSegment.getJoinSegments();
+ joinSegments = joinSegments.stream().filter(joinSegment -> {
+ SqlSegment joinSqlSegment = sqlSegmentMap.get(joinSegment.getJoinTableName());
+ return joinSqlSegment.isRootReachable() && joinSqlSegment.isDirtyQuery();
+ }).collect(Collectors.toList());
+
+ if (!joinSegments.isEmpty()) {
+ sqlBuilder.append(StrUtil.join(" AND ", joinSegments)).append(" ");
+ }
+
+ if (sqlSegment.getSqlCriteria() != null) {
+ sqlCriteria.add(sqlSegment.getSqlCriteria());
+ }
+ }
+ }
+
+ sqlBuilder.append("WHERE ").append(StrUtil.join(" AND ", sqlCriteria));
+
+ OrderBy orderBy = example.getOrderBy();
+ if (orderBy != null) {
+ sqlBuilder.append(" ").append(orderBy);
+ }
+
+ Page page = example.getPage();
+ if (page != null) {
+ sqlBuilder.append(" ").append(page);
+ }
+
+ return sqlBuilder.toString();
+ }
+
+}
diff --git a/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/repository/MybatisPlusExecutor.java b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/repository/MybatisPlusExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..3455c78356e4350f0b1beaca852ba3151b4f5505
--- /dev/null
+++ b/spring-boot-starter-dorive/src/main/java/com/gitee/spring/boot/starter/dorive/repository/MybatisPlusExecutor.java
@@ -0,0 +1,305 @@
+/*
+ * 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.spring.boot.starter.dorive.repository;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gitee.spring.boot.starter.dorive.api.CriterionAppender;
+import com.gitee.spring.boot.starter.dorive.entity.Metadata;
+import com.gitee.spring.boot.starter.dorive.impl.EntityIndexResult;
+import com.gitee.dorive.core.api.EntityFactory;
+import com.gitee.dorive.core.api.MetadataHolder;
+import com.gitee.dorive.core.api.PropertyProxy;
+import com.gitee.dorive.core.api.constant.Order;
+import com.gitee.dorive.core.entity.BoundedContext;
+import com.gitee.dorive.core.entity.Command;
+import com.gitee.dorive.core.entity.EntityElement;
+import com.gitee.dorive.core.entity.definition.EntityDefinition;
+import com.gitee.dorive.core.entity.executor.Criterion;
+import com.gitee.dorive.core.entity.executor.Example;
+import com.gitee.dorive.core.entity.executor.OrderBy;
+import com.gitee.dorive.core.entity.executor.Result;
+import com.gitee.dorive.core.entity.executor.UnionExample;
+import com.gitee.dorive.core.entity.operation.Delete;
+import com.gitee.dorive.core.entity.operation.Insert;
+import com.gitee.dorive.core.entity.operation.Operation;
+import com.gitee.dorive.core.entity.operation.Query;
+import com.gitee.dorive.core.entity.operation.Update;
+import com.gitee.dorive.core.impl.executor.AbstractExecutor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.gitee.spring.boot.starter.dorive.impl.AppenderContext.OPERATOR_CRITERION_APPENDER_MAP;
+
+@Getter
+@Setter
+@ToString
+public class MybatisPlusExecutor extends AbstractExecutor implements MetadataHolder {
+
+ private EntityDefinition entityDefinition;
+ private BaseMapper baseMapper;
+ private Class pojoClass;
+ private EntityFactory entityFactory;
+
+ public MybatisPlusExecutor(EntityElement entityElement,
+ EntityDefinition entityDefinition,
+ BaseMapper baseMapper,
+ Class pojoClass,
+ EntityFactory entityFactory) {
+ super(entityElement);
+ this.entityDefinition = entityDefinition;
+ this.baseMapper = baseMapper;
+ this.pojoClass = pojoClass;
+ this.entityFactory = entityFactory;
+ }
+
+ @Override
+ public Object getMetadata() {
+ return new Metadata(pojoClass);
+ }
+
+ @Override
+ public Result