mirror of
https://gitee.com/jeelowcode/JeeLowCode.git
synced 2026-05-10 05:59:30 +08:00
v1.0.0
This commit is contained in:
36
jeelowcode-framework/jeelowcode-plus/pom.xml
Normal file
36
jeelowcode-framework/jeelowcode-plus/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>jeelowcode-framework</artifactId>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jeelowcode-plus</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>${jeelowcode.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>JeeLowCode低代码平台 - Sql封装</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-utils</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-tenant</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.jsqlparser</groupId>
|
||||
<artifactId>jsqlparser</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.AndExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.*;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildSelect;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoPublicModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoDeleteWrapper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoInsertWrapper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoUpdateWrapper;
|
||||
import com.jeelowcode.framework.plus.chain.entity.TenantIdFilterEntity;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
import com.jeelowcode.framework.plus.enums.DbTypeEnum;
|
||||
import com.jeelowcode.framework.plus.flyweight.FlyweightDBFactory;
|
||||
import com.jeelowcode.framework.plus.template.AbstractDbTemplate;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.enums.YNEnum;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SqlHelper {
|
||||
|
||||
//数据库类型
|
||||
//private static String dbType="postgresql";
|
||||
//private static String dbSchemaName="db_jeelowcode";
|
||||
|
||||
private static String dbType="mysql";
|
||||
private static String dbSchemaName="db_jeelowcode";
|
||||
|
||||
//数据库类型
|
||||
//private static String dbType="oracle";
|
||||
//private static String dbSchemaName="c##jee_test";
|
||||
|
||||
public static void setDbType(String dbType) {
|
||||
SqlHelper.dbType = dbType;
|
||||
}
|
||||
|
||||
|
||||
public static void setDbSchemaName(String dbSchemaName) {
|
||||
SqlHelper.dbSchemaName = dbSchemaName;
|
||||
}
|
||||
|
||||
private static AbstractDbTemplate getAbstractDbTemplate() {
|
||||
DbTypeEnum dbTypeEnum = DbTypeEnum.getByDbCode(dbType);
|
||||
AbstractDbTemplate template = FlyweightDBFactory.getDbType(dbTypeEnum);
|
||||
return template;
|
||||
}
|
||||
|
||||
public static DbColunmTypesEntity getDbColunmTypesEntity() {
|
||||
DbTypeEnum dbTypeEnum = DbTypeEnum.getByDbCode(dbType);
|
||||
AbstractDbTemplate template = FlyweightDBFactory.getDbType(dbTypeEnum);
|
||||
|
||||
SqlInfoEntity sqlInfoEntity=new SqlInfoEntity();
|
||||
SQLInterpretContext context =new SQLInterpretContext(dbSchemaName);
|
||||
sqlInfoEntity.setContext(context);
|
||||
template.operation(sqlInfoEntity);
|
||||
return sqlInfoEntity.getContext().getDbColunmTypes();
|
||||
}
|
||||
|
||||
//获取租户权限
|
||||
private static TenantIdFilterEntity getTenantIdFilterEntity() {
|
||||
//处理租户
|
||||
IJeeLowCodeAdapter adapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
|
||||
Set<String> tenantIgnoreTable = adapter.getTenantIgnoreTable();//忽略的表
|
||||
Set<String> tenantIgnoreUrl = adapter.getTenantIgnoreUrl();//忽略的表
|
||||
boolean tenantEnable = adapter.getTenantEnable();
|
||||
|
||||
TenantIdFilterEntity tenantIdFilterEntity = new TenantIdFilterEntity();
|
||||
tenantIdFilterEntity.setEnable(tenantEnable);
|
||||
tenantIdFilterEntity.setTenantId(Long.parseLong(adapter.getTenantId()));
|
||||
tenantIdFilterEntity.setIgnore(adapter.getTenantIsIgnore());
|
||||
tenantIdFilterEntity.setIgnoreTables(tenantIgnoreTable);
|
||||
tenantIdFilterEntity.setIgnoreUrl(tenantIgnoreUrl);
|
||||
return tenantIdFilterEntity;
|
||||
}
|
||||
|
||||
//新建表
|
||||
public static List<String> createTable(String tableName, String tableAlias, List<FieldModel> fieldModelList) throws JSQLParserException {
|
||||
/**
|
||||
* 创建表分三步
|
||||
* 1.创建简单表 id varchar(10) not null
|
||||
* 2.处理备注
|
||||
* 3.处理主键
|
||||
*/
|
||||
//1.创建表
|
||||
SqlInfoCreateModel<BuildCreateTable> createModel = SqlInfoCreateModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setTableOptions(fieldModelList)
|
||||
.build();
|
||||
|
||||
//2.处理字段备注
|
||||
SqlInfoCommentModel<BuildComment> commentmodel = SqlInfoCommentModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setTableAlias(tableAlias)
|
||||
.setfieldModelList(fieldModelList)
|
||||
.build();
|
||||
//3.处理主键
|
||||
List<String> primaryKeyList = fieldModelList.stream()
|
||||
.filter(fieldModel -> !FuncBase.isEmpty(fieldModel.getIsPrimaryKey()) && !FuncBase.equals(fieldModel.getIsPrimaryKey(), YNEnum.N.getCode()))
|
||||
.map(FieldModel::getFieldCode)
|
||||
.collect(Collectors.toList());
|
||||
//3.处理主键
|
||||
SqlInfoPrimaryKeyModel primaryKeyModel = SqlInfoPrimaryKeyModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setPrimaryKey(primaryKeyList)
|
||||
.build();
|
||||
|
||||
//构建SQL上下文
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setCreateModel(createModel);
|
||||
context.setCommentModel(commentmodel);
|
||||
context.setPrimaryKeyModel(primaryKeyModel);
|
||||
|
||||
//多个
|
||||
AndExpression expression = new AndExpression(createModel.getSqlExpression(), commentmodel.getSqlExpression(),primaryKeyModel.getSqlExpression());
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, expression);
|
||||
|
||||
List<String> ddlList = sqlFormatModelList.stream()
|
||||
.map(SqlFormatModel::getSql)
|
||||
.collect(Collectors.toList());
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
//增加列
|
||||
public static List<String> addColumn(String tableName, FieldModel fieldModel) {
|
||||
/**
|
||||
* 增加列分两步
|
||||
* 1.创建简单表
|
||||
* 2.处理备注
|
||||
*/
|
||||
|
||||
//1.创建表
|
||||
SqlInfoAlterModel<BuildAlter> addColumnModel = SqlInfoAlterModel.builder()
|
||||
.setTableName(tableName)
|
||||
.buildAddColumn(fieldModel);
|
||||
|
||||
//2.处理主键
|
||||
SqlInfoPrimaryKeyModel primaryKeyModel =null;
|
||||
if(FuncBase.equals(fieldModel.getFieldCode(),"id")){
|
||||
primaryKeyModel = SqlInfoPrimaryKeyModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setPrimaryKey(FuncBase.toStrList("id"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
List<FieldModel> fieldModelList = new ArrayList<>();
|
||||
fieldModelList.add(fieldModel);
|
||||
|
||||
SqlInfoCommentModel<BuildComment> commentmodel = SqlInfoCommentModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setfieldModelList(fieldModelList)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setAlterModel(addColumnModel);
|
||||
context.setCommentModel(commentmodel);
|
||||
context.setPrimaryKeyModel(primaryKeyModel);//主键
|
||||
|
||||
//多个
|
||||
AndExpression expression =null;
|
||||
if(FuncBase.isNotEmpty(context.getPrimaryKeyModel())){
|
||||
expression = new AndExpression(addColumnModel.getSqlExpression(), commentmodel.getSqlExpression(),primaryKeyModel.getSqlExpression());
|
||||
}else{
|
||||
expression = new AndExpression(addColumnModel.getSqlExpression(), commentmodel.getSqlExpression());
|
||||
}
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, expression);
|
||||
|
||||
List<String> ddlList = sqlFormatModelList.stream()
|
||||
.map(SqlFormatModel::getSql)
|
||||
.collect(Collectors.toList());
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
//修改列
|
||||
public static List<String> modifyColumnSql(String tableName, FieldModel fieldModel) {
|
||||
/**
|
||||
* 增加列分两步
|
||||
* 1.创建简单表
|
||||
* 2.处理备注
|
||||
*/
|
||||
//修改表
|
||||
SqlInfoAlterModel<BuildAlter> modifyColumnModel = SqlInfoAlterModel.builder()
|
||||
.setTableName(tableName)
|
||||
.buildUpdateColum(fieldModel);
|
||||
|
||||
List<FieldModel> fieldModelList = new ArrayList<>();
|
||||
fieldModelList.add(fieldModel);
|
||||
|
||||
SqlInfoCommentModel<BuildComment> commentModel = SqlInfoCommentModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setfieldModelList(fieldModelList)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setAlterModel(modifyColumnModel);
|
||||
context.setCommentModel(commentModel);
|
||||
|
||||
//多个
|
||||
AndExpression expression = new AndExpression(modifyColumnModel.getSqlExpression(), commentModel.getSqlExpression());
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, expression);
|
||||
|
||||
List<String> ddlList = sqlFormatModelList.stream()
|
||||
.map(SqlFormatModel::getSql)
|
||||
.collect(Collectors.toList());
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
//删除列
|
||||
public static String getDropColumnSql(String tableName,String clumn) {
|
||||
SqlInfoDropModel<BuildDrop> dropModel = SqlInfoDropModel.builder()
|
||||
.buildDropColumn(tableName, clumn);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDropModel(dropModel);
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, dropModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//删除表
|
||||
public static String getDropTableSql(String tableName) {
|
||||
SqlInfoDropModel<BuildDrop> dropTableModel = SqlInfoDropModel.builder()
|
||||
.buildDropTable(tableName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDropModel(dropTableModel);
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, dropTableModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//创建索引
|
||||
public static String createIndex(String tableName,String indexName,List<String> fieldList) {
|
||||
|
||||
SqlInfoCreateIndexModel<BuildCreateIndex> createIndexModel = SqlInfoCreateIndexModel.builder()
|
||||
.setTableName(tableName)
|
||||
.setIndexName(indexName)
|
||||
.setIndexFieldCodeList(fieldList)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setCreateIndexModel(createIndexModel);
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, createIndexModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//删除索引
|
||||
public static String getDropIndex(String tableName,String indexName) {
|
||||
|
||||
SqlInfoDropModel<BuildDrop> dropModel = SqlInfoDropModel.builder()
|
||||
.buildDropIndex(tableName, indexName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDropModel(dropModel);
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, dropModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//校验索引是否存在
|
||||
public static String getIndexExistSql(String tableName,String indexName){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildIndexExist(tableName, indexName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//获取某一个表所有索引
|
||||
public static String getIndexAllByTableSql(String tableName){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildIndexAllByTable(tableName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//校验表是否存在
|
||||
public static String getTableExistSql(String tableName){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildTableExist(tableName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//校验表是否存在
|
||||
public static String getAllTableNameSql(){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildGetAllTableName();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//获取表字段备注
|
||||
public static String getTableFieldComment(String tableName){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildFieldComment(tableName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//获取表备注
|
||||
public static String getTableComment(String tableName){
|
||||
SqlInfoDdlModel<BuildDdl> ddlModel = SqlInfoDdlModel.builder().buildTableComment(tableName);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setDdlModel(ddlModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = ddlExpression(context, ddlModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//--------------dql---------------
|
||||
//通用sql
|
||||
public static String getPublicSql(String sql){
|
||||
SqlInfoPublicModel<BuildSelect> publicModel = SqlInfoPublicModel.builder().setSql(sql).build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
context.setPublicModel(publicModel);
|
||||
List<SqlFormatModel> sqlFormatModelList = sqlExpression(context, publicModel.getSqlExpression());
|
||||
return sqlFormatModelList.get(0).getSql();
|
||||
}
|
||||
|
||||
//查询数据
|
||||
public static SqlInfoQueryWrapper.Wrapper getQueryWrapper(){
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlInfoQueryWrapper.wrapper(dbSchemaName);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
//新增数据
|
||||
public static SqlInfoInsertWrapper.Wrapper getInsertWrapper(){
|
||||
SqlInfoInsertWrapper.Wrapper wrapper = SqlInfoInsertWrapper.wrapper(dbSchemaName);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
//修改数据
|
||||
public static SqlInfoUpdateWrapper.Wrapper getUpdateWrapper(){
|
||||
SqlInfoUpdateWrapper.Wrapper wrapper = SqlInfoUpdateWrapper.wrapper(dbSchemaName);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
//删除数据
|
||||
public static SqlInfoDeleteWrapper.Wrapper getDeleteWrapper(){
|
||||
SqlInfoDeleteWrapper.Wrapper wrapper = SqlInfoDeleteWrapper.wrapper(dbSchemaName);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//自定义 sql
|
||||
public static List<SqlFormatModel> sqlExpression(SQLInterpretContext context, ISQLExpression expression) {
|
||||
TenantIdFilterEntity tenantIdFilterEntity =getTenantIdFilterEntity();
|
||||
SqlInfoEntity sqlInfoEntity = new SqlInfoEntity();
|
||||
List<SqlFormatModel> sqlModelList = sqlExpression(sqlInfoEntity,context, expression, tenantIdFilterEntity);
|
||||
return sqlModelList;
|
||||
}
|
||||
//自定义 ddl
|
||||
public static List<SqlFormatModel> ddlExpression(SQLInterpretContext context, ISQLExpression expression) {
|
||||
SqlInfoEntity sqlInfoEntity = new SqlInfoEntity();
|
||||
List<SqlFormatModel> sqlModelList = sqlExpression(sqlInfoEntity,context, expression, null);
|
||||
return sqlModelList;
|
||||
}
|
||||
//自定义 只需要使用sql解析
|
||||
public static List<SqlFormatModel> parserExpression(SQLInterpretContext context, ISQLExpression expression) {
|
||||
SqlInfoEntity sqlInfoEntity = new SqlInfoEntity();
|
||||
sqlInfoEntity.setSqlParserLevel(3);
|
||||
List<SqlFormatModel> sqlModelList = sqlExpression(sqlInfoEntity,context, expression, null);
|
||||
return sqlModelList;
|
||||
}
|
||||
|
||||
private static List<SqlFormatModel> sqlExpression(SqlInfoEntity sqlInfoEntity,SQLInterpretContext context, ISQLExpression expression, TenantIdFilterEntity tenantIdFilterEntity) {
|
||||
AbstractDbTemplate template = getAbstractDbTemplate();
|
||||
|
||||
sqlInfoEntity.setContext(context);
|
||||
sqlInfoEntity.setSqlExpression(expression);
|
||||
if (FuncBase.isNotEmpty(tenantIdFilterEntity)) {
|
||||
sqlInfoEntity.setTenantIdFilterEntity(tenantIdFilterEntity);
|
||||
}
|
||||
|
||||
template.operation(sqlInfoEntity);
|
||||
List<SqlFormatModel> sqlModelList = sqlInfoEntity.getSqlModelList();
|
||||
if (FuncBase.isEmpty(sqlModelList)) {
|
||||
return sqlModelList;
|
||||
}
|
||||
sqlModelList.forEach(model->{
|
||||
String sql = model.getSql();
|
||||
if(sql.endsWith(";")){
|
||||
System.out.println(sql);
|
||||
}else{
|
||||
System.out.println(sql+";");
|
||||
}
|
||||
});
|
||||
return sqlModelList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T> 返回值
|
||||
*/
|
||||
public interface ISQLExpression<T> {
|
||||
|
||||
|
||||
//解析器
|
||||
T interpret(SQLInterpretContext contextT) throws JSQLParserException;
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build;
|
||||
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.*;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 多条件
|
||||
*/
|
||||
public class AndExpression implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
private ISQLExpression[] expressions;
|
||||
|
||||
public AndExpression(ISQLExpression... expressions) {
|
||||
this.expressions = expressions;
|
||||
}
|
||||
public AndExpression(List<ISQLExpression> expressionList) {
|
||||
expressions =new ISQLExpression[expressionList.size()];
|
||||
for (int i = 0; i < expressionList.size(); i++) {
|
||||
ISQLExpression expression = expressionList.get(i);
|
||||
expressions[i]=expression;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ddl允许多个,dql只允许一个
|
||||
* @param context
|
||||
* @return
|
||||
* @throws JSQLParserException
|
||||
*/
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
List<SqlFormatModel> sqlFormatModelList = this.getDDL(context);
|
||||
if (FuncBase.isNotEmpty(sqlFormatModelList)) {
|
||||
return sqlFormatModelList;
|
||||
}
|
||||
SqlFormatModel sqlFormatModel = this.getDQL(context);
|
||||
return Collections.singletonList(sqlFormatModel);
|
||||
}
|
||||
|
||||
//获取ddl
|
||||
private List<SqlFormatModel> getDDL(SQLInterpretContext context) throws JSQLParserException {
|
||||
|
||||
List<ISQLExpression> ddlList = Arrays.stream(expressions)
|
||||
.filter(expression -> expression instanceof BuildAlter
|
||||
|| expression instanceof BuildCreateIndex
|
||||
|| expression instanceof BuildCreateTable
|
||||
|| expression instanceof BuildDrop
|
||||
|| expression instanceof BuildComment
|
||||
|| expression instanceof BuildPrimaryKey
|
||||
|| expression instanceof BuildDdl)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (FuncBase.isEmpty(ddlList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<SqlFormatModel> resultModelList=new ArrayList<>();
|
||||
for (ISQLExpression<SqlFormatModel> expression : ddlList) {
|
||||
Object obj= expression.interpret(context);
|
||||
if (FuncBase.isEmpty(obj)) {
|
||||
continue;
|
||||
}
|
||||
if(obj instanceof SqlFormatModel){
|
||||
resultModelList.add((SqlFormatModel)obj);
|
||||
}else if(obj instanceof List){
|
||||
resultModelList.addAll((List<SqlFormatModel>)obj);
|
||||
}
|
||||
|
||||
}
|
||||
return resultModelList;
|
||||
}
|
||||
|
||||
private SqlFormatModel getDQL(SQLInterpretContext context) throws JSQLParserException {
|
||||
List<ISQLExpression> expressionList = this.getDQLExpression();
|
||||
if (FuncBase.isEmpty(expressionList)) {
|
||||
throw new JeeLowCodeException("表达式为空");
|
||||
}
|
||||
String sql = "";
|
||||
Map<String, Object> dataMap = new LinkedHashMap<>();
|
||||
int step = 0;
|
||||
for (ISQLExpression expression : expressionList) {//buildselect buildwhere buidlorderby
|
||||
SqlFormatModel sqlFormatModel = (SqlFormatModel) expression.interpret(context);
|
||||
String tmpSql = sqlFormatModel.getSql();
|
||||
Map<String, Object> tmpMap = sqlFormatModel.getDataMap();
|
||||
if (FuncBase.isEmpty(tmpMap)) {
|
||||
sql += " " + tmpSql;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 首先,将entrySet中的元素复制到一个列表中
|
||||
List<Map.Entry<String, Object>> entrieList = new ArrayList<>(tmpMap.entrySet());
|
||||
Collections.reverse(entrieList);
|
||||
|
||||
for (Map.Entry<String, Object> entry : entrieList) {
|
||||
step++;
|
||||
|
||||
String key = entry.getKey(); // 获取键
|
||||
Object value = entry.getValue(); // 获取值
|
||||
|
||||
String newKey = "JEELOWCODE_MPGENVAL" + step;
|
||||
|
||||
// 执行你的替换逻辑
|
||||
tmpSql = tmpSql.replace("#{ew.paramNameValuePairs." + key+"," , "#{" +context.getPreSymbol()+ newKey+"," );
|
||||
tmpSql = tmpSql.replace("#{ew.paramNameValuePairs." + key+"}" , "#{" +context.getPreSymbol()+ newKey+"}" );
|
||||
|
||||
dataMap.put("JEELOWCODE_MPGENVAL" + step, value);
|
||||
}
|
||||
|
||||
sql += " " + tmpSql;
|
||||
}
|
||||
|
||||
return new SqlFormatModel(sql, dataMap);
|
||||
|
||||
}
|
||||
|
||||
//获取dql 排序后的表达式
|
||||
private List<ISQLExpression> getDQLExpression() {
|
||||
|
||||
List<ISQLExpression> dqllList = Arrays.stream(expressions)
|
||||
.filter(expression -> expression instanceof BuildSelect
|
||||
|| expression instanceof BuildJoin
|
||||
|| expression instanceof BuildWhere
|
||||
|| expression instanceof BuildGroupBy
|
||||
|| expression instanceof BuildHaving
|
||||
|| expression instanceof BuildOrderBy
|
||||
|| expression instanceof BuildInsert
|
||||
|| expression instanceof BuildUpdate
|
||||
|| expression instanceof BuildDelete)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (FuncBase.isEmpty(dqllList)) {
|
||||
return null;
|
||||
}
|
||||
//只有一个,不用排序
|
||||
if(FuncBase.isNotEmpty(dqllList) && dqllList.size()==1){
|
||||
return dqllList;
|
||||
}
|
||||
|
||||
//排序
|
||||
List<ISQLExpression> sortList = new ArrayList<>();
|
||||
|
||||
//下面是dql,需要安装sql标准查询的格式来凭接
|
||||
ISQLExpression tmpSelect = null;
|
||||
List<ISQLExpression> tmpJoinList = new ArrayList<>();
|
||||
ISQLExpression tmpWhere = null;
|
||||
ISQLExpression tmpGroupBy = null;
|
||||
ISQLExpression tmpOrderBy = null;
|
||||
ISQLExpression tmpHaving = null;
|
||||
|
||||
ISQLExpression tmpInsert = null;
|
||||
ISQLExpression tmpUpdate = null;
|
||||
ISQLExpression tmpDelete = null;
|
||||
for (ISQLExpression expression : expressions) {
|
||||
if (expression instanceof BuildSelect) {
|
||||
tmpSelect = expression;
|
||||
} else if (expression instanceof BuildJoin) {
|
||||
tmpJoinList.add(expression);//因为会多个
|
||||
} else if (expression instanceof BuildWhere) {
|
||||
tmpWhere = expression;
|
||||
} else if (expression instanceof BuildGroupBy) {
|
||||
tmpGroupBy = expression;
|
||||
} else if (expression instanceof BuildHaving) {
|
||||
tmpHaving = expression;
|
||||
} else if (expression instanceof BuildOrderBy) {
|
||||
tmpOrderBy = expression;
|
||||
} else if (expression instanceof BuildInsert) {
|
||||
tmpInsert = expression;
|
||||
} else if (expression instanceof BuildUpdate) {
|
||||
tmpUpdate = expression;
|
||||
} else if (expression instanceof BuildDelete) {
|
||||
tmpDelete = expression;
|
||||
}
|
||||
}
|
||||
|
||||
//如果是insert类的话,则直接返回
|
||||
if (FuncBase.isNotEmpty(tmpInsert)) {
|
||||
sortList.add(tmpInsert);
|
||||
return sortList;
|
||||
}
|
||||
|
||||
//如果是update 和 delete select 都可以带where
|
||||
if (FuncBase.isNotEmpty(tmpSelect)) {
|
||||
sortList.add(tmpSelect);
|
||||
} else if (FuncBase.isNotEmpty(tmpUpdate)) {
|
||||
sortList.add(tmpUpdate);
|
||||
} else if (FuncBase.isNotEmpty(tmpDelete)) {
|
||||
sortList.add(tmpDelete);
|
||||
} else {
|
||||
throw new JeeLowCodeException("表达式必须有BuildSelect/BuildUpdate/BuildDelete");
|
||||
}
|
||||
|
||||
//第一个
|
||||
ISQLExpression firstExpression = sortList.get(0);
|
||||
if (firstExpression instanceof BuildSelect && FuncBase.isNotEmpty(tmpJoinList)) {//必须是select的情况下,才能inner join
|
||||
sortList.addAll(tmpJoinList);
|
||||
}
|
||||
|
||||
//后面是带 where
|
||||
if (FuncBase.isNotEmpty(tmpWhere)) {
|
||||
sortList.add(tmpWhere);
|
||||
}
|
||||
|
||||
if (firstExpression instanceof BuildSelect && FuncBase.isNotEmpty(tmpGroupBy)) {//必须是select的情况下,才有group by
|
||||
sortList.add(tmpGroupBy);
|
||||
if (FuncBase.isNotEmpty(tmpHaving)) {
|
||||
sortList.add(tmpHaving);
|
||||
}
|
||||
}
|
||||
|
||||
if (firstExpression instanceof BuildSelect && FuncBase.isNotEmpty(tmpOrderBy)) {//必须是select的情况下,才有order by
|
||||
sortList.add(tmpOrderBy);
|
||||
}
|
||||
return sortList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.build.dql.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-03 10:16
|
||||
* @dedescription:
|
||||
*/
|
||||
public class TestBuild {
|
||||
|
||||
/* @Test
|
||||
public void testBuildSelect() throws JSQLParserException {
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
*//* .setColumns("id", "name")*//*
|
||||
.setTableName("tbl_student")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setSelectModel(selectModel);
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
SqlFormatModel interpret = buildSelect.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOrderBy() throws JSQLParserException {
|
||||
|
||||
SqlInfoOrderModel build = SqlInfoOrderModel.builder()
|
||||
.setOrderByAsc("id","name")
|
||||
.setOrderByDesc("age")
|
||||
.setOrderByAsc("sex")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setOrderModel(build);
|
||||
BuildOrderBy buildOrderBy=new BuildOrderBy();
|
||||
|
||||
SqlFormatModel interpret = buildOrderBy.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuildGroupBy() throws JSQLParserException {
|
||||
|
||||
SqlInfoGroupModel build = SqlInfoGroupModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.build();
|
||||
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setGroupModel(build);
|
||||
BuildGroupBy buildGroupBy=new BuildGroupBy();
|
||||
|
||||
SqlFormatModel interpret = buildGroupBy.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWhere() throws JSQLParserException {
|
||||
|
||||
SqlInfoWhereModel build = SqlInfoWhereModel.builder()
|
||||
.gt("id", 12)
|
||||
.ge("age", 18)
|
||||
.ne("name", "张三")
|
||||
.between("height",18,30)
|
||||
.in("a.id",1,2,3,4,5)
|
||||
.like("name","张三")
|
||||
.buildWhere();
|
||||
|
||||
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setWhereModel(build);
|
||||
BuildWhere buildWhere=new BuildWhere();
|
||||
|
||||
SqlFormatModel interpret = buildWhere.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuildDelete() throws JSQLParserException {
|
||||
|
||||
SqlInfoDeleteModel build = SqlInfoDeleteModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.build();
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setDeleteModel(build);
|
||||
BuildDelete buildDelete=new BuildDelete();
|
||||
|
||||
SqlFormatModel interpret = buildDelete.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuildRealDelete() throws JSQLParserException {
|
||||
|
||||
SqlInfoDeleteModel build = SqlInfoDeleteModel.builder()
|
||||
.setTableName("tbl_student",true)
|
||||
.build();
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
BuildDelete buildDelete=new BuildDelete();
|
||||
|
||||
context.setDeleteModel(build);
|
||||
SqlFormatModel interpret = buildDelete.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildInsert() throws JSQLParserException {
|
||||
|
||||
Map<String,Object> addMap=new HashMap<>();
|
||||
addMap.put("age",18);
|
||||
addMap.put("name","张三");
|
||||
|
||||
SqlInfoInsertModel build = SqlInfoInsertModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.addColumn("id", 123)
|
||||
.addMap(addMap)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setInsertModel(build);
|
||||
BuildInsert buildInsert=new BuildInsert();
|
||||
|
||||
SqlFormatModel interpret = buildInsert.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildUpdate() throws JSQLParserException {
|
||||
|
||||
Map<String,Object> updateMap=new HashMap<>();
|
||||
updateMap.put("age",18);
|
||||
updateMap.put("name","张三");
|
||||
|
||||
SqlInfoUpdateModel build = SqlInfoUpdateModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.addColumn("id", 123)
|
||||
.addMap(updateMap)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setUpdateModel(build);
|
||||
BuildUpdate buildUpdate=new BuildUpdate();
|
||||
|
||||
SqlFormatModel interpret = buildUpdate.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(interpret));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAlter_AddColumn() throws JSQLParserException {
|
||||
*//*
|
||||
TableFieldModel fieldModel = new TableFieldModel();
|
||||
fieldModel.setFieldCode("name");
|
||||
fieldModel.setFieldType("varchar(128)");
|
||||
fieldModel.setCommentSql("年龄");
|
||||
|
||||
SqlInfoAlterModel model = SqlInfoAlterModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.buildAddColumn(fieldModel);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setAlterModel(model);
|
||||
|
||||
BuildAlter build=new BuildAlter();
|
||||
SqlFormatModel interpret = build.interpret(context);
|
||||
System.out.println(Func.json2Str(interpret));*//*
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAlter_updaateColumn() throws JSQLParserException {
|
||||
|
||||
*//*TableFieldModel fieldModel = new TableFieldModel();
|
||||
fieldModel.setFieldCode("name");
|
||||
fieldModel.setFieldType("varchar(128)");
|
||||
fieldModel.setCommentSql("年龄");
|
||||
|
||||
SqlInfoAlterModel model = SqlInfoAlterModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.buildUpdateColum(fieldModel);
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setAlterModel(model);
|
||||
|
||||
BuildAlter build=new BuildAlter();
|
||||
|
||||
SqlFormatModel interpret = build.interpret(context);
|
||||
System.out.println(Func.json2Str(interpret));*//*
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDrop_dropTable() throws JSQLParserException {
|
||||
|
||||
SqlInfoDropModel model = SqlInfoDropModel.builder()
|
||||
.buildDropTable("","tbl_student");
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setDropModel(model);
|
||||
|
||||
BuildDrop build=new BuildDrop();
|
||||
List<SqlFormatModel> sqlFormatModelList = build.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDrop_dropColumn() throws JSQLParserException {
|
||||
|
||||
SqlInfoDropModel model = SqlInfoDropModel.builder()
|
||||
.buildDropColumn("","tbl_student","name");
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setDropModel(model);
|
||||
|
||||
BuildDrop build=new BuildDrop();
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = build.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDrop_dropIndex() throws JSQLParserException {
|
||||
|
||||
SqlInfoDropModel model = SqlInfoDropModel.builder()
|
||||
.buildDropIndex("","tbl_student","ind_name");
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setDropModel(model);
|
||||
|
||||
BuildDrop build=new BuildDrop();
|
||||
List<SqlFormatModel> sqlFormatModelList = build.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCreate() throws JSQLParserException {
|
||||
|
||||
List<FieldModel> buildTableFieldModelList=new ArrayList<>();
|
||||
|
||||
FieldModel idModel = new FieldModel();
|
||||
idModel.setFieldCode("id");
|
||||
idModel.setFieldName("id");
|
||||
idModel.setFieldLen(12);
|
||||
idModel.setFieldPointLen(0);
|
||||
idModel.setFieldType(JeeLowCodeFieldTypeEnum.BIGINT);
|
||||
idModel.setIsPrimaryKey("Y");
|
||||
idModel.setIsNull("N");
|
||||
|
||||
|
||||
FieldModel nameModel = new FieldModel();
|
||||
nameModel.setFieldCode("name");
|
||||
nameModel.setFieldName("姓名");
|
||||
nameModel.setFieldLen(12);
|
||||
nameModel.setFieldPointLen(0);
|
||||
nameModel.setFieldType(JeeLowCodeFieldTypeEnum.STRING);
|
||||
nameModel.setIsPrimaryKey("N");
|
||||
nameModel.setIsNull("Y");
|
||||
|
||||
|
||||
buildTableFieldModelList.add(idModel);
|
||||
buildTableFieldModelList.add(nameModel);
|
||||
|
||||
|
||||
SqlInfoCreateModel model = SqlInfoCreateModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.setTableOptions(buildTableFieldModelList)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setCreateModel(model);
|
||||
BuildCreateTable build=new BuildCreateTable();
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = build.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildCreateIndex() throws JSQLParserException {
|
||||
|
||||
SqlInfoCreateIndexModel model = SqlInfoCreateIndexModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.setIndexName("ind_aa")
|
||||
.setIndexFieldCodeList(FuncBase.toStrList("name,age"))
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setCreateIndexModel(model);
|
||||
|
||||
BuildCreateIndex build=new BuildCreateIndex();
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList = build.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAndUpdateExpression() throws JSQLParserException {
|
||||
|
||||
//构建update语句
|
||||
Map<String,Object> updateMap=new HashMap<>();
|
||||
updateMap.put("age",18);
|
||||
updateMap.put("name","张三");
|
||||
|
||||
SqlInfoUpdateModel build = SqlInfoUpdateModel.builder()
|
||||
.setTableName("tbl_student")
|
||||
.addColumn("id", 123)
|
||||
.addMap(updateMap)
|
||||
.build();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
BuildUpdate buildUpdate=new BuildUpdate();
|
||||
context.setUpdateModel(build);
|
||||
|
||||
//构建where语句
|
||||
SqlInfoWhereModel whereModel = SqlInfoWhereModel.builder()
|
||||
.ge("age",18)
|
||||
.like("name","张三")
|
||||
.buildWhere();
|
||||
context.setWhereModel(whereModel);
|
||||
BuildWhere buildWhere=new BuildWhere();
|
||||
|
||||
|
||||
//update语句+where语句
|
||||
AndExpression expression=new AndExpression(buildUpdate,buildWhere);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildSelectExpression() throws JSQLParserException {
|
||||
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.setTableName("tbl_student")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext contextSelect = new SQLInterpretContext();
|
||||
contextSelect.setSelectModel(selectModel);
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
|
||||
|
||||
*//* SqlInfoWhereModel whereOrModel = SqlInfoWhereModel.builder()
|
||||
.ge("age", 18)
|
||||
.or()
|
||||
.le("age",10)
|
||||
.build();
|
||||
SQLInterpretContext<SqlInfoWhereModel> contextWhereOr = new SQLInterpretContext<>(whereOrModel);
|
||||
BuildWhere buildWhereOr=new BuildWhere(contextWhereOr);*//*
|
||||
|
||||
*//* SqlInfoWhereModel whereOrModel2 = SqlInfoWhereModel.builder()
|
||||
.le("age", 182)
|
||||
.notLike("name", "张三2")
|
||||
.or(buildWhereOr)
|
||||
.build();
|
||||
SQLInterpretContext<SqlInfoWhereModel> contextWhereOr2 = new SQLInterpretContext<>(whereOrModel2);
|
||||
BuildWhere buildWhereOr2=new BuildWhere(contextWhereOr2);*//*
|
||||
|
||||
|
||||
SqlInfoWhereModel whereAndModel = SqlInfoWhereModel.builder()// 18<x<65
|
||||
.ge("age", 18)
|
||||
.le("age",65)
|
||||
.buildWhere();
|
||||
SQLInterpretContext contextWhereAnd = new SQLInterpretContext();
|
||||
contextWhereAnd.setWhereModel(whereAndModel);
|
||||
BuildWhere buildWhereAnd=new BuildWhere();
|
||||
buildWhereAnd.setContext(contextWhereAnd);
|
||||
|
||||
SqlInfoWhereModel whereModel = SqlInfoWhereModel.builder()
|
||||
.gt("id", 12)
|
||||
//.or(buildWhereOr)
|
||||
//.or(buildWhereOr2)
|
||||
.eq("na","历史")
|
||||
.buildWhere();
|
||||
SQLInterpretContext contextWhere = new SQLInterpretContext();
|
||||
contextWhere.setWhereModel(whereModel);
|
||||
BuildWhere buildWhere=new BuildWhere();
|
||||
buildWhere.setContext(contextWhere);
|
||||
|
||||
|
||||
SqlInfoGroupModel groupByModel = SqlInfoGroupModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.build();
|
||||
SQLInterpretContext contextGroupBy = new SQLInterpretContext();
|
||||
BuildGroupBy buildGroupBy=new BuildGroupBy();
|
||||
|
||||
SqlInfoOrderModel orderByModel = SqlInfoOrderModel.builder()
|
||||
.setOrderByAsc("age")
|
||||
.build();
|
||||
SQLInterpretContext contextOrderBy = new SQLInterpretContext();
|
||||
BuildOrderBy buildOrderBy=new BuildOrderBy();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setWhereModel(whereModel);
|
||||
context.setSelectModel(selectModel);
|
||||
context.setOrderModel(orderByModel);
|
||||
context.setGroupModel(groupByModel);
|
||||
|
||||
|
||||
//update语句+where语句
|
||||
AndExpression expression=new AndExpression(buildWhere,buildSelect,buildOrderBy,buildGroupBy);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildSelectAllExpression() throws JSQLParserException {
|
||||
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.setTableName("tbl_student")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext contextSelect = new SQLInterpretContext();
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
contextSelect.setSelectModel(selectModel);
|
||||
//
|
||||
AndExpression expression=new AndExpression(buildSelect);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(contextSelect);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildHavingExpression() throws JSQLParserException {
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("name", "count( id ) AS cou")
|
||||
.setTableName("system_dept")
|
||||
.build();
|
||||
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
|
||||
SqlInfoHavingModel havingModel = SqlInfoConditionModel.builder()
|
||||
.gt("cou", 1)
|
||||
.likeLeft("name", "财务部门")
|
||||
.buildHaving();
|
||||
SQLInterpretContext contextHaving = new SQLInterpretContext();
|
||||
contextHaving.setHavingModel(havingModel);
|
||||
BuildHaving buildHaving=new BuildHaving();
|
||||
buildHaving.setContext(contextHaving);
|
||||
|
||||
|
||||
SqlInfoGroupModel groupByModel = SqlInfoGroupModel.builder()
|
||||
.setColumns("name")
|
||||
.build();
|
||||
SQLInterpretContext contextGroupBy = new SQLInterpretContext();
|
||||
BuildGroupBy buildGroupBy=new BuildGroupBy();
|
||||
|
||||
SqlInfoOrderModel orderByModel = SqlInfoOrderModel.builder()
|
||||
.setOrderByAsc("cou")
|
||||
.build();
|
||||
SQLInterpretContext contextOrderBy = new SQLInterpretContext();
|
||||
BuildOrderBy buildOrderBy=new BuildOrderBy();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setSelectModel(selectModel);
|
||||
context.setGroupModel(groupByModel);
|
||||
context.setOrderModel(orderByModel);
|
||||
context.setHavingModel(havingModel);
|
||||
|
||||
//update语句+where语句
|
||||
AndExpression expression=new AndExpression(buildGroupBy,buildSelect,buildOrderBy,buildHaving);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildJoinExpression() throws JSQLParserException {
|
||||
///主表
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("a.*","b.*","c.*")
|
||||
.setTableName("tbl_a","a")
|
||||
.build();
|
||||
SQLInterpretContext contextSelect = new SQLInterpretContext();
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
|
||||
//B表
|
||||
SqlInfoJoinModel joinModelB = SqlInfoJoinModel.builder()
|
||||
.innerJoin()
|
||||
.joinTable("tbl_b", "b")
|
||||
.on("a.id", "b.a_id")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext contextJoinB = new SQLInterpretContext();
|
||||
BuildJoin buildJsonB = new BuildJoin();
|
||||
|
||||
//C表
|
||||
SqlInfoJoinModel joinModelC = SqlInfoJoinModel.builder()
|
||||
.innerJoin()
|
||||
.joinTable("tbl_c", "c")
|
||||
.on("b.id", "c.b_id")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext contextJoinC = new SQLInterpretContext();
|
||||
BuildJoin buildJsonC = new BuildJoin();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setSelectModel(selectModel);
|
||||
context.setJoinModel(joinModelB);
|
||||
//update语句+where语句
|
||||
AndExpression expression=new AndExpression(buildSelect,buildJsonB,buildJsonC);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHavingAndOrExpression() throws JSQLParserException {
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("name", "count( id ) AS cou")
|
||||
.setTableName("system_dept")
|
||||
.build();
|
||||
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
|
||||
|
||||
|
||||
SqlInfoHavingModel havingModel = SqlInfoConditionModel.builder()
|
||||
.gt("cou", 1)
|
||||
.likeLeft("name", "财务部门")
|
||||
.and( andTest ->{
|
||||
andTest.eq("status", 1)
|
||||
.or( orTest ->{
|
||||
orTest.ne("id", 1);
|
||||
});
|
||||
})
|
||||
.buildHaving();
|
||||
SQLInterpretContext contextHaving = new SQLInterpretContext();
|
||||
contextHaving.setHavingModel(havingModel);
|
||||
BuildHaving buildHaving=new BuildHaving();
|
||||
buildHaving.setContext(contextHaving);
|
||||
|
||||
|
||||
SqlInfoGroupModel groupByModel = SqlInfoGroupModel.builder()
|
||||
.setColumns("name")
|
||||
.build();
|
||||
SQLInterpretContext contextGroupBy = new SQLInterpretContext();
|
||||
BuildGroupBy buildGroupBy=new BuildGroupBy();
|
||||
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setSelectModel(selectModel);
|
||||
context.setGroupModel(groupByModel);
|
||||
context.setHavingModel(havingModel);
|
||||
|
||||
//update语句+where语句
|
||||
AndExpression expression=new AndExpression(buildGroupBy,buildSelect,buildHaving);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereAndOrExpression() throws JSQLParserException {
|
||||
SqlInfoSelectModel selectModel = SqlInfoSelectModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.setTableName("tbl_student")
|
||||
.build();
|
||||
|
||||
SQLInterpretContext contextSelect = new SQLInterpretContext();
|
||||
contextSelect.setSelectModel(selectModel);
|
||||
BuildSelect buildSelect = new BuildSelect();
|
||||
|
||||
|
||||
SqlInfoWhereModel whereModel = SqlInfoWhereModel.builder()
|
||||
.gt("id", 12)
|
||||
.and(andTest ->{
|
||||
andTest.eq("name","李四")
|
||||
.or(orTest ->{
|
||||
orTest.eq("name", "张三");
|
||||
});
|
||||
})
|
||||
.eq("na","历史")
|
||||
.buildWhere();
|
||||
SQLInterpretContext contextWhere = new SQLInterpretContext();
|
||||
contextWhere.setWhereModel(whereModel);
|
||||
BuildWhere buildWhere=new BuildWhere();
|
||||
buildWhere.setContext(contextWhere);
|
||||
|
||||
|
||||
SqlInfoGroupModel groupByModel = SqlInfoGroupModel.builder()
|
||||
.setColumns("name", "age")
|
||||
.build();
|
||||
SQLInterpretContext contextGroupBy = new SQLInterpretContext();
|
||||
BuildGroupBy buildGroupBy=new BuildGroupBy();
|
||||
|
||||
SqlInfoOrderModel orderByModel = SqlInfoOrderModel.builder()
|
||||
.setOrderByAsc("age")
|
||||
.build();
|
||||
SQLInterpretContext contextOrderBy = new SQLInterpretContext();
|
||||
BuildOrderBy buildOrderBy=new BuildOrderBy();
|
||||
|
||||
SQLInterpretContext context = new SQLInterpretContext();
|
||||
context.setWhereModel(whereModel);
|
||||
context.setSelectModel(selectModel);
|
||||
context.setOrderModel(orderByModel);
|
||||
context.setGroupModel(groupByModel);
|
||||
|
||||
|
||||
AndExpression expression=new AndExpression(buildWhere,buildSelect,buildOrderBy,buildGroupBy);
|
||||
List<SqlFormatModel> sqlFormatModelList = expression.interpret(context);
|
||||
System.out.println(FuncBase.json2Str(sqlFormatModelList));
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoAlterModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.ddl.alter.JeeLowCodeAlterTable;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.tool.StringPool;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 修改表相关
|
||||
*/
|
||||
public class BuildAlter implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
SqlInfoAlterModel alterModel = context.getAlterModel();
|
||||
|
||||
if(FuncBase.isEmpty(alterModel)){
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = alterModel.getExecuteDdlList();
|
||||
if(FuncBase.isNotEmpty(executeDdlList)){
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
String ddl="";
|
||||
switch (alterModel.getAlterType()) {
|
||||
case ADD_COLUMN:
|
||||
ddl = getAddColumnDDL(context.getSchemaName(),alterModel.getTableName(),alterModel.getFieldModel(),dbColunmTypes);
|
||||
break;
|
||||
case UPDATE_COLUMN:
|
||||
ddl = getModifyColumnDDL(context.getSchemaName(),alterModel.getTableName(),alterModel.getFieldModel(),dbColunmTypes);
|
||||
break;
|
||||
}
|
||||
return PlusUtils.ddl2SqlFormatModel(ddl);
|
||||
}
|
||||
|
||||
|
||||
//获取增加字段ddl
|
||||
private String getAddColumnDDL(String schemaName,String tableName, FieldModel fieldModel, DbColunmTypesEntity dbColunmTypes) {
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
tableName= FuncBase.concatSymbol(tableName,symbol,upperFlag);
|
||||
schemaName= FuncBase.concatSymbol(schemaName,symbol);
|
||||
|
||||
JeeLowCodeFieldTypeEnum fieldTypeEnum = fieldModel.getFieldType();
|
||||
DbColunmTypesEntity.TypeEntity typeEntity = PlusUtils.jeelowCodeType2DbType(fieldTypeEnum, dbColunmTypes);
|
||||
String fieldType = PlusUtils.getDbType(fieldTypeEnum, typeEntity.getDbType(), fieldModel.getFieldLen(), fieldModel.getFieldPointLen(),typeEntity.getDbMaxLen());
|
||||
String defaultValSql = PlusUtils.getDefaultValSql(fieldModel.getFieldDefaultVal(), fieldModel.getIsNull(),fieldModel.getDbNowIsNull());
|
||||
String fieldCode = FuncBase.concatSymbol(fieldModel.getFieldCode(),symbol,upperFlag);
|
||||
|
||||
JeeLowCodeAlterTable alterTable = new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName(schemaName+ StringPool.DOT+tableName);
|
||||
alterTable.addCoulumn(fieldCode, fieldType, defaultValSql);
|
||||
String ddl = alterTable.getFullSQL();
|
||||
return ddl;
|
||||
}
|
||||
|
||||
//修改字段
|
||||
private String getModifyColumnDDL(String schemaName,String tableName, FieldModel fieldModel, DbColunmTypesEntity dbColunmTypes) {
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
|
||||
tableName=FuncBase.concatSymbol(tableName,symbol,upperFlag);
|
||||
schemaName= FuncBase.concatSymbol(schemaName,symbol);
|
||||
|
||||
JeeLowCodeFieldTypeEnum fieldTypeEnum = fieldModel.getFieldType();
|
||||
DbColunmTypesEntity.TypeEntity typeEntity = PlusUtils.jeelowCodeType2DbType(fieldTypeEnum, dbColunmTypes);
|
||||
String fieldType = PlusUtils.getDbType(fieldTypeEnum, typeEntity.getDbType(), fieldModel.getFieldLen(), fieldModel.getFieldPointLen(),typeEntity.getDbMaxLen());
|
||||
String defaultValSql = PlusUtils.getDefaultValSql(fieldModel.getFieldDefaultVal(), fieldModel.getIsNull(),fieldModel.getDbNowIsNull());
|
||||
String fieldCode = fieldModel.getFieldCode();
|
||||
|
||||
JeeLowCodeAlterTable alterTable = new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName(schemaName+ StringPool.DOT+tableName);
|
||||
alterTable.modifyColumn(FuncBase.concatSymbol(fieldCode,symbol,upperFlag), fieldType, defaultValSql);
|
||||
return alterTable.getFullSQL();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoCommentModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 备注 相关
|
||||
*/
|
||||
public class BuildComment implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoCommentModel commentModel = context.getCommentModel();
|
||||
if (FuncBase.isEmpty(commentModel)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = commentModel.getExecuteDdlList();
|
||||
if (FuncBase.isNotEmpty(executeDdlList)) {
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
String schemaName = FuncBase.concatSymbol(context.getSchemaName(), symbol);
|
||||
String tableName = FuncBase.concatSymbol(commentModel.getTableName(), symbol, upperFlag);
|
||||
String tableAlias = commentModel.getTableAlias();
|
||||
List<FieldModel> fieldModelList = commentModel.getFieldModelList();
|
||||
|
||||
List<String> ddlList = new ArrayList<>();
|
||||
String tableDdl = this.tableComment(schemaName, tableName, tableAlias);
|
||||
if (FuncBase.isNotEmpty(tableDdl)) {
|
||||
ddlList.add(tableDdl);
|
||||
}
|
||||
List<String> columnDdlList = this.columnComment(dbColunmTypes, schemaName, tableName, fieldModelList);
|
||||
if (FuncBase.isNotEmpty(columnDdlList)) {
|
||||
ddlList.addAll(columnDdlList);
|
||||
}
|
||||
|
||||
return PlusUtils.ddl2SqlFormatModel(ddlList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表备注
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String tableComment(String schemaName, String tableName, String tableAlias) {
|
||||
if (FuncBase.isEmpty(tableAlias)) {
|
||||
return null;
|
||||
}
|
||||
String str = "COMMENT ON TABLE %s.%s IS '%s';";
|
||||
String ddl = String.format(str, schemaName, tableName, tableAlias);
|
||||
return ddl;
|
||||
}
|
||||
|
||||
private List<String> columnComment(DbColunmTypesEntity dbColunmTypes, String schemaName, String tableName, List<FieldModel> fieldModelList) {
|
||||
|
||||
if (FuncBase.isEmpty(fieldModelList)) {
|
||||
return null;
|
||||
}
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
List<String> ddlList = new ArrayList<>();
|
||||
for (FieldModel fieldModel : fieldModelList) {
|
||||
String fieldCode = FuncBase.concatSymbol(fieldModel.getFieldCode(), symbol, upperFlag);
|
||||
String fieldName = fieldModel.getFieldName();
|
||||
|
||||
String str = "COMMENT ON COLUMN %s.%s.%s IS '%s';";
|
||||
String ddl = String.format(str, schemaName, tableName, fieldCode, fieldName);
|
||||
ddlList.add(ddl);
|
||||
}
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoCreateIndexModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/***
|
||||
* 索引相关
|
||||
*/
|
||||
public class BuildCreateIndex implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoCreateIndexModel model = context.getCreateIndexModel();
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
if(FuncBase.isEmpty(model)){
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = model.getExecuteDdlList();
|
||||
if(FuncBase.isNotEmpty(executeDdlList)){
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
String tableName = FuncBase.concatSymbol(model.getTableName(),symbol,upperFlag);
|
||||
String indexName = FuncBase.concatSymbol(model.getIndexName(),symbol,upperFlag);
|
||||
String schemaName = FuncBase.concatSymbol(context.getSchemaName(),symbol);
|
||||
|
||||
List<String> indexFieldCodeList = model.getIndexFieldCodeList();
|
||||
|
||||
List<String> list = indexFieldCodeList.stream()
|
||||
.map(key -> FuncBase.concatSymbol( key , symbol,upperFlag))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String str = "CREATE INDEX %s ON %s.%s (%s)";
|
||||
String ddl = String.format(str, indexName, schemaName,tableName, String.join(",", list));
|
||||
return PlusUtils.ddl2SqlFormatModel(ddl);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoCreateModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.ddl.create.JeeLowCodeCreateTable;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.tool.StringPool;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 建表相关
|
||||
*/
|
||||
public class BuildCreateTable implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
SqlInfoCreateModel creteModel = context.getCreateModel();
|
||||
if(FuncBase.isEmpty(creteModel)){
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = creteModel.getExecuteDdlList();
|
||||
if(FuncBase.isNotEmpty(executeDdlList)){
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
String tableName = creteModel.getTableName();
|
||||
String schemaName = context.getSchemaName();
|
||||
List<FieldModel> tableOptions = creteModel.getTableOptions();
|
||||
|
||||
String ddl = this.getDDL(schemaName,tableName, tableOptions, dbColunmTypes);
|
||||
return PlusUtils.ddl2SqlFormatModel(ddl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ddl
|
||||
*
|
||||
* @param tableName
|
||||
* @param tableOptions
|
||||
* @param dbColunmTypes
|
||||
* @return
|
||||
*/
|
||||
public String getDDL(String schemaName,String tableName, List<FieldModel> tableOptions, DbColunmTypesEntity dbColunmTypes) {
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
JeeLowCodeCreateTable createTable = new JeeLowCodeCreateTable();
|
||||
|
||||
tableName=FuncBase.concatSymbol(tableName,symbol,upperFlag);
|
||||
schemaName=FuncBase.concatSymbol(schemaName,symbol);
|
||||
for (int i = 0; i < tableOptions.size(); i++) {
|
||||
FieldModel fieldModel = tableOptions.get(i);
|
||||
String fieldCode = FuncBase.concatSymbol(fieldModel.getFieldCode(),symbol,upperFlag);
|
||||
JeeLowCodeFieldTypeEnum fieldTypeEnum = fieldModel.getFieldType();
|
||||
//类型
|
||||
DbColunmTypesEntity.TypeEntity typeEntity = PlusUtils.jeelowCodeType2DbType(fieldTypeEnum, dbColunmTypes);
|
||||
Integer dbMaxLen = typeEntity.getDbMaxLen();
|
||||
if(dbMaxLen < fieldModel.getFieldLen()){
|
||||
fieldModel.setFieldLen(dbMaxLen);
|
||||
}
|
||||
String fieldType = PlusUtils.getDbType(fieldTypeEnum, typeEntity.getDbType(), fieldModel.getFieldLen(), fieldModel.getFieldPointLen(),typeEntity.getDbMaxLen());
|
||||
String defaultValSql = PlusUtils.getDefaultValSql(fieldModel.getFieldDefaultVal(), fieldModel.getIsNull(),null);
|
||||
|
||||
createTable.addCoulumn(fieldCode, fieldType, defaultValSql);
|
||||
}
|
||||
createTable.setTableName(schemaName+ StringPool.DOT+tableName);//表名称
|
||||
String ddl = createTable.getDDL();
|
||||
return ddl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoDdlModel;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通用DDL
|
||||
*/
|
||||
public class BuildDdl implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoDdlModel ddlModel = context.getDdlModel();
|
||||
if (FuncBase.isEmpty(ddlModel)) {
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = ddlModel.getExecuteDdlList();
|
||||
if (FuncBase.isEmpty(executeDdlList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoDropModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.ddl.alter.JeeLowCodeAlterTable;
|
||||
import com.jeelowcode.framework.plus.core.ddl.drop.JeeLowCodeDropTable;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.tool.StringPool;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 删除表,字段,索引
|
||||
*/
|
||||
public class BuildDrop implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoDropModel dropModel = context.getDropModel();
|
||||
if (FuncBase.isEmpty(dropModel)) {
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = dropModel.getExecuteDdlList();
|
||||
if(FuncBase.isNotEmpty(executeDdlList)){
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
String tableName = FuncBase.concatSymbol(dropModel.getTableName(), symbol, upperFlag);
|
||||
String indexName = FuncBase.concatSymbol(dropModel.getIndexName(), symbol, upperFlag);
|
||||
String cloumnCode = FuncBase.concatSymbol(dropModel.getCloumnCode(), symbol, upperFlag);
|
||||
String schemaName = FuncBase.concatSymbol(context.getSchemaName(), symbol);
|
||||
|
||||
String ddl = "";
|
||||
switch (dropModel.getDropType()) {
|
||||
case DROP_TABLE:
|
||||
ddl = this.dropTable(schemaName, tableName);
|
||||
break;
|
||||
case DROP_COLUMN:
|
||||
ddl = this.dropColumn(schemaName, tableName, cloumnCode,dropModel.getCloumnFormat());
|
||||
break;
|
||||
case DROP_INDEX:
|
||||
ddl = this.dropIndex(schemaName, indexName);
|
||||
break;
|
||||
}
|
||||
|
||||
return PlusUtils.ddl2SqlFormatModel(ddl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表
|
||||
*
|
||||
* @param schemaName
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
private String dropTable(String schemaName, String tableName) {
|
||||
JeeLowCodeDropTable dropTable = new JeeLowCodeDropTable();
|
||||
dropTable.setTableName(schemaName + StringPool.DOT + tableName);
|
||||
return dropTable.getFullSQL();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字段
|
||||
*
|
||||
* @param schemaName
|
||||
* @param tableName
|
||||
* @param cloumnCode
|
||||
* @return
|
||||
*/
|
||||
private String dropColumn(String schemaName, String tableName, String cloumnCode,String cloumnFormat) {
|
||||
if(FuncBase.isNotEmpty(cloumnFormat)){
|
||||
cloumnCode =String.format(cloumnFormat,cloumnCode);
|
||||
}
|
||||
JeeLowCodeAlterTable dropColumn = new JeeLowCodeAlterTable();
|
||||
dropColumn.setTableName(schemaName + StringPool.DOT + tableName);
|
||||
dropColumn.dropColumn(cloumnCode);
|
||||
return dropColumn.getFullSQL();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
* @param schemaName
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
private String dropIndex(String schemaName, String indexName) {
|
||||
String str = "DROP INDEX %s.%s";
|
||||
String ddl = String.format(str, schemaName, indexName);
|
||||
return ddl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.SqlInfoPrimaryKeyModel;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 主键相关
|
||||
*/
|
||||
public class BuildPrimaryKey implements ISQLExpression<List<SqlFormatModel>> {
|
||||
|
||||
|
||||
@Override
|
||||
public List<SqlFormatModel> interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoPrimaryKeyModel primaryKeyModel = context.getPrimaryKeyModel();
|
||||
|
||||
if (FuncBase.isEmpty(primaryKeyModel)) {
|
||||
return null;
|
||||
}
|
||||
//存在自定义ddl
|
||||
List<String> executeDdlList = primaryKeyModel.getExecuteDdlList();
|
||||
if(FuncBase.isNotEmpty(executeDdlList)){
|
||||
return PlusUtils.ddl2SqlFormatModel(executeDdlList);
|
||||
}
|
||||
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
|
||||
String symbol = dbColunmTypes.getSymbol();
|
||||
Boolean upperFlag = dbColunmTypes.getUpperFlag();
|
||||
|
||||
String tableName = FuncBase.concatSymbol(primaryKeyModel.getTableName(),symbol,upperFlag);
|
||||
String schemaName = FuncBase.concatSymbol(context.getSchemaName(),symbol);
|
||||
List<String> tmpkeyList = primaryKeyModel.getKeyList();
|
||||
if(FuncBase.isEmpty(tmpkeyList)){
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> keyList = tmpkeyList.stream()
|
||||
.map(key -> FuncBase.concatSymbol( key , symbol,upperFlag))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String str="ALTER TABLE %s.%s ADD PRIMARY KEY(%s)";
|
||||
String ddl = String.format(str,schemaName,tableName,String.join(",",keyList));
|
||||
return PlusUtils.ddl2SqlFormatModel(ddl);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ExpressionModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoConditionModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoHavingModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-29 16:00
|
||||
* @dedescription:
|
||||
*/
|
||||
|
||||
public class BuildCondition {
|
||||
|
||||
public JeeLowCodeQueryWrapper<Object> wrapper = new JeeLowCodeQueryWrapper();
|
||||
|
||||
public SQLInterpretContext context;
|
||||
|
||||
|
||||
public SqlFormatModel context2Condition(SqlInfoConditionModel conditionModel){
|
||||
List<ExpressionModel> expressions =conditionModel.getExpressions();
|
||||
expressions.forEach(expressionModel -> {
|
||||
SqlInfoConditionModel.WhereType whereType = expressionModel.getWhereType();
|
||||
String column = expressionModel.getColumn();
|
||||
Object[] value = expressionModel.getValue();
|
||||
switch (whereType) {
|
||||
case GT://>
|
||||
gt(column, value);
|
||||
break;
|
||||
case GE://>=
|
||||
ge(column, value);
|
||||
break;
|
||||
case NE:// !=
|
||||
ne(column, value);
|
||||
break;
|
||||
case EQ:// =
|
||||
eq(column, value);
|
||||
break;
|
||||
case LT://<
|
||||
lt(column, value);
|
||||
break;
|
||||
case LE://<=
|
||||
le(column, value);
|
||||
break;
|
||||
case BETWEEN:
|
||||
between(column, value);
|
||||
break;
|
||||
case NOT_BETWEEN:
|
||||
notbetween(column, value);
|
||||
break;
|
||||
case IN:
|
||||
in(column, value);
|
||||
break;
|
||||
case NOT_IN:
|
||||
notIn(column, value);
|
||||
break;
|
||||
case LIKE:
|
||||
like(column, value);
|
||||
break;
|
||||
case NOT_LIKE:
|
||||
notLike(column, value);
|
||||
break;
|
||||
case LIKE_LEFT:
|
||||
likeLeft(column, value);
|
||||
break;
|
||||
case LIKE_RIGHT:
|
||||
likeRight(column, value);
|
||||
break;
|
||||
case IS_NULL:
|
||||
isNull(column);
|
||||
break;
|
||||
case IS_NOT_NULL:
|
||||
isNotNull(column);
|
||||
break;
|
||||
case OR:
|
||||
or();
|
||||
break;
|
||||
case OR_BUILD:
|
||||
orBuild((Consumer<SqlInfoConditionModel.Builder>) value[0]);
|
||||
break;
|
||||
case AND_BUILD:
|
||||
andBuild((Consumer<SqlInfoConditionModel.Builder>) value[0]);
|
||||
break;
|
||||
case APPLY:
|
||||
apply(column);
|
||||
break;
|
||||
}
|
||||
});
|
||||
String sqlStr = "";
|
||||
|
||||
if(conditionModel instanceof SqlInfoHavingModel){
|
||||
sqlStr=wrapper.getHavingCustomSqlSegment();
|
||||
}else{
|
||||
sqlStr=wrapper.getCustomSqlSegment();
|
||||
}
|
||||
Map<String, Object> paramNameValuePairs = wrapper.getParamNameValuePairs();
|
||||
|
||||
SqlFormatModel sqlFormatModel = new SqlFormatModel(sqlStr, paramNameValuePairs);
|
||||
return sqlFormatModel;
|
||||
}
|
||||
|
||||
public void gt(String column, Object[] value) {
|
||||
wrapper.gt(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void ge(String column, Object[] value) {
|
||||
wrapper.ge(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void ne(String column, Object[] value) {
|
||||
wrapper.ne(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void eq(String column, Object[] value) {
|
||||
wrapper.eq(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void between(String column, Object[] value) {
|
||||
Object value1=value[0];
|
||||
Object value2=value[1];
|
||||
wrapper.between(column, value1, value2);
|
||||
return;
|
||||
}
|
||||
|
||||
public void notbetween(String column,Object[] value) {
|
||||
Object value1=value[0];
|
||||
Object value2=value[1];
|
||||
wrapper.notBetween(column, value1, value2);
|
||||
return;
|
||||
}
|
||||
|
||||
public void in(String column, Object[] value) {
|
||||
if(value.length>1){
|
||||
wrapper.in(column, value);
|
||||
return;
|
||||
}
|
||||
Object obj = value[0];
|
||||
if(obj instanceof List){
|
||||
List<Object> objList=(List)value[0];
|
||||
wrapper.in(column, objList);
|
||||
}else{
|
||||
wrapper.in(column, obj);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void notIn(String column, Object[] value) {
|
||||
if(value.length>1){
|
||||
wrapper.notIn(column, value);
|
||||
return;
|
||||
}
|
||||
Object obj = value[0];
|
||||
if(obj instanceof List){
|
||||
List<Object> objList=(List)value[0];
|
||||
wrapper.notIn(column, objList);
|
||||
}else{
|
||||
wrapper.notIn(column, obj);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void like(String column, Object[] value) {
|
||||
wrapper.like(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void notLike(String column, Object[] value) {
|
||||
wrapper.notLike(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void likeLeft(String column, Object[] value) {
|
||||
wrapper.likeLeft(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void likeRight(String column, Object[] value) {
|
||||
wrapper.likeRight(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void lt(String column, Object[] value) {
|
||||
wrapper.lt(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void le(String column, Object[] value) {
|
||||
wrapper.le(column, value[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
public void isNull(String column) {
|
||||
wrapper.isNull(column);
|
||||
return;
|
||||
}
|
||||
|
||||
public void isNotNull(String column) {
|
||||
wrapper.isNotNull(column);
|
||||
return;
|
||||
}
|
||||
public void apply(String column) {
|
||||
wrapper.apply(column);
|
||||
return;
|
||||
}
|
||||
public void or() {
|
||||
wrapper.or();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public void orBuild(Consumer<SqlInfoConditionModel.Builder> condition) {
|
||||
try{
|
||||
SqlInfoConditionModel.Builder builder = new SqlInfoConditionModel.Builder();
|
||||
condition.accept(builder);
|
||||
SqlInfoConditionModel<BuildCondition> build = builder.build();
|
||||
BuildCondition buildCondition = new BuildCondition();
|
||||
SqlFormatModel sqlFormatModel = buildCondition.context2Condition(build);
|
||||
|
||||
String tmpSql = sqlFormatModel.getSql();
|
||||
tmpSql=tmpSql.substring(6);
|
||||
Map<String, Object> tmpMap = sqlFormatModel.getDataMap();
|
||||
if (FuncBase.isEmpty(tmpMap)) {//没有参数的情况下
|
||||
String newSql=String.format("( 1!=1 OR %s) ",tmpSql);
|
||||
wrapper.apply(newSql);
|
||||
return;
|
||||
}
|
||||
|
||||
//存在参数的情况下
|
||||
List<Map.Entry<String, Object>> entrieList = new ArrayList<>(tmpMap.entrySet());
|
||||
Collections.reverse(entrieList);
|
||||
|
||||
int step=0;
|
||||
Object[] objects=new Object[entrieList.size()];
|
||||
|
||||
// 然后,从列表的末尾开始遍历
|
||||
for (Map.Entry<String, Object> entry : entrieList) {
|
||||
String key = entry.getKey(); // 获取键
|
||||
Object value = entry.getValue(); // 获取值
|
||||
|
||||
// 执行你的替换逻辑
|
||||
tmpSql = tmpSql.replace("#{"+ FuncBase.PARAM_NAME_VALUE_PAIRS+"." + key + "}", "{"+step+"}");
|
||||
objects[step]=value;
|
||||
|
||||
step++;
|
||||
}
|
||||
String newSql=String.format(" ( 1!=1 OR %s) ",tmpSql);//1!=1 兼容语法
|
||||
wrapper.apply(newSql,objects);
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void andBuild(Consumer<SqlInfoConditionModel.Builder> condition) {
|
||||
try{
|
||||
|
||||
SqlInfoConditionModel.Builder builder = new SqlInfoConditionModel.Builder();
|
||||
condition.accept(builder);
|
||||
SqlInfoConditionModel<BuildCondition> build = builder.build();
|
||||
BuildCondition buildCondition = new BuildCondition();
|
||||
SqlFormatModel sqlFormatModel = buildCondition.context2Condition(build);
|
||||
|
||||
String tmpSql = sqlFormatModel.getSql();
|
||||
tmpSql=tmpSql.substring(6);
|
||||
Map<String, Object> tmpMap = sqlFormatModel.getDataMap();
|
||||
if (FuncBase.isEmpty(tmpMap)) {//没有参数的情况下
|
||||
String newSql=String.format("(%s) ",tmpSql);
|
||||
wrapper.apply(newSql);
|
||||
return;
|
||||
}
|
||||
|
||||
//存在参数的情况下
|
||||
List<Map.Entry<String, Object>> entrieList = new ArrayList<>(tmpMap.entrySet());
|
||||
Collections.reverse(entrieList);
|
||||
|
||||
int step=0;
|
||||
Object[] objects=new Object[entrieList.size()];
|
||||
|
||||
// 然后,从列表的末尾开始遍历
|
||||
for (Map.Entry<String, Object> entry : entrieList) {
|
||||
String key = entry.getKey(); // 获取键
|
||||
Object value = entry.getValue(); // 获取值
|
||||
|
||||
// 执行你的替换逻辑
|
||||
tmpSql = tmpSql.replace("#{"+ FuncBase.PARAM_NAME_VALUE_PAIRS+"." + key + "}", "{"+step+"}");
|
||||
|
||||
objects[step]=value;
|
||||
|
||||
step++;
|
||||
}
|
||||
String newSql=String.format(" (%s) ",tmpSql);
|
||||
wrapper.apply(newSql,objects);
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public JeeLowCodeQueryWrapper<Object> getWrapper() {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public void setWrapper(JeeLowCodeQueryWrapper<Object> wrapper) {
|
||||
this.wrapper = wrapper;
|
||||
}
|
||||
|
||||
public SQLInterpretContext getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public void setContext(SQLInterpretContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoDeleteModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.update.JeeLowCodeUpdateWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 构建 删除 语句
|
||||
*/
|
||||
public class BuildDelete implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
public SqlFormatModel interpret(SQLInterpretContext context){
|
||||
SqlInfoDeleteModel sqlInfo = context.getDeleteModel();
|
||||
String tableName = sqlInfo.getTableName();
|
||||
Boolean isReal = sqlInfo.getReal();
|
||||
|
||||
|
||||
SqlFormatModel sqlFormatModel;
|
||||
if (isReal){//真实删除
|
||||
String sql = "Delete from " + tableName;
|
||||
sqlFormatModel = new SqlFormatModel(sql);
|
||||
}else {//逻辑删除
|
||||
JeeLowCodeUpdateWrapper updateWrapper = new JeeLowCodeUpdateWrapper<>();
|
||||
updateWrapper.set("is_deleted",-1);
|
||||
|
||||
String sqlSet = updateWrapper.getSqlSet();
|
||||
Map<String,Object> paramNameValuePairs = updateWrapper.getParamNameValuePairs();
|
||||
|
||||
//处理null值
|
||||
for (Map.Entry<String,Object> entry : paramNameValuePairs.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if(FuncBase.isEmpty(value)){
|
||||
entry.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
String sql = "update " + tableName + " set " + sqlSet ;
|
||||
sqlFormatModel = new SqlFormatModel(sql, paramNameValuePairs);
|
||||
}
|
||||
return sqlFormatModel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoGroupModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* group by
|
||||
*/
|
||||
public class BuildGroupBy implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
|
||||
SqlInfoGroupModel sqlInfo = context.getGroupModel();
|
||||
String[] columns = sqlInfo.getColumns();
|
||||
|
||||
JeeLowCodeQueryWrapper wrapper=new JeeLowCodeQueryWrapper();
|
||||
wrapper.groupBy(Arrays.asList(columns));
|
||||
String groupByStr = wrapper.getCustomSqlSegment();
|
||||
|
||||
return new SqlFormatModel(groupByStr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoHavingModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
|
||||
/**
|
||||
* having 相关
|
||||
*/
|
||||
public class BuildHaving extends BuildCondition implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
|
||||
SqlInfoHavingModel havingModel = context.getHavingModel();
|
||||
SqlFormatModel sqlFormatModel = super.context2Condition(havingModel);
|
||||
return sqlFormatModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoInsertModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.insert.JeeLowCodeInsertWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 构建 insert 语句
|
||||
*/
|
||||
public class BuildInsert implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context){
|
||||
SqlInfoInsertModel sqlInfo = context.getInsertModel();
|
||||
String tableName = sqlInfo.getTableName();
|
||||
|
||||
Map<String, Object> insertMap = sqlInfo.getInsertMap();
|
||||
|
||||
JeeLowCodeInsertWrapper insertWrapper = new JeeLowCodeInsertWrapper<>();
|
||||
for (Map.Entry<String, Object> entry : insertMap.entrySet()) {
|
||||
insertWrapper.set(entry.getKey(),entry.getValue());
|
||||
}
|
||||
|
||||
|
||||
//封装
|
||||
String sqlSet = insertWrapper.getSqlSet();
|
||||
String customSqlSegment = insertWrapper.getCustomSqlSegment();
|
||||
Map<String, Object> paramNameValuePairs = insertWrapper.getParamNameValuePairs();
|
||||
for (Map.Entry<String,Object> entry : paramNameValuePairs.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if(FuncBase.isEmpty(value)){
|
||||
entry.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> fieldList=new ArrayList<>();
|
||||
List<String> valueList=new ArrayList<>();
|
||||
List<String> setList = FuncBase.toStrList(sqlSet);
|
||||
for(String set:setList){
|
||||
String[] split = set.split("=");
|
||||
String field=split[0];
|
||||
String value=split[1];
|
||||
fieldList.add(field);
|
||||
if(!insertMap.containsKey(field)){//不存在,指定jdbc类型,不然oracle报错
|
||||
value=value.substring(0,value.length()-1)+",jdbcType=VARCHAR}";
|
||||
}else if(FuncBase.isEmpty(insertMap.get(field))){//为空,指定jdbc类型,不然oracle报错
|
||||
value=value.substring(0,value.length()-1)+",jdbcType=VARCHAR}";
|
||||
}
|
||||
valueList.add(value);
|
||||
|
||||
}
|
||||
|
||||
String sql = "insert into " + tableName + "(%s) VALUE(%s) ";
|
||||
String finalSql = String.format(sql, String.join(",", fieldList), String.join(",", valueList));
|
||||
|
||||
SqlFormatModel sqlFormatModel = new SqlFormatModel(finalSql,paramNameValuePairs);
|
||||
return sqlFormatModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoJoinModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
/**
|
||||
* left join ,inner join ,right join相关
|
||||
*/
|
||||
public class BuildJoin implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
|
||||
SqlInfoJoinModel model = context.getJoinModel();
|
||||
SqlInfoJoinModel.JoinType joinType = model.getJoinType();
|
||||
String onStr = model.getOnStr();
|
||||
String tableName = model.getTableName();
|
||||
|
||||
String joinSymbolStr="";
|
||||
switch (joinType) {
|
||||
case LEFT_JOIN:
|
||||
joinSymbolStr = "LEFT JOIN";
|
||||
break;
|
||||
case RIGHT_JOIN:
|
||||
joinSymbolStr = "RIGHT JOIN";
|
||||
break;
|
||||
case INNER_JOIN:
|
||||
joinSymbolStr = "INNER JOIN";
|
||||
break;
|
||||
}
|
||||
String sql= joinSymbolStr+" "+tableName+" on "+onStr;
|
||||
|
||||
SqlFormatModel sqlFormatModel = new SqlFormatModel(sql);
|
||||
return sqlFormatModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoOrderModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
public class BuildOrderBy implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
JeeLowCodeQueryWrapper wrapper=new JeeLowCodeQueryWrapper();
|
||||
|
||||
SqlInfoOrderModel sqlInfoOrderModel = context.getOrderModel();
|
||||
List<SqlInfoOrderModel.OrderByModel> orderModels = sqlInfoOrderModel.getOrderByList();
|
||||
orderModels.forEach(orderModel -> {
|
||||
String[] columns = orderModel.getColumns();//列
|
||||
boolean isAsc = orderModel.isAsc();
|
||||
wrapper.orderBy(true,isAsc, Arrays.asList(columns));
|
||||
});
|
||||
|
||||
String orderByStr = wrapper.getCustomSqlSegment();
|
||||
|
||||
return new SqlFormatModel(orderByStr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoPublicModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
/**
|
||||
* 通用sql
|
||||
*/
|
||||
public class BuildPublicSql implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoPublicModel sqlInfo = context.getPublicModel();
|
||||
String sql = sqlInfo.getSql();//获取原有的sql
|
||||
return new SqlFormatModel(sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoSelectModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
/**
|
||||
* 查询相关
|
||||
*/
|
||||
public class BuildSelect implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoSelectModel sqlInfo = context.getSelectModel();
|
||||
String[] columns = sqlInfo.getColumns();//查询列
|
||||
String tableName = sqlInfo.getTableName();//查询表
|
||||
|
||||
if(FuncBase.isEmpty(columns)){
|
||||
columns = new String[]{"*"};
|
||||
}
|
||||
JeeLowCodeQueryWrapper wrapper=new JeeLowCodeQueryWrapper();
|
||||
wrapper.select(columns);
|
||||
|
||||
String sqlSelect = wrapper.getSqlSelect();
|
||||
|
||||
String sql = "select " + sqlSelect + " from " + tableName;
|
||||
|
||||
|
||||
return new SqlFormatModel(sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoUpdateModel;
|
||||
import com.jeelowcode.framework.plus.core.dql.update.JeeLowCodeUpdateWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 构建 update 语句
|
||||
*/
|
||||
public class BuildUpdate implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context){
|
||||
SqlInfoUpdateModel sqlInfo = context.getUpdateModel();
|
||||
String tableName = sqlInfo.getTableName();
|
||||
JeeLowCodeUpdateWrapper updateWrapper = new JeeLowCodeUpdateWrapper(tableName);
|
||||
|
||||
|
||||
Map<String, Object> updateMap = sqlInfo.getUpdateMap();
|
||||
updateMap.forEach((k,v)->{
|
||||
updateWrapper.set(k,v);
|
||||
});
|
||||
|
||||
String sqlSet = updateWrapper.getSqlSet();
|
||||
Map<String,Object> paramNameValuePairs = updateWrapper.getParamNameValuePairs();
|
||||
|
||||
String newSqlSet="";
|
||||
|
||||
|
||||
List<String> setList = FuncBase.toStrList(sqlSet);
|
||||
for(String set:setList){
|
||||
String[] split = set.split("=");
|
||||
String field=split[0];
|
||||
String value=split[1];
|
||||
if(!updateMap.containsKey(field)){//不存在,指定jdbc类型,不然oracle报错
|
||||
value=value.substring(0,value.length()-1)+",jdbcType=VARCHAR}";
|
||||
}else if(FuncBase.isEmpty(updateMap.get(field))){//为空,指定jdbc类型,不然oracle报错
|
||||
value=value.substring(0,value.length()-1)+",jdbcType=VARCHAR}";
|
||||
}
|
||||
if(FuncBase.isEmpty(newSqlSet)){
|
||||
newSqlSet=field+"="+value;
|
||||
}else{
|
||||
newSqlSet+=","+field+"="+value;
|
||||
}
|
||||
}
|
||||
|
||||
//处理null值
|
||||
for (Map.Entry<String,Object> entry : paramNameValuePairs.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if(FuncBase.isEmpty(value)){
|
||||
entry.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
String sql = "update " + tableName + " set " + newSqlSet ;
|
||||
SqlFormatModel sqlFormatModel = new SqlFormatModel(sql, paramNameValuePairs);
|
||||
|
||||
return sqlFormatModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.build.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoWhereModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
|
||||
/**
|
||||
* 构建where语句相关
|
||||
*/
|
||||
public class BuildWhere extends BuildCondition implements ISQLExpression<SqlFormatModel> {
|
||||
|
||||
|
||||
|
||||
|
||||
public BuildWhere() {
|
||||
}
|
||||
|
||||
public BuildWhere(SQLInterpretContext context){
|
||||
super.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
|
||||
SqlInfoWhereModel whereModel = context.getWhereModel();
|
||||
SqlFormatModel sqlFormatModel = super.context2Condition(whereModel);
|
||||
return sqlFormatModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoConditionModel;
|
||||
|
||||
public class ExpressionModel {
|
||||
private SqlInfoConditionModel.WhereType whereType;
|
||||
private String column;
|
||||
private Object[] value;
|
||||
|
||||
public SqlInfoConditionModel.WhereType getWhereType() {
|
||||
return whereType;
|
||||
}
|
||||
|
||||
public void setWhereType(SqlInfoConditionModel.WhereType whereType) {
|
||||
this.whereType = whereType;
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public Object[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object[] value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ddl.*;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.*;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-23 9:07
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SQLInterpretContext {
|
||||
|
||||
private String preSymbol="ew.";
|
||||
|
||||
private String schemaName;
|
||||
|
||||
private SqlInfoInsertModel insertModel;
|
||||
|
||||
private SqlInfoDeleteModel deleteModel;
|
||||
|
||||
private SqlInfoAlterModel alterModel;
|
||||
|
||||
private SqlInfoSelectModel selectModel;
|
||||
|
||||
private SqlInfoCreateModel createModel;
|
||||
|
||||
private SqlInfoCreateIndexModel createIndexModel;
|
||||
|
||||
private SqlInfoUpdateModel updateModel;
|
||||
|
||||
private SqlInfoDropModel dropModel;
|
||||
|
||||
private SqlInfoWhereModel whereModel;
|
||||
|
||||
private SqlInfoOrderModel orderModel;
|
||||
|
||||
private SqlInfoGroupModel groupModel;
|
||||
|
||||
private SqlInfoHavingModel havingModel;
|
||||
|
||||
private SqlInfoJoinModel joinModel;
|
||||
|
||||
private ExpressionModel expressionModel;
|
||||
|
||||
private DbColunmTypesEntity dbColunmTypes;
|
||||
|
||||
private SqlInfoCommentModel commentModel;
|
||||
|
||||
private SqlInfoPrimaryKeyModel primaryKeyModel;
|
||||
|
||||
private SqlInfoDdlModel ddlModel;
|
||||
|
||||
private SqlInfoPublicModel publicModel;
|
||||
|
||||
|
||||
public SQLInterpretContext(String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
|
||||
///===========================================================================
|
||||
|
||||
|
||||
public String getSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
|
||||
public void setSchemaName(String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
public SqlInfoInsertModel getInsertModel() {
|
||||
return insertModel;
|
||||
}
|
||||
|
||||
public void setInsertModel(SqlInfoInsertModel insertModel) {
|
||||
this.insertModel = insertModel;
|
||||
}
|
||||
|
||||
public SqlInfoDeleteModel getDeleteModel() {
|
||||
return deleteModel;
|
||||
}
|
||||
|
||||
public void setDeleteModel(SqlInfoDeleteModel deleteModel) {
|
||||
this.deleteModel = deleteModel;
|
||||
}
|
||||
|
||||
public SqlInfoAlterModel getAlterModel() {
|
||||
return alterModel;
|
||||
}
|
||||
|
||||
public void setAlterModel(SqlInfoAlterModel alterModel) {
|
||||
this.alterModel = alterModel;
|
||||
}
|
||||
|
||||
public SqlInfoSelectModel getSelectModel() {
|
||||
return selectModel;
|
||||
}
|
||||
|
||||
public void setSelectModel(SqlInfoSelectModel selectModel) {
|
||||
this.selectModel = selectModel;
|
||||
}
|
||||
|
||||
public SqlInfoCreateModel getCreateModel() {
|
||||
return createModel;
|
||||
}
|
||||
|
||||
public void setCreateModel(SqlInfoCreateModel createModel) {
|
||||
this.createModel = createModel;
|
||||
}
|
||||
|
||||
public SqlInfoCreateIndexModel getCreateIndexModel() {
|
||||
return createIndexModel;
|
||||
}
|
||||
|
||||
public void setCreateIndexModel(SqlInfoCreateIndexModel createIndexModel) {
|
||||
this.createIndexModel = createIndexModel;
|
||||
}
|
||||
|
||||
public SqlInfoUpdateModel getUpdateModel() {
|
||||
return updateModel;
|
||||
}
|
||||
|
||||
public void setUpdateModel(SqlInfoUpdateModel updateModel) {
|
||||
this.updateModel = updateModel;
|
||||
}
|
||||
|
||||
public SqlInfoDropModel getDropModel() {
|
||||
return dropModel;
|
||||
}
|
||||
|
||||
public void setDropModel(SqlInfoDropModel dropModel) {
|
||||
this.dropModel = dropModel;
|
||||
}
|
||||
|
||||
public SqlInfoWhereModel getWhereModel() {
|
||||
return whereModel;
|
||||
}
|
||||
|
||||
public void setWhereModel(SqlInfoWhereModel whereModel) {
|
||||
this.whereModel = whereModel;
|
||||
}
|
||||
|
||||
public SqlInfoOrderModel getOrderModel() {
|
||||
return orderModel;
|
||||
}
|
||||
|
||||
public void setOrderModel(SqlInfoOrderModel orderModel) {
|
||||
this.orderModel = orderModel;
|
||||
}
|
||||
|
||||
public SqlInfoGroupModel getGroupModel() {
|
||||
return groupModel;
|
||||
}
|
||||
|
||||
public void setGroupModel(SqlInfoGroupModel groupModel) {
|
||||
this.groupModel = groupModel;
|
||||
}
|
||||
|
||||
public SqlInfoHavingModel getHavingModel() {
|
||||
return havingModel;
|
||||
}
|
||||
|
||||
public void setHavingModel(SqlInfoHavingModel havingModel) {
|
||||
this.havingModel = havingModel;
|
||||
}
|
||||
|
||||
public SqlInfoJoinModel getJoinModel() {
|
||||
return joinModel;
|
||||
}
|
||||
|
||||
public void setJoinModel(SqlInfoJoinModel joinModel) {
|
||||
this.joinModel = joinModel;
|
||||
}
|
||||
|
||||
public ExpressionModel getExpressionModel() {
|
||||
return expressionModel;
|
||||
}
|
||||
|
||||
public void setExpressionModel(ExpressionModel expressionModel) {
|
||||
this.expressionModel = expressionModel;
|
||||
}
|
||||
|
||||
public DbColunmTypesEntity getDbColunmTypes() {
|
||||
return dbColunmTypes;
|
||||
}
|
||||
|
||||
public void setDbColunmTypes(DbColunmTypesEntity dbColunmTypes) {
|
||||
this.dbColunmTypes = dbColunmTypes;
|
||||
}
|
||||
|
||||
public SqlInfoCommentModel getCommentModel() {
|
||||
return commentModel;
|
||||
}
|
||||
|
||||
public void setCommentModel(SqlInfoCommentModel commentModel) {
|
||||
this.commentModel = commentModel;
|
||||
}
|
||||
|
||||
public SqlInfoPrimaryKeyModel getPrimaryKeyModel() {
|
||||
return primaryKeyModel;
|
||||
}
|
||||
|
||||
public void setPrimaryKeyModel(SqlInfoPrimaryKeyModel primaryKeyModel) {
|
||||
this.primaryKeyModel = primaryKeyModel;
|
||||
}
|
||||
|
||||
public SqlInfoDdlModel getDdlModel() {
|
||||
return ddlModel;
|
||||
}
|
||||
|
||||
public void setDdlModel(SqlInfoDdlModel ddlModel) {
|
||||
this.ddlModel = ddlModel;
|
||||
}
|
||||
|
||||
public String getPreSymbol() {
|
||||
return preSymbol;
|
||||
}
|
||||
|
||||
public void setPreSymbol(String preSymbol) {
|
||||
this.preSymbol = preSymbol;
|
||||
}
|
||||
|
||||
public SqlInfoPublicModel getPublicModel() {
|
||||
return publicModel;
|
||||
}
|
||||
|
||||
public void setPublicModel(SqlInfoPublicModel publicModel) {
|
||||
this.publicModel = publicModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
|
||||
/**
|
||||
* 自定义 model
|
||||
*/
|
||||
|
||||
public class SqlInfoBaseModel {
|
||||
|
||||
ISQLExpression sqlExpression;
|
||||
|
||||
public ISQLExpression getSqlExpression() {
|
||||
return sqlExpression;
|
||||
}
|
||||
|
||||
public void setSqlExpression(ISQLExpression sqlExpression) {
|
||||
this.sqlExpression = sqlExpression;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
|
||||
/**
|
||||
* 数据库字段列表
|
||||
*/
|
||||
public class FieldCommentModel extends SqlInfoBaseModel {
|
||||
private String fieldCode;//字段
|
||||
private String fieldName;//字段名称
|
||||
|
||||
public FieldCommentModel(String fieldCode, String fieldName) {
|
||||
this.fieldCode = fieldCode;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public String getFieldCode() {
|
||||
return fieldCode;
|
||||
}
|
||||
|
||||
public void setFieldCode(String fieldCode) {
|
||||
this.fieldCode = fieldCode;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void setFieldName(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildAlter;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-06 11:45
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoAlterModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
private AlterType alterType;//操作类型
|
||||
|
||||
private String tableName;//表名称
|
||||
//addColumn
|
||||
private FieldModel fieldModel;//字段属性
|
||||
|
||||
|
||||
private SqlInfoAlterModel(){}
|
||||
|
||||
|
||||
public enum AlterType{
|
||||
ADD_COLUMN, //增加字段
|
||||
UPDATE_COLUMN //修改字段
|
||||
}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
public static class Builder{
|
||||
|
||||
private SqlInfoAlterModel alterModel = new SqlInfoAlterModel();
|
||||
ISQLExpression<List<SqlFormatModel>> alterExpression = new BuildAlter();
|
||||
|
||||
public Builder setTableName(String tableName){
|
||||
alterModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
//增加字段
|
||||
public SqlInfoAlterModel<BuildAlter> buildAddColumn(FieldModel fieldModel){
|
||||
alterModel.alterType = AlterType.ADD_COLUMN;
|
||||
alterModel.fieldModel =fieldModel;
|
||||
alterModel.setSqlExpression(alterExpression);
|
||||
return alterModel;
|
||||
}
|
||||
|
||||
//更新字段
|
||||
public SqlInfoAlterModel<BuildAlter> buildUpdateColum(FieldModel fieldModel){
|
||||
alterModel.alterType = AlterType.UPDATE_COLUMN;
|
||||
alterModel.fieldModel =fieldModel;
|
||||
alterModel.setSqlExpression(alterExpression);
|
||||
return alterModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public AlterType getAlterType() {
|
||||
return alterType;
|
||||
}
|
||||
|
||||
public void setAlterType(AlterType alterType) {
|
||||
this.alterType = alterType;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public FieldModel getFieldModel() {
|
||||
return fieldModel;
|
||||
}
|
||||
|
||||
public void setFieldModel(FieldModel fieldModel) {
|
||||
this.fieldModel = fieldModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DDL 公共
|
||||
* @param
|
||||
*/
|
||||
public class SqlInfoBaseDdlModel extends SqlInfoBaseModel {
|
||||
|
||||
//优先级最高,有值则只运行这里
|
||||
private List<String> executeDdlList;
|
||||
|
||||
public List<String> getExecuteDdlList() {
|
||||
return executeDdlList;
|
||||
}
|
||||
|
||||
public void setExecuteDdlList(List<String> executeDdlList) {
|
||||
this.executeDdlList = executeDdlList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildComment;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-06 11:45
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoCommentModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
String tableName;
|
||||
String tableAlias;
|
||||
List<FieldModel> fieldModelList;
|
||||
|
||||
|
||||
|
||||
private SqlInfoCommentModel(){}
|
||||
|
||||
//构建表备注
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
|
||||
private SqlInfoCommentModel model = new SqlInfoCommentModel();
|
||||
ISQLExpression<List<SqlFormatModel>> commentExpression = new BuildComment();
|
||||
|
||||
public Builder setTableName(String tableName){
|
||||
model.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
public Builder setTableAlias(String tableAlias){
|
||||
model.tableAlias = tableAlias;
|
||||
return this;
|
||||
}
|
||||
public Builder setfieldModelList(List<FieldModel> fieldModelList){
|
||||
model.fieldModelList = fieldModelList;
|
||||
return this;
|
||||
}
|
||||
//增加字段
|
||||
public SqlInfoCommentModel<BuildComment> build(){
|
||||
model.setSqlExpression(commentExpression);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public String getTableAlias() {
|
||||
return tableAlias;
|
||||
}
|
||||
|
||||
public List<FieldModel> getFieldModelList() {
|
||||
return fieldModelList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildCreateIndex;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-05 17:09
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoCreateIndexModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
String tableName;//表
|
||||
//index
|
||||
private String indexName;//索引名称
|
||||
|
||||
private List<String> indexFieldCodeList;//索引值
|
||||
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoCreateIndexModel sqlInfoCreateModel = new SqlInfoCreateIndexModel();
|
||||
ISQLExpression<List<SqlFormatModel>> expression = new BuildCreateIndex();
|
||||
|
||||
public Builder setTableName(String tableName) {
|
||||
sqlInfoCreateModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIndexName(String indexName) {
|
||||
sqlInfoCreateModel.indexName = indexName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIndexFieldCodeList(List<String> indexFieldCodeList) {
|
||||
sqlInfoCreateModel.indexFieldCodeList = indexFieldCodeList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoCreateIndexModel<BuildCreateIndex> build() {
|
||||
ISQLExpression<List<SqlFormatModel>> expression = new BuildCreateIndex();
|
||||
sqlInfoCreateModel.setSqlExpression(expression);
|
||||
return sqlInfoCreateModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public void setIndexName(String indexName) {
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public List<String> getIndexFieldCodeList() {
|
||||
return indexFieldCodeList;
|
||||
}
|
||||
|
||||
public void setIndexFieldCodeList(List<String> indexFieldCodeList) {
|
||||
this.indexFieldCodeList = indexFieldCodeList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildCreateTable;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-05 17:09
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoCreateModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
String tableName;//表
|
||||
List<FieldModel> tableOptions;
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoCreateModel sqlInfoCreateModel = new SqlInfoCreateModel();
|
||||
ISQLExpression<List<SqlFormatModel>> createTableExpression = new BuildCreateTable();
|
||||
public Builder setTableName(String tableName) {
|
||||
sqlInfoCreateModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTableOptions(List<FieldModel> tableOptions) {
|
||||
sqlInfoCreateModel.tableOptions = tableOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoCreateModel<BuildCreateTable> build() {
|
||||
sqlInfoCreateModel.setSqlExpression(createTableExpression);
|
||||
return sqlInfoCreateModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<FieldModel> getTableOptions() {
|
||||
return tableOptions;
|
||||
}
|
||||
|
||||
public void setTableOptions(List<FieldModel> tableOptions) {
|
||||
this.tableOptions = tableOptions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildDdl;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SqlInfoDdlModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
private DdlType type;//操作类型
|
||||
|
||||
private Map<String,Object> map;//参数
|
||||
|
||||
private SqlInfoDdlModel(){}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
|
||||
private SqlInfoDdlModel ddlModel = new SqlInfoDdlModel();
|
||||
|
||||
ISQLExpression<List<SqlFormatModel>> expression = new BuildDdl();
|
||||
|
||||
public SqlInfoDdlModel<BuildDdl> buildIndexExist(String tableName,String indexName){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("tableName",tableName);
|
||||
map.put("indexName",indexName);
|
||||
ddlModel.type= DdlType.INDEX_EXIST;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
public SqlInfoDdlModel<BuildDdl> buildIndexAllByTable(String tableName){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("tableName",tableName);
|
||||
ddlModel.type= DdlType.INDEX_ALL;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
public SqlInfoDdlModel<BuildDdl> buildTableExist(String tableName){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("tableName",tableName);
|
||||
ddlModel.type= DdlType.TABLE_EXIST;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
public SqlInfoDdlModel<BuildDdl> buildGetAllTableName(){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
ddlModel.type= DdlType.ALL_TABLE_NAME;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
public SqlInfoDdlModel<BuildDdl> buildFieldComment(String tableName){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("tableName",tableName);
|
||||
ddlModel.type= DdlType.TABLE_FIELD_COMMENT;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
public SqlInfoDdlModel<BuildDdl> buildTableComment(String tableName){
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("tableName",tableName);
|
||||
ddlModel.type= DdlType.TABLE_COMMENT;
|
||||
ddlModel.map=map;
|
||||
ddlModel.setSqlExpression(expression);
|
||||
return ddlModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum DdlType{
|
||||
INDEX_EXIST,//索引是否存在
|
||||
INDEX_ALL,//所有索引
|
||||
TABLE_EXIST,//表名是否存在
|
||||
ALL_TABLE_NAME,//所有表名
|
||||
TABLE_COMMENT,//表备注
|
||||
TABLE_FIELD_COMMENT;//表字段备注
|
||||
}
|
||||
|
||||
public DdlType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildDrop;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-06 11:45
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoDropModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
private DropType dropType;//操作类型
|
||||
|
||||
String tableName;//表
|
||||
|
||||
private String cloumnCode;//字段
|
||||
private String cloumnFormat;//格式化
|
||||
|
||||
private String indexName;//索引名称
|
||||
|
||||
private SqlInfoDropModel(){}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
|
||||
private SqlInfoDropModel dropModel = new SqlInfoDropModel();
|
||||
|
||||
ISQLExpression<List<SqlFormatModel>> expression = new BuildDrop();
|
||||
|
||||
public SqlInfoDropModel<BuildDrop> buildDropTable(String tableName){
|
||||
dropModel.tableName = tableName;
|
||||
dropModel.dropType = DropType.DROP_TABLE;
|
||||
dropModel.setSqlExpression(expression);
|
||||
return dropModel;
|
||||
}
|
||||
public SqlInfoDropModel<BuildDrop> buildDropColumn(String tableName,String column){
|
||||
dropModel.tableName = tableName;
|
||||
dropModel.cloumnCode=column;
|
||||
dropModel.dropType = DropType.DROP_COLUMN;
|
||||
dropModel.setSqlExpression(expression);
|
||||
return dropModel;
|
||||
}
|
||||
public SqlInfoDropModel<BuildDrop> buildDropIndex(String tableName,String indexName){
|
||||
dropModel.tableName = tableName;
|
||||
dropModel.dropType = DropType.DROP_INDEX;
|
||||
dropModel.indexName=indexName;
|
||||
dropModel.setSqlExpression(expression);
|
||||
return dropModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public enum DropType{
|
||||
DROP_TABLE, //删除表
|
||||
DROP_COLUMN, //删除字段
|
||||
DROP_INDEX //删除索引
|
||||
}
|
||||
|
||||
public DropType getDropType() {
|
||||
return dropType;
|
||||
}
|
||||
|
||||
public void setDropType(DropType dropType) {
|
||||
this.dropType = dropType;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getCloumnCode() {
|
||||
return cloumnCode;
|
||||
}
|
||||
|
||||
public void setCloumnCode(String cloumnCode) {
|
||||
this.cloumnCode = cloumnCode;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public void setIndexName(String indexName) {
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public String getCloumnFormat() {
|
||||
return cloumnFormat;
|
||||
}
|
||||
|
||||
public void setCloumnFormat(String cloumnFormat) {
|
||||
this.cloumnFormat = cloumnFormat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.ddl;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.ddl.BuildPrimaryKey;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-05 17:09
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoPrimaryKeyModel<T> extends SqlInfoBaseDdlModel {
|
||||
|
||||
String tableName;//表
|
||||
List<String> keyList;
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoPrimaryKeyModel sqlInfoCreateModel = new SqlInfoPrimaryKeyModel();
|
||||
ISQLExpression<List<SqlFormatModel>> primaryKeyExpression = new BuildPrimaryKey();
|
||||
public Builder setTableName(String tableName) {
|
||||
sqlInfoCreateModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPrimaryKey(List<String> keyList) {
|
||||
sqlInfoCreateModel.keyList = keyList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoPrimaryKeyModel build() {
|
||||
sqlInfoCreateModel.setSqlExpression(primaryKeyExpression);
|
||||
return sqlInfoCreateModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<String> getKeyList() {
|
||||
return keyList;
|
||||
}
|
||||
|
||||
public void setKeyList(List<String> keyList) {
|
||||
this.keyList = keyList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildCondition;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildHaving;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildWhere;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.ExpressionModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-30 10:17
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoConditionModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
|
||||
private List<ExpressionModel> expressions = new ArrayList<>();
|
||||
|
||||
public static SqlInfoConditionModel.Builder builder() {
|
||||
return new SqlInfoConditionModel.Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private SqlInfoConditionModel conditionModel = new SqlInfoConditionModel();
|
||||
|
||||
public SqlInfoConditionModel.Builder gt(String column, Object value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.GT, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder ge(String column, Object value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.GE, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder ne(String column, Object value) {
|
||||
if (FuncBase.isEmpty(value)) {
|
||||
return this;
|
||||
}
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.NE, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder eq(String column, Object value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.EQ, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder lt(String column, Object value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.LT, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder le(String column, Object value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.LE, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlInfoConditionModel.Builder between(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.BETWEEN, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder notbetween(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.NOT_BETWEEN, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder in(boolean condition, String column, Object... value) {
|
||||
if (!condition) {
|
||||
return this;
|
||||
}
|
||||
return this.in(column, value);
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder in(String column, Object... value) {
|
||||
if (FuncBase.isEmpty(value)) {
|
||||
return this;
|
||||
}
|
||||
Object valueTmp = value[0];
|
||||
if (FuncBase.isEmpty(valueTmp)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (value.length == 1) {
|
||||
if (valueTmp instanceof List) {
|
||||
List<Object> tmpList = (List<Object>) valueTmp;
|
||||
if (tmpList.size() == 1) {
|
||||
this.eq(column, tmpList.get(0));
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.IN, column, value));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder notIn(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.NOT_IN, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder like(boolean condition, String column, Object... value) {
|
||||
if (!condition) {
|
||||
return this;
|
||||
}
|
||||
return like(column, value);
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder like(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.LIKE, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder notLike(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.NOT_LIKE, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder likeLeft(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.LIKE_LEFT, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder likeRight(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.LIKE_RIGHT, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder isNull(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.IS_NULL, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder isNotNull(String column, Object... value) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.IS_NOT_NULL, column, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder apply(String apply) {
|
||||
conditionModel.expressions.add(buildExpression(WhereType.APPLY, apply, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder or() {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.OR, null, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder or(Consumer<SqlInfoConditionModel.Builder> orBuilderConsumer) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.OR_BUILD, null, orBuilderConsumer));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel.Builder and(Consumer<SqlInfoConditionModel.Builder> andBuilderConsumer) {
|
||||
conditionModel.expressions.add(buildExpression(SqlInfoConditionModel.WhereType.AND_BUILD, null, andBuilderConsumer));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlInfoWhereModel<BuildWhere> buildWhere() {
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildWhere();
|
||||
SqlInfoWhereModel whereModel = new SqlInfoWhereModel();
|
||||
List<ExpressionModel> expressions = conditionModel.getExpressions();
|
||||
whereModel.setExpressions(expressions);
|
||||
whereModel.setSqlExpression(expression);
|
||||
return whereModel;
|
||||
}
|
||||
|
||||
public SqlInfoHavingModel<BuildHaving> buildHaving() {
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildHaving();
|
||||
|
||||
SqlInfoHavingModel havingModel = new SqlInfoHavingModel();
|
||||
List<ExpressionModel> expressions = conditionModel.getExpressions();
|
||||
havingModel.setExpressions(expressions);
|
||||
havingModel.setSqlExpression(expression);
|
||||
return havingModel;
|
||||
}
|
||||
|
||||
public SqlInfoConditionModel<BuildCondition> build() {
|
||||
return conditionModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ExpressionModel> getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
|
||||
public enum WhereType {
|
||||
GT, //>
|
||||
GE, //>=
|
||||
NE, //!=
|
||||
EQ, //=
|
||||
LT, //<
|
||||
LE, //<=
|
||||
BETWEEN,
|
||||
NOT_BETWEEN,
|
||||
IN,
|
||||
NOT_IN,
|
||||
LIKE,
|
||||
NOT_LIKE,
|
||||
LIKE_LEFT,
|
||||
LIKE_RIGHT,
|
||||
IS_NULL,
|
||||
IS_NOT_NULL,
|
||||
OR,
|
||||
OR_BUILD,
|
||||
AND_BUILD,
|
||||
APPLY
|
||||
}
|
||||
|
||||
private static ExpressionModel buildExpression(SqlInfoConditionModel.WhereType whereType, String column, Object... value) {
|
||||
ExpressionModel expression = new ExpressionModel();
|
||||
expression.setWhereType(whereType);
|
||||
expression.setColumn(column);
|
||||
expression.setValue(value);
|
||||
return expression;
|
||||
}
|
||||
|
||||
public void setExpressions(List<ExpressionModel> expressions) {
|
||||
this.expressions = expressions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildDelete;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
public class SqlInfoDeleteModel<T> extends SqlInfoBaseModel {
|
||||
private String tableName;
|
||||
|
||||
private Boolean isReal;
|
||||
|
||||
private SqlInfoDeleteModel(){}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private SqlInfoDeleteModel sqlInfoDeleteModel = new SqlInfoDeleteModel();
|
||||
|
||||
public Builder setTableName(String tableName) {
|
||||
sqlInfoDeleteModel.tableName = tableName;
|
||||
sqlInfoDeleteModel.isReal=false;//逻辑删除
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTableName(String tableName,boolean isReal) {
|
||||
sqlInfoDeleteModel.tableName = tableName;
|
||||
sqlInfoDeleteModel.isReal=isReal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoDeleteModel<BuildDelete> build(){
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildDelete();
|
||||
sqlInfoDeleteModel.setSqlExpression(expression);
|
||||
return sqlInfoDeleteModel;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public Boolean getReal() {
|
||||
return isReal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildDelete;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildGroupBy;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-04 10:51
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoGroupModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private String[] columns;
|
||||
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(String... columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public SqlInfoGroupModel (){}
|
||||
|
||||
public static Builder builder (){
|
||||
return new Builder();
|
||||
}
|
||||
public static class Builder{
|
||||
private SqlInfoGroupModel groupModel = new SqlInfoGroupModel();
|
||||
|
||||
public Builder setColumns(String... columns){
|
||||
groupModel.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoGroupModel<BuildDelete> build(){
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildGroupBy();
|
||||
groupModel.setSqlExpression(expression);
|
||||
return groupModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-04 9:14
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoHavingModel<T> extends SqlInfoConditionModel {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildInsert;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SqlInfoInsertModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private Map<String,Object> insertMap=new LinkedHashMap<>();
|
||||
|
||||
private SqlInfoInsertModel (){}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoInsertModel insertModel = new SqlInfoInsertModel();
|
||||
|
||||
public Builder setTableName(String tableName){
|
||||
insertModel.setTableName(tableName);
|
||||
return this;
|
||||
}
|
||||
public Builder addColumn(String column,Object val){
|
||||
insertModel.insertMap.put(column,val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addMap(Map<String,Object> insertMap){
|
||||
insertModel.insertMap.putAll(insertMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoInsertModel<BuildInsert> build(){
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildInsert();
|
||||
insertModel.setSqlExpression(expression);
|
||||
return insertModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public Map<String, Object> getInsertMap() {
|
||||
return insertMap;
|
||||
}
|
||||
|
||||
public void setInsertMap(Map<String, Object> insertMap) {
|
||||
this.insertMap = insertMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildJoin;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-04 9:14
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoJoinModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private String tableName;
|
||||
private JoinType joinType;
|
||||
private String onStr;
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoJoinModel joinModel = new SqlInfoJoinModel();
|
||||
|
||||
//构建having
|
||||
public Builder joinTable(String tableName,String alias){
|
||||
joinModel.setTableName(tableName+" "+alias);
|
||||
return this;
|
||||
}
|
||||
public Builder innerJoin(){
|
||||
joinModel.joinType= JoinType.INNER_JOIN;
|
||||
return this;
|
||||
}
|
||||
public Builder leftJoin(){
|
||||
joinModel.joinType= JoinType.LEFT_JOIN;
|
||||
return this;
|
||||
}
|
||||
public Builder rightJoin(){
|
||||
joinModel.joinType= JoinType.RIGHT_JOIN;
|
||||
return this;
|
||||
}
|
||||
public Builder on(String leftStr,String rightStr){
|
||||
joinModel.onStr=leftStr+" = "+rightStr;
|
||||
return this;
|
||||
}
|
||||
public SqlInfoJoinModel<SqlFormatModel> build(){
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildJoin();
|
||||
joinModel.setSqlExpression(expression);
|
||||
return joinModel;
|
||||
}
|
||||
}
|
||||
|
||||
public enum JoinType{
|
||||
LEFT_JOIN,
|
||||
RIGHT_JOIN,
|
||||
INNER_JOIN
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public JoinType getJoinType() {
|
||||
return joinType;
|
||||
}
|
||||
|
||||
public void setJoinType(JoinType joinType) {
|
||||
this.joinType = joinType;
|
||||
}
|
||||
|
||||
public String getOnStr() {
|
||||
return onStr;
|
||||
}
|
||||
|
||||
public void setOnStr(String onStr) {
|
||||
this.onStr = onStr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildOrderBy;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-04 9:14
|
||||
* @dedescription:
|
||||
*/
|
||||
|
||||
public class SqlInfoOrderModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private List<OrderByModel> orderByList=new ArrayList<>();
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class OrderByModel{
|
||||
|
||||
public String[] columns;//列
|
||||
|
||||
public boolean asc;//是否是asc 升序
|
||||
|
||||
public void setColumns(String ... columns){
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public boolean isAsc() {
|
||||
return asc;
|
||||
}
|
||||
|
||||
public void setAsc(boolean asc) {
|
||||
this.asc = asc;
|
||||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
private SqlInfoOrderModel infoOrderModel = new SqlInfoOrderModel();
|
||||
|
||||
//升序
|
||||
public Builder setOrderByAsc(String ... columns){
|
||||
OrderByModel model=new OrderByModel();
|
||||
model.setAsc(true);
|
||||
model.setColumns(columns);
|
||||
infoOrderModel.orderByList.add(model);
|
||||
return this;
|
||||
}
|
||||
|
||||
//降序
|
||||
public Builder setOrderByDesc(String ... columns ){
|
||||
OrderByModel model=new OrderByModel();
|
||||
model.setAsc(false);
|
||||
model.setColumns(columns);
|
||||
infoOrderModel.orderByList.add(model);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoOrderModel<BuildOrderBy> build(){
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildOrderBy();
|
||||
infoOrderModel.setSqlExpression(expression);
|
||||
return infoOrderModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<OrderByModel> getOrderByList() {
|
||||
return orderByList;
|
||||
}
|
||||
|
||||
public void setOrderByList(List<OrderByModel> orderByList) {
|
||||
this.orderByList = orderByList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildPublicSql;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildSelect;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
/**
|
||||
* 通用sql
|
||||
*/
|
||||
public class SqlInfoPublicModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private String sql;
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private SqlInfoPublicModel selectModel = new SqlInfoPublicModel();
|
||||
|
||||
public Builder setSql(String sql) {
|
||||
selectModel.sql = sql;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoPublicModel<BuildSelect> build() {
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildPublicSql();
|
||||
selectModel.setSqlExpression(expression);
|
||||
return selectModel;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildSelect;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-03 11:51
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoSelectModel<T> extends SqlInfoBaseModel {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String[] columns;
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private SqlInfoSelectModel selectModel = new SqlInfoSelectModel();
|
||||
|
||||
public Builder setTableName(String tableName) {
|
||||
selectModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
public Builder setTableName(String tableName,String alias) {
|
||||
selectModel.tableName = tableName+" "+alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setColumns(String ... columns){
|
||||
|
||||
selectModel.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlInfoSelectModel<BuildSelect> build() {
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildSelect();
|
||||
selectModel.setSqlExpression(expression);
|
||||
return selectModel;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(String[] columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildUpdate;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SqlInfoBaseModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SqlInfoUpdateModel<T> extends SqlInfoBaseModel {
|
||||
private String tableName;
|
||||
|
||||
private Map<String,Object> updateMap=new LinkedHashMap<>();
|
||||
|
||||
private SqlInfoUpdateModel(){}
|
||||
|
||||
public static Builder builder(){
|
||||
return new Builder();
|
||||
}
|
||||
public static class Builder {
|
||||
SqlInfoUpdateModel updateModel = new SqlInfoUpdateModel();
|
||||
|
||||
public Builder setTableName(String tableName) {
|
||||
updateModel.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addColumn(String column, Object val){
|
||||
updateModel.updateMap.put(column,val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addMap(Map<String,Object> updateMap){
|
||||
updateModel.updateMap.putAll(updateMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlInfoUpdateModel<BuildUpdate> build() {
|
||||
ISQLExpression<SqlFormatModel> expression = new BuildUpdate();
|
||||
updateModel.setSqlExpression(expression);
|
||||
return updateModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public Map<String, Object> getUpdateMap() {
|
||||
return updateMap;
|
||||
}
|
||||
|
||||
public void setUpdateMap(Map<String, Object> updateMap) {
|
||||
this.updateMap = updateMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.dql;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-07-03 10:12
|
||||
* @dedescription:
|
||||
*/
|
||||
public class SqlInfoWhereModel<T> extends SqlInfoConditionModel {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.wrapper;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 公共
|
||||
*/
|
||||
public class BaseWrapper {
|
||||
public String BUILDER_INSERT="builderInsert";
|
||||
public String BUILDER_UPDATE="builderUpdate";
|
||||
public String BUILDER_DELETE="builderDelete";
|
||||
public String BUILDER_SELECT="builderSelect";
|
||||
public String BUILDER_WHERE="builderWhere";
|
||||
public String BUILDER_ORDERBY="builderOrderBy";
|
||||
public String BUILDER_GROUPBY="builderGroupBy";
|
||||
public String BUILDER_HAVING="builderHaving";
|
||||
public String BUILDER_JOIN="builderJoin";
|
||||
|
||||
Set<String> initSet=new HashSet<>();
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.wrapper;
|
||||
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.AndExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildDelete;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildWhere;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoDeleteModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoWhereModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 删除-封装器
|
||||
*/
|
||||
public class SqlInfoDeleteWrapper {
|
||||
|
||||
public static Wrapper wrapper(String dbSchemaName){
|
||||
return new Wrapper(dbSchemaName);
|
||||
}
|
||||
|
||||
public static class Wrapper extends BaseWrapper {
|
||||
|
||||
private String dbSchemaName;
|
||||
private SqlInfoDeleteModel.Builder builderDelete = SqlInfoDeleteModel.builder();
|
||||
private SqlInfoWhereModel.Builder builderWhere = SqlInfoWhereModel.builder();
|
||||
|
||||
public Wrapper(String dbSchemaName) {
|
||||
this.dbSchemaName = dbSchemaName;
|
||||
}
|
||||
|
||||
//逻辑删除
|
||||
public Wrapper setTableName(String tableName) {
|
||||
builderDelete.setTableName(tableName);
|
||||
initSet.add(BUILDER_DELETE);
|
||||
return this;
|
||||
}
|
||||
//true=真实删除,物理删除 false=逻辑删除
|
||||
public Wrapper setTableName(String tableName, boolean isReal) {
|
||||
builderDelete.setTableName(tableName,isReal);
|
||||
initSet.add(BUILDER_DELETE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setWhere(Consumer<SqlInfoWhereModel.Builder> whereBuilderConsumer) {
|
||||
whereBuilderConsumer.accept(builderWhere);
|
||||
initSet.add(BUILDER_WHERE);
|
||||
return this;
|
||||
}
|
||||
public Wrapper build() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlFormatModel buildSql() {
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
SqlInfoDeleteModel<BuildDelete> buildDelete = builderDelete.build();
|
||||
SqlInfoWhereModel<BuildWhere> buildWhere = builderWhere.buildWhere();
|
||||
|
||||
List<ISQLExpression> expressionList=new ArrayList<>();
|
||||
if(initSet.contains(BUILDER_DELETE)){
|
||||
context.setDeleteModel(buildDelete);
|
||||
expressionList.add(new BuildDelete());
|
||||
}
|
||||
if(initSet.contains(BUILDER_WHERE)){
|
||||
context.setWhereModel(buildWhere);
|
||||
expressionList.add(new BuildWhere());
|
||||
}
|
||||
|
||||
ISQLExpression expression = new AndExpression(expressionList);
|
||||
List<SqlFormatModel> sqlFormatModelList = SqlHelper.sqlExpression(context, expression);
|
||||
return sqlFormatModelList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.wrapper;
|
||||
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.AndExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildInsert;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoInsertModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 新增-封装器
|
||||
*/
|
||||
public class SqlInfoInsertWrapper {
|
||||
|
||||
public static Wrapper wrapper(String dbSchemaName){
|
||||
return new Wrapper(dbSchemaName);
|
||||
}
|
||||
public static class Wrapper extends BaseWrapper {
|
||||
|
||||
private String dbSchemaName;
|
||||
private SqlInfoInsertModel.Builder builderInsert= SqlInfoInsertModel.builder();
|
||||
|
||||
public Wrapper(String dbSchemaName) {
|
||||
this.dbSchemaName = dbSchemaName;
|
||||
}
|
||||
|
||||
public Wrapper setTableName(String tableName){
|
||||
builderInsert.setTableName(tableName);
|
||||
return this;
|
||||
}
|
||||
public Wrapper setColumn(String column, Object val){
|
||||
builderInsert.addColumn(column,val);
|
||||
initSet.add(BUILDER_INSERT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setMap(Map<String,Object> insertMap){
|
||||
builderInsert.addMap(insertMap);
|
||||
initSet.add(BUILDER_INSERT);
|
||||
return this;
|
||||
}
|
||||
public Wrapper build() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlFormatModel buildSql() {
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
SqlInfoInsertModel<BuildInsert> buildInsert = builderInsert.build();
|
||||
|
||||
List<ISQLExpression> expressionList=new ArrayList<>();
|
||||
if(initSet.contains(BUILDER_INSERT)){
|
||||
context.setInsertModel(buildInsert);
|
||||
expressionList.add(new BuildInsert());
|
||||
}
|
||||
|
||||
ISQLExpression expression = new AndExpression(expressionList);
|
||||
List<SqlFormatModel> sqlFormatModelList = SqlHelper.sqlExpression(context, expression);
|
||||
return sqlFormatModelList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.wrapper;
|
||||
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.AndExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.*;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.*;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.constant.JeeLowCodeConstant;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 查询-封装器
|
||||
*/
|
||||
public class SqlInfoQueryWrapper {
|
||||
|
||||
|
||||
public static Wrapper wrapper(String dbSchemaName) {
|
||||
return new Wrapper(dbSchemaName);
|
||||
}
|
||||
|
||||
public static class Wrapper extends BaseWrapper {
|
||||
|
||||
private String dbSchemaName;
|
||||
private SqlInfoSelectModel.Builder builderSelect = SqlInfoSelectModel.builder();
|
||||
private SqlInfoWhereModel.Builder builderWhere = SqlInfoWhereModel.builder();
|
||||
private SqlInfoOrderModel.Builder builderOrderBy = SqlInfoOrderModel.builder();
|
||||
private SqlInfoGroupModel.Builder builderGroupBy = SqlInfoGroupModel.builder();
|
||||
private SqlInfoHavingModel.Builder builderHaving = SqlInfoHavingModel.builder();
|
||||
private SqlInfoJoinModel.Builder builderJoin = SqlInfoJoinModel.builder();
|
||||
|
||||
public Wrapper(String dbSchemaName) {
|
||||
this.dbSchemaName = dbSchemaName;
|
||||
}
|
||||
|
||||
//select 相关
|
||||
public Wrapper select(String... columns) {
|
||||
if (FuncBase.isNotEmpty(columns)) {
|
||||
builderSelect.setColumns(columns);
|
||||
initSet.add(BUILDER_SELECT);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper select(List<String> columnsList, boolean aliasFlag) {
|
||||
if (FuncBase.isNotEmpty(columnsList)) {
|
||||
//处理别名
|
||||
if (aliasFlag) {
|
||||
columnsList = FuncBase.fieldCodeAlias(columnsList);
|
||||
}
|
||||
|
||||
builderSelect.setColumns(columnsList.toArray(new String[0]));
|
||||
initSet.add(BUILDER_SELECT);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setTableName(String tableName) {
|
||||
//处理别名
|
||||
builderSelect.setTableName(tableName, JeeLowCodeConstant.TABLE_ALIAS);
|
||||
initSet.add(BUILDER_SELECT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setTableSql(String tableNameSql) {
|
||||
//处理别名
|
||||
String sql = String.format("(%s)", tableNameSql);
|
||||
builderSelect.setTableName(sql, JeeLowCodeConstant.TABLE_ALIAS);
|
||||
initSet.add(BUILDER_SELECT);
|
||||
return this;
|
||||
}
|
||||
|
||||
//where 相关
|
||||
public Wrapper setWhere(Consumer<SqlInfoWhereModel.Builder> whereBuilderConsumer) {
|
||||
whereBuilderConsumer.accept(builderWhere);
|
||||
initSet.add(BUILDER_WHERE);
|
||||
return this;
|
||||
}
|
||||
|
||||
//order by相关
|
||||
public Wrapper orderByAsc(String... columns) {
|
||||
builderOrderBy.setOrderByAsc(columns);
|
||||
initSet.add(BUILDER_ORDERBY);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper orderByDesc(String... columns) {
|
||||
builderOrderBy.setOrderByDesc(columns);
|
||||
initSet.add(BUILDER_ORDERBY);
|
||||
return this;
|
||||
}
|
||||
|
||||
//group by 相关
|
||||
public Wrapper groupByColumns(String... columns) {
|
||||
builderGroupBy.setColumns(columns);
|
||||
initSet.add(BUILDER_GROUPBY);
|
||||
return this;
|
||||
}
|
||||
|
||||
//join 相关
|
||||
public Wrapper joinByinnerJoinTable(String tableName, String alias) {
|
||||
builderJoin.joinTable(tableName, alias);
|
||||
builderJoin.innerJoin();
|
||||
initSet.add(BUILDER_JOIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper joinByleftJoinTable(String tableName, String alias) {
|
||||
builderJoin.joinTable(tableName, alias);
|
||||
builderJoin.leftJoin();
|
||||
initSet.add(BUILDER_JOIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper joinByrightJoinTable(String tableName, String alias) {
|
||||
builderJoin.joinTable(tableName, alias);
|
||||
builderJoin.rightJoin();
|
||||
initSet.add(BUILDER_JOIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper joinOn(String leftStr, String rightStr) {
|
||||
builderJoin.on(leftStr, rightStr);
|
||||
initSet.add(BUILDER_JOIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
//构建having
|
||||
public Wrapper setHaving(Consumer<SqlInfoHavingModel.Builder> havingBuilderConsumer) {
|
||||
havingBuilderConsumer.accept(builderHaving);
|
||||
initSet.add(BUILDER_HAVING);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper build() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlFormatModel buildSql() {
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
SqlInfoSelectModel<BuildSelect> buildSelect = builderSelect.build();
|
||||
SqlInfoWhereModel<BuildWhere> buildWhere = builderWhere.buildWhere();
|
||||
SqlInfoOrderModel<BuildOrderBy> buildOrderBy = builderOrderBy.build();
|
||||
SqlInfoGroupModel<BuildDelete> buildGroupBy = builderGroupBy.build();
|
||||
SqlInfoJoinModel<SqlFormatModel> buildJoin = builderJoin.build();
|
||||
SqlInfoHavingModel<BuildHaving> buildHaving = builderHaving.buildHaving();
|
||||
|
||||
List<ISQLExpression> expressionList = new ArrayList<>();
|
||||
if (initSet.contains(BUILDER_SELECT)) {
|
||||
context.setSelectModel(buildSelect);
|
||||
expressionList.add(new BuildSelect());
|
||||
}
|
||||
if (initSet.contains(BUILDER_WHERE)) {
|
||||
context.setWhereModel(buildWhere);
|
||||
expressionList.add(new BuildWhere());
|
||||
}
|
||||
if (initSet.contains(BUILDER_ORDERBY)) {
|
||||
context.setOrderModel(buildOrderBy);
|
||||
expressionList.add(new BuildOrderBy());
|
||||
}
|
||||
if (initSet.contains(BUILDER_GROUPBY)) {
|
||||
context.setGroupModel(buildGroupBy);
|
||||
expressionList.add(new BuildGroupBy());
|
||||
}
|
||||
if (initSet.contains(BUILDER_JOIN)) {
|
||||
context.setJoinModel(buildJoin);
|
||||
expressionList.add(new BuildJoin());
|
||||
}
|
||||
if (initSet.contains(BUILDER_HAVING)) {
|
||||
context.setHavingModel(buildHaving);
|
||||
expressionList.add(new BuildHaving());
|
||||
}
|
||||
|
||||
if(FuncBase.isEmpty(expressionList)){
|
||||
return new SqlFormatModel();
|
||||
}
|
||||
List<SqlFormatModel> sqlFormatModelList = null;
|
||||
|
||||
ISQLExpression expression = new AndExpression(expressionList);
|
||||
if (initSet.contains(BUILDER_SELECT)) {
|
||||
sqlFormatModelList = SqlHelper.sqlExpression(context, expression);
|
||||
} else {
|
||||
sqlFormatModelList = SqlHelper.parserExpression(context, expression);
|
||||
}
|
||||
|
||||
return sqlFormatModelList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.build.buildmodel.wrapper;
|
||||
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.build.AndExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoUpdateModel;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoWhereModel;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildUpdate;
|
||||
import com.jeelowcode.framework.plus.build.build.dql.BuildWhere;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 更新-封装器
|
||||
*/
|
||||
public class SqlInfoUpdateWrapper {
|
||||
|
||||
public static Wrapper wrapper(String dbSchemaName){
|
||||
return new Wrapper(dbSchemaName);
|
||||
}
|
||||
public static class Wrapper extends BaseWrapper {
|
||||
|
||||
private String dbSchemaName;
|
||||
private SqlInfoUpdateModel.Builder builderUpdate=SqlInfoUpdateModel.builder();;
|
||||
private SqlInfoWhereModel.Builder builderWhere = SqlInfoWhereModel.builder();
|
||||
|
||||
public Wrapper(String dbSchemaName) {
|
||||
this.dbSchemaName = dbSchemaName;
|
||||
}
|
||||
|
||||
//update 相关
|
||||
public Wrapper setTableName(String tableName) {
|
||||
builderUpdate.setTableName(tableName);
|
||||
initSet.add(BUILDER_UPDATE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setColumn(String column, Object val){
|
||||
builderUpdate.addColumn(column,val);
|
||||
initSet.add(BUILDER_UPDATE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setMap(Map<String,Object> updateMap){
|
||||
builderUpdate.addMap(updateMap);
|
||||
initSet.add(BUILDER_UPDATE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Wrapper setWhere(Consumer<SqlInfoWhereModel.Builder> whereBuilderConsumer) {
|
||||
whereBuilderConsumer.accept(builderWhere);
|
||||
initSet.add(BUILDER_WHERE);
|
||||
return this;
|
||||
}
|
||||
public Wrapper build() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlFormatModel buildSql() {
|
||||
SQLInterpretContext context = new SQLInterpretContext(dbSchemaName);
|
||||
SqlInfoUpdateModel<BuildUpdate> buildUpdate = builderUpdate.build();
|
||||
SqlInfoWhereModel<BuildWhere> buildWhere = builderWhere.buildWhere();
|
||||
|
||||
List<ISQLExpression> expressionList=new ArrayList<>();
|
||||
if(initSet.contains(BUILDER_UPDATE)){
|
||||
context.setUpdateModel(buildUpdate);
|
||||
expressionList.add(new BuildUpdate());
|
||||
}
|
||||
if(initSet.contains(BUILDER_WHERE)){
|
||||
context.setWhereModel(buildWhere);
|
||||
expressionList.add(new BuildWhere());
|
||||
}
|
||||
ISQLExpression expression = new AndExpression(expressionList);
|
||||
List<SqlFormatModel> sqlFormatModelList = SqlHelper.sqlExpression(context, expression);
|
||||
return sqlFormatModelList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
|
||||
/**
|
||||
* 创建抽象的记录器类。
|
||||
*/
|
||||
public abstract class AbstractSQLParser {
|
||||
|
||||
public static int levelStandard = 3;//标准解析
|
||||
public static int levelDataPermissions = 2;//数据权限过滤
|
||||
public static int levelTenant = 1;//租户过滤
|
||||
|
||||
protected int level;
|
||||
protected AbstractSQLParser nextSQLParse;//下一个节点解析
|
||||
|
||||
|
||||
public void setNextSQLParse(AbstractSQLParser nextSQLParse) {
|
||||
this.nextSQLParse = nextSQLParse;
|
||||
}
|
||||
|
||||
public void processed(int level, SqlInfoEntity sqlInfoEntity) {
|
||||
if (this.level <= level) {
|
||||
sqlParse(sqlInfoEntity);
|
||||
}
|
||||
if (nextSQLParse != null) {
|
||||
nextSQLParse.processed(level, sqlInfoEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstract protected void sqlParse(SqlInfoEntity sqlInfoEntity);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain;
|
||||
|
||||
|
||||
public class SQLParserChain {
|
||||
private AbstractSQLParser sqlParserChain;
|
||||
|
||||
public AbstractSQLParser getSqlParserChain() {
|
||||
return sqlParserChain;
|
||||
}
|
||||
|
||||
public void setSqlParserChain(AbstractSQLParser... sqlParserChains) {
|
||||
sqlParserChain = sqlParserChains[0];//第一个
|
||||
|
||||
// 首先,检查是否有至少两个解析器,因为我们需要至少两个来设置链
|
||||
if (sqlParserChains == null || sqlParserChains.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 遍历解析器数组,设置每个解析器的下一个解析器
|
||||
for (int i = 0; i < sqlParserChains.length - 1; i++) {
|
||||
sqlParserChains[i].setNextSQLParse(sqlParserChains[i + 1]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.chain.parser.DataPermissionsSQLParser;
|
||||
import com.jeelowcode.framework.plus.chain.parser.StandardSQLParser;
|
||||
import com.jeelowcode.framework.plus.chain.parser.TenantSQLParser;
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
/**
|
||||
* 使用责任链
|
||||
*/
|
||||
public class SQLParserChainClient {
|
||||
|
||||
|
||||
//处理sql
|
||||
public static void sqlParser(SqlInfoEntity sqlInfoEntity){
|
||||
|
||||
//标准解析 -> 数据权限 -> 租户权限
|
||||
|
||||
//标准SQL
|
||||
AbstractSQLParser standardSQLParser = new StandardSQLParser(AbstractSQLParser.levelStandard);
|
||||
//数据权限
|
||||
AbstractSQLParser dataPermissionsSQLParser = new DataPermissionsSQLParser(AbstractSQLParser.levelDataPermissions);
|
||||
//租户权限
|
||||
AbstractSQLParser tenantSQLParser = new TenantSQLParser(AbstractSQLParser.levelTenant);
|
||||
|
||||
//单独要某一个
|
||||
Integer sqlParserLevel = sqlInfoEntity.getSqlParserLevel();
|
||||
if(FuncBase.isNotEmpty(sqlParserLevel)){
|
||||
switch (sqlParserLevel){
|
||||
case 3:
|
||||
standardSQLParser.processed(AbstractSQLParser.levelStandard,sqlInfoEntity);
|
||||
break;
|
||||
case 2:
|
||||
dataPermissionsSQLParser.processed(AbstractSQLParser.levelDataPermissions,sqlInfoEntity);
|
||||
break;
|
||||
case 1:
|
||||
tenantSQLParser.processed(AbstractSQLParser.levelTenant,sqlInfoEntity);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SQLParserChain sqlParserChain=new SQLParserChain();
|
||||
sqlParserChain.setSqlParserChain(standardSQLParser,dataPermissionsSQLParser,tenantSQLParser);
|
||||
AbstractSQLParser sqlParser = sqlParserChain.getSqlParserChain();
|
||||
|
||||
//先走标准sql解析
|
||||
sqlParser.processed(AbstractSQLParser.levelStandard, sqlInfoEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain.entity;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
*/
|
||||
public class DataPermissionFilterEntity {
|
||||
private boolean enable;///是否启动
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain.entity;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 租户权限相关
|
||||
*/
|
||||
public class TenantIdFilterEntity {
|
||||
private boolean enable;///是否启动
|
||||
|
||||
private Long tenantId;//租户id
|
||||
|
||||
private Set<String> ignoreTables; //不过滤的表
|
||||
|
||||
private Set<String> ignoreUrl;//不过滤的url
|
||||
|
||||
private boolean ignore;
|
||||
|
||||
|
||||
|
||||
public Long getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(Long tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public Set<String> getIgnoreTables() {
|
||||
return ignoreTables;
|
||||
}
|
||||
|
||||
public void setIgnoreTables(Set<String> ignoreTables) {
|
||||
this.ignoreTables = ignoreTables;
|
||||
}
|
||||
|
||||
public boolean isIgnore() {
|
||||
return ignore;
|
||||
}
|
||||
|
||||
public void setIgnore(boolean ignore) {
|
||||
this.ignore = ignore;
|
||||
}
|
||||
|
||||
public Set<String> getIgnoreUrl() {
|
||||
return ignoreUrl;
|
||||
}
|
||||
|
||||
public void setIgnoreUrl(Set<String> ignoreUrl) {
|
||||
this.ignoreUrl = ignoreUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain.parser;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.chain.AbstractSQLParser;
|
||||
import com.jeelowcode.framework.plus.chain.entity.DataPermissionFilterEntity;
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
*/
|
||||
public class DataPermissionsSQLParser extends AbstractSQLParser {
|
||||
|
||||
public DataPermissionsSQLParser(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sqlParse(SqlInfoEntity sqlInfoEntity) {
|
||||
try {
|
||||
DataPermissionFilterEntity dataPermissionFilterEntity = sqlInfoEntity.getDataPermissionFilterEntity();
|
||||
SqlFormatModel sqlFormatModel = sqlInfoEntity.getSqlModelList().get(0);
|
||||
if(FuncBase.isEmpty(sqlFormatModel)){
|
||||
return;
|
||||
}
|
||||
if (FuncBase.isEmpty(dataPermissionFilterEntity)) {
|
||||
return;
|
||||
}
|
||||
boolean enable = dataPermissionFilterEntity.isEnable();
|
||||
if (!enable) {//没有启动
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = sqlFormatModel.getSql();
|
||||
|
||||
String newSql = sql+" and deptId=1";
|
||||
|
||||
sqlFormatModel.setSql(newSql);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain.parser;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.build.ISQLExpression;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
|
||||
import com.jeelowcode.framework.plus.chain.AbstractSQLParser;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 标准sql解析
|
||||
*/
|
||||
public class StandardSQLParser extends AbstractSQLParser {
|
||||
|
||||
public StandardSQLParser(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sqlParse(SqlInfoEntity sqlInfoEntity) {
|
||||
try {
|
||||
ISQLExpression<SqlFormatModel> sqlExpression = sqlInfoEntity.getSqlExpression();
|
||||
if(FuncBase.isEmpty(sqlExpression)){
|
||||
return;
|
||||
}
|
||||
SQLInterpretContext context = sqlInfoEntity.getContext();
|
||||
if(FuncBase.isEmpty(context)){
|
||||
return;
|
||||
}
|
||||
DbColunmTypesEntity dbColunmTypes = context.getDbColunmTypes();
|
||||
|
||||
//处理数据库类型
|
||||
context.setDbColunmTypes(dbColunmTypes);
|
||||
|
||||
Object obj =sqlExpression.interpret(context);
|
||||
|
||||
List<SqlFormatModel> sqlFormatModelList=new ArrayList<>();
|
||||
if (FuncBase.isEmpty(obj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(obj instanceof SqlFormatModel){
|
||||
sqlFormatModelList.add((SqlFormatModel)obj);
|
||||
}else if(obj instanceof List){
|
||||
sqlFormatModelList.addAll((List<SqlFormatModel>)obj);
|
||||
}
|
||||
sqlInfoEntity.setSqlModelList(sqlFormatModelList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.chain.parser;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.chain.AbstractSQLParser;
|
||||
import com.jeelowcode.framework.plus.chain.entity.TenantIdFilterEntity;
|
||||
import com.jeelowcode.framework.plus.entity.SqlInfoEntity;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.tenant.utils.JeeLowCodeTenantUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 多租户
|
||||
*/
|
||||
public class TenantSQLParser extends AbstractSQLParser {
|
||||
|
||||
public TenantSQLParser(int level) {
|
||||
this.level=level;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sqlParse(SqlInfoEntity sqlInfoEntity) {
|
||||
try{
|
||||
TenantIdFilterEntity tenantIdFilterEntity = sqlInfoEntity.getTenantIdFilterEntity();
|
||||
if(FuncBase.isEmpty(tenantIdFilterEntity)){
|
||||
return;
|
||||
}
|
||||
|
||||
SqlFormatModel sqlFormatModel = sqlInfoEntity.getSqlModelList().get(0);
|
||||
if(FuncBase.isEmpty(sqlFormatModel)){
|
||||
return;
|
||||
}
|
||||
String sql = sqlFormatModel.getSql();
|
||||
|
||||
|
||||
Long tenantId = tenantIdFilterEntity.getTenantId();
|
||||
if(FuncBase.isEmpty(tenantId)){
|
||||
return;
|
||||
}
|
||||
boolean enable = tenantIdFilterEntity.isEnable();
|
||||
if(!enable){//没有启动
|
||||
return;
|
||||
}
|
||||
boolean ignore = tenantIdFilterEntity.isIgnore();
|
||||
|
||||
Set<String> ignoreTables = tenantIdFilterEntity.getIgnoreTables();
|
||||
Set<String> ignoreUrl = tenantIdFilterEntity.getIgnoreUrl();
|
||||
|
||||
JeeLowCodeTenantUtils.initIgnoreTables(ignoreTables);//初始化
|
||||
JeeLowCodeTenantUtils.initIgnoreUrl(ignoreUrl);
|
||||
boolean threadIgnore = JeeLowCodeTenantUtils.isIgnore();
|
||||
if(!threadIgnore){
|
||||
JeeLowCodeTenantUtils.setIgnore(ignore);//本次
|
||||
}
|
||||
|
||||
|
||||
JeeLowCodeTenantUtils.setTenantId(tenantId);
|
||||
String newSql = JeeLowCodeTenantUtils.parseTenantSql(sql);
|
||||
sqlFormatModel.setSql(newSql);
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.component;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.entity.DbColunmTypesEntity;
|
||||
import com.jeelowcode.framework.plus.entity.FieldModel;
|
||||
import com.jeelowcode.framework.plus.utils.PlusUtils;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.enums.YNEnum;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Order(2) // 指定DbManager的初始化顺序,确保它在SqlSessionFactory之后初始化
|
||||
@DependsOn("sqlSessionFactory") // 指定DbManager依赖于SqlSessionFactory
|
||||
public class DbManager {
|
||||
|
||||
@Autowired
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
@Bean
|
||||
public void initDbManager(){
|
||||
//初始化type
|
||||
initDbType();
|
||||
//初始化schema
|
||||
initDbSchema();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据库的元数据
|
||||
* @param primaryKeyResultSet
|
||||
* @param set
|
||||
* @return
|
||||
*/
|
||||
public Map<String, FieldModel> formatMetaData(ResultSet primaryKeyResultSet, ResultSet set,Map<String,String> remarkMap) {
|
||||
|
||||
Map<String,FieldModel> resultMap=new LinkedHashMap<>();
|
||||
try{
|
||||
//获取主键
|
||||
Set<String> primaryKeySet=new HashSet<>();
|
||||
while (primaryKeyResultSet.next()) {
|
||||
String columnName = primaryKeyResultSet.getString("COLUMN_NAME");
|
||||
if(FuncBase.isEmpty(columnName)){
|
||||
continue;
|
||||
}
|
||||
primaryKeySet.add(columnName.toLowerCase());
|
||||
}
|
||||
|
||||
DbColunmTypesEntity dbColunmTypesEntity = SqlHelper.getDbColunmTypesEntity();
|
||||
|
||||
while (set.next()) {
|
||||
FieldModel fieldModel=new FieldModel();
|
||||
|
||||
String fieldCode = set.getString("COLUMN_NAME").toLowerCase();
|
||||
fieldModel.setFieldCode(fieldCode);//字段
|
||||
|
||||
if(FuncBase.isNotEmpty(remarkMap)){
|
||||
fieldModel.setFieldName(remarkMap.get(fieldCode));//字段名称
|
||||
}else{
|
||||
String fieldName = set.getString("REMARKS");
|
||||
fieldModel.setFieldName(fieldName);//字段名称
|
||||
}
|
||||
|
||||
|
||||
Integer fieldLen = set.getInt("COLUMN_SIZE");//大小
|
||||
fieldModel.setFieldLen(fieldLen);//长度
|
||||
|
||||
Integer fieldPointLen = set.getInt("DECIMAL_DIGITS");//小数
|
||||
fieldModel.setFieldPointLen(FuncBase.isEmpty(fieldPointLen)?0:fieldPointLen);
|
||||
|
||||
String fieldDefaultVal = set.getString("COLUMN_DEF");
|
||||
fieldModel.setFieldDefaultVal(fieldDefaultVal);//字段默认值
|
||||
|
||||
String dbType = set.getString("TYPE_NAME");
|
||||
List<DbColunmTypesEntity.TypeEntity> fieldTypeList = PlusUtils.dbType2JeelowCodeTypeList(dbType, dbColunmTypesEntity);
|
||||
|
||||
List<JeeLowCodeFieldTypeEnum> fieldTypeEnumList=new ArrayList<>();
|
||||
for(DbColunmTypesEntity.TypeEntity entityType:fieldTypeList){
|
||||
JeeLowCodeFieldTypeEnum fieldType = JeeLowCodeFieldTypeEnum.getByFieldType(entityType.getJeeLowCodeType());
|
||||
fieldTypeEnumList.add(fieldType);
|
||||
}
|
||||
|
||||
fieldModel.setJavaFieldTypeList(fieldTypeEnumList);
|
||||
|
||||
fieldModel.setMaxFieldLen(fieldTypeList.get(0).getDbMaxLen());//数据库类型一样,长度也是一样
|
||||
fieldModel.setMaxPointLen(fieldTypeList.get(0).getDbMaxPointLen());//小数位
|
||||
|
||||
fieldModel.setIsPrimaryKey(primaryKeySet.contains(fieldCode)? YNEnum.Y.getCode():YNEnum.N.getCode());//是否是主键
|
||||
|
||||
String isNull = set.getInt("NULLABLE") == 1 ? YNEnum.Y.getCode() : YNEnum.N.getCode();//是
|
||||
fieldModel.setIsNull(isNull);
|
||||
|
||||
resultMap.put(fieldCode,fieldModel);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取现有数据库的元数据
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public Map<String, FieldModel> getDbColumnMetaMap(String tableName,Map<String,String> remarkMap) {
|
||||
DbColunmTypesEntity dbColunmTypesEntity = SqlHelper.getDbColunmTypesEntity();
|
||||
Boolean upperFlag = dbColunmTypesEntity.getUpperFlag();
|
||||
if(FuncBase.isNotEmpty(upperFlag) && upperFlag){
|
||||
tableName=tableName.toUpperCase();
|
||||
}
|
||||
try (SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||
Connection connection = sqlSession.getConnection()) {
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
//获取主键
|
||||
ResultSet primaryKeyResultSet = metaData.getPrimaryKeys(connection.getCatalog(), connection.getSchema(), tableName);
|
||||
ResultSet set = metaData.getColumns(connection.getCatalog(), connection.getSchema(), tableName, "%");
|
||||
Map<String, FieldModel> metaDataMap = formatMetaData(primaryKeyResultSet, set,remarkMap);
|
||||
return metaDataMap;
|
||||
} catch (SQLException e) {
|
||||
throw new JeeLowCodeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取新增列
|
||||
* @param tableName
|
||||
* @param fieldModelList
|
||||
* @param columnMetaMap
|
||||
* @return
|
||||
*/
|
||||
public List<String> getAddColumnDdl(String tableName, List<FieldModel> fieldModelList, Map<String, FieldModel> columnMetaMap) {
|
||||
List<String> ddlList = new ArrayList<>();
|
||||
for (FieldModel fieldModel : fieldModelList) {
|
||||
String fieldCode = fieldModel.getFieldCode();
|
||||
if (columnMetaMap.containsKey(fieldCode)) {//已存在,不走新增
|
||||
continue;
|
||||
}
|
||||
List<String> tmpDdlList = SqlHelper.addColumn(tableName, fieldModel);
|
||||
ddlList.addAll(tmpDdlList);
|
||||
}
|
||||
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取修改ddl列表
|
||||
* @param tableName
|
||||
* @param fieldModelList
|
||||
* @param columnMetaMap
|
||||
* @return
|
||||
*/
|
||||
public List<String> getUpdateColumnDdl(String tableName, List<FieldModel> fieldModelList, Map<String, FieldModel> columnMetaMap) {
|
||||
List<String> ddlList = new ArrayList<>();
|
||||
for (FieldModel fieldModel : fieldModelList) {
|
||||
String fieldCode = fieldModel.getFieldCode();
|
||||
Integer fieldLen = fieldModel.getFieldLen();
|
||||
Integer fieldPointLen = fieldModel.getFieldPointLen();
|
||||
if (!columnMetaMap.containsKey(fieldCode)) {//不存在
|
||||
continue;
|
||||
}
|
||||
//数据库的
|
||||
FieldModel dbFieldModel = columnMetaMap.get(fieldCode);
|
||||
Integer maxFieldLen = dbFieldModel.getMaxFieldLen();//有最大长度
|
||||
Integer maxPointLen = dbFieldModel.getMaxPointLen();//小数位
|
||||
|
||||
boolean lenFlag=false;//整型位长度
|
||||
boolean pointLenFlag=false;//小数位长度
|
||||
if(FuncBase.isNotEmpty(maxFieldLen) && maxFieldLen>0){
|
||||
if(fieldLen>maxFieldLen){//保证和当前输入的一样长度
|
||||
dbFieldModel.setFieldLen(fieldLen);
|
||||
}
|
||||
if(FuncBase.equals(dbFieldModel.getFieldPointLen(), fieldLen)){
|
||||
lenFlag=true;
|
||||
}
|
||||
//校验小数位长度
|
||||
if(FuncBase.isNotEmpty(maxPointLen)){//需要对长度进行校验
|
||||
if(fieldPointLen>maxPointLen){//保证和当前输入的一样长度,下面则是true
|
||||
dbFieldModel.setMaxPointLen(maxPointLen);
|
||||
}
|
||||
if(FuncBase.equals(dbFieldModel.getFieldPointLen(), fieldPointLen)){
|
||||
pointLenFlag=true;
|
||||
}
|
||||
}else{
|
||||
pointLenFlag=true;
|
||||
}
|
||||
}else{//0说明不要对长度进行校验,设置和输入的一样就可以了
|
||||
lenFlag=true;//不用对长度进行校验
|
||||
pointLenFlag=true;
|
||||
}
|
||||
|
||||
fieldModel.setDbNowIsNull(dbFieldModel.getIsNull());//当前状态的
|
||||
|
||||
boolean typeFlag=false;
|
||||
List<JeeLowCodeFieldTypeEnum> fieldTypeList = dbFieldModel.getJavaFieldTypeList();
|
||||
for(JeeLowCodeFieldTypeEnum fieldTypeEnum:fieldTypeList){
|
||||
if(FuncBase.equals(fieldTypeEnum, fieldModel.getFieldType())){
|
||||
typeFlag=true;//一样
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//判断是否一致
|
||||
if (!FuncBase.equals(dbFieldModel.getFieldName(), fieldModel.getFieldName()) ||
|
||||
!lenFlag ||
|
||||
!pointLenFlag ||
|
||||
!FuncBase.equals(dbFieldModel.getFieldName(), fieldModel.getFieldName()) ||
|
||||
!typeFlag ||
|
||||
!FuncBase.equals(dbFieldModel.getIsPrimaryKey(), fieldModel.getIsPrimaryKey()) ||
|
||||
!FuncBase.equals(dbFieldModel.getIsNull(), fieldModel.getIsNull())) {
|
||||
List<String> tmpDdlList = SqlHelper.modifyColumnSql(tableName, fieldModel);
|
||||
ddlList.addAll(tmpDdlList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取删除ddl列表
|
||||
* @param tableName
|
||||
* @param fieldModelList
|
||||
* @param columnMetaMap
|
||||
* @return
|
||||
*/
|
||||
public List<String> getDropColumnDdl(String tableName, List<FieldModel> fieldModelList, Map<String, FieldModel> columnMetaMap) {
|
||||
|
||||
|
||||
|
||||
Set<String> fieldCodeSet = fieldModelList.stream()
|
||||
.map(FieldModel::getFieldCode)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
|
||||
List<String> ddlList = columnMetaMap.entrySet().stream()
|
||||
.filter(entry -> !fieldCodeSet.contains(entry.getKey()))
|
||||
.map(entry ->SqlHelper.getDropColumnSql(tableName,entry.getKey()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ddlList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initDbType(){
|
||||
String dbType="mysql";
|
||||
try (SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||
Connection connection = sqlSession.getConnection()) {
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
dbType = databaseProductName.toLowerCase();
|
||||
}catch (Exception e){
|
||||
throw new JeeLowCodeException("获取数据库类型失败");
|
||||
}
|
||||
SqlHelper.setDbType(dbType);
|
||||
}
|
||||
|
||||
private void initDbSchema(){
|
||||
try (SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||
Connection connection = sqlSession.getConnection()) {
|
||||
String dbSchemaName = connection.getCatalog();
|
||||
if(FuncBase.isEmpty(dbSchemaName)){
|
||||
dbSchemaName = connection.getSchema();
|
||||
}
|
||||
if(FuncBase.isEmpty(dbSchemaName)){
|
||||
throw new JeeLowCodeException("获取数据库 schema 失败");
|
||||
}
|
||||
SqlHelper.setDbSchemaName(dbSchemaName);
|
||||
}catch (Exception e){
|
||||
throw new JeeLowCodeException("获取数据库 schema 失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,允许商用使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与本软件竞争的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.component;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import org.apache.ibatis.builder.StaticSqlSource;
|
||||
import org.apache.ibatis.cache.CacheKey;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.*;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.jeelowcode.framework.global.JeeLowCodeBaseConstant.BASE_PACKAGES_CODE;
|
||||
|
||||
|
||||
@Component
|
||||
@Intercepts({@Signature(
|
||||
type = Executor.class,
|
||||
method = "update",
|
||||
args = {MappedStatement.class, Object.class}
|
||||
), @Signature(
|
||||
type = Executor.class,
|
||||
method = "query",
|
||||
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
|
||||
), @Signature(
|
||||
type = Executor.class,
|
||||
method = "query",
|
||||
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}
|
||||
)})
|
||||
public class JeelowCodePlusInterceptor implements Interceptor {
|
||||
|
||||
private List<String> getSkipMapperList(){//todo 后面需要优化
|
||||
String SKIP_MAPPER_CODE = BASE_PACKAGES_CODE+".framework.mapper";//不做租户拦截的mapper
|
||||
|
||||
|
||||
List<String> skipMapperList=new ArrayList<>();
|
||||
skipMapperList.add(SKIP_MAPPER_CODE);
|
||||
return skipMapperList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
Object target = invocation.getTarget();
|
||||
Object[] args = invocation.getArgs();
|
||||
if (!(target instanceof Executor)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
|
||||
Executor executor = (Executor) target;
|
||||
Object parameter = args[1];
|
||||
boolean isUpdate = args.length == 2;
|
||||
MappedStatement ms = (MappedStatement) args[0];
|
||||
String id = ms.getId();
|
||||
List<String> skipMapperList = getSkipMapperList();
|
||||
for(String skipMapper:skipMapperList){
|
||||
if(id.startsWith(skipMapper)){
|
||||
return invocation.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
if (!id.startsWith(BASE_PACKAGES_CODE)) {//直接跳过,如果不是低代码平台,则直接跳过
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
if (!isUpdate && ms.getSqlCommandType() == SqlCommandType.SELECT) {//查询相关
|
||||
RowBounds rowBounds = (RowBounds) args[2];
|
||||
ResultHandler resultHandler = (ResultHandler) args[3];
|
||||
BoundSql boundSql;
|
||||
if (args.length == 4) {
|
||||
boundSql = ms.getBoundSql(parameter);
|
||||
} else {
|
||||
boundSql = (BoundSql) args[5];
|
||||
}
|
||||
|
||||
String publicSql = SqlHelper.getPublicSql(boundSql.getSql());
|
||||
Object additionalParametersObj = boundSql.getAdditionalParameters();
|
||||
boundSql = new BoundSql(ms.getConfiguration(), publicSql, boundSql.getParameterMappings(), boundSql.getParameterObject());
|
||||
if (FuncBase.isNotEmpty(additionalParametersObj)) {
|
||||
Map<String,Object> additionalParameters = (Map<String,Object>) additionalParametersObj;
|
||||
|
||||
Iterator<Map.Entry<String, Object>> iterator = additionalParameters.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> next = iterator.next();
|
||||
String key = next.getKey();
|
||||
Object value = next.getValue();
|
||||
boundSql.setAdditionalParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
CacheKey cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
|
||||
List<Object> query = null;
|
||||
try {
|
||||
query = executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return query;
|
||||
|
||||
}
|
||||
if (isUpdate) {
|
||||
SqlSource sqlSource = ms.getSqlSource();
|
||||
try {
|
||||
BoundSql boundSql = sqlSource.getBoundSql(parameter);
|
||||
String publicSql = SqlHelper.getPublicSql(boundSql.getSql());
|
||||
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
|
||||
SqlSource newSqlSource = new StaticSqlSource(ms.getConfiguration(), publicSql, parameterMappings);
|
||||
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType());
|
||||
this.copyBuilder(builder, ms);
|
||||
MappedStatement build = builder.build();
|
||||
|
||||
return executor.update(build, parameter);
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return invocation.proceed();
|
||||
|
||||
}
|
||||
|
||||
//复制属性
|
||||
private void copyBuilder(MappedStatement.Builder builder, MappedStatement ms) {
|
||||
builder.resource(ms.getResource());
|
||||
builder.fetchSize(ms.getFetchSize());
|
||||
builder.timeout(ms.getTimeout());
|
||||
builder.statementType(ms.getStatementType());
|
||||
builder.resultSetType(ms.getResultSetType());
|
||||
builder.cache(ms.getCache());
|
||||
builder.parameterMap(ms.getParameterMap());
|
||||
builder.resultMaps(ms.getResultMaps());
|
||||
builder.flushCacheRequired(ms.isFlushCacheRequired());
|
||||
builder.useCache(ms.isUseCache());
|
||||
builder.resultOrdered(ms.isResultOrdered());
|
||||
builder.keyGenerator(ms.getKeyGenerator());
|
||||
if (FuncBase.isNotEmpty(ms.getKeyProperties())) {
|
||||
builder.keyProperty(ms.getKeyProperties()[0]);
|
||||
}
|
||||
if (FuncBase.isNotEmpty(ms.getKeyColumns())) {
|
||||
builder.keyColumn(ms.getKeyColumns()[0]);
|
||||
}
|
||||
builder.databaseId(ms.getDatabaseId());
|
||||
builder.lang(ms.getLang());
|
||||
if (FuncBase.isNotEmpty(ms.getResultSets())) {
|
||||
builder.resultSets(ms.getResultSets()[0]);
|
||||
}
|
||||
|
||||
builder.dirtySelect(ms.isDirtySelect());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,765 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.interfaces.Compare;
|
||||
import com.jeelowcode.framework.plus.core.conditions.interfaces.Func;
|
||||
import com.jeelowcode.framework.plus.core.conditions.interfaces.Join;
|
||||
import com.jeelowcode.framework.plus.core.conditions.interfaces.Nested;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.ColumnSegment;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlLike;
|
||||
import com.jeelowcode.framework.plus.core.enums.WrapperKeyword;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.*;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.sql.SqlUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2017-05-26
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public abstract class AbstractWrapper<T, R, Children extends AbstractWrapper<T, R, Children>> extends Wrapper<T>
|
||||
implements Compare<Children, R>, Nested<Children, Children>, Join<Children>, Func<Children, R> {
|
||||
|
||||
/**
|
||||
* 占位符
|
||||
*/
|
||||
protected final Children typedThis = (Children) this;
|
||||
/**
|
||||
* 必要度量
|
||||
*/
|
||||
protected AtomicInteger paramNameSeq;
|
||||
|
||||
protected Map<String, Object> paramNameValuePairs;
|
||||
/**
|
||||
* 其他
|
||||
*/
|
||||
protected SharedString paramAlias;
|
||||
protected SharedString lastSql;
|
||||
/**
|
||||
* SQL注释
|
||||
*/
|
||||
protected SharedString sqlComment;
|
||||
/**
|
||||
* SQL起始语句
|
||||
*/
|
||||
protected SharedString sqlFirst;
|
||||
/**
|
||||
* 数据库表映射实体类
|
||||
*/
|
||||
private T entity;
|
||||
protected MergeSegments expression;
|
||||
/**
|
||||
* 实体类型(主要用于确定泛型以及取TableInfo缓存)
|
||||
*/
|
||||
private Class<T> entityClass;
|
||||
|
||||
@Override
|
||||
public T getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Children setEntity(T entity) {
|
||||
this.entity = entity;
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public Class<T> getEntityClass() {
|
||||
if (entityClass == null && entity != null) {
|
||||
entityClass = (Class<T>) entity.getClass();
|
||||
}
|
||||
return entityClass;
|
||||
}
|
||||
|
||||
public Children setEntityClass(Class<T> entityClass) {
|
||||
if (entityClass != null) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> Children allEq(boolean condition, Map<R, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
isNull(k);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> Children allEq(boolean condition, BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (filter.test(k, v)) {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
isNull(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children eq(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.EQ, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children ne(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.NE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children gt(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.GT, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children ge(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.GE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children lt(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.LT, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children le(boolean condition, R column, Object val) {
|
||||
return addCondition(condition, column, SqlKeyword.LE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children like(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.LIKE, column, val, SqlLike.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notLike(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.NOT_LIKE, column, val, SqlLike.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children likeLeft(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.LIKE, column, val, SqlLike.LEFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children likeRight(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.LIKE, column, val, SqlLike.RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notLikeLeft(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.NOT_LIKE, column, val, SqlLike.LEFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notLikeRight(boolean condition, R column, Object val) {
|
||||
return likeValue(condition, SqlKeyword.NOT_LIKE, column, val, SqlLike.RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children between(boolean condition, R column, Object val1, Object val2) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.BETWEEN,
|
||||
() -> formatParam(null, val1), SqlKeyword.AND, () -> formatParam(null, val2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notBetween(boolean condition, R column, Object val1, Object val2) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.NOT_BETWEEN,
|
||||
() -> formatParam(null, val1), SqlKeyword.AND, () -> formatParam(null, val2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children and(boolean condition, Consumer<Children> consumer) {
|
||||
return and(condition).addNestedCondition(condition, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children or(boolean condition, Consumer<Children> consumer) {
|
||||
return or(condition).addNestedCondition(condition, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children nested(boolean condition, Consumer<Children> consumer) {
|
||||
return addNestedCondition(condition, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children not(boolean condition, Consumer<Children> consumer) {
|
||||
return not(condition).addNestedCondition(condition, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children or(boolean condition) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.OR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children apply(boolean condition, String applySql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(WrapperKeyword.APPLY, () -> formatSqlMaybeWithParam(applySql, values)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children last(boolean condition, String lastSql) {
|
||||
if (condition) {
|
||||
this.lastSql.setStringValue(StringPool.SPACE + lastSql);
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children comment(boolean condition, String comment) {
|
||||
if (condition) {
|
||||
this.sqlComment.setStringValue(comment);
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children first(boolean condition, String firstSql) {
|
||||
if (condition) {
|
||||
this.sqlFirst.setStringValue(firstSql);
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children exists(boolean condition, String existsSql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.EXISTS,
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, values))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notExists(boolean condition, String existsSql, Object... values) {
|
||||
return not(condition).exists(condition, existsSql, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children isNull(boolean condition, R column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.IS_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children isNotNull(boolean condition, R column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.IS_NOT_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children in(boolean condition, R column, Collection<?> coll) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.IN, inExpression(coll)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children in(boolean condition, R column, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.IN, inExpression(values)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notIn(boolean condition, R column, Collection<?> coll) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.NOT_IN, inExpression(coll)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notIn(boolean condition, R column, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.NOT_IN, inExpression(values)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children inSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.IN,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children gtSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.GT,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children geSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.GE,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children ltSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.LT,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children leSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.LE,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children notInSql(boolean condition, R column, String inValue) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), SqlKeyword.NOT_IN,
|
||||
() -> String.format("(%s)", inValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children groupBy(boolean condition, R column, R... columns) {
|
||||
return doGroupBy(condition, column, CollectionUtils.toList(columns));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children groupBy(boolean condition, R column, List<R> columns) {
|
||||
return doGroupBy(condition, column, columns);
|
||||
}
|
||||
|
||||
public Children doGroupBy(boolean condition, R column, List<R> columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
String one = StringPool.EMPTY;
|
||||
if (column != null) {
|
||||
one = columnToString(column);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(columns)) {
|
||||
one += column != null ? StringPool.COMMA + columnsToString(columns) : columnsToString(columns);
|
||||
}
|
||||
final String finalOne = one;
|
||||
appendSqlSegments(SqlKeyword.GROUP_BY, () -> finalOne);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Children doOrderBy(boolean condition, boolean isAsc, R column, List<R> columns) {
|
||||
return maybeDo(condition, () -> {
|
||||
final SqlKeyword mode = isAsc ? SqlKeyword.ASC : SqlKeyword.DESC;
|
||||
if (column != null) {
|
||||
appendSqlSegments(SqlKeyword.ORDER_BY, columnToSqlSegment(column), mode);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(columns)) {
|
||||
columns.forEach(c -> appendSqlSegments(SqlKeyword.ORDER_BY,
|
||||
columnToSqlSegment(c), mode));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderBy(boolean condition, boolean isAsc, R column, R... columns) {
|
||||
return doOrderBy(condition, isAsc, column, CollectionUtils.toList(columns));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderBy(boolean condition, boolean isAsc, R column, List<R> columns) {
|
||||
return doOrderBy(condition, isAsc, column, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children groupBy(boolean condition, R column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.GROUP_BY, () -> columnToString(column)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children groupBy(boolean condition, List<R> columns) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.GROUP_BY, () -> columnsToString(columns)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderBy(boolean condition, boolean isAsc, R column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.ORDER_BY, columnToSqlSegment(column),
|
||||
isAsc ? SqlKeyword.ASC : SqlKeyword.DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children orderBy(boolean condition, boolean isAsc, List<R> columns) {
|
||||
return maybeDo(condition, () -> columns.forEach(c -> appendSqlSegments(SqlKeyword.ORDER_BY,
|
||||
columnToSqlSegment(c), isAsc ? SqlKeyword.ASC : SqlKeyword.DESC)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children having(boolean condition, String sqlHaving, Object... params) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.HAVING, () -> formatSqlMaybeWithParam(sqlHaving, params)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children func(boolean condition, Consumer<Children> consumer) {
|
||||
return maybeDo(condition, () -> consumer.accept(typedThis));
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部自用
|
||||
* <p>NOT 关键词</p>
|
||||
*/
|
||||
protected Children not(boolean condition) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.NOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部自用
|
||||
* <p>拼接 AND</p>
|
||||
*/
|
||||
protected Children and(boolean condition) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(SqlKeyword.AND));
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部自用
|
||||
* <p>拼接 LIKE 以及 值</p>
|
||||
*/
|
||||
protected Children likeValue(boolean condition, SqlKeyword keyword, R column, Object val, SqlLike sqlLike) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), keyword,
|
||||
() -> formatParam(null, SqlUtils.concatLike(val, sqlLike))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通查询条件
|
||||
*
|
||||
* @param condition 是否执行
|
||||
* @param column 属性
|
||||
* @param sqlKeyword SQL 关键词
|
||||
* @param val 条件值
|
||||
*/
|
||||
protected Children addCondition(boolean condition, R column, SqlKeyword sqlKeyword, Object val) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), sqlKeyword,
|
||||
() -> formatParam(null, val)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 多重嵌套查询条件
|
||||
*
|
||||
* @param condition 查询条件值
|
||||
*/
|
||||
protected Children addNestedCondition(boolean condition, Consumer<Children> consumer) {
|
||||
return maybeDo(condition, () -> {
|
||||
final Children instance = instance();
|
||||
consumer.accept(instance);
|
||||
appendSqlSegments(WrapperKeyword.APPLY, instance);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类返回一个自己的新对象
|
||||
*/
|
||||
protected abstract Children instance();
|
||||
|
||||
/**
|
||||
* 格式化 sql
|
||||
* <p>
|
||||
* 支持 "{0}" 这种,或者 "sql {0} sql" 这种
|
||||
* 也支持 "sql {0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler} sql" 这种
|
||||
*
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param params 参数
|
||||
* @return sql片段
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StringUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (FuncBase.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理入参
|
||||
*
|
||||
* @param mapping 例如: "javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler" 这种
|
||||
* @param param 参数
|
||||
* @return value
|
||||
*/
|
||||
protected final String formatParam(String mapping, Object param) {
|
||||
final String genParamName = Constants.WRAPPER_PARAM + paramNameSeq.incrementAndGet();
|
||||
final String paramStr = getParamAlias() + Constants.WRAPPER_PARAM_MIDDLE + genParamName;
|
||||
paramNameValuePairs.put(genParamName, param);
|
||||
return SqlScriptUtils.safeParam(paramStr, mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数化的做事
|
||||
*
|
||||
* @param condition 做不做
|
||||
* @param something 做什么
|
||||
* @return Children
|
||||
*/
|
||||
protected final Children maybeDo(boolean condition, DoSomething something) {
|
||||
if (condition) {
|
||||
something.doIt();
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取in表达式 包含括号
|
||||
*
|
||||
* @param value 集合
|
||||
*/
|
||||
protected ISqlSegment inExpression(Collection<?> value) {
|
||||
if (CollectionUtils.isEmpty(value)) {
|
||||
return () -> "()";
|
||||
}
|
||||
return () -> value.stream().map(i -> formatParam(null, i))
|
||||
.collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取in表达式 包含括号
|
||||
*
|
||||
* @param values 数组
|
||||
*/
|
||||
protected ISqlSegment inExpression(Object[] values) {
|
||||
if (FuncBase.isEmpty(values)) {
|
||||
return () -> "()";
|
||||
}
|
||||
return () -> Arrays.stream(values).map(i -> formatParam(null, i))
|
||||
.collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
|
||||
}
|
||||
|
||||
/**
|
||||
* 必要的初始化
|
||||
*/
|
||||
protected void initNeed() {
|
||||
paramNameSeq = new AtomicInteger(0);
|
||||
paramNameValuePairs = new HashMap<>(16);
|
||||
expression = new MergeSegments();
|
||||
lastSql = SharedString.emptyString();
|
||||
sqlComment = SharedString.emptyString();
|
||||
sqlFirst = SharedString.emptyString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
entity = null;
|
||||
paramNameSeq.set(0);
|
||||
paramNameValuePairs.clear();
|
||||
expression.clear();
|
||||
lastSql.toEmpty();
|
||||
sqlComment.toEmpty();
|
||||
sqlFirst.toEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加 where 片段
|
||||
*
|
||||
* @param sqlSegments ISqlSegment 数组
|
||||
*/
|
||||
protected void appendSqlSegments(ISqlSegment... sqlSegments) {
|
||||
expression.add(sqlSegments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否使用默认注 排序
|
||||
*
|
||||
* @return true 使用 false 不使用
|
||||
*/
|
||||
public boolean isUseAnnotationOrderBy() {
|
||||
final String _sqlSegment = this.getSqlSegment();
|
||||
if (StringUtils.isBlank(_sqlSegment)) {
|
||||
return true;
|
||||
}
|
||||
final String _sqlSegmentUpper = _sqlSegment.toUpperCase();
|
||||
return !(_sqlSegmentUpper.contains(Constants.ORDER_BY) || _sqlSegmentUpper.contains(Constants.LIMIT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSqlSegment() {
|
||||
return expression.getSqlSegment() + lastSql.getStringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSqlComment() {
|
||||
if (StringUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
return "/*" + sqlComment.getStringValue() + "*/";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSqlFirst() {
|
||||
if (StringUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
return sqlFirst.getStringValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeSegments getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public String getParamAlias() {
|
||||
return paramAlias == null ? Constants.WRAPPER : paramAlias.getStringValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数别名设置,初始化时优先设置该值、重复设置异常
|
||||
*
|
||||
* @param paramAlias 参数别名
|
||||
* @return Children
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public Children setParamAlias(String paramAlias) {
|
||||
Assert.notEmpty(paramAlias, "paramAlias can not be empty!");
|
||||
Assert.isEmpty(paramNameValuePairs, "Please call this method before working!");
|
||||
Assert.isNull(this.paramAlias, "Please do not call the method repeatedly!");
|
||||
this.paramAlias = new SharedString(paramAlias);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 columnName
|
||||
*/
|
||||
protected final ColumnSegment columnToSqlSegment(R column) {
|
||||
return () -> columnToString(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 columnName
|
||||
*/
|
||||
protected String columnToString(R column) {
|
||||
return (String) column;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 columnNames
|
||||
*/
|
||||
protected String columnsToString(R... columns) {
|
||||
return Arrays.stream(columns).map(this::columnToString).collect(joining(StringPool.COMMA));
|
||||
}
|
||||
|
||||
/**
|
||||
* 多字段转换为逗号 "," 分割字符串
|
||||
*
|
||||
* @param columns 多字段
|
||||
*/
|
||||
protected String columnsToString(List<R> columns) {
|
||||
return columns.stream().map(this::columnToString).collect(joining(StringPool.COMMA));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public Children clone() {
|
||||
return SerializationUtils.clone(typedThis);
|
||||
}
|
||||
|
||||
/**
|
||||
* 做事函数
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DoSomething {
|
||||
|
||||
void doIt();
|
||||
}
|
||||
|
||||
public Children getTypedThis() {
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public AtomicInteger getParamNameSeq() {
|
||||
return paramNameSeq;
|
||||
}
|
||||
|
||||
public void setParamNameSeq(AtomicInteger paramNameSeq) {
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParamNameValuePairs() {
|
||||
return paramNameValuePairs;
|
||||
}
|
||||
|
||||
public void setParamNameValuePairs(Map<String, Object> paramNameValuePairs) {
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
}
|
||||
|
||||
public void setParamAlias(SharedString paramAlias) {
|
||||
this.paramAlias = paramAlias;
|
||||
}
|
||||
|
||||
public SharedString getLastSql() {
|
||||
return lastSql;
|
||||
}
|
||||
|
||||
public void setLastSql(SharedString lastSql) {
|
||||
this.lastSql = lastSql;
|
||||
}
|
||||
|
||||
public void setSqlComment(SharedString sqlComment) {
|
||||
this.sqlComment = sqlComment;
|
||||
}
|
||||
|
||||
public void setSqlFirst(SharedString sqlFirst) {
|
||||
this.sqlFirst = sqlFirst;
|
||||
}
|
||||
|
||||
public void setExpression(MergeSegments expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 9:51
|
||||
* @dedescription:
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ISqlSegment extends Serializable {
|
||||
|
||||
/**
|
||||
* SQL 片段
|
||||
*/
|
||||
String getSqlSegment();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 共享查询字段
|
||||
*
|
||||
* @author miemie
|
||||
* @since 2018-11-20
|
||||
*/
|
||||
public class SharedString implements Serializable {
|
||||
private static final long serialVersionUID = -1536422416594422874L;
|
||||
|
||||
/**
|
||||
* 共享的 string 值
|
||||
*/
|
||||
private String stringValue;
|
||||
|
||||
/**
|
||||
* SharedString 里是 ""
|
||||
*/
|
||||
public static SharedString emptyString() {
|
||||
return new SharedString(StringPool.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 置 empty
|
||||
*
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public void toEmpty() {
|
||||
stringValue = StringPool.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 置 null
|
||||
*
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public void toNull() {
|
||||
stringValue = null;
|
||||
}
|
||||
|
||||
public SharedString() {
|
||||
|
||||
}
|
||||
|
||||
public SharedString(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.NormalSegmentList;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.Constants;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 9:53
|
||||
* @dedescription:
|
||||
*/
|
||||
public abstract class Wrapper<T> implements ISqlSegment {
|
||||
|
||||
/**
|
||||
* 实体对象(子类实现)
|
||||
*
|
||||
* @return 泛型 T
|
||||
*/
|
||||
public abstract T getEntity();
|
||||
|
||||
public String getSqlSelect() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSqlSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSqlComment() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSqlFirst() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MergeSegments
|
||||
*/
|
||||
public abstract MergeSegments getExpression();
|
||||
|
||||
/**
|
||||
* 获取自定义SQL 简化自定义XML复杂情况
|
||||
* <p>
|
||||
* 使用方法: `select xxx from table` + ${ew.customSqlSegment}
|
||||
* <p>
|
||||
* 注意事项:
|
||||
* 1. 逻辑删除需要自己拼接条件 (之前自定义也同样)
|
||||
* 2. 不支持wrapper中附带实体的情况 (wrapper自带实体会更麻烦)
|
||||
* 3. 用法 ${ew.customSqlSegment} (不需要where标签包裹,切记!)
|
||||
* 4. ew是wrapper定义别名,不能使用其他的替换
|
||||
*/
|
||||
public String getCustomSqlSegment() {
|
||||
MergeSegments expression = getExpression();
|
||||
if (Objects.nonNull(expression)) {
|
||||
NormalSegmentList normal = expression.getNormal();
|
||||
String sqlSegment = getSqlSegment();
|
||||
if (StringUtils.isNotBlank(sqlSegment)) {
|
||||
if (normal.isEmpty()) {
|
||||
return sqlSegment;
|
||||
} else {
|
||||
return Constants.WHERE + StringPool.SPACE + sqlSegment;
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
|
||||
public String getHavingCustomSqlSegment() {
|
||||
MergeSegments expression = getExpression();
|
||||
if (Objects.nonNull(expression)) {
|
||||
NormalSegmentList normal = expression.getNormal();
|
||||
String sqlSegment = getSqlSegment();
|
||||
if (StringUtils.isNotBlank(sqlSegment)) {
|
||||
if (normal.isEmpty()) {
|
||||
return sqlSegment;
|
||||
} else {
|
||||
return Constants.HAVING + StringPool.SPACE + sqlSegment;
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
|
||||
//和上面一样,只是不返回where ,直接原样凭接
|
||||
public String appendCustomSqlSegment() {
|
||||
MergeSegments expression = getExpression();
|
||||
if (Objects.nonNull(expression)) {
|
||||
String sqlSegment = getSqlSegment();
|
||||
sqlSegment=sqlSegment.substring(1,sqlSegment.length()-1);//去掉左右括号()
|
||||
if (StringUtils.isNotBlank(sqlSegment)) {
|
||||
return sqlSegment;
|
||||
}
|
||||
}
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件为空(包含entity)
|
||||
*/
|
||||
public boolean isEmptyOfWhere() {
|
||||
return isEmptyOfNormal() ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件不为空(包含entity)
|
||||
*/
|
||||
public boolean isNonEmptyOfWhere() {
|
||||
return !isEmptyOfWhere();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean nonEmptyOfWhere() {
|
||||
return isNonEmptyOfWhere();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件为空(不包含entity)
|
||||
*/
|
||||
public boolean isEmptyOfNormal() {
|
||||
return CollectionUtils.isEmpty(getExpression().getNormal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件为空(不包含entity)
|
||||
*/
|
||||
public boolean isNonEmptyOfNormal() {
|
||||
return !isEmptyOfNormal();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean nonEmptyOfNormal() {
|
||||
return isNonEmptyOfNormal();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取格式化后的执行sql
|
||||
*
|
||||
* @return sql
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public String getTargetSql() {
|
||||
return getSqlSegment().replaceAll("#\\{.+?}", "?");
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件清空
|
||||
*
|
||||
* @since 3.3.1
|
||||
*/
|
||||
abstract public void clear();
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
* <p>比较值</p>
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2017-05-26
|
||||
*/
|
||||
public interface Compare<Children, R> extends Serializable {
|
||||
|
||||
/**
|
||||
* map 所有非空属性等于 =
|
||||
*
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @return children
|
||||
*/
|
||||
default <V> Children allEq(Map<R, V> params) {
|
||||
return allEq(params, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* map 所有非空属性等于 =
|
||||
*
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
|
||||
* @return children
|
||||
*/
|
||||
default <V> Children allEq(Map<R, V> params, boolean null2IsNull) {
|
||||
return allEq(true, params, null2IsNull);
|
||||
}
|
||||
|
||||
/**
|
||||
* map 所有非空属性等于 =
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
|
||||
* @return children
|
||||
*/
|
||||
<V> Children allEq(boolean condition, Map<R, V> params, boolean null2IsNull);
|
||||
|
||||
/**
|
||||
* 字段过滤接口,传入多参数时允许对参数进行过滤
|
||||
*
|
||||
* @param filter 返回 true 来允许字段传入比对条件中
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @return children
|
||||
*/
|
||||
default <V> Children allEq(BiPredicate<R, V> filter, Map<R, V> params) {
|
||||
return allEq(filter, params, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段过滤接口,传入多参数时允许对参数进行过滤
|
||||
*
|
||||
* @param filter 返回 true 来允许字段传入比对条件中
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
|
||||
* @return children
|
||||
*/
|
||||
default <V> Children allEq(BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull) {
|
||||
return allEq(true, filter, params, null2IsNull);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段过滤接口,传入多参数时允许对参数进行过滤
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param filter 返回 true 来允许字段传入比对条件中
|
||||
* @param params map 类型的参数, key 是字段名, value 是字段值
|
||||
* @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
|
||||
* @return children
|
||||
*/
|
||||
<V> Children allEq(boolean condition, BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull);
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children eq(R column, Object val) {
|
||||
return eq(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children eq(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* 不等于 <>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children ne(R column, Object val) {
|
||||
return ne(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不等于 <>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children ne(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* 大于 >
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children gt(R column, Object val) {
|
||||
return gt(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于 >
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children gt(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* 大于等于 >=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children ge(R column, Object val) {
|
||||
return ge(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于等于 >=
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children ge(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* 小于 <
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children lt(R column, Object val) {
|
||||
return lt(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于 <
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children lt(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* 小于等于 <=
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children le(R column, Object val) {
|
||||
return le(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于等于 <=
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children le(boolean condition, R column, Object val);
|
||||
|
||||
|
||||
/**
|
||||
* BETWEEN 值1 AND 值2
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val1 值1
|
||||
* @param val2 值2
|
||||
* @return children
|
||||
*/
|
||||
default Children between(R column, Object val1, Object val2) {
|
||||
return between(true, column, val1, val2);
|
||||
}
|
||||
|
||||
/**
|
||||
* BETWEEN 值1 AND 值2
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val1 值1
|
||||
* @param val2 值2
|
||||
* @return children
|
||||
*/
|
||||
Children between(boolean condition, R column, Object val1, Object val2);
|
||||
|
||||
/**
|
||||
* NOT BETWEEN 值1 AND 值2
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val1 值1
|
||||
* @param val2 值2
|
||||
* @return children
|
||||
*/
|
||||
default Children notBetween(R column, Object val1, Object val2) {
|
||||
return notBetween(true, column, val1, val2);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT BETWEEN 值1 AND 值2
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val1 值1
|
||||
* @param val2 值2
|
||||
* @return children
|
||||
*/
|
||||
Children notBetween(boolean condition, R column, Object val1, Object val2);
|
||||
|
||||
/**
|
||||
* LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children like(R column, Object val) {
|
||||
return like(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值%'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children like(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLike(R column, Object val) {
|
||||
return notLike(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值%'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children notLike(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeLeft(R column, Object val) {
|
||||
return notLikeLeft(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '%值'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children notLikeLeft(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* NOT LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children notLikeRight(R column, Object val) {
|
||||
return notLikeRight(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT LIKE '值%'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children notLikeRight(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* LIKE '%值'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeLeft(R column, Object val) {
|
||||
return likeLeft(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '%值'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children likeLeft(boolean condition, R column, Object val);
|
||||
|
||||
/**
|
||||
* LIKE '值%'
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children likeRight(R column, Object val) {
|
||||
return likeRight(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE '值%'
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
Children likeRight(boolean condition, R column, Object val);
|
||||
}
|
||||
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.interfaces;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.toolkit.CollectionUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2017-05-26
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public interface Func<Children, R> extends Serializable {
|
||||
|
||||
/**
|
||||
* 字段 IS NULL
|
||||
* <p>例: isNull("name")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
default Children isNull(R column) {
|
||||
return isNull(true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 IS NULL
|
||||
* <p>例: isNull(true, "name")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
Children isNull(boolean condition, R column);
|
||||
|
||||
/**
|
||||
* 字段 IS NOT NULL
|
||||
* <p>例: isNotNull("name")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
default Children isNotNull(R column) {
|
||||
return isNotNull(true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 IS NOT NULL
|
||||
* <p>例: isNotNull(true, "name")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
Children isNotNull(boolean condition, R column);
|
||||
|
||||
/**
|
||||
* 字段 IN (value.get(0), value.get(1), ...)
|
||||
* <p>例: in("id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||
*
|
||||
* <li> 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param coll 数据集合
|
||||
* @return children
|
||||
*/
|
||||
default Children in(R column, Collection<?> coll) {
|
||||
return in(true, column, coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 IN (value.get(0), value.get(1), ...)
|
||||
* <p>例: in(true, "id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||
*
|
||||
* <li> 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param coll 数据集合
|
||||
* @return children
|
||||
*/
|
||||
Children in(boolean condition, R column, Collection<?> coll);
|
||||
|
||||
/**
|
||||
* 字段 IN (v0, v1, ...)
|
||||
* <p>例: in("id", 1, 2, 3, 4, 5)</p>
|
||||
*
|
||||
* <li> 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
default Children in(R column, Object... values) {
|
||||
return in(true, column, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 IN (v0, v1, ...)
|
||||
* <p>例: in(true, "id", 1, 2, 3, 4, 5)</p>
|
||||
*
|
||||
* <li> 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
Children in(boolean condition, R column, Object... values);
|
||||
|
||||
/**
|
||||
* 字段 NOT IN (value.get(0), value.get(1), ...)
|
||||
* <p>例: notIn("id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||
*
|
||||
* <li> 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param coll 数据集合
|
||||
* @return children
|
||||
*/
|
||||
default Children notIn(R column, Collection<?> coll) {
|
||||
return notIn(true, column, coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 NOT IN (value.get(0), value.get(1), ...)
|
||||
* <p>例: notIn(true, "id", Arrays.asList(1, 2, 3, 4, 5))</p>
|
||||
*
|
||||
* <li> 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param coll 数据集合
|
||||
* @return children
|
||||
*/
|
||||
Children notIn(boolean condition, R column, Collection<?> coll);
|
||||
|
||||
/**
|
||||
* 字段 NOT IN (v0, v1, ...)
|
||||
* <p>例: notIn("id", 1, 2, 3, 4, 5)</p>
|
||||
*
|
||||
* <li> 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
default Children notIn(R column, Object... values) {
|
||||
return notIn(true, column, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 NOT IN (v0, v1, ...)
|
||||
* <p>例: notIn(true, "id", 1, 2, 3, 4, 5)</p>
|
||||
*
|
||||
* <li> 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错</li>
|
||||
* <li> 若要在特定条件下不拼接, 可在 condition 条件中判断 </li>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
Children notIn(boolean condition, R column, Object... values);
|
||||
|
||||
/**
|
||||
* 字段 IN ( sql语句 )
|
||||
* <p>!! sql 注入方式的 in 方法 !!</p>
|
||||
* <p>例1: inSql("id", "1")</p>
|
||||
* <p>例2: inSql("id", "select id from table where id < 3")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children inSql(R column, String sql) {
|
||||
return inSql(true, column, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 IN ( sql语句 )
|
||||
* <p>!! sql 注入方式的 in 方法 !!</p>
|
||||
* <p>例1: inSql(true, "id", "1")</p>
|
||||
* <p>例2: inSql(true, "id", "select id from table where id < 3")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children inSql(boolean condition, R column, String sql);
|
||||
|
||||
/**
|
||||
* 字段 > ( sql语句 )
|
||||
* <p>例1: gtSql(true, "id", "1")</p>
|
||||
* <p>例1: gtSql(true, "id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children gtSql(boolean condition, R column, String sql);
|
||||
|
||||
/**
|
||||
* 字段 > ( sql语句 )
|
||||
* <p>例1: gtSql("id", "1")</p>
|
||||
* <p>例1: gtSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children gtSql(R column, String sql) {
|
||||
return gtSql(true, column, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 >= ( sql语句 )
|
||||
* <p>例1: geSql(true, "id", "1")</p>
|
||||
* <p>例1: geSql(true, "id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children geSql(boolean condition, R column, String sql);
|
||||
|
||||
/**
|
||||
* 字段 >= ( sql语句 )
|
||||
* <p>例1: geSql("id", "1")</p>
|
||||
* <p>例1: geSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children geSql(R column, String sql) {
|
||||
return geSql(true, column, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 < ( sql语句 )
|
||||
* <p>例1: ltSql(true, "id", "1")</p>
|
||||
* <p>例1: ltSql(true , "id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children ltSql(boolean condition, R column, String sql);
|
||||
|
||||
/**
|
||||
* 字段 < ( sql语句 )
|
||||
* <p>例1: ltSql("id", "1")</p>
|
||||
* <p>例1: ltSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children ltSql(R column, String sql) {
|
||||
return ltSql(true, column, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 <= ( sql语句 )
|
||||
* <p>例1: leSql(true, "id", "1")</p>
|
||||
* <p>例1: leSql(true ,"id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param sql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children leSql(boolean condition, R column, String sql);
|
||||
|
||||
/**
|
||||
* 字段 <= ( sql语句 )
|
||||
* <p>例1: leSql("id", "1")</p>
|
||||
* <p>例1: leSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children leSql(R column, String inValue) {
|
||||
return leSql(true, column, inValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 NOT IN ( sql语句 )
|
||||
* <p>!! sql 注入方式的 not in 方法 !!</p>
|
||||
* <p>例1: notInSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例2: notInSql("id", "select id from table where id < 3")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @param inValue sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3
|
||||
* @return children
|
||||
*/
|
||||
default Children notInSql(R column, String inValue) {
|
||||
return notInSql(true, column, inValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段 NOT IN ( sql语句 )
|
||||
* <p>!! sql 注入方式的 not in 方法 !!</p>
|
||||
* <p>例1: notInSql(true, "id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例2: notInSql(true, "id", "select id from table where id < 3")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3
|
||||
* @return children
|
||||
*/
|
||||
Children notInSql(boolean condition, R column, String inValue);
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy(true, "id")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @return children
|
||||
*/
|
||||
Children groupBy(boolean condition, R column);
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy("id")</p>
|
||||
*
|
||||
* @param column 单个字段
|
||||
* @return children
|
||||
*/
|
||||
default Children groupBy(R column) {
|
||||
return groupBy(true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy(true, Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
Children groupBy(boolean condition, List<R> columns);
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy(Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
default Children groupBy(List<R> columns) {
|
||||
return groupBy(true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy("id", "name")</p>
|
||||
*
|
||||
* @param column 单个字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
default Children groupBy(R column, R... columns) {
|
||||
return groupBy(true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy(true, "id", "name")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
Children groupBy(boolean condition, R column, R... columns);
|
||||
|
||||
/**
|
||||
* 分组:GROUP BY 字段, ...
|
||||
* <p>例: groupBy(true, "id", Arrays.asList("name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
* @since 3.5.4
|
||||
*/
|
||||
Children groupBy(boolean condition, R column, List<R> columns);
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc(true, "id")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByAsc(boolean condition, R column) {
|
||||
return orderBy(condition, true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc("id")</p>
|
||||
*
|
||||
* @param column 单个字段
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByAsc(R column) {
|
||||
return orderByAsc(true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc(true, Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByAsc(boolean condition, List<R> columns) {
|
||||
return orderBy(condition, true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc(Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByAsc(List<R> columns) {
|
||||
return orderByAsc(true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
*
|
||||
* @param column 字段
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByAsc(R column, R... columns) {
|
||||
return orderByAsc(true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param columns 字段数组
|
||||
*/
|
||||
default Children orderByAsc(boolean condition, R column, R... columns) {
|
||||
return orderBy(condition, true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... ASC
|
||||
* <p>例: orderByAsc(true, Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段数组
|
||||
* @return children
|
||||
* @since 3.5.4
|
||||
*/
|
||||
default Children orderByAsc(boolean condition, R column, List<R> columns) {
|
||||
return orderBy(condition, true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
* <p>例: orderByDesc(true, "id")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByDesc(boolean condition, R column) {
|
||||
return orderBy(condition, false, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
* <p>例: orderByDesc("id")</p>
|
||||
*
|
||||
* @param column 字段
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByDesc(R column) {
|
||||
return orderByDesc(true, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
* <p>例: orderByDesc(true, Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
default Children orderByDesc(boolean condition, List<R> columns) {
|
||||
return orderBy(condition, false, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
*
|
||||
* @param columns 字段列表
|
||||
*/
|
||||
default Children orderByDesc(List<R> columns) {
|
||||
return orderByDesc(true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
*
|
||||
* @param column 单个字段
|
||||
* @param columns 字段列表
|
||||
*/
|
||||
default Children orderByDesc(R column, R... columns) {
|
||||
return orderByDesc(true, column, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段列表
|
||||
*/
|
||||
default Children orderByDesc(boolean condition, R column, R... columns) {
|
||||
return orderBy(condition, false, column, CollectionUtils.toList(columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ... DESC
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 单个字段
|
||||
* @param columns 字段列表
|
||||
* @since 3.5.4
|
||||
*/
|
||||
default Children orderByDesc(boolean condition, R column, List<R> columns) {
|
||||
return orderBy(condition, false, column, columns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ...
|
||||
* <p>例: orderBy(true, "id")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param isAsc 是否是 ASC 排序
|
||||
* @param column 单个字段
|
||||
* @return children
|
||||
*/
|
||||
Children orderBy(boolean condition, boolean isAsc, R column);
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ...
|
||||
* <p>例: orderBy(true, Arrays.asList("id", "name"))</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param isAsc 是否是 ASC 排序
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
Children orderBy(boolean condition, boolean isAsc, List<R> columns);
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ...
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param isAsc 是否是 ASC 排序
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
Children orderBy(boolean condition, boolean isAsc, R column, R... columns);
|
||||
|
||||
/**
|
||||
* 排序:ORDER BY 字段, ...
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param isAsc 是否是 ASC 排序
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
* @since 3.5.4
|
||||
*/
|
||||
Children orderBy(boolean condition, boolean isAsc, R column, List<R> columns);
|
||||
|
||||
|
||||
/**
|
||||
* HAVING ( sql语句 )
|
||||
* <p>例1: having("sum(age) > 10")</p>
|
||||
* <p>例2: having("sum(age) > {0}", 10)</p>
|
||||
*
|
||||
* @param sqlHaving sql 语句
|
||||
* @param params 参数数组
|
||||
* @return children
|
||||
*/
|
||||
default Children having(String sqlHaving, Object... params) {
|
||||
return having(true, sqlHaving, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* HAVING ( sql语句 )
|
||||
* <p>例1: having(true, "sum(age) > 10")</p>
|
||||
* <p>例2: having(true, "sum(age) > {0}", 10)</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param sqlHaving sql 语句
|
||||
* @param params 参数数组
|
||||
* @return children
|
||||
*/
|
||||
Children having(boolean condition, String sqlHaving, Object... params);
|
||||
|
||||
/**
|
||||
* 消费函数
|
||||
*
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
default Children func(Consumer<Children> consumer) {
|
||||
return func(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费函数
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
* @since 3.3.1
|
||||
*/
|
||||
Children func(boolean condition, Consumer<Children> consumer);
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
* <p>拼接</p>
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2017-05-26
|
||||
*/
|
||||
public interface Join<Children> extends Serializable {
|
||||
|
||||
/**
|
||||
* 拼接 OR
|
||||
*
|
||||
* @return children
|
||||
*/
|
||||
default Children or() {
|
||||
return or(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接 OR
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @return children
|
||||
*/
|
||||
Children or(boolean condition);
|
||||
|
||||
/**
|
||||
* 拼接 sql
|
||||
* <p>!! 会有 sql 注入风险 !!</p>
|
||||
* <p>例1: apply("id = 1")</p>
|
||||
* <p>例2: apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")</p>
|
||||
* <p>例3: apply("date_format(dateColumn,'%Y-%m-%d') = {0}", LocalDate.now())</p>
|
||||
* <p>例4: apply("name={0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler}", "老王")</p>
|
||||
*
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
default Children apply(String applySql, Object... values) {
|
||||
return apply(true, applySql, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接 sql
|
||||
* <p>!! 会有 sql 注入风险 !!</p>
|
||||
* <p>例1: apply("id = 1")</p>
|
||||
* <p>例2: apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")</p>
|
||||
* <p>例3: apply("date_format(dateColumn,'%Y-%m-%d') = {0}", LocalDate.now())</p>
|
||||
* <p>例4: apply("name={0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler}", "老王")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
Children apply(boolean condition, String applySql, Object... values);
|
||||
|
||||
/**
|
||||
* 无视优化规则直接拼接到 sql 的最后(有sql注入的风险,请谨慎使用)
|
||||
* <p>例: last("limit 1")</p>
|
||||
* <p>注意只能调用一次,多次调用以最后一次为准</p>
|
||||
*
|
||||
* @param lastSql sql语句
|
||||
* @return children
|
||||
*/
|
||||
default Children last(String lastSql) {
|
||||
return last(true, lastSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无视优化规则直接拼接到 sql 的最后(有sql注入的风险,请谨慎使用)
|
||||
* <p>例: last("limit 1")</p>
|
||||
* <p>注意只能调用一次,多次调用以最后一次为准</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param lastSql sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children last(boolean condition, String lastSql);
|
||||
|
||||
/**
|
||||
* sql 注释(会拼接在 sql 的最后面)
|
||||
* <p>
|
||||
* 自3.5.6开始,默认不处理转义字符,如有需要,调用{@link com.baomidou.mybatisplus.core.toolkit.sql.StringEscape#escapeRawString(String)}
|
||||
* </p>
|
||||
*
|
||||
* @param comment sql注释
|
||||
* @return children
|
||||
*/
|
||||
default Children comment(String comment) {
|
||||
return comment(true, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* sql 注释(会拼接在 sql 的最后面)
|
||||
* <p>
|
||||
* 自3.5.6开始,默认不处理转义字符,如有需要,调用{@link com.baomidou.mybatisplus.core.toolkit.sql.StringEscape#escapeRawString(String)}
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param comment sql注释
|
||||
* @return children
|
||||
*/
|
||||
Children comment(boolean condition, String comment);
|
||||
|
||||
/**
|
||||
* sql 起始句(会拼接在SQL语句的起始处)
|
||||
* <p>
|
||||
* 自3.5.6开始,默认不处理转义字符,如有需要,调用{@link com.baomidou.mybatisplus.core.toolkit.sql.StringEscape#escapeRawString(String)}
|
||||
* </p>
|
||||
*
|
||||
* @param firstSql 起始语句
|
||||
* @return children
|
||||
*/
|
||||
default Children first(String firstSql) {
|
||||
return first(true, firstSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* sql 起始句(会拼接在SQL语句的起始处)
|
||||
* <p>
|
||||
* 自3.5.6开始,默认不处理转义字符,如有需要,调用{@link com.baomidou.mybatisplus.core.toolkit.sql.StringEscape#escapeRawString(String)}
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param firstSql 起始语句
|
||||
* @return children
|
||||
* @since 3.3.1
|
||||
*/
|
||||
Children first(boolean condition, String firstSql);
|
||||
|
||||
/**
|
||||
* 拼接 EXISTS ( sql语句 )
|
||||
* <p>!! sql 注入方法 !!</p>
|
||||
* <p>例: exists("select id from table where age = 1")</p>
|
||||
*
|
||||
* @param existsSql sql语句
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
default Children exists(String existsSql, Object... values) {
|
||||
return exists(true, existsSql, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接 EXISTS ( sql语句 )
|
||||
* <p>!! sql 注入方法 !!</p>
|
||||
* <p>例: exists("select id from table where age = 1")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param existsSql sql语句
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
Children exists(boolean condition, String existsSql, Object... values);
|
||||
|
||||
/**
|
||||
* 拼接 NOT EXISTS ( sql语句 )
|
||||
* <p>!! sql 注入方法 !!</p>
|
||||
* <p>例: notExists("select id from table where age = 1")</p>
|
||||
*
|
||||
* @param existsSql sql语句
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
default Children notExists(String existsSql, Object... values) {
|
||||
return notExists(true, existsSql, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接 NOT EXISTS ( sql语句 )
|
||||
* <p>!! sql 注入方法 !!</p>
|
||||
* <p>例: notExists("select id from table where age = 1")</p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param existsSql sql语句
|
||||
* @param values 数据数组
|
||||
* @return children
|
||||
*/
|
||||
Children notExists(boolean condition, String existsSql, Object... values);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.interfaces;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 查询条件封装
|
||||
* <p>嵌套</p>
|
||||
* <li>泛型 Param 是具体需要运行函数的类(也是 wrapper 的子类)</li>
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2017-05-26
|
||||
*/
|
||||
public interface Nested<Param, Children> extends Serializable {
|
||||
|
||||
/**
|
||||
* AND 嵌套
|
||||
* <p>
|
||||
* 例: and(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
default Children and(Consumer<Param> consumer) {
|
||||
return and(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* AND 嵌套
|
||||
* <p>
|
||||
* 例: and(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
Children and(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* OR 嵌套
|
||||
* <p>
|
||||
* 例: or(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
default Children or(Consumer<Param> consumer) {
|
||||
return or(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* OR 嵌套
|
||||
* <p>
|
||||
* 例: or(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
Children or(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* 正常嵌套 不带 AND 或者 OR
|
||||
* <p>
|
||||
* 例: nested(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
default Children nested(Consumer<Param> consumer) {
|
||||
return nested(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常嵌套 不带 AND 或者 OR
|
||||
* <p>
|
||||
* 例: nested(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
Children nested(boolean condition, Consumer<Param> consumer);
|
||||
|
||||
/**
|
||||
* not嵌套
|
||||
* <p>
|
||||
* 例: not(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
default Children not(Consumer<Param> consumer) {
|
||||
return not(true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* not嵌套
|
||||
* <p>
|
||||
* 例: not(i -> i.eq("name", "李白").ne("status", "活着"))
|
||||
* </p>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param consumer 消费函数
|
||||
* @return children
|
||||
*/
|
||||
Children not(boolean condition, Consumer<Param> consumer);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:02
|
||||
* @dedescription:
|
||||
*/
|
||||
public abstract class AbstractISegmentList extends ArrayList<ISqlSegment> implements ISqlSegment, StringPool {
|
||||
|
||||
/**
|
||||
* 最后一个值
|
||||
*/
|
||||
ISqlSegment lastValue = null;
|
||||
/**
|
||||
* 刷新 lastValue
|
||||
*/
|
||||
boolean flushLastValue = false;
|
||||
/**
|
||||
* 结果集缓存
|
||||
*/
|
||||
private String sqlSegment = EMPTY;
|
||||
/**
|
||||
* 是否缓存过结果集
|
||||
*/
|
||||
private boolean cacheSqlSegment = true;
|
||||
|
||||
/**
|
||||
* 重写方法,做个性化适配
|
||||
*
|
||||
* @param c 元素集合
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends ISqlSegment> c) {
|
||||
List<ISqlSegment> list = new ArrayList<>(c);
|
||||
boolean goon = transformList(list, list.get(0), list.get(list.size() - 1));
|
||||
if (goon) {
|
||||
cacheSqlSegment = false;
|
||||
if (flushLastValue) {
|
||||
this.flushLastValue(list);
|
||||
}
|
||||
return super.addAll(list);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在其中对值进行判断以及更改 list 的内部元素
|
||||
*
|
||||
* @param list 传入进来的 ISqlSegment 集合
|
||||
* @param firstSegment ISqlSegment 集合里第一个值
|
||||
* @param lastSegment ISqlSegment 集合里最后一个值
|
||||
* @return true 是否继续向下执行; false 不再向下执行
|
||||
*/
|
||||
protected abstract boolean transformList(List<ISqlSegment> list, ISqlSegment firstSegment, ISqlSegment lastSegment);
|
||||
|
||||
/**
|
||||
* 刷新属性 lastValue
|
||||
*/
|
||||
private void flushLastValue(List<ISqlSegment> list) {
|
||||
lastValue = list.get(list.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除元素里最后一个值</br>
|
||||
* 并刷新属性 lastValue
|
||||
*/
|
||||
void removeAndFlushLast() {
|
||||
remove(size() - 1);
|
||||
flushLastValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSqlSegment() {
|
||||
if (cacheSqlSegment) {
|
||||
return sqlSegment;
|
||||
}
|
||||
cacheSqlSegment = true;
|
||||
sqlSegment = childrenSqlSegment();
|
||||
return sqlSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有该类进行过 addAll 操作,才会触发这个方法
|
||||
* <p>
|
||||
* 方法内可以放心进行操作
|
||||
*
|
||||
* @return sqlSegment
|
||||
*/
|
||||
protected abstract String childrenSqlSegment();
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
lastValue = null;
|
||||
sqlSegment = EMPTY;
|
||||
cacheSqlSegment = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:03
|
||||
* @dedescription:
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ColumnSegment extends ISqlSegment {
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:10
|
||||
* @dedescription:
|
||||
*/
|
||||
public class GroupBySegmentList extends AbstractISegmentList {
|
||||
|
||||
@Override
|
||||
protected boolean transformList(List<ISqlSegment> list, ISqlSegment firstSegment, ISqlSegment lastSegment) {
|
||||
list.remove(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String childrenSqlSegment() {
|
||||
if (isEmpty()) {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
return this.stream().map(ISqlSegment::getSqlSegment).collect(joining(StringPool.COMMA, StringPool.SPACE + SqlKeyword.GROUP_BY.getSqlSegment() + StringPool.SPACE, StringPool.EMPTY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:13
|
||||
* @dedescription:
|
||||
*/
|
||||
public class HavingSegmentList extends AbstractISegmentList {
|
||||
|
||||
@Override
|
||||
protected boolean transformList(List<ISqlSegment> list, ISqlSegment firstSegment, ISqlSegment lastSegment) {
|
||||
if (!isEmpty()) {
|
||||
this.add(SqlKeyword.AND);
|
||||
}
|
||||
list.remove(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String childrenSqlSegment() {
|
||||
if (isEmpty()) {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
return this.stream().map(ISqlSegment::getSqlSegment).collect(joining(StringPool.SPACE, StringPool.SPACE + SqlKeyword.HAVING.getSqlSegment() + StringPool.SPACE, StringPool.EMPTY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.enums.WrapperKeyword;
|
||||
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:07
|
||||
* @dedescription:
|
||||
*/
|
||||
public enum MatchSegment {
|
||||
GROUP_BY(i -> i == SqlKeyword.GROUP_BY),
|
||||
ORDER_BY(i -> i == SqlKeyword.ORDER_BY),
|
||||
NOT(i -> i == SqlKeyword.NOT),
|
||||
AND(i -> i == SqlKeyword.AND),
|
||||
OR(i -> i == SqlKeyword.OR),
|
||||
AND_OR(i -> i == SqlKeyword.AND || i == SqlKeyword.OR),
|
||||
EXISTS(i -> i == SqlKeyword.EXISTS),
|
||||
HAVING(i -> i == SqlKeyword.HAVING),
|
||||
APPLY(i -> i == WrapperKeyword.APPLY);
|
||||
|
||||
private final Predicate<ISqlSegment> predicate;
|
||||
|
||||
public boolean match(ISqlSegment segment) {
|
||||
return getPredicate().test(segment);
|
||||
}
|
||||
|
||||
MatchSegment(Predicate<ISqlSegment> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
public Predicate<ISqlSegment> getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:09
|
||||
* @dedescription:
|
||||
*/
|
||||
public class MergeSegments implements ISqlSegment {
|
||||
|
||||
private final NormalSegmentList normal = new NormalSegmentList();
|
||||
private final GroupBySegmentList groupBy = new GroupBySegmentList();
|
||||
private final HavingSegmentList having = new HavingSegmentList();
|
||||
private final OrderBySegmentList orderBy = new OrderBySegmentList();
|
||||
|
||||
|
||||
private String sqlSegment = StringPool.EMPTY;
|
||||
|
||||
private boolean cacheSqlSegment = true;
|
||||
|
||||
public void add(ISqlSegment... iSqlSegments) {
|
||||
List<ISqlSegment> list = Arrays.asList(iSqlSegments);
|
||||
ISqlSegment firstSqlSegment = list.get(0);
|
||||
if (MatchSegment.ORDER_BY.match(firstSqlSegment)) {
|
||||
orderBy.addAll(list);
|
||||
} else if (MatchSegment.GROUP_BY.match(firstSqlSegment)) {
|
||||
groupBy.addAll(list);
|
||||
} else if (MatchSegment.HAVING.match(firstSqlSegment)) {
|
||||
having.addAll(list);
|
||||
} else {
|
||||
normal.addAll(list);
|
||||
}
|
||||
cacheSqlSegment = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSqlSegment() {
|
||||
if (cacheSqlSegment) {
|
||||
return sqlSegment;
|
||||
}
|
||||
cacheSqlSegment = true;
|
||||
if (normal.isEmpty()) {
|
||||
if (!groupBy.isEmpty() || !orderBy.isEmpty()) {
|
||||
sqlSegment = groupBy.getSqlSegment() + having.getSqlSegment() + orderBy.getSqlSegment();
|
||||
}
|
||||
} else {
|
||||
sqlSegment = normal.getSqlSegment() + groupBy.getSqlSegment() + having.getSqlSegment() + orderBy.getSqlSegment();
|
||||
}
|
||||
return sqlSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理
|
||||
*
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public void clear() {
|
||||
sqlSegment = StringPool.EMPTY;
|
||||
cacheSqlSegment = true;
|
||||
normal.clear();
|
||||
groupBy.clear();
|
||||
having.clear();
|
||||
orderBy.clear();
|
||||
}
|
||||
|
||||
public NormalSegmentList getNormal() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
public GroupBySegmentList getGroupBy() {
|
||||
return groupBy;
|
||||
}
|
||||
|
||||
public HavingSegmentList getHaving() {
|
||||
return having;
|
||||
}
|
||||
|
||||
public OrderBySegmentList getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
public void setSqlSegment(String sqlSegment) {
|
||||
this.sqlSegment = sqlSegment;
|
||||
}
|
||||
|
||||
public boolean isCacheSqlSegment() {
|
||||
return cacheSqlSegment;
|
||||
}
|
||||
|
||||
public void setCacheSqlSegment(boolean cacheSqlSegment) {
|
||||
this.cacheSqlSegment = cacheSqlSegment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:06
|
||||
* @dedescription:
|
||||
*/
|
||||
public class NormalSegmentList extends AbstractISegmentList {
|
||||
|
||||
/**
|
||||
* 是否处理了的上个 not
|
||||
*/
|
||||
private boolean executeNot = true;
|
||||
|
||||
public NormalSegmentList() {
|
||||
this.flushLastValue = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean transformList(List<ISqlSegment> list, ISqlSegment firstSegment, ISqlSegment lastSegment) {
|
||||
if (list.size() == 1) {
|
||||
/* 只有 and() 以及 or() 以及 not() 会进入 */
|
||||
if (!MatchSegment.NOT.match(firstSegment)) {
|
||||
//不是 not
|
||||
if (isEmpty()) {
|
||||
//sqlSegment是 and 或者 or 并且在第一位,不继续执行
|
||||
return false;
|
||||
}
|
||||
boolean matchLastAnd = MatchSegment.AND.match(lastValue);
|
||||
boolean matchLastOr = MatchSegment.OR.match(lastValue);
|
||||
if (matchLastAnd || matchLastOr) {
|
||||
//上次最后一个值是 and 或者 or
|
||||
if (matchLastAnd && MatchSegment.AND.match(firstSegment)) {
|
||||
return false;
|
||||
} else if (matchLastOr && MatchSegment.OR.match(firstSegment)) {
|
||||
return false;
|
||||
} else {
|
||||
//和上次的不一样
|
||||
removeAndFlushLast();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
executeNot = false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (MatchSegment.APPLY.match(firstSegment)) {
|
||||
list.remove(0);
|
||||
}
|
||||
if (!MatchSegment.AND_OR.match(lastValue) && !isEmpty()) {
|
||||
add(SqlKeyword.AND);
|
||||
}
|
||||
if (!executeNot) {
|
||||
list.add(0, SqlKeyword.NOT);
|
||||
executeNot = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String childrenSqlSegment() {
|
||||
if (MatchSegment.AND_OR.match(lastValue)) {
|
||||
removeAndFlushLast();
|
||||
}
|
||||
final String str = this.stream().map(ISqlSegment::getSqlSegment).collect(Collectors.joining(StringPool.SPACE));
|
||||
return (StringPool.LEFT_BRACKET + str + StringPool.RIGHT_BRACKET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
flushLastValue = true;
|
||||
executeNot = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.conditions.segments;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.enums.SqlKeyword;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:14
|
||||
* @dedescription:
|
||||
*/
|
||||
public class OrderBySegmentList extends AbstractISegmentList {
|
||||
|
||||
@Override
|
||||
protected boolean transformList(List<ISqlSegment> list, ISqlSegment firstSegment, ISqlSegment lastSegment) {
|
||||
list.remove(0);
|
||||
final List<ISqlSegment> sqlSegmentList = new ArrayList<>(list);
|
||||
list.clear();
|
||||
list.add(() -> sqlSegmentList.stream().map(ISqlSegment::getSqlSegment).collect(joining(StringPool.SPACE)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String childrenSqlSegment() {
|
||||
if (isEmpty()) {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
return this.stream().map(ISqlSegment::getSqlSegment).collect(joining(StringPool.COMMA, StringPool.SPACE + SqlKeyword.ORDER_BY.getSqlSegment() + StringPool.SPACE, StringPool.EMPTY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.ddl.alter;
|
||||
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.alter.Alter;
|
||||
import net.sf.jsqlparser.statement.alter.AlterExpression;
|
||||
import net.sf.jsqlparser.statement.alter.AlterOperation;
|
||||
import net.sf.jsqlparser.statement.create.table.ColDataType;
|
||||
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
|
||||
import net.sf.jsqlparser.statement.create.table.Index;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-27 13:38
|
||||
* @dedescription:
|
||||
*/
|
||||
public class JeeLowCodeAlterTable {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private AlterOperation alterOperation;
|
||||
|
||||
private List<Index> indices = new ArrayList<>();
|
||||
|
||||
private List<ColumnDefinition> columnDefinitions = new ArrayList<>();
|
||||
|
||||
private List<AlterExpression> expressions = new ArrayList<>();
|
||||
|
||||
private Alter alter ;
|
||||
|
||||
|
||||
public void setTableName(String tableName){
|
||||
this.tableName = tableName;
|
||||
alter = new Alter();
|
||||
alter.setTable(new Table(tableName));
|
||||
}
|
||||
|
||||
public void setAlterOperation(AlterOperation alterOperation){
|
||||
this.alterOperation = alterOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字段
|
||||
* @param columnName
|
||||
* @param dataType
|
||||
* @param specs
|
||||
*/
|
||||
public void addCoulumn(String columnName, String dataType,String... specs){
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setOperation(AlterOperation.ADD);
|
||||
AlterExpression.ColumnDataType columnDataType = new AlterExpression.ColumnDataType(columnName,false,new ColDataType(dataType),Arrays.asList(specs));
|
||||
alterExpression.addColDataType(columnDataType);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
public void addIndex(String indexName, String... columns){
|
||||
Index index = new Index();
|
||||
index.setName(indexName);
|
||||
index.setColumnsNames(Arrays.asList(columns));
|
||||
index.setType("index");
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setOperation(AlterOperation.ADD);
|
||||
alterExpression.setIndex(index);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
public void dropColumn(String columnName){
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setOperation(AlterOperation.DROP);
|
||||
alterExpression.setColumnName(columnName);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
public void dropIndex(String indexName){
|
||||
Index index = new Index();
|
||||
index.setName(indexName);
|
||||
index.setType("index");
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setIndex(index);
|
||||
alterExpression.setOperation(AlterOperation.DROP);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
public void alterColumn(String columnName, String dataType, AlterOperation alterOperation,String... specs){
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setColumnName(columnName);
|
||||
AlterExpression.ColumnDataType columnDataType = new AlterExpression.ColumnDataType(false);
|
||||
columnDataType.setColumnName(columnName);
|
||||
columnDataType.setColDataType(new ColDataType(dataType));
|
||||
columnDataType.setColumnSpecs(Arrays.asList(specs));
|
||||
alterExpression.addColDataType(columnDataType);
|
||||
alterExpression.setOperation(alterOperation);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
|
||||
//字段属性
|
||||
public void modifyColumn(String columnName, String dateType , String... specs){
|
||||
AlterExpression.ColumnDataType columnDataType = new AlterExpression.ColumnDataType(false);
|
||||
columnDataType.setColumnName(columnName);
|
||||
columnDataType.setColDataType(new ColDataType(dateType));
|
||||
columnDataType.setColumnSpecs(Arrays.asList(specs));
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.addColDataType(columnDataType);
|
||||
alterExpression.setOperation(AlterOperation.MODIFY);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
//字段改变
|
||||
public void change(String oldName, String newName, String dataType, String... specs){
|
||||
AlterExpression.ColumnDataType columnDataType = new AlterExpression.ColumnDataType(false);
|
||||
columnDataType.setColumnName(newName);
|
||||
columnDataType.setColumnSpecs(Arrays.asList(specs));
|
||||
columnDataType.setColDataType(new ColDataType(dataType));
|
||||
AlterExpression alterExpression = new AlterExpression();
|
||||
alterExpression.setColumnOldName(oldName);
|
||||
alterExpression.setOperation(AlterOperation.CHANGE);
|
||||
alterExpression.addColDataType(columnDataType);
|
||||
expressions.add(alterExpression);
|
||||
}
|
||||
|
||||
|
||||
public String getFullSQL(){
|
||||
alter.setAlterExpressions(expressions);
|
||||
return alter.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dropTable(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.setAlterOperation(AlterOperation.DROP);
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCoulumn(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.setAlterOperation(AlterOperation.ALTER);
|
||||
alterTable.addCoulumn("name","varchar(20)","not null","COMMENT '姓名'");
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
@Test
|
||||
public void test_modifyCoulumn(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.modifyColumn("name","varchar(20)","not null","COMMENT '姓名'");
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dropColumn(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.dropColumn("name");
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_addIndex(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.addIndex("ind_name1","id","name");
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dropIndex(){
|
||||
JeeLowCodeAlterTable alterTable=new JeeLowCodeAlterTable();
|
||||
alterTable.setTableName("tbl_lin2");
|
||||
alterTable.dropIndex("ind_name1");
|
||||
System.out.println(alterTable.getFullSQL());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.ddl.create;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.create.table.ColDataType;
|
||||
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
|
||||
import net.sf.jsqlparser.statement.create.table.CreateTable;
|
||||
import net.sf.jsqlparser.statement.create.table.Index;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-27 10:40
|
||||
* @dedescription:
|
||||
*/
|
||||
public class JeeLowCodeCreateTable {
|
||||
|
||||
//表名
|
||||
private String tableName;
|
||||
|
||||
//别名
|
||||
private List<String> tableOptions;
|
||||
|
||||
//字段
|
||||
private List<ColumnDefinition> columnDefinitions=new ArrayList<>();
|
||||
|
||||
//索引
|
||||
private List<Index> indices = new ArrayList<>();
|
||||
|
||||
public void setTableName(String tableName){
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public void setTableOptions(List<String> tableOptions) {
|
||||
this.tableOptions = tableOptions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addCoulumn(String columnName, String dataType, String... specs){
|
||||
ColumnDefinition columnDefinition = new ColumnDefinition(columnName,new ColDataType(dataType));
|
||||
if (!FuncBase.isEmpty(specs)){
|
||||
columnDefinition.addColumnSpecs(specs);
|
||||
}
|
||||
this.columnDefinitions.add(columnDefinition);
|
||||
}
|
||||
|
||||
|
||||
public String getDDL(){
|
||||
CreateTable createTable = new CreateTable();
|
||||
createTable.setTable(new Table(tableName));
|
||||
createTable.setTableOptionsStrings(tableOptions);
|
||||
createTable.setColumnDefinitions(columnDefinitions);
|
||||
createTable.setIndexes(indices);
|
||||
return createTable.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreate(){
|
||||
JeeLowCodeCreateTable createTable=new JeeLowCodeCreateTable();
|
||||
createTable.setTableName("tbl_lin2");
|
||||
createTable.addCoulumn("id","varchar(12)","PRIMARY KEY","COMMENT 'id'","not null");
|
||||
createTable.addCoulumn("name","varchar(20)","not null","COMMENT '姓名'");
|
||||
System.out.println(createTable.getDDL());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.ddl.drop;
|
||||
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.drop.Drop;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 删除表
|
||||
* @author JX
|
||||
* @create 2024-03-27 13:38
|
||||
* @dedescription:
|
||||
*/
|
||||
public class JeeLowCodeDropTable {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private Drop drop ;
|
||||
|
||||
public void setTableName(String tableName){
|
||||
this.tableName = tableName;
|
||||
drop = new Drop();
|
||||
drop.setName(new Table(tableName));
|
||||
drop.setType("TABLE");
|
||||
}
|
||||
|
||||
|
||||
public String getFullSQL(){
|
||||
return drop.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dropTable(){
|
||||
JeeLowCodeDropTable dropTable=new JeeLowCodeDropTable();
|
||||
dropTable.setTableName("tbl_lin2");
|
||||
// alterTable.setAlterOperation(AlterOperation.);
|
||||
System.out.println(dropTable.getFullSQL());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.delete;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.AbstractWrapper;
|
||||
import com.jeelowcode.framework.plus.core.conditions.SharedString;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-27 17:46
|
||||
* @dedescription:
|
||||
*/
|
||||
public class JeeLowCodeDeleteWrapper<T> extends AbstractWrapper<T, String, JeeLowCodeDeleteWrapper<T>> {
|
||||
|
||||
|
||||
|
||||
public JeeLowCodeDeleteWrapper() {
|
||||
this((T) null);
|
||||
}
|
||||
|
||||
public JeeLowCodeDeleteWrapper(T entity) {
|
||||
super.setEntity(entity);
|
||||
super.initNeed();
|
||||
}
|
||||
|
||||
|
||||
public JeeLowCodeDeleteWrapper(AtomicInteger paramNameSeq,
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment){
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
this.paramAlias = paramAlias;
|
||||
this.lastSql = lastSql;
|
||||
this.sqlComment = sqlComment;
|
||||
this.expression = new MergeSegments();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected JeeLowCodeDeleteWrapper instance() {
|
||||
return new JeeLowCodeDeleteWrapper( paramNameSeq , paramNameValuePairs , expression , paramAlias , SharedString.emptyString() , SharedString.emptyString());
|
||||
}
|
||||
|
||||
|
||||
public void orderby(){
|
||||
return;
|
||||
}
|
||||
|
||||
public void groupBy(){
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.insert;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.AbstractWrapper;
|
||||
import com.jeelowcode.framework.plus.core.conditions.SharedString;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
import com.jeelowcode.framework.plus.core.dql.update.Update;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.CollectionUtils;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.Constants;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringUtils;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-27 17:47
|
||||
* @dedescription:
|
||||
*/
|
||||
public class JeeLowCodeInsertWrapper<T> extends AbstractWrapper<T, String, JeeLowCodeInsertWrapper<T>>
|
||||
implements Update<JeeLowCodeInsertWrapper<T>, String> {
|
||||
private final List<String> sqlSet;
|
||||
|
||||
|
||||
public JeeLowCodeInsertWrapper() {
|
||||
// 如果无参构造函数,请注意实体 NULL 情况 SET 必须有否则 SQL 异常
|
||||
this(null);
|
||||
}
|
||||
|
||||
public JeeLowCodeInsertWrapper(T entity) {
|
||||
super.setEntity(entity);
|
||||
super.initNeed();
|
||||
this.sqlSet = new ArrayList<>();
|
||||
}
|
||||
|
||||
private JeeLowCodeInsertWrapper(T entity, List<String> sqlSet, AtomicInteger paramNameSeq,
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst) {
|
||||
super.setEntity(entity);
|
||||
this.sqlSet = sqlSet;
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
this.expression = mergeSegments;
|
||||
this.paramAlias = paramAlias;
|
||||
this.lastSql = lastSql;
|
||||
this.sqlComment = sqlComment;
|
||||
this.sqlFirst = sqlFirst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getSqlSet() {
|
||||
if (CollectionUtils.isEmpty(sqlSet)) {
|
||||
return null;
|
||||
}
|
||||
return String.join(Constants.COMMA, sqlSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JeeLowCodeInsertWrapper<T> set(boolean condition, String column, Object val, String mapping) {
|
||||
return maybeDo(condition, () -> {
|
||||
String sql = formatParam(mapping, val);
|
||||
sqlSet.add(column + Constants.EQUALS + sql);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public JeeLowCodeInsertWrapper<T> setSql(boolean condition, String setSql, Object... params) {
|
||||
if (condition && StringUtils.isNotBlank(setSql)) {
|
||||
sqlSet.add(formatSqlMaybeWithParam(setSql, params));
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected JeeLowCodeInsertWrapper<T> instance() {
|
||||
return new JeeLowCodeInsertWrapper<>(getEntity(), null, paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
||||
paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
sqlSet.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.select;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.AbstractWrapper;
|
||||
import com.jeelowcode.framework.plus.core.conditions.SharedString;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
import com.jeelowcode.framework.plus.core.exceptions.JeelowcodeSqlException;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.CollectionUtils;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.sql.SqlInjectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Entity 对象封装操作类
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2018-05-25
|
||||
*/
|
||||
public class JeeLowCodeQueryWrapper<T> extends AbstractWrapper<T, String, JeeLowCodeQueryWrapper<T>>
|
||||
implements Query<JeeLowCodeQueryWrapper<T>, T, String> {
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
*/
|
||||
protected final SharedString sqlSelect = new SharedString();
|
||||
|
||||
|
||||
|
||||
public JeeLowCodeQueryWrapper() {
|
||||
this((T) null);
|
||||
}
|
||||
|
||||
public JeeLowCodeQueryWrapper(T entity) {
|
||||
super.setEntity(entity);
|
||||
super.initNeed();
|
||||
}
|
||||
|
||||
public JeeLowCodeQueryWrapper(Class<T> entityClass) {
|
||||
super.setEntityClass(entityClass);
|
||||
super.initNeed();
|
||||
}
|
||||
|
||||
public JeeLowCodeQueryWrapper(T entity, String... columns) {
|
||||
super.setEntity(entity);
|
||||
super.initNeed();
|
||||
this.select(Arrays.asList(columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* 非对外公开的构造方法,只用于生产嵌套 sql
|
||||
*
|
||||
* @param entityClass 本不应该需要的
|
||||
*/
|
||||
private JeeLowCodeQueryWrapper(T entity, Class<T> entityClass, AtomicInteger paramNameSeq,
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst) {
|
||||
super.setEntity(entity);
|
||||
super.setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
this.expression = mergeSegments;
|
||||
this.paramAlias = paramAlias;
|
||||
this.lastSql = lastSql;
|
||||
this.sqlComment = sqlComment;
|
||||
this.sqlFirst = sqlFirst;
|
||||
}
|
||||
|
||||
private JeeLowCodeQueryWrapper(T entity, Class<T> entityClass, AtomicInteger paramNameSeq,
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst, String tableName) {
|
||||
super.setEntity(entity);
|
||||
super.setEntityClass(entityClass);
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
this.expression = mergeSegments;
|
||||
this.paramAlias = paramAlias;
|
||||
this.lastSql = lastSql;
|
||||
this.sqlComment = sqlComment;
|
||||
this.sqlFirst = sqlFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 SQL 注入过滤
|
||||
*/
|
||||
private boolean checkSqlInjection;
|
||||
|
||||
/**
|
||||
* 开启检查 SQL 注入
|
||||
*/
|
||||
public JeeLowCodeQueryWrapper<T> checkSqlInjection() {
|
||||
this.checkSqlInjection = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String columnToString(String column) {
|
||||
if (checkSqlInjection && SqlInjectionUtils.check(column)) {
|
||||
throw new JeelowcodeSqlException("Discovering SQL injection column: " + column);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JeeLowCodeQueryWrapper<T> select(boolean condition, List<String> columns) {
|
||||
if (condition && CollectionUtils.isNotEmpty(columns)) {
|
||||
this.sqlSelect.setStringValue(String.join(StringPool.COMMA, columns));
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
return sqlSelect.getStringValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用于生成嵌套 sql
|
||||
* <p>
|
||||
* 故 sqlSelect 不向下传递
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
protected JeeLowCodeQueryWrapper<T> instance() {
|
||||
return new JeeLowCodeQueryWrapper<>(getEntity(), getEntityClass(), paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
||||
paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
sqlSelect.toNull();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.select;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author miemie
|
||||
* @since 2018-12-12
|
||||
*/
|
||||
public interface Query<Children, T, R> extends Serializable {
|
||||
|
||||
/**
|
||||
* 指定查询字段
|
||||
*
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default Children select(R... columns) {
|
||||
return select(true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定查询字段
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default Children select(boolean condition, R... columns) {
|
||||
return select(condition, Arrays.asList(columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定查询字段
|
||||
*
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
default Children select(List<R> columns) {
|
||||
return select(true, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定查询字段
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param columns 字段列表
|
||||
* @return children
|
||||
*/
|
||||
Children select(boolean condition, List<R> columns);
|
||||
|
||||
/**
|
||||
* 过滤查询的字段信息(主键除外!)
|
||||
* <p>注意只有内部有 entity 才能使用该方法</p>
|
||||
*/
|
||||
// default Children select(Predicate<TableFieldInfo> predicate) {
|
||||
// return select(null, predicate);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 过滤查询的字段信息(主键除外!)
|
||||
* <p>例1: 只要 java 字段名以 "test" 开头的 -> select(i -> i.getProperty().startsWith("test"))</p>
|
||||
* <p>例2: 只要 java 字段属性是 CharSequence 类型的 -> select(TableFieldInfo::isCharSequence)</p>
|
||||
* <p>例3: 只要 java 字段没有填充策略的 -> select(i -> i.getFieldFill() == FieldFill.DEFAULT)</p>
|
||||
* <p>例4: 要全部字段 -> select(i -> true)</p>
|
||||
* <p>例5: 只要主键字段 -> select(i -> false)</p>
|
||||
*
|
||||
* @param predicate 过滤方式
|
||||
* @return children
|
||||
*/
|
||||
// Children select(Class<T> entityClass, Predicate<TableFieldInfo> predicate);
|
||||
|
||||
/**
|
||||
* 查询条件 SQL 片段
|
||||
*/
|
||||
String getSqlSelect();
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.update;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.AbstractWrapper;
|
||||
import com.jeelowcode.framework.plus.core.conditions.SharedString;
|
||||
import com.jeelowcode.framework.plus.core.conditions.segments.MergeSegments;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.CollectionUtils;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.Constants;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Update 条件封装
|
||||
*
|
||||
* @author hubin miemie HCL
|
||||
* @since 2018-05-30
|
||||
*/
|
||||
public class JeeLowCodeUpdateWrapper<T> extends AbstractWrapper<T, String, JeeLowCodeUpdateWrapper<T>>
|
||||
implements Update<JeeLowCodeUpdateWrapper<T>, String> {
|
||||
|
||||
/**
|
||||
* SQL 更新字段内容,例如:name='1', age=2
|
||||
*/
|
||||
private final List<String> sqlSet;
|
||||
|
||||
|
||||
public JeeLowCodeUpdateWrapper() {
|
||||
// 如果无参构造函数,请注意实体 NULL 情况 SET 必须有否则 SQL 异常
|
||||
this(null);
|
||||
}
|
||||
|
||||
public JeeLowCodeUpdateWrapper(T entity) {
|
||||
super.setEntity(entity);
|
||||
super.initNeed();
|
||||
this.sqlSet = new ArrayList<>();
|
||||
}
|
||||
|
||||
private JeeLowCodeUpdateWrapper(T entity, List<String> sqlSet, AtomicInteger paramNameSeq,
|
||||
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
|
||||
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst) {
|
||||
super.setEntity(entity);
|
||||
this.sqlSet = sqlSet;
|
||||
this.paramNameSeq = paramNameSeq;
|
||||
this.paramNameValuePairs = paramNameValuePairs;
|
||||
this.expression = mergeSegments;
|
||||
this.paramAlias = paramAlias;
|
||||
this.lastSql = lastSql;
|
||||
this.sqlComment = sqlComment;
|
||||
this.sqlFirst = sqlFirst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getSqlSet() {
|
||||
if (CollectionUtils.isEmpty(sqlSet)) {
|
||||
return null;
|
||||
}
|
||||
return String.join(Constants.COMMA, sqlSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JeeLowCodeUpdateWrapper<T> set(boolean condition, String column, Object val, String mapping) {
|
||||
return maybeDo(condition, () -> {
|
||||
String sql = formatParam(mapping, val);
|
||||
sqlSet.add(column + Constants.EQUALS + sql);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public JeeLowCodeUpdateWrapper<T> setSql(boolean condition, String setSql, Object... params) {
|
||||
if (condition && StringUtils.isNotBlank(setSql)) {
|
||||
sqlSet.add(formatSqlMaybeWithParam(setSql, params));
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected JeeLowCodeUpdateWrapper<T> instance() {
|
||||
return new JeeLowCodeUpdateWrapper<>(getEntity(), null, paramNameSeq, paramNameValuePairs, new MergeSegments(),
|
||||
paramAlias, SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
sqlSet.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.dql.update;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author miemie
|
||||
* @since 2018-12-12
|
||||
*/
|
||||
public interface Update<Children, R> extends Serializable {
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children set(R column, Object val) {
|
||||
return set(true, column, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param condition 是否加入 set
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
default Children set(boolean condition, R column, Object val) {
|
||||
return set(condition, column, val, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @param mapping 例: javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler
|
||||
* @return children
|
||||
*/
|
||||
default Children set(R column, Object val, String mapping) {
|
||||
return set(true, column, val, mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param condition 是否加入 set
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @param mapping 例: javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler
|
||||
* @return children
|
||||
*/
|
||||
Children set(boolean condition, R column, Object val, String mapping);
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param setSql set sql
|
||||
* 例1: setSql("id=1")
|
||||
* 例2: apply("dateColumn={0}", LocalDate.now())
|
||||
* 例3: apply("dateColumn={0}", LocalDate.now())
|
||||
* 例4: apply("name={0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler}", "老王")
|
||||
* @return children
|
||||
*/
|
||||
default Children setSql(String setSql, Object... params) {
|
||||
return setSql(true, setSql, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 更新 SQL 的 SET 片段
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param setSql set sql
|
||||
* 例1: setSql("id=1")
|
||||
* 例2: apply("dateColumn={0}", LocalDate.now())
|
||||
* 例3: apply("dateColumn={0}", LocalDate.now())
|
||||
* 例4: apply("name={0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler}", "老王")
|
||||
* @return children
|
||||
*/
|
||||
Children setSql(boolean condition, String setSql, Object... params);
|
||||
|
||||
/**
|
||||
* 获取 更新 SQL 的 SET 片段
|
||||
*/
|
||||
String getSqlSet();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.enums;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
import com.jeelowcode.framework.plus.core.toolkit.StringPool;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:01
|
||||
* @dedescription:
|
||||
*/
|
||||
public enum SqlKeyword implements ISqlSegment {
|
||||
AND("AND"),
|
||||
OR("OR"),
|
||||
NOT("NOT"),
|
||||
IN("IN"),
|
||||
NOT_IN("NOT IN"),
|
||||
LIKE("LIKE"),
|
||||
NOT_LIKE("NOT LIKE"),
|
||||
EQ(StringPool.EQUALS),
|
||||
NE("<>"),
|
||||
GT(StringPool.RIGHT_CHEV),
|
||||
GE(">="),
|
||||
LT(StringPool.LEFT_CHEV),
|
||||
LE("<="),
|
||||
IS_NULL("IS NULL"),
|
||||
IS_NOT_NULL("IS NOT NULL"),
|
||||
GROUP_BY("GROUP BY"),
|
||||
HAVING("HAVING"),
|
||||
ORDER_BY("ORDER BY"),
|
||||
EXISTS("EXISTS"),
|
||||
NOT_EXISTS("NOT EXISTS"),
|
||||
BETWEEN("BETWEEN"),
|
||||
NOT_BETWEEN("NOT BETWEEN"),
|
||||
ASC("ASC"),
|
||||
DESC("DESC");
|
||||
|
||||
private final String keyword;
|
||||
|
||||
@Override
|
||||
public String getSqlSegment() {
|
||||
return this.keyword;
|
||||
}
|
||||
|
||||
SqlKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.enums;
|
||||
|
||||
/**
|
||||
* SQL like 枚举
|
||||
*
|
||||
* @author Caratacus
|
||||
* @since 2016-12-4
|
||||
*/
|
||||
public enum SqlLike {
|
||||
/**
|
||||
* %值
|
||||
*/
|
||||
LEFT,
|
||||
/**
|
||||
* 值%
|
||||
*/
|
||||
RIGHT,
|
||||
/**
|
||||
* %值%
|
||||
*/
|
||||
DEFAULT
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.enums;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.conditions.ISqlSegment;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:08
|
||||
* @dedescription:
|
||||
*/
|
||||
public enum WrapperKeyword implements ISqlSegment {
|
||||
/**
|
||||
* 只用作于辨识,不用于其他
|
||||
*/
|
||||
APPLY(null);
|
||||
|
||||
private final String keyword;
|
||||
|
||||
@Override
|
||||
public String getSqlSegment() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
WrapperKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.exceptions;
|
||||
|
||||
/**
|
||||
* MybatisPlus 异常类
|
||||
*
|
||||
* @author hubin
|
||||
* @since 2016-01-23
|
||||
*/
|
||||
public class JeelowcodeSqlException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JeelowcodeSqlException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JeelowcodeSqlException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public JeelowcodeSqlException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.model;
|
||||
|
||||
public class OrderByModel {
|
||||
/**
|
||||
* 默认排序字段
|
||||
*/
|
||||
private String column;
|
||||
|
||||
/**
|
||||
* 默认排序类型
|
||||
*/
|
||||
private String order;
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public String getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(String order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SqlFormatModel {
|
||||
private String sql;
|
||||
private Map<String,Object> dataMap;
|
||||
|
||||
public SqlFormatModel() {
|
||||
}
|
||||
|
||||
public SqlFormatModel(String sql, Map<String, Object> dataMap) {
|
||||
this.sql = sql;
|
||||
this.dataMap = dataMap;
|
||||
}
|
||||
|
||||
public SqlFormatModel(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public void setSql(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public Map<String, Object> getDataMap() {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public void setDataMap(Map<String, Object> dataMap) {
|
||||
this.dataMap = dataMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.model;
|
||||
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
|
||||
/**
|
||||
* 创建表-字段
|
||||
*/
|
||||
public class TableFieldModel {
|
||||
String fieldCode;
|
||||
JeeLowCodeFieldTypeEnum fieldType;//字段类型
|
||||
String defaultValSql;
|
||||
|
||||
public String getFieldCode() {
|
||||
return fieldCode;
|
||||
}
|
||||
|
||||
public void setFieldCode(String fieldCode) {
|
||||
this.fieldCode = fieldCode;
|
||||
}
|
||||
|
||||
public JeeLowCodeFieldTypeEnum getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public void setFieldType(JeeLowCodeFieldTypeEnum fieldType) {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getDefaultValSql() {
|
||||
return defaultValSql;
|
||||
}
|
||||
|
||||
public void setDefaultValSql(String defaultValSql) {
|
||||
this.defaultValSql = defaultValSql;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WhereModel {
|
||||
|
||||
private List<String> whereList;
|
||||
|
||||
public List<String> getWhereList() {
|
||||
return whereList;
|
||||
}
|
||||
|
||||
public void setWhereList(List<String> whereList) {
|
||||
this.whereList = whereList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 10:26
|
||||
* @dedescription:
|
||||
*/
|
||||
public final class Assert {
|
||||
|
||||
/**
|
||||
* 断言这个 boolean 为 true
|
||||
* <p>为 false 则抛出异常</p>
|
||||
*
|
||||
* @param expression boolean 值
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void isTrue(boolean expression, String message, Object... params) {
|
||||
if (!expression) {
|
||||
throw ExceptionUtils.mpe(message, params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 boolean 为 false
|
||||
* <p>为 true 则抛出异常</p>
|
||||
*
|
||||
* @param expression boolean 值
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void isFalse(boolean expression, String message, Object... params) {
|
||||
isTrue(!expression, message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 object 为 null
|
||||
* <p>不为 null 则抛异常</p>
|
||||
*
|
||||
* @param object 对象
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void isNull(Object object, String message, Object... params) {
|
||||
isTrue(object == null, message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 object 不为 null
|
||||
* <p>为 null 则抛异常</p>
|
||||
*
|
||||
* @param object 对象
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void notNull(Object object, String message, Object... params) {
|
||||
isTrue(object != null, message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 value 不为 empty
|
||||
* <p>为 empty 则抛异常</p>
|
||||
*
|
||||
* @param value 字符串
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void notEmpty(String value, String message, Object... params) {
|
||||
isTrue(StringUtils.isNotBlank(value), message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 collection 不为 empty
|
||||
* <p>为 empty 则抛异常</p>
|
||||
*
|
||||
* @param collection 集合
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void notEmpty(Collection<?> collection, String message, Object... params) {
|
||||
isTrue(CollectionUtils.isNotEmpty(collection), message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 map 不为 empty
|
||||
* <p>为 empty 则抛异常</p>
|
||||
*
|
||||
* @param map 集合
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void notEmpty(Map<?, ?> map, String message, Object... params) {
|
||||
isTrue(CollectionUtils.isNotEmpty(map), message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 map 为 empty
|
||||
* <p>为 empty 则抛异常</p>
|
||||
*
|
||||
* @param map 集合
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void isEmpty(Map<?, ?> map, String message, Object... params) {
|
||||
isTrue(CollectionUtils.isEmpty(map), message, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言这个 数组 不为 empty
|
||||
* <p>为 empty 则抛异常</p>
|
||||
*
|
||||
* @param array 数组
|
||||
* @param message 消息
|
||||
*/
|
||||
public static void notEmpty(Object[] array, String message, Object... params) {
|
||||
isTrue(FuncBase.isNotEmpty(array), message, params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Collection工具类
|
||||
*
|
||||
* @author Caratacus
|
||||
* @since 2016-09-19
|
||||
*/
|
||||
public class CollectionUtils {
|
||||
|
||||
private static final int MAX_POWER_OF_TWO = 1 << (Integer.SIZE - 2);
|
||||
|
||||
private static boolean isJdk8;
|
||||
|
||||
static {
|
||||
// Java 8
|
||||
// Java 9+: 9,11,17
|
||||
try {
|
||||
isJdk8 = System.getProperty("java.version").startsWith("1.8.");
|
||||
} catch (Exception ignore) {
|
||||
isJdk8 = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验集合是否为空
|
||||
*
|
||||
* @param coll 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
return (coll == null || coll.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验集合是否不为空
|
||||
*
|
||||
* @param coll 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll) {
|
||||
return !isEmpty(coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Map是否为空
|
||||
*
|
||||
* @param map 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
return (map == null || map.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Map是否不为空
|
||||
*
|
||||
* @param map 入参
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认HashMap
|
||||
*
|
||||
* @param <K> K
|
||||
* @param <V> V
|
||||
* @return HashMap
|
||||
* @see com.google.common.collect.Maps#newHashMap()
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public static <K, V> HashMap<K, V> newHashMap() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据预期大小创建HashMap.
|
||||
*
|
||||
* @param expectedSize 预期大小
|
||||
* @param <K> K
|
||||
* @param <V> V
|
||||
* @return HashMap
|
||||
* @see com.google.common.collect.Maps#newHashMapWithExpectedSize
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize) {
|
||||
return new HashMap<>(capacity(expectedSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用来过渡下Jdk1.8下ConcurrentHashMap的性能bug
|
||||
* https://bugs.openjdk.java.net/browse/JDK-8161372
|
||||
*
|
||||
* A temporary workaround for Java 8 ConcurrentHashMap#computeIfAbsent specific performance issue: JDK-8161372.</br>
|
||||
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8161372">https://bugs.openjdk.java.net/browse/JDK-8161372</a>
|
||||
*
|
||||
* @param concurrentHashMap ConcurrentHashMap 没限制类型了,非ConcurrentHashMap就别调用这方法了
|
||||
* @param key key
|
||||
* @param mappingFunction function
|
||||
* @param <K> k
|
||||
* @param <V> v
|
||||
* @return V
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public static <K, V> V computeIfAbsent(Map<K, V> concurrentHashMap, K key, Function<? super K, ? extends V> mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
if (isJdk8) {
|
||||
V v = concurrentHashMap.get(key);
|
||||
if (null == v) {
|
||||
// issue#11986 lock bug
|
||||
// v = map.computeIfAbsent(key, func);
|
||||
|
||||
// this bug fix methods maybe cause `func.apply` multiple calls.
|
||||
v = mappingFunction.apply(key);
|
||||
if (null == v) {
|
||||
return null;
|
||||
}
|
||||
final V res = concurrentHashMap.putIfAbsent(key, v);
|
||||
if (null != res) {
|
||||
// if pre value present, means other thread put value already, and putIfAbsent not effect
|
||||
// return exist value
|
||||
return res;
|
||||
}
|
||||
// if pre value is null, means putIfAbsent effected, return current value
|
||||
}
|
||||
return v;
|
||||
} else {
|
||||
return concurrentHashMap.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a capacity that is sufficient to keep the map from being resized as
|
||||
* long as it grows no larger than expectedSize and the load factor is >= its
|
||||
* default (0.75).
|
||||
*
|
||||
* @see com.google.common.collect.Maps#capacity(int)
|
||||
* @since 3.4.0
|
||||
*/
|
||||
private static int capacity(int expectedSize) {
|
||||
if (expectedSize < 3) {
|
||||
if (expectedSize < 0) {
|
||||
throw new IllegalArgumentException("expectedSize cannot be negative but was: " + expectedSize);
|
||||
}
|
||||
return expectedSize + 1;
|
||||
}
|
||||
if (expectedSize < MAX_POWER_OF_TWO) {
|
||||
// This is the calculation used in JDK8 to resize when a putAll
|
||||
// happens; it seems to be the most conservative calculation we
|
||||
// can make. 0.75 is the default load factor.
|
||||
return (int) ((float) expectedSize / 0.75F + 1.0F);
|
||||
}
|
||||
return Integer.MAX_VALUE; // any large value
|
||||
}
|
||||
|
||||
// 提供处理Map多key取值工具方法
|
||||
|
||||
/**
|
||||
* 批量取出Map中的值
|
||||
*
|
||||
* @param map map
|
||||
* @param keys 键的集合
|
||||
* @param <K> key的泛型
|
||||
* @param <V> value的泛型
|
||||
* @return value的泛型的集合
|
||||
*/
|
||||
public static <K, V> List<V> getCollection(Map<K, V> map, Iterable<K> keys) {
|
||||
List<V> result = new ArrayList<>();
|
||||
if (map != null && !map.isEmpty() && keys != null) {
|
||||
keys.forEach(key -> Optional.ofNullable(map.get(key)).ifPresent(result::add));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量取出Map中的值
|
||||
*
|
||||
* @param map map
|
||||
* @param keys 键的集合
|
||||
* @param comparator 排序器
|
||||
* @param <K> key的泛型
|
||||
* @param <V> value的泛型
|
||||
* @return value的泛型的集合
|
||||
*/
|
||||
public static <K, V> List<V> getCollection(Map<K, V> map, Iterable<K> keys, Comparator<V> comparator) {
|
||||
Objects.requireNonNull(comparator);
|
||||
List<V> result = getCollection(map, keys);
|
||||
Collections.sort(result, comparator);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建List
|
||||
*
|
||||
* @since 3.5.4
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> List<T> toList(T... t) {
|
||||
if (t != null) {
|
||||
return Arrays.asList(t);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* mybatis_plus 自用常量集中管理
|
||||
*
|
||||
* @author miemie
|
||||
* @since 2018-07-22
|
||||
*/
|
||||
public interface Constants extends StringPool, Serializable {
|
||||
|
||||
/**
|
||||
* project name
|
||||
*/
|
||||
String MYBATIS_PLUS = "mybatis-plus";
|
||||
|
||||
/**
|
||||
* MD5
|
||||
*/
|
||||
String MD5 = "MD5";
|
||||
/**
|
||||
* AES
|
||||
*/
|
||||
String AES = "AES";
|
||||
/**
|
||||
* AES 算法
|
||||
*/
|
||||
String AES_CBC_CIPHER = "AES/CBC/PKCS5Padding";
|
||||
/**
|
||||
* as
|
||||
*/
|
||||
String AS = " AS ";
|
||||
|
||||
|
||||
/**
|
||||
* 实体类
|
||||
*/
|
||||
String ENTITY = "et";
|
||||
/**
|
||||
* 实体类 带后缀 ==> .
|
||||
*/
|
||||
String ENTITY_DOT = ENTITY + DOT;
|
||||
/**
|
||||
* wrapper 类
|
||||
*/
|
||||
String WRAPPER = "ew";
|
||||
/**
|
||||
* wrapper 类 带后缀 ==> .
|
||||
*/
|
||||
String WRAPPER_DOT = WRAPPER + DOT;
|
||||
/**
|
||||
* wrapper 类的属性 entity
|
||||
*/
|
||||
String WRAPPER_ENTITY = WRAPPER_DOT + "entity";
|
||||
/**
|
||||
* wrapper 类的属性 sqlSegment
|
||||
*/
|
||||
String WRAPPER_SQLSEGMENT = WRAPPER_DOT + "sqlSegment";
|
||||
/**
|
||||
* wrapper 类的属性 emptyOfNormal
|
||||
*/
|
||||
String WRAPPER_EMPTYOFNORMAL = WRAPPER_DOT + "emptyOfNormal";
|
||||
/**
|
||||
* wrapper 类的属性 nonEmptyOfNormal
|
||||
*/
|
||||
String WRAPPER_NONEMPTYOFNORMAL = WRAPPER_DOT + "nonEmptyOfNormal";
|
||||
/**
|
||||
* wrapper 类的属性 nonEmptyOfEntity
|
||||
*/
|
||||
String WRAPPER_NONEMPTYOFENTITY = WRAPPER_DOT + "nonEmptyOfEntity";
|
||||
/**
|
||||
* wrapper 类的属性 emptyOfWhere
|
||||
*/
|
||||
String WRAPPER_EMPTYOFWHERE = WRAPPER_DOT + "emptyOfWhere";
|
||||
/**
|
||||
* wrapper 类的判断属性 nonEmptyOfWhere
|
||||
*/
|
||||
String WRAPPER_NONEMPTYOFWHERE = WRAPPER_DOT + "nonEmptyOfWhere";
|
||||
/**
|
||||
* wrapper 类的属性 entity 带后缀 ==> .
|
||||
*/
|
||||
String WRAPPER_ENTITY_DOT = WRAPPER_DOT + "entity" + DOT;
|
||||
/**
|
||||
* wrapper 类的属性 expression 下级属性 order
|
||||
*/
|
||||
String WRAPPER_EXPRESSION_ORDER = WRAPPER_DOT + "useAnnotationOrderBy";
|
||||
/**
|
||||
* UpdateWrapper 类的属性 sqlSet
|
||||
*/
|
||||
String U_WRAPPER_SQL_SET = WRAPPER_DOT + "sqlSet";
|
||||
/**
|
||||
* QueryWrapper 类的属性 sqlSelect
|
||||
*/
|
||||
String Q_WRAPPER_SQL_SELECT = WRAPPER_DOT + "sqlSelect";
|
||||
/**
|
||||
* wrapper 类的属性 sqlComment
|
||||
*/
|
||||
String Q_WRAPPER_SQL_COMMENT = WRAPPER_DOT + "sqlComment";
|
||||
/**
|
||||
* wrapper 类的属性 sqlFirst
|
||||
*/
|
||||
String Q_WRAPPER_SQL_FIRST = WRAPPER_DOT + "sqlFirst";
|
||||
/**
|
||||
* columnMap
|
||||
*/
|
||||
@Deprecated
|
||||
String COLUMN_MAP = "cm";
|
||||
/**
|
||||
* columnMap.isEmpty
|
||||
*/
|
||||
String COLUMN_MAP_IS_EMPTY = COLUMN_MAP + DOT + "isEmpty";
|
||||
/**
|
||||
* collection
|
||||
*
|
||||
* @see #COLL
|
||||
* @deprecated 3.5.2 后面修改成collection
|
||||
*/
|
||||
@Deprecated
|
||||
String COLLECTION = "coll";
|
||||
|
||||
/**
|
||||
* @since 3.5.2
|
||||
*/
|
||||
String COLL = "coll";
|
||||
/**
|
||||
* list
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
String LIST = "list";
|
||||
/**
|
||||
* where
|
||||
*/
|
||||
String WHERE = "WHERE";
|
||||
|
||||
/*
|
||||
* having
|
||||
*/
|
||||
String HAVING = "HAVING";
|
||||
/**
|
||||
* limit
|
||||
*/
|
||||
String LIMIT = "LIMIT";
|
||||
|
||||
/**
|
||||
* @since 3.5.2
|
||||
*/
|
||||
String ARRAY = "array";
|
||||
/**
|
||||
* order by
|
||||
*/
|
||||
String ORDER_BY = "ORDER BY";
|
||||
/**
|
||||
* asc
|
||||
*/
|
||||
String ASC = "ASC";
|
||||
/**
|
||||
* desc
|
||||
*/
|
||||
String DESC = "DESC";
|
||||
/**
|
||||
* 乐观锁字段
|
||||
*/
|
||||
String MP_OPTLOCK_VERSION_ORIGINAL = "MP_OPTLOCK_VERSION_ORIGINAL";
|
||||
|
||||
/**
|
||||
* wrapper 内部参数相关
|
||||
*/
|
||||
String WRAPPER_PARAM = "MPGENVAL";
|
||||
String WRAPPER_PARAM_MIDDLE = ".paramNameValuePairs" + DOT;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
|
||||
import com.jeelowcode.framework.plus.core.exceptions.JeelowcodeSqlException;
|
||||
|
||||
/**
|
||||
* 异常辅助工具类
|
||||
*
|
||||
* @author HCL
|
||||
* @since 2018-07-24
|
||||
*/
|
||||
public final class ExceptionUtils {
|
||||
|
||||
private ExceptionUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个新的异常,统一构建,方便统一处理
|
||||
*
|
||||
* @param msg 消息
|
||||
* @param t 异常信息
|
||||
* @return 返回异常
|
||||
*/
|
||||
public static JeelowcodeSqlException mpe(String msg, Throwable t, Object... params) {
|
||||
return new JeelowcodeSqlException(String.format(msg, params), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载的方法
|
||||
*
|
||||
* @param msg 消息
|
||||
* @return 返回异常
|
||||
*/
|
||||
public static JeelowcodeSqlException mpe(String msg, Object... params) {
|
||||
return new JeelowcodeSqlException(String.format(msg, params));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载的方法
|
||||
*
|
||||
* @param t 异常
|
||||
* @return 返回异常
|
||||
*/
|
||||
public static JeelowcodeSqlException mpe(Throwable t) {
|
||||
return new JeelowcodeSqlException(t);
|
||||
}
|
||||
|
||||
public static void throwMpe(boolean condition, String msg, Object... params) {
|
||||
if (condition) {
|
||||
throw mpe(msg, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2023, baomidou (jobob@qq.com).
|
||||
*
|
||||
* Licensed 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.
|
||||
*//*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* <p> copy from spring-core#org.springframework.util.SerializationUtils version 5.2.8 </p>
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public class SerializationUtils {
|
||||
|
||||
/**
|
||||
* Deep clone an {@code Object} using serialization.
|
||||
* <p>This is many times slower than writing clone methods by hand
|
||||
* on all objects in your object graph. However, for complex object
|
||||
* graphs, or for those that don't support deep cloning this can
|
||||
* be a simple alternative implementation. Of course all the objects
|
||||
* must be {@code Serializable}.</p>
|
||||
*
|
||||
* @param <T> the type of the object involved
|
||||
* @param object the {@code Serializable} object to clone
|
||||
* @return the cloned object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Serializable> T clone(final T object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
final byte[] objectData = serialize(object);
|
||||
return (T) deserialize(objectData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given object to a byte array.
|
||||
*
|
||||
* @param object the object to serialize
|
||||
* @return an array of bytes representing the object in a portable fashion
|
||||
*/
|
||||
public static byte[] serialize(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
|
||||
oos.writeObject(object);
|
||||
oos.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalArgumentException("Failed to serialize object of type: " + object.getClass(), ex);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the byte array into an object.
|
||||
*
|
||||
* @param bytes a serialized object
|
||||
* @return the result of deserializing the bytes
|
||||
*/
|
||||
public static Object deserialize(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
|
||||
return ois.readObject();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalArgumentException("Failed to deserialize object", ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalStateException("Failed to deserialize object type", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
本软件受适用的国家软件著作权法(包括国际条约)和开源协议 双重保护许可。
|
||||
|
||||
开源协议中文释意如下:
|
||||
1.JeeLowCode开源版本无任何限制,在遵循本开源协议(Apache2.0)条款下,【允许商用】使用,不会造成侵权行为。
|
||||
2.允许基于本平台软件开展业务系统开发。
|
||||
3.在任何情况下,您不得使用本软件开发可能被认为与【本软件竞争】的软件。
|
||||
|
||||
最终解释权归:http://www.jeelowcode.com
|
||||
*/
|
||||
package com.jeelowcode.framework.plus.core.toolkit;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-03-26 9:55
|
||||
* @dedescription:
|
||||
*/
|
||||
public interface StringPool {
|
||||
|
||||
String AMPERSAND = "&";
|
||||
String AND = "and";
|
||||
String AT = "@";
|
||||
String ASTERISK = "*";
|
||||
String STAR = ASTERISK;
|
||||
String BACK_SLASH = "\\";
|
||||
String COLON = ":";
|
||||
String COMMA = ",";
|
||||
String DASH = "-";
|
||||
String DOLLAR = "$";
|
||||
String DOT = ".";
|
||||
String DOTDOT = "..";
|
||||
String DOT_CLASS = ".class";
|
||||
String DOT_JAVA = ".java";
|
||||
String DOT_XML = ".xml";
|
||||
String EMPTY = "";
|
||||
String EQUALS = "=";
|
||||
String FALSE = "false";
|
||||
String SLASH = "/";
|
||||
String HASH = "#";
|
||||
String HAT = "^";
|
||||
String LEFT_BRACE = "{";
|
||||
String LEFT_BRACKET = "(";
|
||||
String LEFT_CHEV = "<";
|
||||
String DOT_NEWLINE = ",\n";
|
||||
String NEWLINE = "\n";
|
||||
String N = "n";
|
||||
String NO = "no";
|
||||
String NULL = "null";
|
||||
String NUM = "NUM";
|
||||
String OFF = "off";
|
||||
String ON = "on";
|
||||
String PERCENT = "%";
|
||||
String PIPE = "|";
|
||||
String PLUS = "+";
|
||||
String QUESTION_MARK = "?";
|
||||
String EXCLAMATION_MARK = "!";
|
||||
String QUOTE = "\"";
|
||||
String RETURN = "\r";
|
||||
String TAB = "\t";
|
||||
String RIGHT_BRACE = "}";
|
||||
String RIGHT_BRACKET = ")";
|
||||
String RIGHT_CHEV = ">";
|
||||
String SEMICOLON = ";";
|
||||
String SINGLE_QUOTE = "'";
|
||||
String BACKTICK = "`";
|
||||
String SPACE = " ";
|
||||
String SQL = "sql";
|
||||
String TILDA = "~";
|
||||
String LEFT_SQ_BRACKET = "[";
|
||||
String RIGHT_SQ_BRACKET = "]";
|
||||
String TRUE = "true";
|
||||
String UNDERSCORE = "_";
|
||||
String UTF_8 = "UTF-8";
|
||||
String US_ASCII = "US-ASCII";
|
||||
String ISO_8859_1 = "ISO-8859-1";
|
||||
String Y = "y";
|
||||
String YES = "yes";
|
||||
String ONE = "1";
|
||||
String ZERO = "0";
|
||||
String DOLLAR_LEFT_BRACE = "${";
|
||||
String HASH_LEFT_BRACE = "#{";
|
||||
String CRLF = "\r\n";
|
||||
|
||||
String HTML_NBSP = " ";
|
||||
String HTML_AMP = "&";
|
||||
String HTML_QUOTE = """;
|
||||
String HTML_LT = "<";
|
||||
String HTML_GT = ">";
|
||||
|
||||
// ---------------------------------------------------------------- array
|
||||
|
||||
String[] EMPTY_ARRAY = new String[0];
|
||||
|
||||
byte[] BYTES_NEW_LINE = StringPool.NEWLINE.getBytes();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user