use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.
the class SqlConfigParseUtilsTest method testAllInnerNull.
@Test
public void testAllInnerNull() throws Exception {
String sql = "select * from (select * from table where 1=1 #[and id=:id and name like :name] #[and status=:status]) left join table2 on";
SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { null, null, null });
System.err.println(JSON.toJSONString(result));
}
use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.
the class SqlConfigParseUtilsTest method testAtValue.
@Test
public void testAtValue() throws Exception {
String sql = "select * from table where 1=1 #[and id=:id] and name like @value(:name) #[and status=:status]";
SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "id", "name", "status" }, new Object[] { "1", null, "1" });
System.err.println(JSON.toJSONString(result));
}
use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.
the class MongoElasticUtils method wrapES.
/**
* @todo 结合条件组织elasticSearch最终的执行语句
* @param sqlToyConfig
* @param paramNames
* @param paramValues
* @return
*/
public static String wrapES(SqlToyConfig sqlToyConfig, String[] paramNames, Object[] paramValues) {
if (paramNames == null || paramNames.length == 0) {
return sqlToyConfig.getSql(null);
}
SqlToyResult sqlToyResult = wrapNoSql(sqlToyConfig, paramNames, paramValues);
// 替换mql中的参数(双引号)
if (sqlToyConfig.getNoSqlConfigModel().isSqlMode()) {
return replaceSqlParams(sqlToyResult.getSql(), sqlToyResult.getParamsValue(), "'");
}
String elasticJson = replaceNoSqlParams(sqlToyResult.getSql(), sqlToyResult.getParamsValue(), "\"").trim();
// json格式补全
if (!elasticJson.startsWith("{")) {
elasticJson = "{".concat(elasticJson);
}
if (!elasticJson.endsWith("}")) {
elasticJson = elasticJson.concat("}");
}
return elasticJson;
}
use of org.sagacity.sqltoy.config.model.SqlToyResult in project sagacity-sqltoy by chenrenfei.
the class MongoElasticUtils method wrapMql.
/**
* @todo 结合条件组织mongodb 的查询语句
* @param sqlToyConfig
* @param paramNames
* @param paramValues
* @return
*/
public static String wrapMql(SqlToyConfig sqlToyConfig, String[] paramNames, Object[] paramValues) {
if (paramNames == null || paramNames.length == 0) {
return sqlToyConfig.getSql(null);
}
SqlToyResult sqlToyResult = wrapNoSql(sqlToyConfig, paramNames, paramValues);
if (sqlToyConfig.getNoSqlConfigModel().isSqlMode()) {
return replaceSqlParams(sqlToyResult.getSql(), sqlToyResult.getParamsValue(), "'");
}
String mongoJson = replaceNoSqlParams(sqlToyResult.getSql(), sqlToyResult.getParamsValue(), "'").trim();
// json格式补全
if (!mongoJson.startsWith("{")) {
mongoJson = "{".concat(mongoJson);
}
if (!mongoJson.endsWith("}")) {
mongoJson = mongoJson.concat("}");
}
return mongoJson;
}
Aggregations