Search in sources :

Example 1 with QueryExecutor

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

the class TranslateFactory method doSqlCheck.

/**
 * @todo 执行sql检测
 * @param sqlToyContext
 * @param checkerConfig
 * @param preCheckTime
 * @return
 * @throws Exception
 */
private static List doSqlCheck(final SqlToyContext sqlToyContext, final CheckerConfigModel checkerConfig, Timestamp preCheckTime) throws Exception {
    final SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(checkerConfig.getSql(), SqlType.search, "");
    String dataSourceName = checkerConfig.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, new QueryExecutor(checkerConfig.getSql(), sqlToyConfig.getParamsName(), new Object[] { new Date(preCheckTime.getTime()) }), 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) Date(java.util.Date) DataSource(javax.sql.DataSource)

Example 2 with QueryExecutor

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

the class Elastic method findPage.

/**
 * @todo 分页查询
 * @param pageModel
 * @return
 */
public Page findPage(Page pageModel) {
    QueryExecutor queryExecutor = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.search, "");
    NoSqlConfigModel noSqlConfig = sqlToyConfig.getNoSqlConfigModel();
    if (noSqlConfig == null) {
        throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    Page pageResult = null;
    try {
        if (noSqlConfig.isSqlMode()) {
            ElasticEndpoint esConfig = sqlToyContext.getElasticEndpoint(noSqlConfig.getEndpoint());
            if (esConfig.isNativeSql()) {
                throw new UnsupportedOperationException("elastic native sql pagination is not support!");
            }
            pageResult = ElasticSqlPlugin.findPage(sqlToyContext, sqlToyConfig, pageModel, queryExecutor);
        } else {
            pageResult = ElasticSearchPlugin.findPage(sqlToyContext, sqlToyConfig, pageModel, queryExecutor);
        }
        if (pageResult.getRecordCount() == 0 && sqlToyContext.isPageOverToFirst()) {
            pageResult.setPageNo(1L);
        }
        return pageResult;
    } 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) Page(org.sagacity.sqltoy.model.Page) ElasticEndpoint(org.sagacity.sqltoy.config.model.ElasticEndpoint) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException)

Example 3 with QueryExecutor

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

the class Elastic method findTop.

/**
 * @todo 查询前多少条记录
 * @param topSize
 * @return
 */
public List<?> findTop(final int topSize) {
    QueryExecutor queryExecutor = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.search, "");
    if (sqlToyConfig.getNoSqlConfigModel() == null) {
        throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    try {
        if (sqlToyConfig.getNoSqlConfigModel().isSqlMode()) {
            return ElasticSqlPlugin.findTop(sqlToyContext, sqlToyConfig, queryExecutor, topSize);
        }
        return ElasticSearchPlugin.findTop(sqlToyContext, sqlToyConfig, queryExecutor, topSize);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DataAccessException(e);
    }
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException)

Example 4 with QueryExecutor

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

the class Elastic 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 5 with QueryExecutor

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

the class Elastic method find.

/**
 * @todo 集合记录查询
 * @return
 */
public List<?> find() {
    QueryExecutor queryExecutor = build();
    SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.search, "");
    if (sqlToyConfig.getNoSqlConfigModel() == null) {
        throw new IllegalArgumentException(ERROR_MESSAGE);
    }
    try {
        if (sqlToyConfig.getNoSqlConfigModel().isSqlMode()) {
            return ElasticSqlPlugin.findTop(sqlToyContext, sqlToyConfig, queryExecutor, null);
        }
        return ElasticSearchPlugin.findTop(sqlToyContext, sqlToyConfig, queryExecutor, null);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DataAccessException(e);
    }
}
Also used : QueryExecutor(org.sagacity.sqltoy.model.QueryExecutor) SqlToyConfig(org.sagacity.sqltoy.config.model.SqlToyConfig) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException) DataAccessException(org.sagacity.sqltoy.exception.DataAccessException)

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