Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
e246010d
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,发现更多精彩内容 >>
提交
e246010d
编写于
5月 06, 2014
作者:
S
Stephane Nicoll
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #102 from remast/master
* pull102: polishing Add exception translator for EclipseLink exceptions
上级
658f7f58
e1830885
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
276 addition
and
0 deletion
+276
-0
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkExceptionTranslator.java
...ework/orm/eclipselink/EclipseLinkExceptionTranslator.java
+51
-0
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkSystemException.java
...framework/orm/eclipselink/EclipseLinkSystemException.java
+43
-0
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkUtils.java
...org/springframework/orm/eclipselink/EclipseLinkUtils.java
+42
-0
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkExceptionTranslatorTests.java
.../orm/eclipselink/EclipseLinkExceptionTranslatorTests.java
+44
-0
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkSystemExceptionTests.java
...work/orm/eclipselink/EclipseLinkSystemExceptionTests.java
+56
-0
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkUtilsTests.java
...pringframework/orm/eclipselink/EclipseLinkUtilsTests.java
+40
-0
未找到文件。
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkExceptionTranslator.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
org.eclipse.persistence.exceptions.EclipseLinkException
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.support.PersistenceExceptionTranslator
;
/**
* {@link PersistenceExceptionTranslator} capable of translating {@link EclipseLinkException}
* instances to Spring's {@link DataAccessException} hierarchy.
*
* @author Jan Stamer
* @since 4.1
* @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
*/
public
class
EclipseLinkExceptionTranslator
implements
PersistenceExceptionTranslator
{
public
DataAccessException
translateExceptionIfPossible
(
RuntimeException
ex
)
{
if
(
ex
instanceof
EclipseLinkException
)
{
return
convertEclipseLinkAccessException
((
EclipseLinkException
)
ex
);
}
return
null
;
}
/**
* Convert the given EclipseLinkException to an appropriate exception from
* the {@code org.springframework.dao} hierarchy.
* @param ex EclipseLinkException that occurred
* @return a corresponding DataAccessException
* @see EclipseLinkUtils#convertEclipseLinkAccessException
*/
protected
DataAccessException
convertEclipseLinkAccessException
(
EclipseLinkException
ex
)
{
return
EclipseLinkUtils
.
convertEclipseLinkAccessException
(
ex
);
}
}
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkSystemException.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
org.eclipse.persistence.exceptions.EclipseLinkException
;
import
org.springframework.dao.UncategorizedDataAccessException
;
/**
* EclipseLink-specific subclass of UncategorizedDataAccessException, for
* EclipseLink system errors that do not match any concrete
* <code>org.springframework.dao</code> exceptions.
*
* @author Jan Stamer
* @since 4.1
* @see EclipseLinkUtils#convertEclipseLinkAccessException(EclipseLinkException)
*/
@SuppressWarnings
(
"serial"
)
public
class
EclipseLinkSystemException
extends
UncategorizedDataAccessException
{
/**
* Create a new HibernateSystemException, wrapping an arbitrary
* {@link EclipseLinkException}.
* @param cause the HibernateException thrown
*/
public
EclipseLinkSystemException
(
EclipseLinkException
cause
)
{
super
(
cause
!=
null
?
cause
.
getMessage
()
:
null
,
cause
);
}
}
spring-orm/src/main/java/org/springframework/orm/eclipselink/EclipseLinkUtils.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
org.eclipse.persistence.exceptions.EclipseLinkException
;
import
org.springframework.dao.DataAccessException
;
/**
* Helper class featuring methods for Eclipse Link. Also provides support for
* exception translation.
*
* @author Jan Stamer
* @since 3.2
*/
public
abstract
class
EclipseLinkUtils
{
/**
* Convert the given EclipseLinkException to an appropriate exception from
* the <code>org.springframework.dao</code> hierarchy.
* @param ex EclipseLinkException that occurred
* @return the corresponding DataAccessException instance
* @see EclipseLinkExceptionTranslator#convertEclipseLinkAccessException(EclipseLinkException)
*/
public
static
DataAccessException
convertEclipseLinkAccessException
(
EclipseLinkException
ex
)
{
return
new
EclipseLinkSystemException
(
ex
);
}
}
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkExceptionTranslatorTests.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
static
org
.
junit
.
Assert
.*;
import
org.eclipse.persistence.exceptions.DatabaseException
;
import
org.junit.Test
;
/**
* @author Jan Stamer
*/
public
class
EclipseLinkExceptionTranslatorTests
{
@Test
public
void
wrongException
()
{
EclipseLinkExceptionTranslator
exceptionTranslator
=
new
EclipseLinkExceptionTranslator
();
assertNull
(
exceptionTranslator
.
translateExceptionIfPossible
(
new
IllegalArgumentException
()));
}
@SuppressWarnings
(
"ThrowableResultOfMethodCallIgnored"
)
@Test
public
void
eclipseLinkException
()
{
EclipseLinkExceptionTranslator
exceptionTranslator
=
new
EclipseLinkExceptionTranslator
();
assertNotNull
(
exceptionTranslator
.
translateExceptionIfPossible
(
DatabaseException
.
databaseAccessorNotConnected
()));
assertNotNull
(
exceptionTranslator
.
translateExceptionIfPossible
(
DatabaseException
.
databaseAccessorNotConnected
()));
}
}
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkSystemExceptionTests.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
static
org
.
junit
.
Assert
.*;
import
org.eclipse.persistence.exceptions.DatabaseException
;
import
org.hibernate.HibernateException
;
import
org.junit.Test
;
/**
* @author Jan Stamer
*/
@SuppressWarnings
(
"serial"
)
public
class
EclipseLinkSystemExceptionTests
{
@Test
public
void
withNull
()
{
EclipseLinkSystemException
exception
=
new
EclipseLinkSystemException
(
null
);
assertNull
(
exception
.
getCause
());
assertNull
(
exception
.
getMessage
());
}
@Test
public
void
createWithCause
()
{
DatabaseException
dbExceptionWithCause
=
new
DatabaseException
(
"my custom exception cause"
)
{
};
EclipseLinkSystemException
elSystemException
=
new
EclipseLinkSystemException
(
dbExceptionWithCause
);
assertEquals
(
dbExceptionWithCause
,
elSystemException
.
getCause
());
assertTrue
(
elSystemException
.
getMessage
().
contains
(
"my custom exception cause"
));
}
@Test
public
void
createWithNullCause
()
throws
HibernateException
{
DatabaseException
dbExceptionWithCause
=
new
DatabaseException
((
String
)
null
)
{
};
EclipseLinkSystemException
elSystemException
=
new
EclipseLinkSystemException
(
dbExceptionWithCause
);
assertEquals
(
dbExceptionWithCause
,
elSystemException
.
getCause
());
assertTrue
(
elSystemException
.
getMessage
().
contains
(
"null"
));
}
}
spring-orm/src/test/java/org/springframework/orm/eclipselink/EclipseLinkUtilsTests.java
0 → 100644
浏览文件 @
e246010d
/*
* Copyright 2002-2014 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.orm.eclipselink
;
import
static
org
.
junit
.
Assert
.*;
import
org.eclipse.persistence.exceptions.DatabaseException
;
import
org.junit.Test
;
/**
* @author Jan Stamer
*/
public
class
EclipseLinkUtilsTests
{
@Test
public
void
withNull
()
{
assertNotNull
(
EclipseLinkUtils
.
convertEclipseLinkAccessException
(
null
));
}
@Test
public
void
testWithEclipseLinkException
()
{
assertNotNull
(
EclipseLinkUtils
.
convertEclipseLinkAccessException
(
DatabaseException
.
databaseAccessorNotConnected
()));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录