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