Skip to content

Commit

Permalink
defaultEnable改成enable
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed May 30, 2023
1 parent 0b8cc0d commit 9d3a60f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.easy.query.core.basic.jdbc.executor.EntityExpressionExecutor;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.basic.plugin.interceptor.InterceptorEntry;
import com.easy.query.core.basic.plugin.interceptor.Interceptor;
import com.easy.query.core.configuration.QueryConfiguration;
import com.easy.query.core.context.QueryRuntimeContext;
import com.easy.query.core.enums.ExecuteMethodEnum;
Expand Down Expand Up @@ -52,11 +52,11 @@ public Insertable<T> insert(T entity) {

protected void insertBefore() {
//是否使用自定义插入策略
List<InterceptorEntry> insertInterceptors = entityMetadata.getEntityInterceptors();
List<String> insertInterceptors = entityMetadata.getEntityInterceptors();
if (EasyCollectionUtil.isNotEmpty(insertInterceptors)) {
QueryConfiguration easyQueryConfiguration = entityInsertExpressionBuilder.getRuntimeContext().getQueryConfiguration();
List<EntityInterceptor> entityInterceptors = entityInsertExpressionBuilder.getExpressionContext().getInterceptorFilter(insertInterceptors)
.map(interceptor -> (EntityInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor.getName())).collect(Collectors.toList());
.map(interceptor -> (EntityInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor)).filter(Interceptor::enable).collect(Collectors.toList());
if (EasyCollectionUtil.isNotEmpty(entityInterceptors)) {
Class<?> entityClass = entityMetadata.getEntityClass();
for (T entity : entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.easy.query.core.basic.jdbc.executor.EntityExpressionExecutor;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.basic.plugin.interceptor.InterceptorEntry;
import com.easy.query.core.basic.plugin.interceptor.Interceptor;
import com.easy.query.core.configuration.QueryConfiguration;
import com.easy.query.core.context.QueryRuntimeContext;
import com.easy.query.core.enums.ExecuteMethodEnum;
Expand All @@ -19,7 +19,6 @@
import com.easy.query.core.expression.sql.builder.EntityTableExpressionBuilder;
import com.easy.query.core.expression.sql.builder.EntityUpdateExpressionBuilder;
import com.easy.query.core.basic.jdbc.executor.ExecutorContext;
import com.easy.query.core.expression.sql.builder.ExpressionContext;
import com.easy.query.core.metadata.EntityMetadata;
import com.easy.query.core.util.EasyCollectionUtil;

Expand Down Expand Up @@ -65,11 +64,11 @@ public long executeRows() {
}

protected void updateBefore() {
List<InterceptorEntry> updateInterceptors = entityMetadata.getEntityInterceptors();
List<String> updateInterceptors = entityMetadata.getEntityInterceptors();
if (EasyCollectionUtil.isNotEmpty(updateInterceptors)) {
QueryConfiguration easyQueryConfiguration = entityUpdateExpressionBuilder.getRuntimeContext().getQueryConfiguration();
List<EntityInterceptor> entityInterceptors = entityUpdateExpressionBuilder.getExpressionContext().getInterceptorFilter(updateInterceptors)
.map(interceptor -> (EntityInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor.getName())).collect(Collectors.toList());
.map(interceptor -> (EntityInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor)).filter(Interceptor::enable).collect(Collectors.toList());
if (EasyCollectionUtil.isNotEmpty(entityInterceptors)) {
Class<?> entityClass = entityMetadata.getEntityClass();
for (T entity : entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.easy.query.core.basic.jdbc.tx.Transaction;
import com.easy.query.core.enums.con.ConnectionStrategyEnum;
import com.easy.query.core.exception.EasyQuerySQLCommandException;

import java.util.List;

Expand All @@ -26,8 +27,17 @@ default Transaction beginTransaction(){
* (Note that Connection.TRANSACTION_NONE cannot be used because it specifies that transactions are not supported.)
* @param isolationLevel
* @return
* @throws EasyQuerySQLCommandException repeat begin transaction
*/
Transaction beginTransaction(Integer isolationLevel);

default Transaction tryBeginTransaction(Integer isolationLevel){
Transaction transaction = getTransactionOrNull();
if(transaction!=null){
return transaction;
}
return beginTransaction(isolationLevel);
}
List<EasyConnection> getEasyConnections(int count,String dataSourceName, ConnectionStrategyEnum connectionStrategy);
default boolean isOpenTransaction(){
return getTransactionOrNull()!=null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ default int order(){
* 可以设置为动态值
* @return
*/
default boolean defaultEnable(){return true;}
default boolean enable(){return true;}
/**
* 拦截器名称
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ public void noInterceptor() {
}

@Override
public Stream<InterceptorEntry> getInterceptorFilter(List<InterceptorEntry> queryInterceptors) {
public Stream<String> getInterceptorFilter(List<String> queryInterceptors) {
boolean interceptorBehavior = getBehavior().hasBehavior(EasyBehaviorEnum.USE_INTERCEPTOR);
//如果当前操作存在interceptor的behavior那么就不应该在interceptors里面
//否则应该在interceptors里面
return queryInterceptors.stream().filter(o -> {
//如果是启用了的
if (interceptorBehavior) {
//拦截器手动指定使用的或者默认要用的并且没有说不用的
return useInterceptors.contains(o.getName()) || (o.isDefaultEnable() && !noInterceptors.contains(o.getName()));
return useInterceptors.contains(o) || !noInterceptors.contains(o);
} else {
//手动指定要用的并且不在不使用里面
return useInterceptors.contains(o.getName()) && !noInterceptors.contains(o.getName());
return useInterceptors.contains(o) && !noInterceptors.contains(o);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface ExpressionContext {
void noInterceptor(String name);
void useInterceptor();
void noInterceptor();
Stream<InterceptorEntry> getInterceptorFilter(List<InterceptorEntry> queryInterceptors);
Stream<String> getInterceptorFilter(List<String> queryInterceptors);

default void executeMethod(ExecuteMethodEnum executeMethod){
executeMethod(executeMethod,false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ protected SQLBuilderSegment buildSetSQLSegment(EntityTableExpressionBuilder tabl
QueryConfiguration easyQueryConfiguration = getRuntimeContext().getQueryConfiguration();
getExpressionContext().getInterceptorFilter(entityMetadata.getUpdateSetInterceptors())
.forEach(interceptor -> {
UpdateSetInterceptor globalInterceptor = (UpdateSetInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor.getName());
globalInterceptor.configure(entityMetadata.getEntityClass(), this, sqlColumnSetter);
UpdateSetInterceptor globalInterceptor = (UpdateSetInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor);
if(globalInterceptor.enable()){
globalInterceptor.configure(entityMetadata.getEntityClass(), this, sqlColumnSetter);
}
});
}
if (entityMetadata.hasVersionColumn()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public AbstractPredicateEntityExpressionBuilder(ExpressionContext expressionCont
protected boolean useLogicDelete(EntityMetadata entityMetadata) {
return expressionContext.getBehavior().hasBehavior(EasyBehaviorEnum.LOGIC_DELETE) && entityMetadata.enableLogicDelete();
}

/**
* 存在问题 update必须要总的predicate但是如果在这边导致我手动指定where也会有这个version
*
Expand Down Expand Up @@ -73,8 +74,8 @@ protected PredicateSegment sqlPredicateFilter(EntityTableExpressionBuilder table
QueryConfiguration easyQueryConfiguration = getRuntimeContext().getQueryConfiguration();
expressionContext.getInterceptorFilter(entityMetadata.getPredicateFilterInterceptors())
.forEach(interceptor -> {
PredicateFilterInterceptor globalSelectInterceptorStrategy = (PredicateFilterInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor.getName());
if (globalSelectInterceptorStrategy != null) {
PredicateFilterInterceptor globalSelectInterceptorStrategy = (PredicateFilterInterceptor) easyQueryConfiguration.getEasyInterceptor(interceptor);
if (globalSelectInterceptorStrategy != null && globalSelectInterceptorStrategy.enable()) {
globalSelectInterceptorStrategy.configure(entityMetadata.getEntityClass(), this, sqlPredicate);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public boolean isMultiDataSourceMapping() {
/**
* 查询过滤器
*/
private final List<InterceptorEntry> predicateFilterInterceptors = new ArrayList<>();
private final List<InterceptorEntry> entityInterceptors = new ArrayList<>();
private final List<InterceptorEntry> updateSetInterceptors = new ArrayList<>();
private final List<String> predicateFilterInterceptors = new ArrayList<>();
private final List<String> entityInterceptors = new ArrayList<>();
private final List<String> updateSetInterceptors = new ArrayList<>();
private final LinkedHashMap<String, ColumnMetadata> property2ColumnMap = new LinkedHashMap<>();
private final Map<String/*property name*/, String/*column name*/> keyPropertiesMap = new LinkedHashMap<>();
private final List<String/*column name*/> incrementColumns = new ArrayList<>(4);
Expand Down Expand Up @@ -291,15 +291,14 @@ protected void entityGlobalInterceptorConfigurationInit(QueryConfiguration confi
List<Interceptor> globalInterceptors = configuration.getEasyInterceptors().stream().sorted(Comparator.comparingInt(Interceptor::order)).collect(Collectors.toList());
for (Interceptor globalInterceptor : globalInterceptors) {
if (globalInterceptor.apply(entityClass)) {
InterceptorEntry easyInterceptorEntry = new InterceptorEntry(globalInterceptor.name(), globalInterceptor.defaultEnable());
if (globalInterceptor instanceof PredicateFilterInterceptor) {
predicateFilterInterceptors.add(easyInterceptorEntry);
predicateFilterInterceptors.add(globalInterceptor.name());
}
if (globalInterceptor instanceof EntityInterceptor) {
entityInterceptors.add(easyInterceptorEntry);
entityInterceptors.add(globalInterceptor.name());
}
if (globalInterceptor instanceof UpdateSetInterceptor) {
updateSetInterceptors.add(easyInterceptorEntry);
updateSetInterceptors.add(globalInterceptor.name());
}
}
}
Expand Down Expand Up @@ -421,15 +420,15 @@ public boolean enableLogicDelete() {
}


public List<InterceptorEntry> getPredicateFilterInterceptors() {
public List<String> getPredicateFilterInterceptors() {
return predicateFilterInterceptors;
}

public List<InterceptorEntry> getEntityInterceptors() {
public List<String> getEntityInterceptors() {
return entityInterceptors;
}

public List<InterceptorEntry> getUpdateSetInterceptors() {
public List<String> getUpdateSetInterceptors() {
return updateSetInterceptors;
}

Expand Down

0 comments on commit 9d3a60f

Please sign in to comment.