Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
a0139abf
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,发现更多精彩内容 >>
提交
a0139abf
编写于
3月 09, 2009
作者:
T
Thomas Risberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a DuplicatKeyException catagory for SQLException translation (SPR-5125)
上级
d9f5a7a6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
108 addition
and
9 deletion
+108
-9
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java
...work/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java
+5
-0
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java
.../java/org/springframework/jdbc/support/SQLErrorCodes.java
+10
-0
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml
...rces/org/springframework/jdbc/support/sql-error-codes.xml
+39
-9
org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java
...jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java
+8
-0
org.springframework.transaction/src/main/java/org/springframework/dao/DuplicateKeyException.java
...n/java/org/springframework/dao/DuplicateKeyException.java
+46
-0
未找到文件。
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java
浏览文件 @
a0139abf
...
@@ -32,6 +32,7 @@ import org.springframework.dao.DataIntegrityViolationException;
...
@@ -32,6 +32,7 @@ import org.springframework.dao.DataIntegrityViolationException;
import
org.springframework.dao.DeadlockLoserDataAccessException
;
import
org.springframework.dao.DeadlockLoserDataAccessException
;
import
org.springframework.dao.PermissionDeniedDataAccessException
;
import
org.springframework.dao.PermissionDeniedDataAccessException
;
import
org.springframework.dao.TransientDataAccessResourceException
;
import
org.springframework.dao.TransientDataAccessResourceException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.jdbc.BadSqlGrammarException
;
import
org.springframework.jdbc.BadSqlGrammarException
;
import
org.springframework.jdbc.InvalidResultSetAccessException
;
import
org.springframework.jdbc.InvalidResultSetAccessException
;
...
@@ -224,6 +225,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
...
@@ -224,6 +225,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
logTranslation
(
task
,
sql
,
sqlEx
,
false
);
logTranslation
(
task
,
sql
,
sqlEx
,
false
);
return
new
InvalidResultSetAccessException
(
task
,
sql
,
sqlEx
);
return
new
InvalidResultSetAccessException
(
task
,
sql
,
sqlEx
);
}
}
else
if
(
Arrays
.
binarySearch
(
this
.
sqlErrorCodes
.
getDuplicateKeyCodes
(),
errorCode
)
>=
0
)
{
logTranslation
(
task
,
sql
,
sqlEx
,
false
);
return
new
DuplicateKeyException
(
buildMessage
(
task
,
sql
,
sqlEx
),
sqlEx
);
}
else
if
(
Arrays
.
binarySearch
(
this
.
sqlErrorCodes
.
getDataIntegrityViolationCodes
(),
errorCode
)
>=
0
)
{
else
if
(
Arrays
.
binarySearch
(
this
.
sqlErrorCodes
.
getDataIntegrityViolationCodes
(),
errorCode
)
>=
0
)
{
logTranslation
(
task
,
sql
,
sqlEx
,
false
);
logTranslation
(
task
,
sql
,
sqlEx
,
false
);
return
new
DataIntegrityViolationException
(
buildMessage
(
task
,
sql
,
sqlEx
),
sqlEx
);
return
new
DataIntegrityViolationException
(
buildMessage
(
task
,
sql
,
sqlEx
),
sqlEx
);
...
...
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java
浏览文件 @
a0139abf
...
@@ -41,6 +41,8 @@ public class SQLErrorCodes {
...
@@ -41,6 +41,8 @@ public class SQLErrorCodes {
private
String
[]
invalidResultSetAccessCodes
=
new
String
[
0
];
private
String
[]
invalidResultSetAccessCodes
=
new
String
[
0
];
private
String
[]
duplicateKeyCodes
=
new
String
[
0
];
private
String
[]
dataIntegrityViolationCodes
=
new
String
[
0
];
private
String
[]
dataIntegrityViolationCodes
=
new
String
[
0
];
private
String
[]
permissionDeniedCodes
=
new
String
[
0
];
private
String
[]
permissionDeniedCodes
=
new
String
[
0
];
...
@@ -112,6 +114,14 @@ public class SQLErrorCodes {
...
@@ -112,6 +114,14 @@ public class SQLErrorCodes {
return
this
.
invalidResultSetAccessCodes
;
return
this
.
invalidResultSetAccessCodes
;
}
}
public
String
[]
getDuplicateKeyCodes
()
{
return
duplicateKeyCodes
;
}
public
void
setDuplicateKeyCodes
(
String
[]
duplicateKeyCodes
)
{
this
.
duplicateKeyCodes
=
duplicateKeyCodes
;
}
public
void
setDataIntegrityViolationCodes
(
String
[]
dataIntegrityViolationCodes
)
{
public
void
setDataIntegrityViolationCodes
(
String
[]
dataIntegrityViolationCodes
)
{
this
.
dataIntegrityViolationCodes
=
StringUtils
.
sortStringArray
(
dataIntegrityViolationCodes
);
this
.
dataIntegrityViolationCodes
=
StringUtils
.
sortStringArray
(
dataIntegrityViolationCodes
);
}
}
...
...
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml
浏览文件 @
a0139abf
...
@@ -21,8 +21,11 @@
...
@@ -21,8 +21,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
-007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491
</value>
<value>
-007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
-803
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
-407,-530,-531,-532,-543,-544,-545,-603,-667
,-803
</value>
<value>
-407,-530,-531,-532,-543,-544,-545,-603,-667
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
-904,-971
</value>
<value>
-904,-971
</value>
...
@@ -45,8 +48,11 @@
...
@@ -45,8 +48,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08
</value>
<value>
42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
23505
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
22001,22005,23502,23503,235
05,235
13,X0Y32
</value>
<value>
22001,22005,23502,23503,23513,X0Y32
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
04501,08004,42Y07
</value>
<value>
04501,08004,42Y07
</value>
...
@@ -63,8 +69,11 @@
...
@@ -63,8 +69,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
42000,42001,42101,42102,42111,42112,42121,42122,42132
</value>
<value>
42000,42001,42101,42102,42111,42112,42121,42122,42132
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
23001
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
22003,22012,22025,23000
,23001
</value>
<value>
22003,22012,22025,23000
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
90046,90100,90117,90121,90126
</value>
<value>
90046,90100,90117,90121,90126
</value>
...
@@ -78,6 +87,9 @@
...
@@ -78,6 +87,9 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
-22,-28
</value>
<value>
-22,-28
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
-104
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
-9
</value>
<value>
-9
</value>
</property>
</property>
...
@@ -93,8 +105,11 @@
...
@@ -93,8 +105,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
-201,-217,-696
</value>
<value>
-201,-217,-696
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
-239,-268,-6017
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
-
239,-268,-
692,-11030
</value>
<value>
-692,-11030
</value>
</property>
</property>
</bean>
</bean>
...
@@ -108,8 +123,11 @@
...
@@ -108,8 +123,11 @@
<property
name=
"permissionDeniedCodes"
>
<property
name=
"permissionDeniedCodes"
>
<value>
229
</value>
<value>
229
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
2601,2627
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
544,
2601,2627,
8114,8115
</value>
<value>
544,8114,8115
</value>
</property>
</property>
<property
name=
"cannotAcquireLockCodes"
>
<property
name=
"cannotAcquireLockCodes"
>
<value>
1222
</value>
<value>
1222
</value>
...
@@ -123,8 +141,11 @@
...
@@ -123,8 +141,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
1054,1064,1146
</value>
<value>
1054,1064,1146
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
1062
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
630,839,840,893,1
062,1
169,1215,1216,1217,1451,1452,1557
</value>
<value>
630,839,840,893,1169,1215,1216,1217,1451,1452,1557
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
1
</value>
<value>
1
</value>
...
@@ -144,8 +165,11 @@
...
@@ -144,8 +165,11 @@
<property
name=
"invalidResultSetAccessCodes"
>
<property
name=
"invalidResultSetAccessCodes"
>
<value>
17003
</value>
<value>
17003
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
1
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
1
,1
400,1722,2291,2292
</value>
<value>
1400,1722,2291,2292
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
17002,17447
</value>
<value>
17002,17447
</value>
...
@@ -168,8 +192,11 @@
...
@@ -168,8 +192,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
03000,42000,42601,42602,42622,42804,42P01
</value>
<value>
03000,42000,42601,42602,42622,42804,42P01
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
23505
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
23000,23502,23503,235
05,235
14
</value>
<value>
23000,23502,23503,23514
</value>
</property>
</property>
<property
name=
"dataAccessResourceFailureCodes"
>
<property
name=
"dataAccessResourceFailureCodes"
>
<value>
53000,53100,53200,53300
</value>
<value>
53000,53100,53200,53300
</value>
...
@@ -196,8 +223,11 @@
...
@@ -196,8 +223,11 @@
<property
name=
"badSqlGrammarCodes"
>
<property
name=
"badSqlGrammarCodes"
>
<value>
101,102,103,104,105,106,107,108,109,110,111,112,113,116,120,121,123,207,208,213,257,512
</value>
<value>
101,102,103,104,105,106,107,108,109,110,111,112,113,116,120,121,123,207,208,213,257,512
</value>
</property>
</property>
<property
name=
"duplicateKeyCodes"
>
<value>
2601
</value>
</property>
<property
name=
"dataIntegrityViolationCodes"
>
<property
name=
"dataIntegrityViolationCodes"
>
<value>
233,423,511,515,530,547,26
01,26
15,2714
</value>
<value>
233,423,511,515,530,547,2615,2714
</value>
</property>
</property>
<property
name=
"transientDataAccessResourceCodes"
>
<property
name=
"transientDataAccessResourceCodes"
>
<value>
921,1105
</value>
<value>
921,1105
</value>
...
...
org.springframework.jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java
浏览文件 @
a0139abf
...
@@ -27,6 +27,7 @@ import org.springframework.dao.DataAccessException;
...
@@ -27,6 +27,7 @@ import org.springframework.dao.DataAccessException;
import
org.springframework.dao.DataAccessResourceFailureException
;
import
org.springframework.dao.DataAccessResourceFailureException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.dao.DeadlockLoserDataAccessException
;
import
org.springframework.dao.DeadlockLoserDataAccessException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.jdbc.BadSqlGrammarException
;
import
org.springframework.jdbc.BadSqlGrammarException
;
import
org.springframework.jdbc.InvalidResultSetAccessException
;
import
org.springframework.jdbc.InvalidResultSetAccessException
;
...
@@ -39,6 +40,7 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
...
@@ -39,6 +40,7 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
static
{
static
{
ERROR_CODES
.
setBadSqlGrammarCodes
(
new
String
[]
{
"1"
,
"2"
});
ERROR_CODES
.
setBadSqlGrammarCodes
(
new
String
[]
{
"1"
,
"2"
});
ERROR_CODES
.
setInvalidResultSetAccessCodes
(
new
String
[]
{
"3"
,
"4"
});
ERROR_CODES
.
setInvalidResultSetAccessCodes
(
new
String
[]
{
"3"
,
"4"
});
ERROR_CODES
.
setDuplicateKeyCodes
(
new
String
[]
{
"10"
});
ERROR_CODES
.
setDataAccessResourceFailureCodes
(
new
String
[]
{
"5"
});
ERROR_CODES
.
setDataAccessResourceFailureCodes
(
new
String
[]
{
"5"
});
ERROR_CODES
.
setDataIntegrityViolationCodes
(
new
String
[]
{
"6"
});
ERROR_CODES
.
setDataIntegrityViolationCodes
(
new
String
[]
{
"6"
});
ERROR_CODES
.
setCannotAcquireLockCodes
(
new
String
[]
{
"7"
});
ERROR_CODES
.
setCannotAcquireLockCodes
(
new
String
[]
{
"7"
});
...
@@ -64,6 +66,12 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
...
@@ -64,6 +66,12 @@ public class SQLErrorCodeSQLExceptionTranslatorTests extends TestCase {
checkTranslation
(
sext
,
7
,
CannotAcquireLockException
.
class
);
checkTranslation
(
sext
,
7
,
CannotAcquireLockException
.
class
);
checkTranslation
(
sext
,
8
,
DeadlockLoserDataAccessException
.
class
);
checkTranslation
(
sext
,
8
,
DeadlockLoserDataAccessException
.
class
);
checkTranslation
(
sext
,
9
,
CannotSerializeTransactionException
.
class
);
checkTranslation
(
sext
,
9
,
CannotSerializeTransactionException
.
class
);
checkTranslation
(
sext
,
10
,
DuplicateKeyException
.
class
);
SQLException
dupKeyEx
=
new
SQLException
(
""
,
""
,
10
);
DataAccessException
dksex
=
sext
.
translate
(
"task"
,
"SQL"
,
dupKeyEx
);
assertTrue
(
"Not instance of DataIntegrityViolationException"
,
DataIntegrityViolationException
.
class
.
isAssignableFrom
(
dksex
.
getClass
()));
// Test fallback. We assume that no database will ever return this error code,
// Test fallback. We assume that no database will ever return this error code,
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
...
...
org.springframework.transaction/src/main/java/org/springframework/dao/DuplicateKeyException.java
0 → 100644
浏览文件 @
a0139abf
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.dao
;
/**
* Exception thrown when an attempt to insert or update data
* results in violation of an primary key or unique constraint.
* Note that this is not necessarily a purely relational concept;
* unique primary keys are required by most database types.
*
* @author Thomas Risberg
*/
public
class
DuplicateKeyException
extends
DataIntegrityViolationException
{
/**
* Constructor for DuplicateKeyException.
* @param msg the detail message
*/
public
DuplicateKeyException
(
String
msg
)
{
super
(
msg
);
}
/**
* Constructor for DuplicateKeyException.
* @param msg the detail message
* @param cause the root cause from the data access API in use
*/
public
DuplicateKeyException
(
String
msg
,
Throwable
cause
)
{
super
(
msg
,
cause
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录