Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
53692a79
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
53692a79
编写于
9月 09, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polishing
上级
b07a7be2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
26 deletion
+31
-26
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
...ework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
+31
-26
未找到文件。
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java
浏览文件 @
53692a79
...
@@ -24,6 +24,7 @@ import java.sql.SQLException;
...
@@ -24,6 +24,7 @@ import java.sql.SQLException;
import
java.sql.Time
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -32,33 +33,34 @@ import org.springframework.jdbc.InvalidResultSetAccessException;
...
@@ -32,33 +33,34 @@ import org.springframework.jdbc.InvalidResultSetAccessException;
/**
/**
* Default implementation of Spring's {@link SqlRowSet} interface.
* Default implementation of Spring's {@link SqlRowSet} interface.
*
*
* <p>This implementation wraps a <code>javax.sql.ResultSet</code>,
* <p>This implementation wraps a <code>javax.sql.ResultSet</code>, catching any SQLExceptions
* catching any SQLExceptions and translating them to the
* and translating them to the appropriate Spring {@link InvalidResultSetAccessException}.
* appropriate Spring {@link InvalidResultSetAccessException}.
*
* <p>Note: Since JDBC 4.0 it has been clarified that any methods using a String to identify the column should
* be using the column label. The column label is assigned using the ALIAS keyword in the SQL query string. When the
* query doesn't use an ALIAS the default label is the column name. Most JDBC ResultSet implementations follow this
* new pattern but there are some exceptions such as the com.sun.rowset.CachedRowSetImpl which only uses the column
* name ignoring any column labels. Since Spring 3.0.5 this class will translate column labels to the correct column
* index to provide better support for the com.sun.rowset.CachedRowSetImpl which is the default implementation used by
* the JdbcTemplate when working with RowSets.
*
*
* <p>The passed-in ResultSets should already be disconnected if the SqlRowSet
* <p>The passed-in ResultSets should already be disconnected if the SqlRowSet is supposed
* is supposed to be usable in a disconnected fashion. This means that
* to be usable in a disconnected fashion. This means that you will usually pass in a
* you will usually pass in a <code>javax.sql.rowset.CachedRowSet</code>,
* <code>javax.sql.rowset.CachedRowSet</code>, which implements the ResultSet interface.
* which implements the ResultSet interface.
*
*
* <p>Note: This class implements the <code>java.io.Serializable</code>
* <p>Note: Since JDBC 4.0, it has been clarified that any methods using a String to identify
* marker interface through the SqlRowSet interface, but is only actually
* the column should be using the column label. The column label is assigned using the ALIAS
* serializable if the disconnected ResultSet/RowSet contained in it is
* keyword in the SQL query string. When the query doesn't use an ALIAS, the default label is
* serializable. Most CachedRowSet implementations are actually serializable.
* the column name. Most JDBC ResultSet implementations follow this new pattern but there are
* exceptions such as the <code>com.sun.rowset.CachedRowSetImpl</code> class which only uses
* the column name, ignoring any column labels. As of Spring 3.0.5, ResultSetWrappingSqlRowSet
* will translate column labels to the correct column index to provide better support for the
* <code>com.sun.rowset.CachedRowSetImpl</code> which is the default implementation used by
* {@link org.springframework.jdbc.core.JdbcTemplate} when working with RowSets.
*
* <p>Note: This class implements the <code>java.io.Serializable</code> marker interface
* through the SqlRowSet interface, but is only actually serializable if the disconnected
* ResultSet/RowSet contained in it is serializable. Most CachedRowSet implementations
* are actually serializable, so this should usually work out.
*
*
* @author Thomas Risberg
* @author Thomas Risberg
* @author Juergen Hoeller
* @author Juergen Hoeller
* @since 1.2
* @since 1.2
* @see java.sql.ResultSet
* @see java.sql.ResultSet
* @see javax.sql.rowset.CachedRowSet
* @see javax.sql.rowset.CachedRowSet
* @see org.springframework.jdbc.core.JdbcTemplate#queryForRowSet
*/
*/
public
class
ResultSetWrappingSqlRowSet
implements
SqlRowSet
{
public
class
ResultSetWrappingSqlRowSet
implements
SqlRowSet
{
...
@@ -97,13 +99,14 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
...
@@ -97,13 +99,14 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
int
columnCount
=
rsmd
.
getColumnCount
();
int
columnCount
=
rsmd
.
getColumnCount
();
this
.
columnLabelMap
=
new
HashMap
<
String
,
Integer
>(
columnCount
);
this
.
columnLabelMap
=
new
HashMap
<
String
,
Integer
>(
columnCount
);
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
columnLabelMap
.
put
(
rsmd
.
getColumnLabel
(
i
),
Integer
.
valueOf
(
i
)
);
this
.
columnLabelMap
.
put
(
rsmd
.
getColumnLabel
(
i
),
i
);
}
}
}
}
else
{
else
{
this
.
columnLabelMap
=
new
HashMap
<
String
,
Integer
>(
0
);
this
.
columnLabelMap
=
Collections
.
emptyMap
(
);
}
}
}
catch
(
SQLException
se
)
{
}
catch
(
SQLException
se
)
{
throw
new
InvalidResultSetAccessException
(
se
);
throw
new
InvalidResultSetAccessException
(
se
);
}
}
...
@@ -130,16 +133,18 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
...
@@ -130,16 +133,18 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
* @see java.sql.ResultSet#findColumn(String)
* @see java.sql.ResultSet#findColumn(String)
*/
*/
public
int
findColumn
(
String
columnLabel
)
throws
InvalidResultSetAccessException
{
public
int
findColumn
(
String
columnLabel
)
throws
InvalidResultSetAccessException
{
Integer
columnIndex
=
columnLabelMap
.
get
(
columnLabel
);
Integer
columnIndex
=
this
.
columnLabelMap
.
get
(
columnLabel
);
if
(
columnIndex
==
null
)
{
if
(
columnIndex
!=
null
)
{
return
columnIndex
;
}
else
{
try
{
try
{
columnIndex
=
this
.
resultSet
.
findColumn
(
columnLabel
);
return
this
.
resultSet
.
findColumn
(
columnLabel
);
}
}
catch
(
SQLException
se
)
{
catch
(
SQLException
se
)
{
throw
new
InvalidResultSetAccessException
(
se
);
throw
new
InvalidResultSetAccessException
(
se
);
}
}
}
}
return
columnIndex
.
intValue
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录