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();
}
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;
}
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);
}
}
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);
}
}
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();
}
Aggregations