Search in sources :

Example 16 with QueryExecutor

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

the class ParallQueryExecutor method call.

@Override
public ParallQueryResult call() {
    ParallQueryResult result = new ParallQueryResult();
    try {
        ParallQueryExtend extend = parallQuery.getExtend();
        QueryExecutor queryExecutor = new QueryExecutor(extend.sql).resultType(extend.resultType).names(paramNames).values(paramValues);
        // 分页
        if (extend.page != null) {
            result.setResult(dialectFactory.findPage(sqlToyContext, queryExecutor, sqlToyConfig, extend.page.getPageNo(), extend.page.getPageSize(), dataSource));
        } else {
            result.setResult(dialectFactory.findByQuery(sqlToyContext, queryExecutor, sqlToyConfig, null, dataSource));
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
    }
    return result;
}
Also used : ParallQueryExtend(org.sagacity.sqltoy.model.inner.ParallQueryExtend) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) ParallQueryResult(org.sagacity.sqltoy.model.ParallQueryResult)

Example 17 with QueryExecutor

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

the class Query method findTop.

/**
 * @todo 取前多少条记录
 * @param topSize
 * @return
 */
public List<?> findTop(final double topSize) {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    QueryResult result = dialectFactory.findTop(sqlToyContext, queryExecute, sqlToyConfig, topSize, 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 18 with QueryExecutor

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

the class Query method count.

/**
 * @todo 查询记录集的数量
 * @return
 */
public Long count() {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    return dialectFactory.getCountBySql(sqlToyContext, queryExecute, sqlToyConfig, getDataSource(sqlToyConfig));
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig)

Example 19 with QueryExecutor

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

the class Query method getValue.

/**
 * @todo 获取单值
 * @return
 */
public Object getValue() {
    QueryExecutor queryExecute = new QueryExecutor(sql).names(names).values(values);
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    QueryResult result = dialectFactory.findByQuery(sqlToyContext, queryExecute, sqlToyConfig, null, getDataSource(sqlToyConfig));
    List rows = result.getRows();
    if (rows != null && rows.size() > 0) {
        return ((List) rows.get(0)).get(0);
    }
    return null;
}
Also used : QueryResult(org.sagacity.sqltoy.model.QueryResult) QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) List(java.util.List)

Example 20 with QueryExecutor

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

the class Query method findPage.

/**
 * @TODO 进行分页查询
 * @param page
 * @return
 */
public Page<?> findPage(final Page page) {
    QueryExecutor queryExecute = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
    if (page.getSkipQueryCount()) {
        return (Page<?>) dialectFactory.findSkipTotalCountPage(sqlToyContext, queryExecute, sqlToyConfig, page.getPageNo(), page.getPageSize(), getDataSource(sqlToyConfig)).getPageResult();
    }
    return (Page<?>) dialectFactory.findPage(sqlToyContext, queryExecute, sqlToyConfig, page.getPageNo(), page.getPageSize(), getDataSource(sqlToyConfig)).getPageResult();
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) Page(org.sagacity.sqltoy.model.Page)

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