Search in sources :

Example 21 with QueryExecutor

use of org.sagacity.sqltoy.model.QueryExecutor in project sagacity-sqltoy by chenrenfei.

the class Query method find.

/**
 * @todo 查询结果集合
 * @return
 */
public List<?> find() {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    QueryResult result = dialectFactory.findByQuery(sqlToyContext, queryExecute, sqlToyConfig, lockMode, getDataSource(sqlToyConfig));
    return result.getRows();
}
Also used : QueryResult(org.sagacity.sqltoy.model.QueryResult) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig)

Example 22 with QueryExecutor

use of org.sagacity.sqltoy.model.QueryExecutor in project sagacity-sqltoy by chenrenfei.

the class Mongo method build.

/**
 * @todo 构造统一的查询条件
 * @return
 */
private QueryExecutor build() {
    QueryExecutor queryExecutor = null;
    if (entity != null) {
        queryExecutor = new QueryExecutor(sql, entity);
    } else {
        queryExecutor = new QueryExecutor(sql).names(names).values(values);
    }
    if (resultType != null) {
        queryExecutor.resultType(resultType);
    }
    queryExecutor.humpMapLabel(humpMapLabel);
    return queryExecutor;
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor)

Example 23 with QueryExecutor

use of org.sagacity.sqltoy.model.QueryExecutor in project sagacity-sqltoy by chenrenfei.

the class Mongo method findTop.

/**
 * @todo 查询前多少条记录
 * @param topSize
 * @return
 */
public List<?> findTop(final Float topSize) {
    QueryExecutor queryExecutor = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.search, "");
    NoSqlConfigModel noSqlModel = sqlToyConfig.getNoSqlConfigModel();
    if (noSqlModel == null || noSqlModel.getCollection() == null || noSqlModel.getFields() == null) {
        throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    try {
        QueryExecutorExtend extend = queryExecutor.getInnerModel();
        // 最后的执行语句
        String realMql = MongoElasticUtils.wrapMql(sqlToyConfig, extend.getParamsName(sqlToyConfig), extend.getParamsValue(sqlToyContext, sqlToyConfig));
        return findTop(getMongoTemplate(), sqlToyConfig, topSize, realMql, (Class) extend.resultType, extend.humpMapLabel);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DataAccessException(e);
    }
}
Also used : NoSqlConfigModel(org.sagacity.sqltoy.config.model.NoSqlConfigModel) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) QueryExecutorExtend(org.sagacity.sqltoy.model.inner.QueryExecutorExtend) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException)

Example 24 with QueryExecutor

use of org.sagacity.sqltoy.model.QueryExecutor in project sagacity-sqltoy by chenrenfei.

the class Mongo method findPage.

/**
 * @todo 分页查询
 * @param page
 * @return
 */
public Page findPage(Page page) {
    QueryExecutor queryExecutor = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.search, "");
    NoSqlConfigModel noSqlModel = sqlToyConfig.getNoSqlConfigModel();
    if (noSqlModel == null || noSqlModel.getCollection() == null || noSqlModel.getFields() == null) {
        throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    try {
        QueryExecutorExtend extend = queryExecutor.getInnerModel();
        // 最后的执行语句
        String realMql = MongoElasticUtils.wrapMql(sqlToyConfig, extend.getParamsName(sqlToyConfig), extend.getParamsValue(sqlToyContext, sqlToyConfig));
        return findPage(getMongoTemplate(), sqlToyConfig, page, realMql, (Class) extend.resultType, extend.humpMapLabel);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DataAccessException(e);
    }
}
Also used : NoSqlConfigModel(org.sagacity.sqltoy.config.model.NoSqlConfigModel) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) QueryExecutorExtend(org.sagacity.sqltoy.model.inner.QueryExecutorExtend) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException)

Example 25 with QueryExecutor

use of org.sagacity.sqltoy.model.QueryExecutor in project sagacity-sqltoy by chenrenfei.

the class TranslateFactory method getSqlCacheData.

/**
 * @todo 通过sql查询获取缓存数据
 * @param sqlToyContext
 * @param cacheModel
 * @param cacheType
 * @return
 * @throws Exception
 */
private static List getSqlCacheData(final SqlToyContext sqlToyContext, TranslateConfigModel cacheModel, String cacheType) throws Exception {
    final SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(cacheModel.getSql(), SqlType.search, "");
    QueryExecutor queryExecutor = null;
    if (StringUtil.isBlank(cacheType)) {
        queryExecutor = new QueryExecutor(cacheModel.getSql());
    } else {
        queryExecutor = new QueryExecutor(cacheModel.getSql(), sqlToyConfig.getParamsName(), new Object[] { cacheType.trim() });
    }
    String dataSourceName = cacheModel.getDataSource();
    if (dataSourceName == null) {
        dataSourceName = sqlToyConfig.getDataSource();
    }
    DataSourceSelector dataSourceSelector = sqlToyContext.getDataSourceSelector();
    DataSource dataSource = dataSourceSelector.getDataSource(sqlToyContext.getApplicationContext(), null, dataSourceName, null, sqlToyContext.getDefaultDataSource());
    return DialectFactory.getInstance().findByQuery(sqlToyContext, queryExecutor, sqlToyConfig, null, dataSource).getRows();
}
Also used : DataSourceSelector(org.sagacity.sqltoy.plugins.datasource.DataSourceSelector) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) JSONObject(com.alibaba.fastjson.JSONObject) DataSource(javax.sql.DataSource)

Aggregations

QueryExecutor (org.sagacity.sqltoy.model.QueryExecutor)25 SqlToyConfig (org.sagacity.sqltoy.config.model.SqlToyConfig)20 DataAccessException (org.sagacity.sqltoy.exception.DataAccessException)8 QueryResult (org.sagacity.sqltoy.model.QueryResult)6 NoSqlConfigModel (org.sagacity.sqltoy.config.model.NoSqlConfigModel)4 ParallQueryExecutor (org.sagacity.sqltoy.dialect.executor.ParallQueryExecutor)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DataSource (javax.sql.DataSource)3 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)3 QueryExecutorExtend (org.sagacity.sqltoy.model.inner.QueryExecutorExtend)3 Entry (java.util.Map.Entry)2 Page (org.sagacity.sqltoy.model.Page)2 ParallQueryResult (org.sagacity.sqltoy.model.ParallQueryResult)2 EntityQueryExtend (org.sagacity.sqltoy.model.inner.EntityQueryExtend)2 DataSourceSelector (org.sagacity.sqltoy.plugins.datasource.DataSourceSelector)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Serializable (java.io.Serializable)1 Connection (java.sql.Connection)1 Date (java.util.Date)1