改进系统多数据库部署兼容性,将SQL取余、求字符串长度函数由JDBC规范的函数改为自定义函数

This commit is contained in:
datagear 2021-03-05 22:21:55 +08:00
parent 0493f4b765
commit 59cb2f8213
21 changed files with 331 additions and 191 deletions

View File

@ -222,7 +222,7 @@ public abstract class AbstractMybatisDataPermissionEntityService<ID, T extends D
*/
protected List<Integer> getPermissions(User user, List<ID> ids, int permissionForAbsence)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
addDataPermissionParameters(params, user);
params.put("ids", ids);

View File

@ -81,7 +81,6 @@ public abstract class AbstractMybatisEntityService<ID, T extends Entity<ID>> ext
*/
protected boolean deleteById(ID id, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
params.put("id", id);
return (deleteMybatis("deleteById", params) > 0);
@ -119,7 +118,6 @@ public abstract class AbstractMybatisEntityService<ID, T extends Entity<ID>> ext
*/
protected T getById(ID id, Map<String, Object> params, boolean postProcessSelect)
{
addIdentifierQuoteParameter(params);
params.put("id", id);
T entity = selectOneMybatis("getById", params);

View File

@ -7,16 +7,11 @@
package org.datagear.management.service.impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.datagear.management.domain.User;
import org.datagear.management.util.dialect.MbSqlDialect;
@ -24,7 +19,6 @@ import org.datagear.persistence.Order;
import org.datagear.persistence.PagingData;
import org.datagear.persistence.PagingQuery;
import org.datagear.persistence.Query;
import org.datagear.util.JdbcUtil;
import org.datagear.util.StringUtil;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
@ -60,6 +54,18 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
/** 分页查询SQL尾部片段 */
public static final String PAGING_QUERY_FOOT_SQL = "_pagingQueryFoot";
/** {@linkplain MbSqlDialect#funcNameReplace()}的MyBatis参数名 */
public static final String FUNC_NAME_REPLACE = "_FUNC_REPLACE";
/** {@linkplain MbSqlDialect#funcNameModInt()}的MyBatis参数名 */
public static final String FUNC_NAME_MODINT = "_FUNC_MODINT";
/** {@linkplain MbSqlDialect#funcNameLength()}的MyBatis参数名 */
public static final String FUNC_NAME_LENGTH = "_FUNC_LENGTH";
/** {@linkplain MbSqlDialect#funcNameMax()}的MyBatis参数名 */
public static final String FUNC_NAME_MAX = "_FUNC_MAX";
private MbSqlDialect dialect;
private String identifierQuoteKey = DEFAULT_IDENTIFIER_QUOTE_KEY;
@ -123,7 +129,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
{
checkAddInput(entity);
addIdentifierQuoteParameter(params);
params.put("entity", entity);
insertMybatis("insert", params);
@ -153,7 +158,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
{
checkUpdateInput(entity);
addIdentifierQuoteParameter(params);
params.put("entity", entity);
return (updateMybatis("update", params) > 0);
@ -179,7 +183,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected boolean delete(T obj, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
params.put("obj", obj);
return (deleteMybatis("delete", params) > 0);
@ -199,7 +202,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected T get(T param, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
params.put("param", param);
T entity = selectOneMybatis("get", params);
@ -241,8 +243,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected List<T> query(String statement, Query query, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
addQueryaram(params, query);
addQueryParam(params, query);
List<T> list = selectListMybatis(statement, params);
postProcessSelects(list);
@ -259,8 +260,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected List<T> query(String statement, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
List<T> list = selectListMybatis(statement, params);
postProcessSelects(list);
@ -307,8 +306,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected PagingData<T> pagingQuery(String statement, PagingQuery pagingQuery, Map<String, Object> params)
{
addIdentifierQuoteParameter(params);
addQueryaram(params, pagingQuery);
addQueryParam(params, pagingQuery);
int total = (Integer) selectOneMybatis(statement + "Count", params);
@ -316,7 +314,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
int startIndex = pagingData.getStartIndex();
addPagingQueryParams(params, startIndex, pagingData.getPageSize());
addDialectParamsPagingQuery(params, startIndex, pagingData.getPageSize());
List<T> list = null;
@ -336,39 +334,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
return pagingData;
}
/**
* 添加分页查询参数
*
* @param params
* @param startIndex
* 起始索引{@code 0}开始
* @param fetchSize
* 页大小
*/
protected void addPagingQueryParams(Map<String, Object> params, int startIndex, int fetchSize)
{
params.put(PAGING_QUERY_SUPPORTED, this.dialect.supportsPaging());
String sqlHead = null;
String sqlFoot = null;
if (this.dialect.supportsPaging())
{
sqlHead = this.dialect.pagingSqlHead(startIndex, fetchSize);
sqlFoot = this.dialect.pagingSqlFoot(startIndex, fetchSize);
}
else
{
// 不支持的话设为空字符串方便底层SQL Mapper处理
sqlHead = "";
sqlFoot = "";
}
params.put(PAGING_QUERY_HEAD_SQL, sqlHead);
params.put(PAGING_QUERY_FOOT_SQL, sqlFoot);
}
/**
* 后置处理查询结果列表
* <p>
@ -441,7 +406,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param query
* @return
*/
protected void addQueryaram(Map<String, Object> param, Query query)
protected void addQueryParam(Map<String, Object> param, Query query)
{
String keyword = query.getKeyword();
String condition = query.getCondition();
@ -484,6 +449,49 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
}
}
protected void addDialectParamsBase(Map<String, Object> param)
{
param.put(this.identifierQuoteKey, this.dialect.getIdentifierQuote());
param.put(FUNC_NAME_REPLACE, this.dialect.funcNameReplace());
param.put(FUNC_NAME_MODINT, this.dialect.funcNameModInt());
param.put(FUNC_NAME_LENGTH, this.dialect.funcNameLength());
param.put(FUNC_NAME_MAX, this.dialect.funcNameMax());
}
/**
* 添加分页查询参数
*
* @param params
* @param startIndex
* 起始索引{@code 0}开始
* @param fetchSize
* 页大小
*/
protected void addDialectParamsPagingQuery(Map<String, Object> params, int startIndex, int fetchSize)
{
params.put(PAGING_QUERY_SUPPORTED, this.dialect.supportsPaging());
String sqlHead = null;
String sqlFoot = null;
if (this.dialect.supportsPaging())
{
sqlHead = this.dialect.pagingSqlHead(startIndex, fetchSize);
sqlFoot = this.dialect.pagingSqlFoot(startIndex, fetchSize);
}
else
{
// 不支持的话设为空字符串方便底层SQL Mapper处理
sqlHead = "";
sqlFoot = "";
}
params.put(PAGING_QUERY_HEAD_SQL, sqlHead);
params.put(PAGING_QUERY_FOOT_SQL, sqlFoot);
}
/**
* 查询一个
*
@ -492,9 +500,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected <TT> TT selectOneMybatis(String statement)
{
SqlSession sqlSession = getSqlSession();
return sqlSession.selectOne(toGlobalSqlId(statement));
return selectOneMybatis(statement, buildParamMap());
}
/**
@ -504,11 +510,11 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param parameter
* @return
*/
protected <TT> TT selectOneMybatis(String statement, Object parameter)
protected <TT> TT selectOneMybatis(String statement, Map<String, Object> parameter)
{
SqlSession sqlSession = getSqlSession();
addDialectParamsBase(parameter);
return sqlSession.selectOne(toGlobalSqlId(statement), parameter);
return getSqlSession().selectOne(toGlobalSqlId(statement), parameter);
}
/**
@ -519,9 +525,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected <E> List<E> selectListMybatis(String statement)
{
SqlSession sqlSession = getSqlSession();
return sqlSession.selectList(toGlobalSqlId(statement));
return selectListMybatis(statement, buildParamMap());
}
/**
@ -531,11 +535,11 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param parameter
* @return
*/
protected <E> List<E> selectListMybatis(String statement, Object parameter)
protected <E> List<E> selectListMybatis(String statement, Map<String, Object> parameter)
{
SqlSession sqlSession = getSqlSession();
addDialectParamsBase(parameter);
return sqlSession.selectList(toGlobalSqlId(statement), parameter);
return getSqlSession().selectList(toGlobalSqlId(statement), parameter);
}
/**
@ -546,11 +550,11 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param rowBounds
* @return
*/
protected <E> List<E> selectListMybatis(String statement, Object parameter, RowBounds rowBounds)
protected <E> List<E> selectListMybatis(String statement, Map<String, Object> parameter, RowBounds rowBounds)
{
SqlSession sqlSession = getSqlSession();
addDialectParamsBase(parameter);
return sqlSession.selectList(toGlobalSqlId(statement), parameter, rowBounds);
return getSqlSession().selectList(toGlobalSqlId(statement), parameter, rowBounds);
}
/**
@ -561,7 +565,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected int insertMybatis(String statement)
{
return getSqlSession().insert(toGlobalSqlId(statement));
return insertMybatis(statement, buildParamMap());
}
/**
@ -571,8 +575,10 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param parameter
* @return
*/
protected int insertMybatis(String statement, Object parameter)
protected int insertMybatis(String statement, Map<String, Object> parameter)
{
addDialectParamsBase(parameter);
return getSqlSession().insert(toGlobalSqlId(statement), parameter);
}
@ -584,7 +590,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected int updateMybatis(String statement)
{
return getSqlSession().update(toGlobalSqlId(statement));
return updateMybatis(statement, buildParamMap());
}
/**
@ -594,8 +600,10 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param parameter
* @return
*/
protected int updateMybatis(String statement, Object parameter)
protected int updateMybatis(String statement, Map<String, Object> parameter)
{
addDialectParamsBase(parameter);
return getSqlSession().update(toGlobalSqlId(statement), parameter);
}
@ -607,7 +615,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
*/
protected int deleteMybatis(String statement)
{
return getSqlSession().delete(toGlobalSqlId(statement));
return deleteMybatis(statement, buildParamMap());
}
/**
@ -617,8 +625,10 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
* @param parameter
* @return
*/
protected int deleteMybatis(String statement, Object parameter)
protected int deleteMybatis(String statement, Map<String, Object> parameter)
{
addDialectParamsBase(parameter);
return getSqlSession().delete(toGlobalSqlId(statement), parameter);
}
@ -633,16 +643,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
return getSqlNamespace() + "." + localSqlId;
}
/**
* 添加标识符引用符参数
*
* @param params
*/
protected void addIdentifierQuoteParameter(Map<String, Object> params)
{
params.put(this.identifierQuoteKey, this.dialect.getIdentifierQuote());
}
/**
* 为标识符添加引用符
*
@ -655,47 +655,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
return iq + s + iq;
}
/**
* 获取数据库标识引用符
* <p>
* 如果数据库不可用将返回{@linkplain #CONNECTION_NOT_AVALIABLE}
* </p>
*
* @param dataSource
* @return
*/
protected String getIdentifierQuote(DataSource dataSource)
{
String identifierQuote = " ";
Connection cn = null;
try
{
cn = dataSource.getConnection();
identifierQuote = cn.getMetaData().getIdentifierQuoteString();
}
catch (SQLException e)
{
}
finally
{
close(cn);
}
return identifierQuote;
}
/**
* 关闭{@linkplain Connection}
*
* @param cn
*/
protected void close(Connection cn)
{
JdbcUtil.closeConnection(cn);
}
/**
* 判断对象字符串数组集合Map是否为空
*
@ -739,19 +698,6 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
return new HashMap<>();
}
/**
* 构建参数映射表
*
* @return
*/
protected Map<String, Object> buildParamMapWithIdentifierQuoteParameter()
{
Map<String, Object> map = new HashMap<>();
addIdentifierQuoteParameter(map);
return map;
}
/**
* 获取sql语句的名字空间
*

View File

@ -59,7 +59,6 @@ public class AnalysisProjectServiceImpl extends AbstractMybatisDataPermissionEnt
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);

View File

@ -100,7 +100,7 @@ public class AuthorizationServiceImpl extends AbstractMybatisDataPermissionEntit
@Override
public int deleteByResource(String resourceType, String... resources)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("resourceType", resourceType);
params.put("resources", resources);

View File

@ -185,7 +185,6 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);
@ -233,7 +232,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addSqlDataSetEntity(SqlDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertSqlDataSetEntity", params) > 0);
@ -241,7 +240,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addJsonValueDataSetEntity(JsonValueDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertJsonValueDataSetEntity", params) > 0);
@ -249,7 +248,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addJsonFileDataSetEntity(JsonFileDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertJsonFileDataSetEntity", params) > 0);
@ -257,7 +256,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addExcelDataSetEntity(ExcelDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertExcelDataSetEntity", params) > 0);
@ -265,7 +264,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addCsvValueDataSetEntity(CsvValueDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertCsvValueDataSetEntity", params) > 0);
@ -273,7 +272,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addCsvFileDataSetEntity(CsvFileDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertCsvFileDataSetEntity", params) > 0);
@ -281,7 +280,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean addHttpDataSetEntity(HttpDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("insertHttpDataSetEntity", params) > 0);
@ -321,7 +320,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateSqlDataSetEntity(SqlDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateSqlDataSetEntity", params) > 0);
@ -329,7 +328,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateJsonValueDataSetEntity(JsonValueDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateJsonValueDataSetEntity", params) > 0);
@ -337,7 +336,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateJsonFileDataSetEntity(JsonFileDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateJsonFileDataSetEntity", params) > 0);
@ -345,7 +344,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateExcelDataSetEntity(ExcelDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateExcelDataSetEntity", params) > 0);
@ -353,7 +352,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateCsvValueDataSetEntity(CsvValueDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateCsvValueDataSetEntity", params) > 0);
@ -361,7 +360,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateCsvFileDataSetEntity(CsvFileDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateCsvFileDataSetEntity", params) > 0);
@ -369,7 +368,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected boolean updateHttpDataSetEntity(HttpDataSetEntity entity)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("entity", entity);
return (updateMybatis("updateHttpDataSetEntity", params) > 0);
@ -446,7 +445,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
if (dataSetEntity == null)
return;
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("dataSetId", dataSetEntity.getId());
List<DataSetPropertyPO> propertyPOs = selectListMybatis("getPropertyPOs", params);
@ -460,7 +459,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected SqlDataSetEntity getSqlDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
SqlDataSetEntity entity = selectOneMybatis("getSqlDataSetEntityById", params);
@ -470,7 +469,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected JsonValueDataSetEntity getJsonValueDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
JsonValueDataSetEntity entity = selectOneMybatis("getJsonValueDataSetEntityById", params);
@ -480,7 +479,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected JsonFileDataSetEntity getJsonFileDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
JsonFileDataSetEntity entity = selectOneMybatis("getJsonFileDataSetEntityById", params);
@ -493,7 +492,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected ExcelDataSetEntity getExcelDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
ExcelDataSetEntity entity = selectOneMybatis("getExcelDataSetEntityById", params);
@ -506,7 +505,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected CsvValueDataSetEntity getCsvValueDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
CsvValueDataSetEntity entity = selectOneMybatis("getCsvValueDataSetEntityById", params);
@ -516,7 +515,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected CsvFileDataSetEntity getCsvFileDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
CsvFileDataSetEntity entity = selectOneMybatis("getCsvFileDataSetEntityById", params);
@ -529,7 +528,7 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected HttpDataSetEntity getHttpDataSetEntityById(String id)
{
Map<String, Object> params = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> params = buildParamMap();
params.put("id", id);
HttpDataSetEntity entity = selectOneMybatis("getHttpDataSetEntityById", params);
@ -562,27 +561,43 @@ public class DataSetEntityServiceImpl extends AbstractMybatisDataPermissionEntit
protected void saveDataSetPropertyPOs(DataSetEntity entity)
{
deleteMybatis("deletePropertyPOs", entity.getId());
Map<String, Object> delParams = buildParamMap();
delParams.put("dataSetId", entity.getId());
deleteMybatis("deletePropertyPOs", delParams);
List<DataSetPropertyPO> pos = DataSetPropertyPO.from(entity);
if (!pos.isEmpty())
{
for (DataSetPropertyPO relation : pos)
insertMybatis("insertPropertyPO", relation);
{
Map<String, Object> insertParams = buildParamMap();
insertParams.put("entity", relation);
insertMybatis("insertPropertyPO", insertParams);
}
}
}
protected void saveDataSetParamPOs(DataSetEntity entity)
{
deleteMybatis("deleteParamPOs", entity.getId());
Map<String, Object> delParams = buildParamMap();
delParams.put("dataSetId", entity.getId());
deleteMybatis("deleteParamPOs", delParams);
List<DataSetParamPO> pos = DataSetParamPO.from(entity);
if (!pos.isEmpty())
{
for (DataSetParamPO relation : pos)
insertMybatis("insertParamPO", relation);
{
Map<String, Object> insertParams = buildParamMap();
insertParams.put("entity", relation);
insertMybatis("insertParamPO", insertParams);
}
}
}

View File

@ -59,7 +59,6 @@ public class DataSetResDirectoryServiceImpl extends
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);

View File

@ -148,7 +148,6 @@ public class HtmlChartWidgetEntityServiceImpl
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);
@ -197,14 +196,22 @@ public class HtmlChartWidgetEntityServiceImpl
protected void saveWidgetDataSetRelations(HtmlChartWidgetEntity entity)
{
deleteMybatis("deleteDataSetRelationById", entity.getId());
Map<String, Object> delParams = buildParamMap();
delParams.put("id", entity.getId());
deleteMybatis("deleteDataSetRelationById", delParams);
List<WidgetDataSetRelation> relations = getWidgetDataSetRelations(entity);
if (!relations.isEmpty())
{
for (WidgetDataSetRelation relation : relations)
insertMybatis("insertDataSetRelation", relation);
{
Map<String, Object> insertParams = buildParamMap();
insertParams.put("entity", relation);
insertMybatis("insertDataSetRelation", insertParams);
}
}
}
@ -269,7 +276,7 @@ public class HtmlChartWidgetEntityServiceImpl
protected void setChartDataSets(HtmlChartWidgetEntity widget, boolean forAnalysis)
{
Map<String, Object> sqlParams = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> sqlParams = buildParamMap();
sqlParams.put("widgetId", widget.getId());
List<WidgetDataSetRelation> relations = selectListMybatis("getDataSetRelations", sqlParams);

View File

@ -109,7 +109,6 @@ public class HtmlTplDashboardWidgetEntityServiceImpl
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);

View File

@ -49,7 +49,7 @@ public class RoleUserServiceImpl extends AbstractMybatisEntityService<String, Ro
@Override
public RoleUser getByRoleAndUser(Role role, User user)
{
Map<String, Object> paramMap = buildParamMapWithIdentifierQuoteParameter();
Map<String, Object> paramMap = buildParamMap();
paramMap.put("role", role);
paramMap.put("user", user);

View File

@ -119,7 +119,6 @@ public class SchemaServiceImpl extends AbstractMybatisDataPermissionEntityServic
public int updateCreateUserId(String oldUserId, String newUserId)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("oldUserId", oldUserId);
params.put("newUserId", newUserId);
@ -130,7 +129,6 @@ public class SchemaServiceImpl extends AbstractMybatisDataPermissionEntityServic
public int deleteByUserId(String... userIds)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("userIds", userIds);
return updateMybatis("deleteByUserId", params);

View File

@ -79,7 +79,7 @@ public class SqlHistoryServiceImpl extends AbstractMybatisEntityService<String,
param.put("schemaId", schemaId);
param.put("userId", userId);
addPagingQueryParams(param, 0, HISTORY_REMAIN);
addDialectParamsPagingQuery(param, 0, HISTORY_REMAIN);
// 如果不支持分页则删除30天以前的历史
if (!getDialect().supportsPaging())

View File

@ -142,7 +142,6 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
public User getByName(String name)
{
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("name", name);
User user = selectOneMybatis("getByName", params);
@ -158,7 +157,6 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
newPassword = this.userPasswordEncoder.encode(newPassword);
Map<String, Object> params = buildParamMap();
addIdentifierQuoteParameter(params);
params.put("id", id);
params.put("password", newPassword);

View File

@ -1,7 +1,7 @@
/*
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
@ -51,4 +51,45 @@ public class DerbyFunctionSupport
return source.replaceAll(regex, target);
}
/**
* 取最大值
*
* @param v0
* @param v1
* @return
*/
public static Integer maxInt(Integer v0, Integer v1)
{
if (v0 == null)
return v1;
if (v1 == null)
return v0;
return Math.max(v0, v1);
}
/**
* 取余数
*
* @param valueNum
* @param divNum
* @return
*/
public static int modInt(int valueNum, int divNum)
{
return valueNum % divNum;
}
/**
* 取字符串长度
*
* @param str
* @return
*/
public static int lengthStr(String str)
{
return (str == null ? 0 : str.length());
}
}

View File

@ -24,6 +24,14 @@ import org.datagear.management.service.impl.AbstractMybatisService;
*/
public abstract class MbSqlDialect
{
public static final String FUNC_NAME_REPLACE = "DATAGEAR_REPLACE";
public static final String FUNC_NAME_MODINT = "DATAGEAR_FUNC_MODINT";
public static final String FUNC_NAME_LENGTH = "DATAGEAR_FUNC_LENGTH";
public static final String FUNC_NAME_MAX = "MAX";
/** 标识符引用符 */
private String identifierQuote;
@ -47,6 +55,46 @@ public abstract class MbSqlDialect
this.identifierQuote = identifierQuote;
}
/**
* 获取替换字符串子串的函数名
*
* @return
*/
public String funcNameReplace()
{
return FUNC_NAME_REPLACE;
}
/**
* 获取求余函数名
*
* @return
*/
public String funcNameModInt()
{
return FUNC_NAME_MODINT;
}
/**
* 获取求字符串长度的函数名
*
* @return
*/
public String funcNameLength()
{
return FUNC_NAME_LENGTH;
}
/**
* 获取MAX函数名
*
* @return
*/
public String funcNameMax()
{
return FUNC_NAME_MAX;
}
/**
* 将字符串转换为SQL字符串字面值
* <p>

View File

@ -16,6 +16,7 @@ import org.datagear.connection.support.DerbyURLSensor;
import org.datagear.connection.support.MySqlURLSensor;
import org.datagear.connection.support.OracleURLSensor;
import org.datagear.connection.support.PostgresqlURLSensor;
import org.datagear.connection.support.SqlServerURLSensor;
import org.datagear.util.JdbcUtil;
import org.datagear.util.StringUtil;
import org.slf4j.Logger;
@ -47,6 +48,8 @@ public class MbSqlDialectBuilder
public static final String DIALECT_NAME_POSTGRESQL = "postgresql";
public static final String DIALECT_NAME_SQLSERVER = "sqlserver";
public static final String DIALECT_NAME_DEFAULT = "default";
/** 方言名 */
@ -162,6 +165,10 @@ public class MbSqlDialectBuilder
{
dialect = buildPostgresqlMbSqlDialect(cn);
}
else if (DIALECT_NAME_SQLSERVER.equalsIgnoreCase(dialectName))
{
dialect = buildSqlserverMbSqlDialect(cn);
}
else if (DIALECT_NAME_DEFAULT.equalsIgnoreCase(dialectName))
{
dialect = buildDefaultMbSqlDialect(cn);
@ -201,6 +208,10 @@ public class MbSqlDialectBuilder
{
dialect = buildPostgresqlMbSqlDialect(cn);
}
else if (SqlServerURLSensor.INSTANCE.supports(url))
{
dialect = buildSqlserverMbSqlDialect(cn);
}
return dialect;
}
@ -225,6 +236,11 @@ public class MbSqlDialectBuilder
return new PostgresqlMbSqlDialect(getIdentifierQuote(cn));
}
protected SqlserverMbSqlDialect buildSqlserverMbSqlDialect(Connection cn) throws SQLException
{
return new SqlserverMbSqlDialect(getIdentifierQuote(cn));
}
protected DefaultMbSqlDialect buildDefaultMbSqlDialect(Connection cn) throws SQLException
{
return new DefaultMbSqlDialect(getIdentifierQuote(cn));

View File

@ -0,0 +1,65 @@
/*
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
package org.datagear.management.util.dialect;
/**
* SQL Server 方言
*
* @author datagear@163.com
*
*/
public class SqlserverMbSqlDialect extends MbSqlDialect
{
public static final String DEFAULT_FUNC_PREFIX = "dbo.";
public SqlserverMbSqlDialect()
{
super();
}
public SqlserverMbSqlDialect(String identifierQuote)
{
super(identifierQuote);
}
@Override
public String funcNameReplace()
{
return DEFAULT_FUNC_PREFIX + super.funcNameReplace();
}
@Override
public String funcNameModInt()
{
return DEFAULT_FUNC_PREFIX + super.funcNameModInt();
}
@Override
public String funcNameLength()
{
return DEFAULT_FUNC_PREFIX + super.funcNameLength();
}
@Override
public boolean supportsPaging()
{
return false;
}
@Override
public String pagingSqlHead(int index, int fetchSize)
{
return null;
}
@Override
public String pagingSqlFoot(int index, int fetchSize)
{
return null;
}
}

View File

@ -763,3 +763,14 @@ ALTER TABLE DATAGEAR_VERSION DROP COLUMN VERSION_BUILD;
--
ALTER TABLE DATAGEAR_HCW_DS ADD COLUMN DS_ATTACHMENT VARCHAR(20);
--
--valueNum
--divNum
CREATE FUNCTION DATAGEAR_FUNC_MODINT(valueNum INTEGER, divNum INTEGER) RETURNS INTEGER
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.modInt';
--
--valueStr
CREATE FUNCTION DATAGEAR_FUNC_LENGTH(value0Num VARCHAR(1000)) RETURNS INTEGER
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.lengthStr';

View File

@ -110,7 +110,7 @@
)
VALUES
(
#{dataSetId}, #{child.name}, #{child.type}, #{child.label, jdbcType=VARCHAR}, #{order}
#{entity.dataSetId}, #{entity.child.name}, #{entity.child.type}, #{entity.child.label, jdbcType=VARCHAR}, #{entity.order}
)
</insert>
@ -122,8 +122,8 @@
)
VALUES
(
#{dataSetId}, #{child.name}, #{child.type}, #{child.required}, #{child.desc, jdbcType=VARCHAR},
#{child.inputType, jdbcType=VARCHAR}, #{child.inputPayload, jdbcType=VARCHAR}, #{order}
#{entity.dataSetId}, #{entity.child.name}, #{entity.child.type}, #{entity.child.required}, #{entity.child.desc, jdbcType=VARCHAR},
#{entity.child.inputType, jdbcType=VARCHAR}, #{entity.child.inputPayload, jdbcType=VARCHAR}, #{entity.order}
)
</insert>

View File

@ -24,8 +24,8 @@
)
VALUES
(
#{widgetId}, #{dataSetId}, #{propertySignsJson, jdbcType=VARCHAR}, #{alias, jdbcType=VARCHAR}, #{attachment, jdbcType=VARCHAR},
#{paramValuesJson, jdbcType=VARCHAR}, #{order}
#{entity.widgetId}, #{entity.dataSetId}, #{entity.propertySignsJson, jdbcType=VARCHAR}, #{entity.alias, jdbcType=VARCHAR}, #{entity.attachment, jdbcType=VARCHAR},
#{entity.paramValuesJson, jdbcType=VARCHAR}, #{entity.order}
)
</insert>

View File

@ -38,7 +38,7 @@
</when><otherwise>
SELECT
IDPQV.DATA_ID,
MOD(MAX(DISTINCT IDPQV.AUTH_PRIORITY_PERMISSION), 100) AS DATA_PERMISSION
${_FUNC_MODINT}(${_FUNC_MAX}(DISTINCT IDPQV.AUTH_PRIORITY_PERMISSION), 100) AS DATA_PERMISSION
FROM
(
SELECT
@ -53,7 +53,7 @@
WHEN PQV.AUTH_RESOURCE_TYPE IS NULL THEN <choose><when test="DP_UNSET_PERMISSION != null">${DP_UNSET_PERMISSION}</when><otherwise>0</otherwise></choose>
/*次高级权限值加权,具体资源授权始终高于模式匹配授权,字符数多的模式匹配授权高于字符数少的模式匹配授权*/
WHEN PQV.AUTH_RESOURCE_TYPE = '${DP_RESOURCE_TYPE}_PATTERN'
THEN (MOD(LENGTH(PQV.AUTH_RESOURCE)*100, 800000) + PQV.AUTH_PRIORITY_PERMISSION)
THEN (${_FUNC_MODINT}(${_FUNC_LENGTH}(PQV.AUTH_RESOURCE)*100, 800000) + PQV.AUTH_PRIORITY_PERMISSION)
WHEN PQV.AUTH_RESOURCE_TYPE = '${DP_RESOURCE_TYPE}'
THEN (900000 + PQV.AUTH_PRIORITY_PERMISSION)
END
@ -75,7 +75,7 @@
ON
(PQV.AUTH_RESOURCE_TYPE = '${DP_RESOURCE_TYPE}' AND PQV.AUTH_RESOURCE = IDQV.DP_AUTH_DATA_ID)
<if test='DP_RESOURCE_SUPPORT_PATTERN != null and DP_RESOURCE_SUPPORT_PATTERN == true'>
OR (PQV.AUTH_RESOURCE_TYPE = '${DP_RESOURCE_TYPE}_PATTERN' AND IDQV.DP_AUTH_DATA_PATTERN_SRC LIKE DATAGEAR_REPLACE(PQV.AUTH_RESOURCE, '*', '%'))
OR (PQV.AUTH_RESOURCE_TYPE = '${DP_RESOURCE_TYPE}_PATTERN' AND IDQV.DP_AUTH_DATA_PATTERN_SRC LIKE ${_FUNC_REPLACE}(PQV.AUTH_RESOURCE, '*', '%'))
</if>
) IDPQV
GROUP BY