use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class ClickHouseDialect method load.
@Override
public Serializable load(SqlToyContext sqlToyContext, Serializable entity, List<Class> cascadeTypes, LockMode lockMode, Connection conn, Integer dbType, String dialect, String tableName) throws Exception {
EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
// 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search, dialect);
String loadSql = sqlToyConfig.getSql(dialect);
return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, cascadeTypes, conn, dbType);
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class TranslateConfigParse method parseTranslateConfig.
/**
* @todo 解析translate配置文件
* @param translateMap
* @param checker
* @param translateConfig
* @param charset
* @throws Exception
*/
public static DefaultConfig parseTranslateConfig(final SqlToyContext sqlToyContext, final HashMap<String, TranslateConfigModel> translateMap, final List<CheckerConfigModel> checker, String translateConfig, String charset) throws Exception {
return (DefaultConfig) XMLUtil.readXML(translateConfig, charset, false, new XMLCallbackHandler() {
@Override
public Object process(Document doc, Element root) throws Exception {
// 解析缓存翻译配置
Element node = root.element("cache-translates");
DefaultConfig defaultConfig = new DefaultConfig();
if (node.attribute("disk-store-path") != null)
defaultConfig.setDiskStorePath(node.attributeValue("disk-store-path"));
List<Element> elts;
for (String translateType : TRANSLATE_TYPES) {
elts = node.elements(translateType.concat(TRANSLATE_SUFFIX));
if (elts != null && !elts.isEmpty()) {
int index = 1;
for (Element elt : elts) {
TranslateConfigModel translateCacheModel = new TranslateConfigModel();
XMLUtil.setAttributes(elt, translateCacheModel);
translateCacheModel.setType(translateType);
if (translateType.equals("sql")) {
if (StringUtil.isBlank(translateCacheModel.getSql())) {
String sql = (elt.element("sql") != null) ? elt.elementText("sql") : elt.getText();
String sqlId = "SQLTOY_TRANSLATE_Cache_ID_00" + index;
boolean isShowSql = StringUtil.matches(sql, SqlToyConstants.NOT_PRINT_REGEX);
SqlToyConfig sqlToyConfig = new SqlToyConfig(sqlId, StringUtil.clearMistyChars(SqlUtil.clearMark(sql), " "));
sqlToyConfig.setShowSql(!isShowSql);
sqlToyContext.putSqlToyConfig(sqlToyConfig);
translateCacheModel.setSql(sqlId);
}
index++;
}
// 过期时长
if (translateCacheModel.getKeepAlive() <= 0)
translateCacheModel.setKeepAlive(SqlToyConstants.getCacheExpireSeconds());
translateMap.put(translateCacheModel.getCache(), translateCacheModel);
}
}
}
// 解析更新检测器
node = root.element("cache-update-checkers");
if (node != null) {
for (String translateType : TRANSLATE_TYPES) {
elts = node.elements(translateType.concat(CHECKER_SUFFIX));
if (elts != null && !elts.isEmpty()) {
int index = 1;
for (Element elt : elts) {
CheckerConfigModel checherConfigModel = new CheckerConfigModel();
XMLUtil.setAttributes(elt, checherConfigModel);
checherConfigModel.setType(translateType);
if (translateType.equals("sql")) {
if (StringUtil.isBlank(checherConfigModel.getSql())) {
String sqlId = "SQLTOY_TRANSLATE_Check_ID_00" + index;
String sql = (elt.element("sql") != null) ? elt.elementText("sql") : elt.getText();
boolean isShowSql = StringUtil.matches(sql, SqlToyConstants.NOT_PRINT_REGEX);
SqlToyConfig sqlToyConfig = new SqlToyConfig(sqlId, StringUtil.clearMistyChars(SqlUtil.clearMark(sql), " "));
sqlToyConfig.setShowSql(!isShowSql);
sqlToyContext.putSqlToyConfig(sqlToyConfig);
checherConfigModel.setSql(sqlId);
}
index++;
}
// 剔除tab\回车等特殊字符
String frequency = StringUtil.clearMistyChars(checherConfigModel.getCheckFrequency(), "");
List<TimeSection> timeSections = new ArrayList<TimeSection>();
// frequency的格式 frequency="0..12?15,12..18:30?10,18:30..24?60"
if (StringUtil.isNotBlank(frequency)) {
// 统一格式,去除全角字符,去除空白
frequency = frequency.replaceAll("\\;", ",").replaceAll("\\?", "?").replaceAll("\\.", ".").replaceAll("\\。", ".").replaceAll("\\,", ",").trim();
// 可以是单个频率值,表示0到24小时采用统一的频率
if (CommonUtils.isInteger(frequency)) {
TimeSection section = new TimeSection();
section.setStart(0);
section.setEnd(2400);
section.setIntervalSeconds(Integer.parseInt(frequency));
timeSections.add(section);
} else {
// 归整分割符号统一为逗号,将时间格式由HH:mm 转为HHmm格式
String[] sectionsStr = frequency.split("\\,");
for (int i = 0; i < sectionsStr.length; i++) {
TimeSection section = new TimeSection();
// 问号切割获取时间区间和时间间隔
String[] sectionPhase = sectionsStr[i].split("\\?");
// 获取开始和结束时间点
String[] startEnd = sectionPhase[0].split("\\.{2}");
section.setIntervalSeconds(Integer.parseInt(sectionPhase[1].trim()));
section.setStart(getHourMinute(startEnd[0].trim()));
section.setEnd(getHourMinute(startEnd[1].trim()));
timeSections.add(section);
}
}
}
checherConfigModel.setTimeSections(timeSections);
checker.add(checherConfigModel);
}
}
}
}
return defaultConfig;
}
});
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class SqlToyDaoSupport method executeSql.
/**
* @todo 解析sql中的参数名称,以此名称到entity中提取对应的值作为查询条件值执行sql
* @param sqlOrNamedSql
* @param entity
* @param reflectPropertyHandler
* @return
* @throws Exception
*/
protected Long executeSql(final String sqlOrNamedSql, final Serializable entity, final ReflectPropertyHandler reflectPropertyHandler) throws Exception {
SqlToyConfig sqlToyConfig = getSqlToyConfig(sqlOrNamedSql, SqlType.update);
// 根据sql中的变量从entity对象中提取参数值
Object[] paramValues = SqlConfigParseUtils.reflectBeanParams(sqlToyConfig.getParamsName(), entity, reflectPropertyHandler);
return executeSql(sqlOrNamedSql, sqlToyConfig.getParamsName(), paramValues, false, this.getDataSource(null));
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class Elastic method findPage.
/**
* @todo 分页查询
* @param pageModel
* @return
* @throws Exception
*/
public PaginationModel findPage(PaginationModel pageModel) throws Exception {
QueryExecutor queryExecutor = build();
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql);
if (sqlToyConfig.getNoSqlConfigModel() == null)
throw new Exception(ERROR_MESSAGE);
if (sqlToyConfig.getNoSqlConfigModel().isSqlMode())
return ElasticSqlPlugin.findPage(sqlToyContext, sqlToyConfig, pageModel, queryExecutor);
return ElasticSearchPlugin.findPage(sqlToyContext, sqlToyConfig, pageModel, queryExecutor);
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class DB2Dialect method load.
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.dialect.Dialect#load(java.io.Serializable,
* java.util.List, java.sql.Connection)
*/
@Override
public Serializable load(final SqlToyContext sqlToyContext, Serializable entity, List<Class> cascadeTypes, LockMode lockMode, Connection conn, final String tableName) throws Exception {
EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
// 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search);
String loadSql = sqlToyConfig.getSql();
if (lockMode != null) {
switch(lockMode) {
case UPGRADE_NOWAIT:
case UPGRADE:
loadSql = loadSql + " for update with rs";
break;
}
}
return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, cascadeTypes, conn);
}
Aggregations