use of org.sagacity.sqltoy.model.QueryResult 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();
}
use of org.sagacity.sqltoy.model.QueryResult 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;
}
use of org.sagacity.sqltoy.model.QueryResult 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.QueryResult in project sagacity-sqltoy by chenrenfei.
the class ResultUtils method processResultSet.
/**
* @todo 处理sql查询时的结果集,当没有反调或voClass反射处理时以数组方式返回resultSet的数据
* @param sqlToyContext
* @param sqlToyConfig
* @param conn
* @param rs
* @param rowCallbackHandler
* @param updateRowHandler
* @param decryptHandler
* @param startColIndex
* @return
* @throws Exception
*/
public static QueryResult processResultSet(final SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, Connection conn, ResultSet rs, RowCallbackHandler rowCallbackHandler, UpdateRowHandler updateRowHandler, DecryptHandler decryptHandler, int startColIndex) throws Exception {
QueryResult result = new QueryResult();
// 记录行记数器
int index = 0;
if (rowCallbackHandler != null) {
while (rs.next()) {
rowCallbackHandler.processRow(rs, index);
index++;
}
result.setRows(rowCallbackHandler.getResult());
} else {
// 重新组合解密字段(entityMeta中的和sql自定义的合并)
IgnoreCaseSet decryptColumns = (decryptHandler == null) ? null : decryptHandler.getColumns();
if (sqlToyConfig.getDecryptColumns() != null) {
if (decryptColumns == null) {
decryptColumns = sqlToyConfig.getDecryptColumns();
} else {
decryptColumns.addAll(sqlToyConfig.getDecryptColumns());
}
}
DecryptHandler realDecryptHandler = null;
if (decryptColumns != null && !decryptColumns.isEmpty()) {
realDecryptHandler = new DecryptHandler(sqlToyContext.getFieldsSecureProvider(), decryptColumns);
}
// 取得字段列数,在没有rowCallbackHandler時用数组返回
int rowCnt = rs.getMetaData().getColumnCount();
// 类型转成string的列
Set<String> strTypeCols = getStringColumns(sqlToyConfig);
boolean hasToStrCols = !strTypeCols.isEmpty();
String[] labelNames = new String[rowCnt - startColIndex];
String[] labelTypes = new String[rowCnt - startColIndex];
HashMap<String, Integer> labelIndexMap = new HashMap<String, Integer>();
String labeNameLow;
for (int i = startColIndex; i < rowCnt; i++) {
labelNames[index] = rs.getMetaData().getColumnLabel(i + 1);
labeNameLow = labelNames[index].toLowerCase();
labelIndexMap.put(labeNameLow, index);
labelTypes[index] = rs.getMetaData().getColumnTypeName(i + 1);
// 类型因缓存翻译、格式化转为string
if (hasToStrCols) {
if (strTypeCols.contains(labeNameLow)) {
labelTypes[index] = "VARCHAR";
}
}
index++;
}
result.setLabelNames(labelNames);
result.setLabelTypes(labelTypes);
// 返回结果为非VO class时才可以应用旋转和汇总合计功能
try {
result.setRows(getResultSet(sqlToyConfig, sqlToyContext, conn, rs, updateRowHandler, realDecryptHandler, rowCnt, labelIndexMap, labelNames, startColIndex));
}// update 2019-09-11 此处增加数组溢出异常是因为经常有开发设置缓存cache-indexs时写错误,为了增加错误提示信息的友好性增加此处理
catch (Exception oie) {
logger.error("sql={} 提取结果发生异常:{}!", sqlToyConfig.getId(), oie.getMessage());
throw oie;
}
}
// 填充记录数
if (result.getRows() != null) {
result.setRecordCount(Long.valueOf(result.getRows().size()));
}
return result;
}
Aggregations