我想知道是否有可能在iBatis 2.3.4.726版中将第一行从Oracle Cursor映射到java.util.Map(使用列名作为键)。我想到了TypeHandlerCallback:
public class MapResultTypeHandler implements TypeHandlerCallback {
@Override
public void setParameter(final ParameterSetter parameterSetter, final Object o) throws SQLException {
throw new UnsupportedOperationException();
}
@Override
public Map<String, Object> getResult(final ResultGetter resultGetter) throws SQLException {
ResultSet resultSet = resultGetter.getResultSet();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnsNumber = metaData.getColumnCount();
Map<String, Object> result = new HashMap<>(columnsNumber);
do {
for(int i=1; i <= columnsNumber; ++i) {
result.put(metaData.getColumnName(i), resultSet.getObject(i));
}
} while (resultSet.next());
return result;
}
@Override
public Object valueOf(final String s) {
return null;
}
}
不幸的是,方法getMetaData抛出:
UnsupportedOperationException("CallableStatement does not support this method.");
还有其他实现这一目标的可能性吗?
答案 0 :(得分:0)
我终于设法将Oracle Cursor映射到Map!我不得不修改getResult方法的第一行。看起来应该像这样:
ResultSet resultSet = (ResultSet) resultGetter.getObject();