Search in sources :

Example 81 with SqlToyConfig

use of org.sagacity.sqltoy.config.model.SqlToyConfig 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)

Example 82 with SqlToyConfig

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

the class SqlToyDaoSupport method getCountByQuery.

/**
 * @todo 指定数据源查询记录数量
 * @param queryExecutor
 * @return
 */
protected Long getCountByQuery(final QueryExecutor queryExecutor) {
    QueryExecutorExtend extend = queryExecutor.getInnerModel();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(extend.sql, SqlType.search, getDialect(extend.dataSource));
    return dialectFactory.getCountBySql(sqlToyContext, queryExecutor, sqlToyConfig, this.getDataSource(extend.dataSource, sqlToyConfig));
}
Also used : SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) QueryExecutorExtend(org.sagacity.sqltoy.model.inner.QueryExecutorExtend)

Aggregations

SqlToyConfig (org.sagacity.sqltoy.config.model.SqlToyConfig)82 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)22 Serializable (java.io.Serializable)20 QueryExecutor (org.sagacity.sqltoy.model.QueryExecutor)20 QueryResult (org.sagacity.sqltoy.model.QueryResult)20 Connection (java.sql.Connection)19 ArrayList (java.util.ArrayList)19 DataSourceCallbackHandler (org.sagacity.sqltoy.callback.DataSourceCallbackHandler)19 List (java.util.List)16 DataAccessException (org.sagacity.sqltoy.exception.DataAccessException)16 QueryExecutorExtend (org.sagacity.sqltoy.model.inner.QueryExecutorExtend)15 SqlToyResult (org.sagacity.sqltoy.config.model.SqlToyResult)12 BaseException (org.sagacity.sqltoy.exception.BaseException)10 NoSqlConfigModel (org.sagacity.sqltoy.config.model.NoSqlConfigModel)5 DataSource (javax.sql.DataSource)4 Test (org.junit.jupiter.api.Test)4 ParallQueryExecutor (org.sagacity.sqltoy.dialect.executor.ParallQueryExecutor)4 QueryExecutor (org.sagacity.sqltoy.executor.QueryExecutor)4 InputStream (java.io.InputStream)3 Document (org.w3c.dom.Document)3