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
8c785b21
Commit
8c785b21
authored
Apr 07, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
7a4b87be
bccbbc14
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
16 deletions
+132
-16
pom.xml
spring-boot-devtools/pom.xml
+16
-0
DevToolsDataSourceAutoConfiguration.java
...ls/autoconfigure/DevToolsDataSourceAutoConfiguration.java
+36
-10
AbstractDevToolsDataSourceAutoConfigurationTests.java
...ure/AbstractDevToolsDataSourceAutoConfigurationTests.java
+13
-5
DevToolsPooledDataSourceAutoConfigurationTests.java
...igure/DevToolsPooledDataSourceAutoConfigurationTests.java
+67
-1
No files found.
spring-boot-devtools/pom.xml
View file @
8c785b21
...
@@ -132,6 +132,17 @@
...
@@ -132,6 +132,17 @@
<artifactId>
spring-hateoas
</artifactId>
<artifactId>
spring-hateoas
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.derby
</groupId>
<artifactId>
derby
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.derby
</groupId>
<artifactId>
derbyclient
</artifactId>
<version>
${derby.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-websocket
</artifactId>
<artifactId>
tomcat-embed-websocket
</artifactId>
...
@@ -152,6 +163,11 @@
...
@@ -152,6 +163,11 @@
<artifactId>
websocket-client
</artifactId>
<artifactId>
websocket-client
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.hsqldb
</groupId>
<artifactId>
hsqldb
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<artifactId>
postgresql
</artifactId>
...
...
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java
View file @
8c785b21
...
@@ -42,7 +42,6 @@ import org.springframework.context.annotation.Conditional;
...
@@ -42,7 +42,6 @@ import org.springframework.context.annotation.Conditional;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.ConfigurationCondition
;
import
org.springframework.context.annotation.ConfigurationCondition
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
import
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
...
@@ -85,12 +84,6 @@ public class DevToolsDataSourceAutoConfiguration {
...
@@ -85,12 +84,6 @@ public class DevToolsDataSourceAutoConfiguration {
static
final
class
NonEmbeddedInMemoryDatabaseShutdownExecutor
static
final
class
NonEmbeddedInMemoryDatabaseShutdownExecutor
implements
DisposableBean
{
implements
DisposableBean
{
private
static
final
Set
<
String
>
IN_MEMORY_DRIVER_CLASS_NAMES
=
new
HashSet
<>(
Arrays
.
asList
(
"org.apache.derby.jdbc.EmbeddedDriver"
,
"org.h2.Driver"
,
"org.h2.jdbcx.JdbcDataSource"
,
"org.hsqldb.jdbcDriver"
,
"org.hsqldb.jdbc.JDBCDriver"
,
"org.hsqldb.jdbc.pool.JDBCXADataSource"
));
private
final
DataSource
dataSource
;
private
final
DataSource
dataSource
;
private
final
DataSourceProperties
dataSourceProperties
;
private
final
DataSourceProperties
dataSourceProperties
;
...
@@ -109,9 +102,42 @@ public class DevToolsDataSourceAutoConfiguration {
...
@@ -109,9 +102,42 @@ public class DevToolsDataSourceAutoConfiguration {
}
}
private
boolean
dataSourceRequiresShutdown
()
{
private
boolean
dataSourceRequiresShutdown
()
{
return
IN_MEMORY_DRIVER_CLASS_NAMES
for
(
InMemoryDatabase
inMemoryDatabase
:
InMemoryDatabase
.
values
())
{
.
contains
(
this
.
dataSourceProperties
.
determineDriverClassName
())
if
(
inMemoryDatabase
.
matches
(
this
.
dataSourceProperties
))
{
&&
(!(
this
.
dataSource
instanceof
EmbeddedDatabase
));
return
true
;
}
}
return
false
;
}
private
static
enum
InMemoryDatabase
{
DERBY
(
null
,
"org.apache.derby.jdbc.EmbeddedDriver"
),
H2
(
"jdbc:h2:mem:"
,
"org.h2.Driver"
,
"org.h2.jdbcx.JdbcDataSource"
),
HQSQLDB
(
"jdbc:hsqldb:mem:"
,
"org.hsqldb.jdbcDriver"
,
"org.hsqldb.jdbc.JDBCDriver"
,
"org.hsqldb.jdbc.pool.JDBCXADataSource"
);
private
final
String
urlPrefix
;
private
final
Set
<
String
>
driverClassNames
;
InMemoryDatabase
(
String
urlPrefix
,
String
...
driverClassNames
)
{
this
.
urlPrefix
=
urlPrefix
;
this
.
driverClassNames
=
new
HashSet
<
String
>(
Arrays
.
asList
(
driverClassNames
));
}
boolean
matches
(
DataSourceProperties
properties
)
{
String
url
=
properties
.
getUrl
();
return
(
url
==
null
||
this
.
urlPrefix
==
null
||
url
.
startsWith
(
this
.
urlPrefix
))
&&
this
.
driverClassNames
.
contains
(
properties
.
determineDriverClassName
());
}
}
}
}
}
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java
View file @
8c785b21
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -95,8 +95,17 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
...
@@ -95,8 +95,17 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
return
statement
;
return
statement
;
}
}
protected
final
ConfigurableApplicationContext
createContext
(
Class
<?>...
classes
)
{
return
this
.
createContext
(
null
,
classes
);
}
protected
final
ConfigurableApplicationContext
createContext
(
String
driverClassName
,
protected
final
ConfigurableApplicationContext
createContext
(
String
driverClassName
,
Class
<?>...
classes
)
{
Class
<?>...
classes
)
{
return
this
.
createContext
(
driverClassName
,
null
,
classes
);
}
protected
final
ConfigurableApplicationContext
createContext
(
String
driverClassName
,
String
url
,
Class
<?>...
classes
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
classes
);
context
.
register
(
classes
);
context
.
register
(
DevToolsDataSourceAutoConfiguration
.
class
);
context
.
register
(
DevToolsDataSourceAutoConfiguration
.
class
);
...
@@ -104,14 +113,13 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
...
@@ -104,14 +113,13 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
context
,
EnvironmentTestUtils
.
addEnvironment
(
context
,
"spring.datasource.driver-class-name:"
+
driverClassName
);
"spring.datasource.driver-class-name:"
+
driverClassName
);
}
}
if
(
url
!=
null
)
{
EnvironmentTestUtils
.
addEnvironment
(
context
,
"spring.datasource.url:"
+
url
);
}
context
.
refresh
();
context
.
refresh
();
return
context
;
return
context
;
}
}
protected
final
ConfigurableApplicationContext
createContext
(
Class
<?>...
classes
)
{
return
this
.
createContext
(
null
,
classes
);
}
@Configuration
@Configuration
static
class
SingleDataSourceConfiguration
{
static
class
SingleDataSourceConfiguration
{
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsPooledDataSourceAutoConfigurationTests.java
View file @
8c785b21
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -57,4 +57,70 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
...
@@ -57,4 +57,70 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
verify
(
statement
,
times
(
0
)).
execute
(
"SHUTDOWN"
);
verify
(
statement
,
times
(
0
)).
execute
(
"SHUTDOWN"
);
}
}
@Test
public
void
h2ServerIsNotShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.h2.Driver"
,
"jdbc:h2:hsql://localhost"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
0
)).
execute
(
"SHUTDOWN"
);
}
@Test
public
void
inMemoryh2IsShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.h2.Driver"
,
"jdbc:h2:mem:test"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
1
)).
execute
(
"SHUTDOWN"
);
}
@Test
public
void
hsqlServerIsNotShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.hsqldb.jdbcDriver"
,
"jdbc:hsqldb:hsql://localhost"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
0
)).
execute
(
"SHUTDOWN"
);
}
@Test
public
void
inMemoryHsqlIsShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.hsqldb.jdbcDriver"
,
"jdbc:hsqldb:mem:test"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
1
)).
execute
(
"SHUTDOWN"
);
}
@Test
public
void
derbyClientIsNotShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.apache.derby.jdbc.ClientDriver"
,
"jdbc:derby://localhost"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
0
)).
execute
(
"SHUTDOWN"
);
}
@Test
public
void
inMemoryDerbyIsShutdown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.apache.derby.jdbc.EmbeddedDriver"
,
"jdbc:derby:memory:test"
,
DataSourceAutoConfiguration
.
class
,
DataSourceSpyConfiguration
.
class
);
Statement
statement
=
configureDataSourceBehaviour
(
context
.
getBean
(
DataSource
.
class
));
context
.
close
();
verify
(
statement
,
times
(
1
)).
execute
(
"SHUTDOWN"
);
}
}
}
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