Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
818809d7
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
818809d7
编写于
6月 14, 2012
作者:
L
lancea
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7145913: CachedRowSetSwriter.insertNewRow() throws SQLException
Reviewed-by: joehw, naoto, psandoz, forax
上级
a00f0039
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
132 addition
and
93 deletion
+132
-93
src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java
...e/classes/com/sun/rowset/internal/CachedRowSetWriter.java
+132
-93
未找到文件。
src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java
浏览文件 @
818809d7
/*
/*
* Copyright (c) 2003, 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 201
2
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -828,39 +828,55 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
...
@@ -828,39 +828,55 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
*/
*/
private
boolean
insertNewRow
(
CachedRowSet
crs
,
private
boolean
insertNewRow
(
CachedRowSet
crs
,
PreparedStatement
pstmt
,
CachedRowSetImpl
crsRes
)
throws
SQLException
{
PreparedStatement
pstmt
,
CachedRowSetImpl
crsRes
)
throws
SQLException
{
int
i
=
0
;
int
icolCount
=
crs
.
getMetaData
().
getColumnCount
();
boolean
returnVal
=
false
;
boolean
returnVal
=
false
;
PreparedStatement
pstmtSel
=
con
.
prepareStatement
(
selectCmd
,
ResultSet
.
TYPE_SCROLL_SENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
try
(
PreparedStatement
pstmtSel
=
con
.
prepareStatement
(
selectCmd
,
ResultSet
rs
,
rs2
=
null
;
ResultSet
.
TYPE_SCROLL_SENSITIVE
,
DatabaseMetaData
dbmd
=
con
.
getMetaData
();
ResultSet
.
CONCUR_READ_ONLY
);
rs
=
pstmtSel
.
executeQuery
();
ResultSet
rs
=
pstmtSel
.
executeQuery
();
String
table
=
crs
.
getTableName
();
ResultSet
rs2
=
con
.
getMetaData
().
getPrimaryKeys
(
null
,
null
,
rs2
=
dbmd
.
getPrimaryKeys
(
null
,
null
,
table
);
crs
.
getTableName
())
String
[]
primaryKeys
=
new
String
[
icolCount
];
)
{
ResultSetMetaData
rsmd
=
crs
.
getMetaData
();
int
icolCount
=
rsmd
.
getColumnCount
();
String
[]
primaryKeys
=
new
String
[
icolCount
];
int
k
=
0
;
int
k
=
0
;
while
(
rs2
.
next
())
{
while
(
rs2
.
next
())
{
String
pkcolname
=
rs2
.
getString
(
"COLUMN_NAME"
);
primaryKeys
[
k
]
=
rs2
.
getString
(
"COLUMN_NAME"
);
primaryKeys
[
k
]
=
pkcolname
;
k
++;
k
++;
}
}
if
(
rs
.
next
())
{
if
(
rs
.
next
())
{
for
(
int
j
=
0
;
j
<
primaryKeys
.
length
;
j
++)
{
for
(
String
pkName
:
primaryKeys
)
{
if
(
primaryKeys
[
j
]
!=
null
)
{
if
(!
isPKNameValid
(
pkName
,
rsmd
))
{
if
(
crs
.
getObject
(
primaryKeys
[
j
])
==
null
){
/* We came here as one of the the primary keys
* of the table is not present in the cached
* rowset object, it should be an autoincrement column
* and not included while creating CachedRowSet
* Object, proceed to check for other primary keys
*/
continue
;
}
Object
crsPK
=
crs
.
getObject
(
pkName
);
if
(
crsPK
==
null
)
{
/*
* It is possible that the PK is null on some databases
* and will be filled in at insert time (MySQL for example)
*/
break
;
break
;
}
}
String
crsPK
=
(
crs
.
getObject
(
primaryKeys
[
j
])).
toString
();
String
rsPK
=
(
rs
.
getObject
(
primaryKeys
[
j
])
).
toString
();
String
rsPK
=
rs
.
getObject
(
pkName
).
toString
();
if
(
crsPK
.
equals
(
rsPK
))
{
if
(
crsPK
.
toString
()
.
equals
(
rsPK
))
{
returnVal
=
true
;
returnVal
=
true
;
this
.
crsResolve
.
moveToInsertRow
();
this
.
crsResolve
.
moveToInsertRow
();
for
(
i
=
1
;
i
<=
icolCount
;
i
++)
{
for
(
int
i
=
1
;
i
<=
icolCount
;
i
++)
{
String
colname
=
(
rs
.
getMetaData
()).
getColumnName
(
i
);
String
colname
=
(
rs
.
getMetaData
()).
getColumnName
(
i
);
if
(
colname
.
equals
(
primaryKeys
[
j
]
))
if
(
colname
.
equals
(
pkName
))
this
.
crsResolve
.
updateObject
(
i
,
rsPK
);
this
.
crsResolve
.
updateObject
(
i
,
rsPK
);
else
else
this
.
crsResolve
.
updateNull
(
i
);
this
.
crsResolve
.
updateNull
(
i
);
...
@@ -870,12 +886,13 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
...
@@ -870,12 +886,13 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
}
}
}
}
}
}
}
if
(
returnVal
)
if
(
returnVal
)
{
return
returnVal
;
return
returnVal
;
}
try
{
try
{
for
(
i
=
1
;
i
<=
icolCount
;
i
++)
{
for
(
int
i
=
1
;
i
<=
icolCount
;
i
++)
{
Object
obj
=
crs
.
getObject
(
i
);
Object
obj
=
crs
.
getObject
(
i
);
if
(
obj
!=
null
)
{
if
(
obj
!=
null
)
{
pstmt
.
setObject
(
i
,
obj
);
pstmt
.
setObject
(
i
,
obj
);
...
@@ -884,20 +901,20 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
...
@@ -884,20 +901,20 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
}
}
}
}
i
=
pstmt
.
executeUpdate
();
pstmt
.
executeUpdate
();
return
false
;
return
false
;
}
catch
(
SQLException
ex
)
{
}
catch
(
SQLException
ex
)
{
/*
*
/
*
* Cursor will come here if executeUpdate fails.
* Cursor will come here if executeUpdate fails.
* There can be many reasons why the insertion failed,
* There can be many reasons why the insertion failed,
* one can be violation of primary key.
* one can be violation of primary key.
* Hence we cannot exactly identify why the insertion failed
* Hence we cannot exactly identify why the insertion failed,
* Present the current row as a null row to the us
er.
* present the current row as a null row to the call
er.
*
*/
*/
this
.
crsResolve
.
moveToInsertRow
();
this
.
crsResolve
.
moveToInsertRow
();
for
(
i
=
1
;
i
<=
icolCount
;
i
++)
{
for
(
int
i
=
1
;
i
<=
icolCount
;
i
++)
{
this
.
crsResolve
.
updateNull
(
i
);
this
.
crsResolve
.
updateNull
(
i
);
}
}
...
@@ -907,6 +924,7 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
...
@@ -907,6 +924,7 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
return
true
;
return
true
;
}
}
}
}
}
/**
/**
* Deletes the row in the underlying data source that corresponds to
* Deletes the row in the underlying data source that corresponds to
...
@@ -1437,4 +1455,25 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
...
@@ -1437,4 +1455,25 @@ public class CachedRowSetWriter implements TransactionalWriter, Serializable {
}
}
static
final
long
serialVersionUID
=-
8506030970299413976L
;
static
final
long
serialVersionUID
=-
8506030970299413976L
;
/**
* Validate whether the Primary Key is known to the CachedRowSet. If it is
* not, it is an auto-generated key
* @param pk - Primary Key to validate
* @param rsmd - ResultSetMetadata for the RowSet
* @return true if found, false otherwise (auto generated key)
*/
private
boolean
isPKNameValid
(
String
pk
,
ResultSetMetaData
rsmd
)
throws
SQLException
{
boolean
isValid
=
false
;
int
cols
=
rsmd
.
getColumnCount
();
for
(
int
i
=
1
;
i
<=
cols
;
i
++)
{
String
colName
=
rsmd
.
getColumnClassName
(
i
);
if
(
colName
.
equalsIgnoreCase
(
pk
))
{
isValid
=
true
;
break
;
}
}
return
isValid
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录