Search in sources :

Example 71 with SqlToyResult

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));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 72 with SqlToyResult

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));
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult) Test(org.junit.jupiter.api.Test)

Example 73 with SqlToyResult

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;
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult)

Example 74 with SqlToyResult

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;
}
Also used : SqlToyResult(org.sagacity.sqltoy.config.model.SqlToyResult)

Aggregations

SqlToyResult (org.sagacity.sqltoy.config.model.SqlToyResult)74 QueryExecutorExtend (org.sagacity.sqltoy.model.inner.QueryExecutorExtend)19 List (java.util.List)16 ArrayList (java.util.ArrayList)15 SqlToyConfig (org.sagacity.sqltoy.config.model.SqlToyConfig)12 Connection (java.sql.Connection)11 DataSourceCallbackHandler (org.sagacity.sqltoy.callback.DataSourceCallbackHandler)11 QueryResult (org.sagacity.sqltoy.model.QueryResult)11 Test (org.junit.jupiter.api.Test)9 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)8 BaseException (org.sagacity.sqltoy.exception.BaseException)6 SqlWithAnalysis (org.sagacity.sqltoy.config.model.SqlWithAnalysis)5 DataAccessException (org.sagacity.sqltoy.exception.DataAccessException)5 Type (java.lang.reflect.Type)4 HashMap (java.util.HashMap)4 OneToManyModel (org.sagacity.sqltoy.config.model.OneToManyModel)4 TableCascadeModel (org.sagacity.sqltoy.config.model.TableCascadeModel)4 DBType (org.sagacity.sqltoy.utils.DataSourceUtils.DBType)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2