use of org.sagacity.sqltoy.model.IgnoreCaseSet 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;
}
use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class SqlXMLConfigParse method parseSecureDecrypt.
/**
* @TODO 解析解密字段
* @param sqlToyConfig
* @param decryptElts
*/
public static void parseSecureDecrypt(SqlToyConfig sqlToyConfig, NodeList decryptElts) {
if (decryptElts == null || decryptElts.getLength() == 0) {
return;
}
Element decryptElt = (Element) decryptElts.item(0);
if (decryptElt.hasAttribute("columns")) {
String[] columns = trimParams(decryptElt.getAttribute("columns").toLowerCase().split("\\,"));
IgnoreCaseSet decryptColumns = new IgnoreCaseSet();
for (String col : columns) {
decryptColumns.add(col);
}
sqlToyConfig.setDecryptColumns(decryptColumns);
}
}
Aggregations