Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
46ecf7a9
Commit
46ecf7a9
authored
May 22, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only unwrap when DataSource is a wrapper for required type
Closes gh-16863
parent
da12ad0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
DataSourceUnwrapper.java
...va/org/springframework/boot/jdbc/DataSourceUnwrapper.java
+6
-3
DataSourceUnwrapperTests.java
...g/springframework/boot/jdbc/DataSourceUnwrapperTests.java
+17
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceUnwrapper.java
View file @
46ecf7a9
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -76,11 +76,14 @@ public final class DataSourceUnwrapper {
private
static
<
S
>
S
safeUnwrap
(
Wrapper
wrapper
,
Class
<
S
>
target
)
{
try
{
return
wrapper
.
unwrap
(
target
);
if
(
wrapper
.
isWrapperFor
(
target
))
{
return
wrapper
.
unwrap
(
target
);
}
}
catch
(
Exception
ex
)
{
return
null
;
// Continue
}
return
null
;
}
private
static
class
DelegatingDataSourceUnwrapper
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java
View file @
46ecf7a9
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
jdbc
;
import
java.sql.SQLException
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariDataSource
;
...
...
@@ -27,6 +29,9 @@ import org.springframework.jdbc.datasource.DelegatingDataSource;
import
org.springframework.jdbc.datasource.SingleConnectionDataSource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
/**
* Tests for {@link DataSourceUnwrapper}.
...
...
@@ -91,6 +96,17 @@ public class DataSourceUnwrapperTests {
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrappingIsNotAttemptedWhenDataSourceIsNotWrapperForTarget
()
throws
SQLException
{
DataSource
dataSource
=
mock
(
DataSource
.
class
);
DataSource
actual
=
DataSourceUnwrapper
.
unwrap
(
dataSource
,
HikariDataSource
.
class
);
assertThat
(
actual
).
isNull
();
verify
(
dataSource
).
isWrapperFor
(
HikariDataSource
.
class
);
verifyNoMoreInteractions
(
dataSource
);
}
private
DataSource
wrapInProxy
(
DataSource
dataSource
)
{
return
(
DataSource
)
new
ProxyFactory
(
dataSource
).
getProxy
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment