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
b1cb8bb3
Commit
b1cb8bb3
authored
Jan 03, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
b9e3dc57
8ccd4db5
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
346 additions
and
169 deletions
+346
-169
EndpointMBeanExportAutoConfiguration.java
...e/autoconfigure/EndpointMBeanExportAutoConfiguration.java
+1
-1
ManagementContextConfigurationsImportSelector.java
...figure/ManagementContextConfigurationsImportSelector.java
+23
-6
AbstractJmxEndpoint.java
...mework/boot/actuate/endpoint/jmx/AbstractJmxEndpoint.java
+0
-2
AuditEventsJmxEndpoint.java
...ork/boot/actuate/endpoint/jmx/AuditEventsJmxEndpoint.java
+5
-1
DataEndpointMBean.java
...ramework/boot/actuate/endpoint/jmx/DataEndpointMBean.java
+0
-2
EndpointMBean.java
...ingframework/boot/actuate/endpoint/jmx/EndpointMBean.java
+0
-2
EndpointMBeanExporter.java
...work/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java
+21
-3
JmxEndpoint.java
...pringframework/boot/actuate/endpoint/jmx/JmxEndpoint.java
+4
-2
LoggersEndpointMBean.java
...ework/boot/actuate/endpoint/jmx/LoggersEndpointMBean.java
+0
-2
ShutdownEndpointMBean.java
...work/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java
+0
-2
ManagementContextConfigurationsImportSelectorTests.java
...e/ManagementContextConfigurationsImportSelectorTests.java
+68
-0
DatabaseLookup.java
...gframework/boot/autoconfigure/orm/jpa/DatabaseLookup.java
+85
-0
JpaProperties.java
...ngframework/boot/autoconfigure/orm/jpa/JpaProperties.java
+2
-22
CustomHibernateJpaAutoConfigurationTests.java
...ure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java
+7
-6
DatabaseLookupTests.java
...ework/boot/autoconfigure/orm/jpa/DatabaseLookupTests.java
+106
-0
DatabasePlatformTests.java
...ork/boot/autoconfigure/orm/jpa/DatabasePlatformTests.java
+0
-86
TestRestTemplate.java
...pringframework/boot/test/web/client/TestRestTemplate.java
+15
-22
TestRestTemplateTests.java
...framework/boot/test/web/client/TestRestTemplateTests.java
+5
-7
DatabaseDriver.java
...in/java/org/springframework/boot/jdbc/DatabaseDriver.java
+4
-3
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfiguration.java
View file @
b1cb8bb3
...
...
@@ -90,7 +90,7 @@ public class EndpointMBeanExportAutoConfiguration {
@Bean
@ConditionalOnBean
(
AuditEventRepository
.
class
)
@ConditionalOnEnabledEndpoint
(
"auditevents"
)
public
AuditEventsJmxEndpoint
a
bstractEndpointMBean
(
public
AuditEventsJmxEndpoint
a
uditEventsEndpoint
(
AuditEventRepository
auditEventRepository
)
{
return
new
AuditEventsJmxEndpoint
(
this
.
objectMapper
,
auditEventRepository
);
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationsImportSelector.java
View file @
b1cb8bb3
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure;
import
java.util.ArrayList
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.context.annotation.DeferredImportSelector
;
...
...
@@ -27,6 +28,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.io.support.SpringFactoriesLoader
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.util.ClassUtils
;
/**
* Selects configuration classes for the management context configuration. Entries are
...
...
@@ -47,11 +49,26 @@ class ManagementContextConfigurationsImportSelector
@Override
public
String
[]
selectImports
(
AnnotationMetadata
metadata
)
{
// Find all possible auto configuration classes, filtering duplicates
List
<
String
>
factories
=
new
ArrayList
<
String
>(
new
LinkedHashSet
<
String
>(
SpringFactoriesLoader
.
loadFactoryNames
(
ManagementContextConfiguration
.
class
,
this
.
classLoader
)));
AnnotationAwareOrderComparator
.
sort
(
factories
);
return
factories
.
toArray
(
new
String
[
0
]);
List
<
String
>
names
=
loadFactoryNames
();
Set
<
Class
<?>>
classes
=
new
LinkedHashSet
<
Class
<?>>();
for
(
String
factoryName
:
names
)
{
classes
.
add
(
ClassUtils
.
resolveClassName
(
factoryName
,
this
.
classLoader
));
}
return
getSortedClassNames
(
new
ArrayList
<
Class
<?>>(
classes
));
}
protected
List
<
String
>
loadFactoryNames
()
{
return
SpringFactoriesLoader
.
loadFactoryNames
(
ManagementContextConfiguration
.
class
,
this
.
classLoader
);
}
private
String
[]
getSortedClassNames
(
List
<
Class
<?>>
classes
)
{
AnnotationAwareOrderComparator
.
sort
(
classes
);
List
<
String
>
names
=
new
ArrayList
<
String
>();
for
(
Class
<?>
sourceClass
:
classes
)
{
names
.
add
(
sourceClass
.
getName
());
}
return
names
.
toArray
(
new
String
[
names
.
size
()]);
}
@Override
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/AbstractJmxEndpoint.java
View file @
b1cb8bb3
...
...
@@ -22,7 +22,6 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
import
org.springframework.boot.actuate.endpoint.EndpointProperties
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.core.env.Environment
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
import
org.springframework.util.ObjectUtils
;
/**
...
...
@@ -33,7 +32,6 @@ import org.springframework.util.ObjectUtils;
* @author Phillip Webb
* @since 1.5.0
*/
@ManagedResource
public
abstract
class
AbstractJmxEndpoint
implements
JmxEndpoint
,
EnvironmentAware
{
private
final
DataConverter
dataConverter
;
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/AuditEventsJmxEndpoint.java
View file @
b1cb8bb3
...
...
@@ -28,6 +28,7 @@ import org.springframework.boot.actuate.audit.AuditEventRepository;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.jmx.export.annotation.ManagedOperation
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* {@link JmxEndpoint} for {@link AuditEventRepository}.
...
...
@@ -72,7 +73,10 @@ public class AuditEventsJmxEndpoint extends AbstractJmxEndpoint {
private
Date
parseDate
(
String
date
)
{
try
{
return
new
SimpleDateFormat
(
DATE_FORMAT
).
parse
(
date
);
if
(
StringUtils
.
hasLength
(
date
))
{
return
new
SimpleDateFormat
(
DATE_FORMAT
).
parse
(
date
);
}
return
null
;
}
catch
(
ParseException
ex
)
{
throw
new
IllegalArgumentException
(
ex
);
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java
View file @
b1cb8bb3
...
...
@@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.jmx.export.annotation.ManagedAttribute
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
/**
* Simple wrapper around {@link Endpoint} implementations that provide actuator data of
...
...
@@ -29,7 +28,6 @@ import org.springframework.jmx.export.annotation.ManagedResource;
* @author Christian Dupuis
* @author Andy Wilkinson
*/
@ManagedResource
public
class
DataEndpointMBean
extends
EndpointMBean
{
/**
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java
View file @
b1cb8bb3
...
...
@@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.jmx.export.annotation.ManagedAttribute
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -35,7 +34,6 @@ import org.springframework.util.ObjectUtils;
* @see JmxEndpoint
* @see DataEndpointMBean
*/
@ManagedResource
public
abstract
class
EndpointMBean
implements
JmxEndpoint
{
private
final
DataConverter
dataConverter
;
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporter.java
View file @
b1cb8bb3
...
...
@@ -46,9 +46,12 @@ import org.springframework.jmx.export.MBeanExporter;
import
org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
import
org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler
;
import
org.springframework.jmx.export.metadata.InvalidMetadataException
;
import
org.springframework.jmx.export.metadata.JmxAttributeSource
;
import
org.springframework.jmx.export.naming.MetadataNamingStrategy
;
import
org.springframework.jmx.export.naming.SelfNaming
;
import
org.springframework.jmx.support.ObjectNameManager
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
/**
...
...
@@ -70,7 +73,7 @@ public class EndpointMBeanExporter extends MBeanExporter
private
static
final
Log
logger
=
LogFactory
.
getLog
(
EndpointMBeanExporter
.
class
);
private
final
AnnotationJmxAttributeSource
attributeSource
=
new
Annotation
JmxAttributeSource
();
private
final
AnnotationJmxAttributeSource
attributeSource
=
new
Endpoint
JmxAttributeSource
();
private
final
MetadataMBeanInfoAssembler
assembler
=
new
MetadataMBeanInfoAssembler
(
this
.
attributeSource
);
...
...
@@ -253,8 +256,8 @@ public class EndpointMBeanExporter extends MBeanExporter
if
(
bean
instanceof
SelfNaming
)
{
return
((
SelfNaming
)
bean
).
getObjectName
();
}
if
(
bean
instanceof
EndpointMBean
)
{
return
getObjectName
((
EndpointMBean
)
bean
,
beanKey
);
if
(
bean
instanceof
JmxEndpoint
)
{
return
getObjectName
((
JmxEndpoint
)
bean
,
beanKey
);
}
return
this
.
defaultNamingStrategy
.
getObjectName
(
bean
,
beanKey
);
}
...
...
@@ -363,4 +366,19 @@ public class EndpointMBeanExporter extends MBeanExporter
}
}
/**
* {@link JmxAttributeSource} for {@link JmxEndpoint JmxEndpoints}.
*/
private
static
class
EndpointJmxAttributeSource
extends
AnnotationJmxAttributeSource
{
@Override
public
org
.
springframework
.
jmx
.
export
.
metadata
.
ManagedResource
getManagedResource
(
Class
<?>
beanClass
)
throws
InvalidMetadataException
{
Assert
.
state
(
super
.
getManagedResource
(
beanClass
)
==
null
,
"@ManagedResource annotation found on JmxEndpoint "
+
beanClass
);
return
new
org
.
springframework
.
jmx
.
export
.
metadata
.
ManagedResource
();
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpoint.java
View file @
b1cb8bb3
...
...
@@ -17,11 +17,13 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
jmx
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
/**
* A strategy for the JMX layer on top of an {@link Endpoint}. Implementations are allowed
* to use {@code @ManagedAttribute} and the full Spring JMX machinery. Implementations may
* be backed by an actual {@link Endpoint} or may be specifically designed for JMX only.
* to use {@code @ManagedAttribute} and the full Spring JMX machinery but should not use
* the {@link ManagedResource @ManagedResource} annotation. Implementations may be backed
* by an actual {@link Endpoint} or may be specifically designed for JMX only.
*
* @author Phillip Webb
* @since 1.5.0
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/LoggersEndpointMBean.java
View file @
b1cb8bb3
...
...
@@ -24,7 +24,6 @@ import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import
org.springframework.boot.logging.LogLevel
;
import
org.springframework.jmx.export.annotation.ManagedAttribute
;
import
org.springframework.jmx.export.annotation.ManagedOperation
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
import
org.springframework.util.Assert
;
/**
...
...
@@ -33,7 +32,6 @@ import org.springframework.util.Assert;
* @author Vedran Pavic
* @since 1.5.0
*/
@ManagedResource
public
class
LoggersEndpointMBean
extends
EndpointMBean
{
public
LoggersEndpointMBean
(
String
beanName
,
Endpoint
<?>
endpoint
,
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java
View file @
b1cb8bb3
...
...
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.ShutdownEndpoint
;
import
org.springframework.jmx.export.annotation.ManagedOperation
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
/**
* Special endpoint wrapper for {@link ShutdownEndpoint}.
...
...
@@ -29,7 +28,6 @@ import org.springframework.jmx.export.annotation.ManagedResource;
* @author Christian Dupuis
* @author Andy Wilkinson
*/
@ManagedResource
public
class
ShutdownEndpointMBean
extends
EndpointMBean
{
/**
...
...
spring-boot-a
utoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DatabasePlatform
.java
→
spring-boot-a
ctuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementContextConfigurationsImportSelectorTests
.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -14,60 +14,55 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
a
utoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
a
ctuate
.
autoconfigure
;
import
org.springframework.boot.jdbc.DatabaseDriver
;
import
org.springframework.orm.jpa.vendor.Database
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* Mapper between {@link Database} and {@link DatabaseDriver}.
*
* @author Eddú Meléndez
*/
enum
DatabasePlatform
{
DB2
(
Database
.
DB2
,
DatabaseDriver
.
DB2
),
import
org.junit.Test
;
DERBY
(
Database
.
DERBY
,
DatabaseDriver
.
DERBY
),
import
org.springframework.core.annotation.Order
;
H2
(
Database
.
H2
,
DatabaseDriver
.
H2
),
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
HSQL
(
Database
.
HSQL
,
DatabaseDriver
.
HSQLDB
),
INFORMIX
(
Database
.
INFORMIX
,
DatabaseDriver
.
INFORMIX
),
MYSQL
(
Database
.
MYSQL
,
DatabaseDriver
.
MYSQL
),
ORACLE
(
Database
.
ORACLE
,
DatabaseDriver
.
ORACLE
),
/**
* Tests for {@link ManagementContextConfigurationsImportSelector}.
*
* @author Phillip Webb
*/
public
class
ManagementContextConfigurationsImportSelectorTests
{
@Test
public
void
selectImportsShouldOrderResult
()
throws
Exception
{
String
[]
imports
=
new
TestManagementContextConfigurationsImportSelector
()
.
selectImports
(
null
);
assertThat
(
imports
).
containsExactly
(
A
.
class
.
getName
(),
B
.
class
.
getName
(),
C
.
class
.
getName
());
}
POSTGRESQL
(
Database
.
POSTGRESQL
,
DatabaseDriver
.
POSTGRESQL
),
private
static
class
TestManagementContextConfigurationsImportSelector
extends
ManagementContextConfigurationsImportSelector
{
SQL_SERVER
(
Database
.
SQL_SERVER
,
DatabaseDriver
.
SQLSERVER
);
@Override
protected
List
<
String
>
loadFactoryNames
()
{
return
Arrays
.
asList
(
C
.
class
.
getName
(),
A
.
class
.
getName
(),
B
.
class
.
getName
());
}
private
final
Database
database
;
}
private
final
DatabaseDriver
driver
;
@Order
(
1
)
private
static
class
A
{
DatabasePlatform
(
Database
database
,
DatabaseDriver
driver
)
{
this
.
database
=
database
;
this
.
driver
=
driver
;
}
public
Database
getDatabase
()
{
return
this
.
database
;
}
@Order
(
2
)
private
static
class
B
{
public
DatabaseDriver
getDriver
()
{
return
this
.
driver
;
}
public
static
DatabasePlatform
fromDatabaseDriver
(
DatabaseDriver
driver
)
{
for
(
DatabasePlatform
mapper
:
values
())
{
if
(
mapper
.
getDriver
()
==
driver
)
{
return
mapper
;
}
}
return
null
;
@Order
(
3
)
private
static
class
C
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DatabaseLookup.java
0 → 100644
View file @
b1cb8bb3
/*
* Copyright 2012-2017 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
.
boot
.
autoconfigure
.
orm
.
jpa
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.sql.DataSource
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.jdbc.DatabaseDriver
;
import
org.springframework.jdbc.support.JdbcUtils
;
import
org.springframework.jdbc.support.MetaDataAccessException
;
import
org.springframework.orm.jpa.vendor.Database
;
/**
* Utility to lookup well known {@link Database Databases} from a {@link DataSource}.
*
* @author Eddú Meléndez
* @author Phillip Webb
*/
final
class
DatabaseLookup
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
DatabaseLookup
.
class
);
private
static
final
Map
<
DatabaseDriver
,
Database
>
LOOKUP
;
static
{
Map
<
DatabaseDriver
,
Database
>
map
=
new
HashMap
<
DatabaseDriver
,
Database
>();
map
.
put
(
DatabaseDriver
.
DERBY
,
Database
.
DERBY
);
map
.
put
(
DatabaseDriver
.
H2
,
Database
.
H2
);
map
.
put
(
DatabaseDriver
.
HSQLDB
,
Database
.
HSQL
);
map
.
put
(
DatabaseDriver
.
MYSQL
,
Database
.
MYSQL
);
map
.
put
(
DatabaseDriver
.
ORACLE
,
Database
.
ORACLE
);
map
.
put
(
DatabaseDriver
.
POSTGRESQL
,
Database
.
POSTGRESQL
);
map
.
put
(
DatabaseDriver
.
SQLSERVER
,
Database
.
SQL_SERVER
);
map
.
put
(
DatabaseDriver
.
DB2
,
Database
.
DB2
);
map
.
put
(
DatabaseDriver
.
INFORMIX
,
Database
.
INFORMIX
);
LOOKUP
=
Collections
.
unmodifiableMap
(
map
);
}
private
DatabaseLookup
()
{
}
/**
* Return the most suitable {@link Database} for the given {@link DataSource}.
* @param dataSource the source {@link DataSource}
* @return the most sutable {@link Database}
*/
public
static
Database
getDatabase
(
DataSource
dataSource
)
{
if
(
dataSource
==
null
)
{
return
Database
.
DEFAULT
;
}
try
{
String
url
=
(
String
)
JdbcUtils
.
extractDatabaseMetaData
(
dataSource
,
"getURL"
);
DatabaseDriver
driver
=
DatabaseDriver
.
fromJdbcUrl
(
url
);
Database
database
=
LOOKUP
.
get
(
driver
);
if
(
database
!=
null
)
{
return
database
;
}
}
catch
(
MetaDataAccessException
ex
)
{
logger
.
warn
(
"Unable to determine jdbc url from datasource"
,
ex
);
}
return
Database
.
DEFAULT
;
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -21,15 +21,9 @@ import java.util.Map;
import
javax.sql.DataSource
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
import
org.springframework.boot.jdbc.DatabaseDriver
;
import
org.springframework.jdbc.support.JdbcUtils
;
import
org.springframework.jdbc.support.MetaDataAccessException
;
import
org.springframework.orm.jpa.vendor.Database
;
import
org.springframework.util.StringUtils
;
...
...
@@ -45,8 +39,6 @@ import org.springframework.util.StringUtils;
@ConfigurationProperties
(
prefix
=
"spring.jpa"
)
public
class
JpaProperties
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
JpaProperties
.
class
);
/**
* Additional native properties to set on the JPA provider.
*/
...
...
@@ -144,19 +136,7 @@ public class JpaProperties {
if
(
this
.
database
!=
null
)
{
return
this
.
database
;
}
try
{
String
jdbcUrl
=
(
String
)
JdbcUtils
.
extractDatabaseMetaData
(
dataSource
,
"getURL"
);
DatabasePlatform
databasePlatform
=
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
fromJdbcUrl
(
jdbcUrl
));
if
(
databasePlatform
!=
null
)
{
return
databasePlatform
.
getDatabase
();
}
}
catch
(
MetaDataAccessException
ex
)
{
logger
.
warn
(
"Unable to determine jdbc url from datasource"
,
ex
);
}
return
Database
.
DEFAULT
;
return
DatabaseLookup
.
getDatabase
(
dataSource
);
}
public
static
class
Hibernate
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -41,7 +41,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDD
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link HibernateJpaAutoConfiguration}.
...
...
@@ -120,7 +120,8 @@ public class CustomHibernateJpaAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration
.
class
,
HibernateJpaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
HibernateJpaVendorAdapter
bean
=
this
.
context
.
getBean
(
HibernateJpaVendorAdapter
.
class
);
HibernateJpaVendorAdapter
bean
=
this
.
context
.
getBean
(
HibernateJpaVendorAdapter
.
class
);
Database
database
=
(
Database
)
ReflectionTestUtils
.
getField
(
bean
,
"database"
);
assertThat
(
database
).
isEqualTo
(
Database
.
H2
);
}
...
...
@@ -139,11 +140,11 @@ public class CustomHibernateJpaAutoConfigurationTests {
DataSource
dataSource
=
mock
(
DataSource
.
class
);
try
{
given
(
dataSource
.
getConnection
()).
willReturn
(
mock
(
Connection
.
class
));
given
(
dataSource
.
getConnection
().
getMetaData
())
.
willReturn
(
mock
(
DatabaseMetaData
.
class
));
given
(
dataSource
.
getConnection
().
getMetaData
())
.
willReturn
(
mock
(
DatabaseMetaData
.
class
));
}
catch
(
SQLException
e
)
{
//Do nothing
//
Do nothing
}
return
dataSource
;
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/DatabaseLookupTests.java
0 → 100644
View file @
b1cb8bb3
/*
* Copyright 2012-2017 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
.
boot
.
autoconfigure
.
orm
.
jpa
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.springframework.orm.jpa.vendor.Database
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link DatabaseLookup}.
*
* @author Eddú Meléndez
* @author Phillip Webb
*/
public
class
DatabaseLookupTests
{
@Test
public
void
getDatabaseWhenDataSourceIsNullShouldReturnDefault
()
throws
Exception
{
assertThat
(
DatabaseLookup
.
getDatabase
(
null
)).
isEqualTo
(
Database
.
DEFAULT
);
}
@Test
public
void
getDatabaseWhenDataSourceIsUnknownShouldReturnDefault
()
throws
Exception
{
testGetDatabase
(
"jdbc:idontexist:"
,
Database
.
DEFAULT
);
}
@Test
public
void
getDatabaseWhenDerbyShouldReturnDerby
()
throws
Exception
{
testGetDatabase
(
"jdbc:derby:"
,
Database
.
DERBY
);
}
@Test
public
void
getDatabaseWhenH2ShouldReturnH2
()
throws
Exception
{
testGetDatabase
(
"jdbc:h2:"
,
Database
.
H2
);
}
@Test
public
void
getDatabaseWhenHsqldbShouldReturnHsqldb
()
throws
Exception
{
testGetDatabase
(
"jdbc:hsqldb:"
,
Database
.
HSQL
);
}
@Test
public
void
getDatabaseWhenMysqlShouldReturnMysql
()
throws
Exception
{
testGetDatabase
(
"jdbc:mysql:"
,
Database
.
MYSQL
);
}
@Test
public
void
getDatabaseWhenOracleShouldReturnOracle
()
throws
Exception
{
testGetDatabase
(
"jdbc:oracle:"
,
Database
.
ORACLE
);
}
@Test
public
void
getDatabaseWhenPostgresShouldReturnPostgres
()
throws
Exception
{
testGetDatabase
(
"jdbc:postgresql:"
,
Database
.
POSTGRESQL
);
}
@Test
public
void
getDatabaseWhenSqlserverShouldReturnSqlserver
()
throws
Exception
{
testGetDatabase
(
"jdbc:sqlserver:"
,
Database
.
SQL_SERVER
);
}
@Test
public
void
getDatabaseWhenDb2ShouldReturnDb2
()
throws
Exception
{
testGetDatabase
(
"jdbc:db2:"
,
Database
.
DB2
);
}
@Test
public
void
getDatabaseWhenInformixShouldReturnInformix
()
throws
Exception
{
testGetDatabase
(
"jdbc:informix-sqli:"
,
Database
.
INFORMIX
);
}
private
void
testGetDatabase
(
String
url
,
Database
expected
)
throws
Exception
{
DataSource
dataSource
=
mock
(
DataSource
.
class
);
Connection
connection
=
mock
(
Connection
.
class
);
DatabaseMetaData
metaData
=
mock
(
DatabaseMetaData
.
class
);
given
(
dataSource
.
getConnection
()).
willReturn
(
connection
);
given
(
connection
.
getMetaData
()).
willReturn
(
metaData
);
given
(
metaData
.
getURL
()).
willReturn
(
url
);
Database
database
=
DatabaseLookup
.
getDatabase
(
dataSource
);
assertThat
(
database
).
isEqualTo
(
expected
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/DatabasePlatformTests.java
deleted
100644 → 0
View file @
b9e3dc57
/*
* Copyright 2012-2016 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
.
boot
.
autoconfigure
.
orm
.
jpa
;
import
org.junit.Test
;
import
org.springframework.boot.jdbc.DatabaseDriver
;
import
org.springframework.orm.jpa.vendor.Database
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DatabasePlatform}.
*
* @author Eddú Meléndez
*/
public
class
DatabasePlatformTests
{
@Test
public
void
databaseDriverLookups
()
{
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
DB2
))
.
isEqualTo
(
DatabasePlatform
.
DB2
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
DERBY
))
.
isEqualTo
(
DatabasePlatform
.
DERBY
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
H2
))
.
isEqualTo
(
DatabasePlatform
.
H2
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
HSQLDB
))
.
isEqualTo
(
DatabasePlatform
.
HSQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
INFORMIX
))
.
isEqualTo
(
DatabasePlatform
.
INFORMIX
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
MYSQL
))
.
isEqualTo
(
DatabasePlatform
.
MYSQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
ORACLE
))
.
isEqualTo
(
DatabasePlatform
.
ORACLE
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
POSTGRESQL
))
.
isEqualTo
(
DatabasePlatform
.
POSTGRESQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
SQLSERVER
))
.
isEqualTo
(
DatabasePlatform
.
SQL_SERVER
);
}
@Test
public
void
databaseLookups
()
{
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
DB2
)
.
getDatabase
())
.
isEqualTo
(
Database
.
DB2
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
DERBY
)
.
getDatabase
())
.
isEqualTo
(
Database
.
DERBY
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
H2
)
.
getDatabase
())
.
isEqualTo
(
Database
.
H2
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
HSQLDB
)
.
getDatabase
())
.
isEqualTo
(
Database
.
HSQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
INFORMIX
)
.
getDatabase
())
.
isEqualTo
(
Database
.
INFORMIX
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
MYSQL
)
.
getDatabase
())
.
isEqualTo
(
Database
.
MYSQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
ORACLE
)
.
getDatabase
())
.
isEqualTo
(
Database
.
ORACLE
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
POSTGRESQL
)
.
getDatabase
())
.
isEqualTo
(
Database
.
POSTGRESQL
);
assertThat
(
DatabasePlatform
.
fromDatabaseDriver
(
DatabaseDriver
.
SQLSERVER
)
.
getDatabase
())
.
isEqualTo
(
Database
.
SQL_SERVER
);
}
}
spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -48,7 +48,6 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.InterceptingClientHttpRequestFactory
;
import
org.springframework.http.client.support.BasicAuthorizationInterceptor
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
...
...
@@ -144,11 +143,19 @@ public class TestRestTemplate {
if
(
username
==
null
)
{
return
;
}
List
<
ClientHttpRequestInterceptor
>
interceptors
=
Collections
.<
ClientHttpRequestInterceptor
>
singletonList
(
new
BasicAuthorizationInterceptor
(
username
,
password
));
restTemplate
.
setRequestFactory
(
new
InterceptingClientHttpRequestFactory
(
restTemplate
.
getRequestFactory
(),
interceptors
));
List
<
ClientHttpRequestInterceptor
>
interceptors
=
restTemplate
.
getInterceptors
();
if
(
interceptors
==
null
)
{
interceptors
=
Collections
.
emptyList
();
}
interceptors
=
new
ArrayList
<
ClientHttpRequestInterceptor
>(
interceptors
);
Iterator
<
ClientHttpRequestInterceptor
>
iterator
=
interceptors
.
iterator
();
while
(
iterator
.
hasNext
())
{
if
(
iterator
.
next
()
instanceof
BasicAuthorizationInterceptor
)
{
iterator
.
remove
();
}
}
interceptors
.
add
(
new
BasicAuthorizationInterceptor
(
username
,
password
));
restTemplate
.
setInterceptors
(
interceptors
);
}
/**
...
...
@@ -985,8 +992,7 @@ public class TestRestTemplate {
public
TestRestTemplate
withBasicAuth
(
String
username
,
String
password
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
setMessageConverters
(
getRestTemplate
().
getMessageConverters
());
restTemplate
.
setInterceptors
(
removeBasicAuthInterceptorIfPresent
(
getRestTemplate
().
getInterceptors
()));
restTemplate
.
setInterceptors
(
getRestTemplate
().
getInterceptors
());
restTemplate
.
setRequestFactory
(
getRestTemplate
().
getRequestFactory
());
restTemplate
.
setUriTemplateHandler
(
getRestTemplate
().
getUriTemplateHandler
());
TestRestTemplate
testRestTemplate
=
new
TestRestTemplate
(
restTemplate
,
username
,
...
...
@@ -996,19 +1002,6 @@ public class TestRestTemplate {
return
testRestTemplate
;
}
private
List
<
ClientHttpRequestInterceptor
>
removeBasicAuthInterceptorIfPresent
(
List
<
ClientHttpRequestInterceptor
>
interceptors
)
{
List
<
ClientHttpRequestInterceptor
>
updatedInterceptors
=
new
ArrayList
<
ClientHttpRequestInterceptor
>(
interceptors
);
Iterator
<
ClientHttpRequestInterceptor
>
iterator
=
updatedInterceptors
.
iterator
();
while
(
iterator
.
hasNext
())
{
if
(
iterator
.
next
()
instanceof
BasicAuthorizationInterceptor
)
{
iterator
.
remove
();
}
}
return
interceptors
;
}
/**
* Options used to customize the Apache Http Client if it is used.
*/
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -160,16 +160,15 @@ public class TestRestTemplateTests {
.
isInstanceOf
(
CustomHttpComponentsClientHttpRequestFactory
.
class
);
assertThat
(
basicAuthTemplate
.
getRestTemplate
().
getUriTemplateHandler
())
.
isSameAs
(
originalTemplate
.
getRestTemplate
().
getUriTemplateHandler
());
assertThat
(
basicAuthTemplate
.
getRestTemplate
().
getInterceptors
())
.
containsExactlyElementsOf
(
originalTemplate
.
getRestTemplate
().
getInterceptors
());
assertThat
(
basicAuthTemplate
.
getRestTemplate
().
getInterceptors
()).
hasSize
(
1
);
assertBasicAuthorizationInterceptorCredentials
(
basicAuthTemplate
,
"user"
,
"password"
);
}
@Test
public
void
withBasicAuthReplacesBasicAuthInterceptorWhenAlreadyPresent
()
{
TestRestTemplate
original
=
new
TestRestTemplate
(
"foo"
,
"bar"
);
TestRestTemplate
original
=
new
TestRestTemplate
(
"foo"
,
"bar"
)
.
withBasicAuth
(
"replace"
,
"repalce"
);
TestRestTemplate
basicAuth
=
original
.
withBasicAuth
(
"user"
,
"password"
);
assertThat
(
basicAuth
.
getRestTemplate
().
getMessageConverters
())
.
containsExactlyElementsOf
(
...
...
@@ -181,8 +180,7 @@ public class TestRestTemplateTests {
.
isInstanceOf
(
CustomHttpComponentsClientHttpRequestFactory
.
class
);
assertThat
(
basicAuth
.
getRestTemplate
().
getUriTemplateHandler
())
.
isSameAs
(
original
.
getRestTemplate
().
getUriTemplateHandler
());
assertThat
(
basicAuth
.
getRestTemplate
().
getInterceptors
())
.
containsExactlyElementsOf
(
original
.
getRestTemplate
().
getInterceptors
());
assertThat
(
basicAuth
.
getRestTemplate
().
getInterceptors
()).
hasSize
(
1
);
assertBasicAuthorizationInterceptorCredentials
(
basicAuth
,
"user"
,
"password"
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java
View file @
b1cb8bb3
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -72,8 +72,8 @@ public enum DatabaseDriver {
/**
* Maria DB.
*/
MARIADB
(
"MySQL"
,
"org.mariadb.jdbc.Driver"
,
"
org.mariadb.jdbc.MariaDbDataSource"
,
"
SELECT 1"
)
{
MARIADB
(
"MySQL"
,
"org.mariadb.jdbc.Driver"
,
"org.mariadb.jdbc.MariaDbDataSource"
,
"SELECT 1"
)
{
@Override
public
String
getId
()
{
...
...
@@ -181,6 +181,7 @@ public enum DatabaseDriver {
protected
Collection
<
String
>
getUrlPrefixes
()
{
return
Arrays
.
asList
(
"informix-sqli"
,
"informix-direct"
);
}
};
private
final
String
productName
;
...
...
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