/*
* 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.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.gitee.dorive.api.entity.def.BindingDef;
import com.gitee.dorive.api.entity.def.EntityDef;
import com.gitee.dorive.api.entity.ele.EntityElement;
import com.gitee.dorive.api.entity.ele.FieldElement;
import com.gitee.dorive.core.api.binder.Binder;
import com.gitee.dorive.core.api.binder.Processor;
import com.gitee.dorive.core.api.context.Context;
import com.gitee.dorive.core.entity.enums.BindingType;
import com.gitee.dorive.core.entity.enums.JoinType;
import com.gitee.dorive.core.entity.executor.Example;
import com.gitee.dorive.core.impl.binder.*;
import com.gitee.dorive.core.impl.endpoint.BindEndpoint;
import com.gitee.dorive.core.impl.endpoint.FieldEndpoint;
import com.gitee.dorive.core.impl.processor.SpELProcessor;
import com.gitee.dorive.core.repository.AbstractContextRepository;
import com.gitee.dorive.core.repository.CommonRepository;
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<Binder> allBinders;
private List<StrongBinder> strongBinders;
private List<WeakBinder> weakBinders;
private List<ValueRouteBinder> valueRouteBinders;
private List<ValueFilterBinder> valueFilterBinders;
// 决定了关联查询具体使用哪种实现
private Map<String, List<StrongBinder>> mergedStrongBindersMap;
private Map<String, List<ValueRouteBinder>> mergedValueRouteBindersMap;
private StrongBinder boundIdBinder;
private List<String> selfFields;
private JoinType joinType;
public BinderResolver(AbstractContextRepository<?, ?> repository) {
this.repository = repository;
}
public void resolve(EntityElement entityElement) {
EntityDef entityDef = entityElement.getEntityDef();
List<BindingDef> bindingDefs = entityElement.getBindingDefs();
Class<?> genericType = entityElement.getGenericType();
String primaryKey = entityElement.getPrimaryKey();
this.allBinders = new ArrayList<>(bindingDefs.size());
this.strongBinders = new ArrayList<>(bindingDefs.size());
this.weakBinders = new ArrayList<>(bindingDefs.size());
this.valueRouteBinders = new ArrayList<>(bindingDefs.size());
this.valueFilterBinders = new ArrayList<>(bindingDefs.size());
this.mergedStrongBindersMap = new LinkedHashMap<>(bindingDefs.size() * 4 / 3 + 1);
this.mergedValueRouteBindersMap = new LinkedHashMap<>(bindingDefs.size() * 4 / 3 + 1);
this.boundIdBinder = null;
this.selfFields = new ArrayList<>(bindingDefs.size());
this.joinType = JoinType.UNION;
String fieldErrorMsg = "The field configured for @Binding does not exist within the entity! type: {}, field: {}";
for (BindingDef bindingDef : bindingDefs) {
resetBindingDef(bindingDef);
BindingType bindingType = determineBindingType(bindingDef);
Processor processor = newProcessor(bindingDef);
if (bindingType == BindingType.VALUE_ROUTE) {
BindEndpoint bindEndpoint = newBindEndpoint(bindingDef);
ValueRouteBinder valueRouteBinder = new ValueRouteBinder(bindingDef, null, bindEndpoint, processor);
allBinders.add(valueRouteBinder);
valueRouteBinders.add(valueRouteBinder);
String belongAccessPath = valueRouteBinder.getBelongAccessPath();
List<ValueRouteBinder> valueRouteBinders = mergedValueRouteBindersMap.computeIfAbsent(belongAccessPath, key -> new ArrayList<>(2));
valueRouteBinders.add(valueRouteBinder);
continue;
}
String field = bindingDef.getField();
FieldElement fieldElement = entityElement.getFieldElement(field);
Assert.notNull(fieldElement, fieldErrorMsg, genericType.getName(), field);
FieldEndpoint fieldEndpoint = new FieldEndpoint(fieldElement, "#entity." + field);
if (bindingType == BindingType.STRONG) {
BindEndpoint bindEndpoint = newBindEndpoint(bindingDef);
StrongBinder strongBinder = new StrongBinder(bindingDef, fieldEndpoint, bindEndpoint, processor);
allBinders.add(strongBinder);
strongBinders.add(strongBinder);
String belongAccessPath = strongBinder.getBelongAccessPath();
List<StrongBinder> strongBinders = mergedStrongBindersMap.computeIfAbsent(belongAccessPath, key -> new ArrayList<>(2));
strongBinders.add(strongBinder);
if (strongBinder.isSameType() && primaryKey.equals(field)) {
if (entityDef.getPriority() == 0) {
entityDef.setPriority(-1);
}
boundIdBinder = strongBinder;
}
selfFields.add(field);
} else if (bindingType == BindingType.WEAK) {
WeakBinder weakBinder = new WeakBinder(bindingDef, fieldEndpoint, null, processor);
allBinders.add(weakBinder);
weakBinders.add(weakBinder);
} else if (bindingType == BindingType.VALUE_FILTER) {
ValueFilterBinder valueFilterBinder = new ValueFilterBinder(bindingDef, fieldEndpoint, null, processor);
allBinders.add(valueFilterBinder);
valueFilterBinders.add(valueFilterBinder);
}
}
mergedStrongBindersMap = Collections.unmodifiableMap(mergedStrongBindersMap);
mergedValueRouteBindersMap = Collections.unmodifiableMap(mergedValueRouteBindersMap);
selfFields = Collections.unmodifiableList(selfFields);
if (mergedStrongBindersMap.size() == 1 && mergedStrongBindersMap.containsKey("/")) {
List<StrongBinder> binders = mergedStrongBindersMap.get("/");
boolean hasCollection = CollUtil.findOne(binders, AbstractBinder::isBindCollection) != null;
if (!hasCollection) {
joinType = binders.size() == 1 ? JoinType.SINGLE : JoinType.MULTI;
}
}
}
private void resetBindingDef(BindingDef bindingDef) {
String field = StrUtil.trim(bindingDef.getField());
String value = StrUtil.trim(bindingDef.getValue());
String bind = StrUtil.trim(bindingDef.getBind());
String expression = StrUtil.trim(bindingDef.getExpression());
Class<?> processor = bindingDef.getProcessor();
String bindField = StrUtil.trim(bindingDef.getBindField());
// 兼容以往版本
if (bind.startsWith("/")) {
bind = StrUtil.removePrefix(bind, "/");
}
if (bind.startsWith("./")) {
bind = StrUtil.removePrefix(bind, "./");
}
if (StringUtils.isNotBlank(bind) && StringUtils.isNotBlank(expression)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目是采用领域驱动设计的轻量级Java业务框架源码,总共有252个文件组成,涵盖224个Java源文件、12个XML配置文件、5个工厂类文件、5个导入文件、2个PNG图片、1个.gitignore文件、1个LICENSE文件、1个Markdown文件和1个JSON文件。此框架旨在帮助开发者快速构建领域驱动模型,提供多种开箱即用的功能,以提升项目开发效率。
资源推荐
资源详情
资源评论
收起资源包目录
基于领域驱动设计的轻量级Java业务框架源码 (252个子文件)
spring.factories 321B
spring.factories 126B
spring.factories 121B
spring.factories 119B
spring.factories 117B
.gitignore 281B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 129B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 59B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 54B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 52B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 50B
BinderResolver.java 12KB
AbstractContextRepository.java 11KB
MybatisPlusExecutor.java 11KB
ContextExecutor.java 10KB
EntityDefinitionReader.java 10KB
StepwiseQueryExecutor.java 8KB
SegmentUnitResolver.java 7KB
MergedRepositoryResolver.java 7KB
AbstractInnerRepository.java 7KB
MybatisPlusRepository.java 7KB
UnionExecutor.java 6KB
AbstractQueryExecutor.java 6KB
EntityMapperResolver.java 6KB
ExampleExecutor.java 6KB
AbstractRepository.java 6KB
EntityElementResolver.java 6KB
QueryTypeResolver.java 6KB
CommonRepository.java 6KB
SqlQueryExecutor.java 6KB
AppenderContext.java 5KB
FactoryExecutor.java 5KB
ValueObjEntityFactory.java 5KB
LambdaExample.java 5KB
CountSqlQueryExecutor.java 5KB
BatchEntityHandler.java 5KB
AbstractEntityJoiner.java 4KB
Example.java 4KB
AbstractGenericRepository.java 4KB
LimitedAutowiredBeanPostProcessor.java 4KB
MultiEntityJoiner.java 4KB
KeyValuesResolver.java 4KB
AbstractProxyRepository.java 4KB
DefaultTypeDomainResolver.java 4KB
AbstractQueryRepository.java 4KB
AbstractEventRepository.java 4KB
DoriveInjectionConfiguration.java 4KB
AbstractEventListener.java 4KB
UnionEntityJoiner.java 4KB
OperationFactory.java 4KB
EntityListenerAdapter.java 4KB
Repository.java 4KB
EntityElement.java 4KB
DerivedResolver.java 3KB
SelectSegmentBuilder.java 3KB
DefaultEntityFactory.java 3KB
CriterionUtils.java 3KB
MapExpConverter.java 3KB
SingleEntityJoiner.java 3KB
RepositoryRootEventListener.java 3KB
ExecutorEventListener.java 3KB
SpecificFields.java 3KB
QueryExampleResolver.java 3KB
RefImpl.java 3KB
MultiInBuilder.java 3KB
NameSelector.java 3KB
RepositoryEventListener.java 3KB
ExecutorBatchEventListener.java 3KB
ExampleUtils.java 3KB
ConstructResolver.java 3KB
SelectSegment.java 3KB
SelectTypeMatcher.java 3KB
LimitedCglibSubclassingInstantiationStrategy.java 3KB
RefInjector.java 3KB
RepositoryContext.java 2KB
QueryContext.java 2KB
Result.java 2KB
AbstractBinder.java 2KB
AbstractContext.java 2KB
RefObjImpl.java 2KB
CommonEvent.java 2KB
ResObject.java 2KB
ReflectUtils.java 2KB
MybatisPlusConfiguration.java 2KB
QueryField.java 2KB
ParameterControllerAdvice.java 2KB
LimitedRootInitializingBean.java 2KB
EventExecutor.java 2KB
EntityListenerDef.java 2KB
SpELProcessor.java 2KB
ValueFilterBinder.java 2KB
ValueRouteBinder.java 2KB
DefaultSqlHelper.java 2KB
MergedRepository.java 2KB
Aggregate.java 2KB
DoriveEventConfiguration.java 2KB
QueryUnit.java 2KB
CriterionDef.java 2KB
SpELEndpoint.java 2KB
DynamicEnvPostProcessor.java 2KB
共 252 条
- 1
- 2
- 3
资源评论
csbysj2020
- 粉丝: 2422
- 资源: 5454
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功