Skip to content

Commit

Permalink
feat: [#185]添加toSQLResult方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed May 23, 2024
1 parent d63e436 commit 5f5d669
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.easy.query.core.basic.api.internal.TableReNameable;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.common.ToSQLResult;
import com.easy.query.core.expression.sql.builder.EntityDeleteExpressionBuilder;
import com.easy.query.core.expression.sql.builder.ExpressionContext;

Expand All @@ -31,6 +32,16 @@ default String toSQL() {

String toSQL(ToSQLContext toSQLContext);

/**
* 传入生成sql的上下文用来获取生成sql后的表达式内部的参数
* @return 包含sql和sql结果比如参数
*/

default ToSQLResult toSQLResult() {
ToSQLContext toSQLContext = DefaultToSQLContext.defaultToSQLContext(getExpressionContext().getTableContext(),true);
String sql = toSQL(toSQLContext);
return new ToSQLResult(sql,toSQLContext);
}
/**
* 是否允许删除命令
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.easy.query.core.basic.api.internal.SQLExecuteStrategy;
import com.easy.query.core.basic.api.internal.SQLOnDuplicateKeyIgnore;
import com.easy.query.core.basic.api.internal.TableReNameable;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.common.ToSQLResult;
import com.easy.query.core.expression.sql.builder.EntityInsertExpressionBuilder;

import java.util.Collection;
Expand All @@ -21,19 +23,33 @@ public interface Insertable<T, TChain> extends SQLExecuteRows, Interceptable<TCh
TChain insert(T entity);

TChain insert(Collection<T> entities);

EntityInsertExpressionBuilder getEntityInsertExpressionBuilder();

/**
*
* @param fillAutoIncrement
* @return
*/
long executeRows(boolean fillAutoIncrement);

@Override
default long executeRows(){
default long executeRows() {
return executeRows(false);
}
String toSQL(T entity);

String toSQL(T entity);

String toSQL(T entity, ToSQLContext toSQLContext);

/**
* 传入生成sql的上下文用来获取生成sql后的表达式内部的参数
*
* @return 包含sql和sql结果比如参数
*/

default ToSQLResult toSQLResult(T entity) {
ToSQLContext toSQLContext = DefaultToSQLContext.defaultToSQLContext(getEntityInsertExpressionBuilder().getExpressionContext().getTableContext(), true);
String sql = toSQL(entity, toSQLContext);
return new ToSQLResult(sql, toSQLContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.easy.query.core.basic.api.internal.ConfigureVersionable;
import com.easy.query.core.basic.api.internal.SQLExecuteStrategy;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.common.ToSQLResult;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.parser.core.base.ColumnConfigurer;
import com.easy.query.core.expression.parser.core.base.ColumnOnlySelector;
Expand Down Expand Up @@ -71,4 +74,15 @@ default ClientEntityUpdatable<T> whereColumns(SQLExpression1<ColumnOnlySelector<

ClientEntityUpdatable<T> columnConfigure(SQLExpression1<ColumnConfigurer<T>> columnConfigureExpression);
String toSQL(Object entity);
String toSQL(Object entity, ToSQLContext toSQLContext);
/**
* 传入生成sql的上下文用来获取生成sql后的表达式内部的参数
* @return 包含sql和sql结果比如参数
*/

default ToSQLResult toSQLResult(Object entity) {
ToSQLContext toSQLContext = DefaultToSQLContext.defaultToSQLContext(getUpdateExpressionBuilder().getExpressionContext().getTableContext(),true);
String sql = toSQL(entity, toSQLContext);
return new ToSQLResult(sql,toSQLContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.easy.query.core.basic.api.internal.WithVersionable;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.common.ToSQLResult;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.parser.core.available.TableAvailable;
import com.easy.query.core.expression.parser.core.base.ColumnSetter;
Expand Down Expand Up @@ -144,5 +145,12 @@ default String toSQL() {
}

String toSQL(ToSQLContext toSQLContext);

default ToSQLResult toSQLResult() {
TableContext tableContext = getExpressionContext().getTableContext();
ToSQLContext toSQLContext = DefaultToSQLContext.defaultToSQLContext(tableContext,true);
String sql = toSQL(toSQLContext);
return new ToSQLResult(sql,toSQLContext);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ public ClientEntityUpdatable<T> ignoreVersion(boolean ignored) {

@Override
public String toSQL(Object entity) {
return toSQLWithParam(entity, DefaultToSQLContext.defaultToSQLContext(entityUpdateExpressionBuilder.getExpressionContext().getTableContext(),false));
return toSQL(entity, DefaultToSQLContext.defaultToSQLContext(entityUpdateExpressionBuilder.getExpressionContext().getTableContext(),false));
}

private String toSQLWithParam(Object entity, ToSQLContext toSQLContext) {
@Override
public String toSQL(Object entity, ToSQLContext toSQLContext) {
return entityUpdateExpressionBuilder.toExpression(entity).toSQL(toSQLContext);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easy.query.core.basic.api.update.impl;

import com.easy.query.core.basic.api.update.ClientEntityUpdatable;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
import com.easy.query.core.enums.SQLExecuteStrategyEnum;
import com.easy.query.core.exception.EasyQueryConcurrentException;
import com.easy.query.core.expression.lambda.SQLExpression1;
Expand Down Expand Up @@ -106,6 +107,11 @@ public String toSQL(Object entity) {
return null;
}

@Override
public String toSQL(Object entity, ToSQLContext toSQLContext) {
return "";
}

@Override
public ClientEntityUpdatable<T> batch(boolean use) {
return this;
Expand Down

0 comments on commit 5f5d669

Please sign in to comment.