use of org.sagacity.sqltoy.config.model.SqlToyConfig 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);
}
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class Execute method submit.
/**
* @todo 执行并返回修改的记录数量
* @return
*/
public Long submit() {
if (StringUtil.isBlank(sql)) {
throw new IllegalArgumentException("execute operate sql is null!");
}
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(sql, SqlType.update, super.getDialect());
QueryExecutor queryExecute = build();
return dialectFactory.executeSql(sqlToyContext, sqlToyConfig, queryExecute, null, autoCommit, getDataSource(sqlToyConfig));
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class Mongo method find.
/**
* @todo 集合记录查询
* @return
*/
public List<?> find() {
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));
// 聚合查询
if (noSqlModel.isHasAggs()) {
return aggregate(getMongoTemplate(), sqlToyConfig, realMql, (Class) extend.resultType, extend.humpMapLabel);
}
return findTop(getMongoTemplate(), sqlToyConfig, null, realMql, (Class) extend.resultType, extend.humpMapLabel);
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException(e);
}
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class Query method findRandom.
/**
* @todo 随机取记录
* @param randomSize
* @return
*/
public List<?> findRandom(final double randomSize) {
QueryExecutor queryExecute = build();
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
QueryResult result = dialectFactory.getRandomResult(sqlToyContext, queryExecute, sqlToyConfig, new Double(randomSize), getDataSource(sqlToyConfig));
return result.getRows();
}
use of org.sagacity.sqltoy.config.model.SqlToyConfig in project sagacity-sqltoy by chenrenfei.
the class Query method getOne.
/**
* @todo 获取一条记录
* @return
*/
public Object getOne() {
QueryExecutor queryExecute = build();
SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(queryExecute, SqlType.search, getDialect());
QueryResult result = dialectFactory.findByQuery(sqlToyContext, queryExecute, sqlToyConfig, lockMode, getDataSource(sqlToyConfig));
List rows = result.getRows();
if (rows != null && rows.size() > 0) {
return rows.get(0);
}
return null;
}
Aggregations