Skip to content

Commit adbded3

Browse files
committed
Apply eclipse formatting rules to 3dc932d
1 parent 53c4859 commit adbded3

16 files changed

+174
-149
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricDataSourceAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.springframework.context.annotation.Import;
3131

3232
/**
33-
* {@link EnableAutoConfiguration Auto-configuration} that provides
34-
* metrics on dataSource usage.
33+
* {@link EnableAutoConfiguration Auto-configuration} that provides metrics on dataSource
34+
* usage.
3535
*
3636
* @author Stephane Nicoll
3737
* @since 1.2.0

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/DataSourcePublicMetrics.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.LinkedHashSet;
2222
import java.util.Map;
23+
2324
import javax.annotation.PostConstruct;
2425
import javax.sql.DataSource;
2526

@@ -33,8 +34,7 @@
3334
import org.springframework.context.annotation.Primary;
3435

3536
/**
36-
* A {@link PublicMetrics} implementation that provides data source usage
37-
* statistics.
37+
* A {@link PublicMetrics} implementation that provides data source usage statistics.
3838
*
3939
* @author Stephane Nicoll
4040
* @since 1.2.0
@@ -49,29 +49,32 @@ public class DataSourcePublicMetrics implements PublicMetrics {
4949
@Autowired
5050
private Collection<DataSourceMetadataProvider> dataSourceMetadataProviders;
5151

52-
private final Map<String, DataSourceMetadata> dataSourceMetadataByPrefix
53-
= new HashMap<String, DataSourceMetadata>();
52+
private final Map<String, DataSourceMetadata> dataSourceMetadataByPrefix = new HashMap<String, DataSourceMetadata>();
5453

5554
@PostConstruct
5655
public void initialize() {
57-
Map<String, DataSource> dataSources = this.applicationContext.getBeansOfType(DataSource.class);
56+
Map<String, DataSource> dataSources = this.applicationContext
57+
.getBeansOfType(DataSource.class);
5858
DataSource primaryDataSource = getPrimaryDataSource();
5959

60-
61-
DataSourceMetadataProvider provider = new CompositeDataSourceMetadataProvider(this.dataSourceMetadataProviders);
60+
DataSourceMetadataProvider provider = new CompositeDataSourceMetadataProvider(
61+
this.dataSourceMetadataProviders);
6262
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
63-
String prefix = createPrefix(entry.getKey(), entry.getValue(), entry.getValue().equals(primaryDataSource));
64-
DataSourceMetadata dataSourceMetadata = provider.getDataSourceMetadata(entry.getValue());
63+
String prefix = createPrefix(entry.getKey(), entry.getValue(), entry
64+
.getValue().equals(primaryDataSource));
65+
DataSourceMetadata dataSourceMetadata = provider.getDataSourceMetadata(entry
66+
.getValue());
6567
if (dataSourceMetadata != null) {
66-
dataSourceMetadataByPrefix.put(prefix, dataSourceMetadata);
68+
this.dataSourceMetadataByPrefix.put(prefix, dataSourceMetadata);
6769
}
6870
}
6971
}
7072

7173
@Override
7274
public Collection<Metric<?>> metrics() {
7375
Collection<Metric<?>> result = new LinkedHashSet<Metric<?>>();
74-
for (Map.Entry<String, DataSourceMetadata> entry : dataSourceMetadataByPrefix.entrySet()) {
76+
for (Map.Entry<String, DataSourceMetadata> entry : this.dataSourceMetadataByPrefix
77+
.entrySet()) {
7578
String prefix = entry.getKey();
7679
// Make sure the prefix ends with a dot
7780
if (!prefix.endsWith(".")) {
@@ -91,19 +94,23 @@ public Collection<Metric<?>> metrics() {
9194
}
9295

9396
/**
94-
* Create the prefix to use for the metrics to associate with the given {@link DataSource}.
97+
* Create the prefix to use for the metrics to associate with the given
98+
* {@link DataSource}.
9599
* @param dataSourceName the name of the data source bean
96100
* @param dataSource the data source to configure
97101
* @param primary if this data source is the primary data source
98102
* @return a prefix for the given data source
99103
*/
100-
protected String createPrefix(String dataSourceName, DataSource dataSource, boolean primary) {
104+
protected String createPrefix(String dataSourceName, DataSource dataSource,
105+
boolean primary) {
101106
StringBuilder sb = new StringBuilder("datasource.");
102107
if (primary) {
103108
sb.append("primary");
104109
}
105-
else if (endWithDataSource(dataSourceName)) { // Strip the data source part out of the name
106-
sb.append(dataSourceName.substring(0, dataSourceName.length() - DATASOURCE_SUFFIX.length()));
110+
else if (endWithDataSource(dataSourceName)) { // Strip the data source part out of
111+
// the name
112+
sb.append(dataSourceName.substring(0, dataSourceName.length()
113+
- DATASOURCE_SUFFIX.length()));
107114
}
108115
else {
109116
sb.append(dataSourceName);
@@ -131,7 +138,7 @@ protected boolean endWithDataSource(String value) {
131138
*/
132139
private DataSource getPrimaryDataSource() {
133140
try {
134-
return applicationContext.getBean(DataSource.class);
141+
return this.applicationContext.getBean(DataSource.class);
135142
}
136143
catch (NoSuchBeanDefinitionException e) {
137144
return null;

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricDataSourceAutoConfigurationTests.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure;
1818

19-
import static org.junit.Assert.*;
20-
2119
import java.sql.Connection;
2220
import java.sql.SQLException;
2321
import java.util.Collection;
@@ -26,11 +24,9 @@
2624

2725
import javax.sql.DataSource;
2826

29-
import com.zaxxer.hikari.HikariDataSource;
3027
import org.apache.commons.dbcp.BasicDataSource;
3128
import org.junit.After;
3229
import org.junit.Test;
33-
3430
import org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics;
3531
import org.springframework.boot.actuate.endpoint.PublicMetrics;
3632
import org.springframework.boot.actuate.metrics.Metric;
@@ -44,8 +40,12 @@
4440
import org.springframework.jdbc.core.ConnectionCallback;
4541
import org.springframework.jdbc.core.JdbcTemplate;
4642

43+
import com.zaxxer.hikari.HikariDataSource;
44+
45+
import static org.junit.Assert.assertEquals;
46+
import static org.junit.Assert.assertTrue;
47+
4748
/**
48-
*
4949
* @author Stephane Nicoll
5050
*/
5151
public class MetricDataSourceAutoConfigurationTests {
@@ -78,44 +78,44 @@ public void multipleDataSources() {
7878
load(MultipleDataSourcesConfig.class);
7979
PublicMetrics bean = this.context.getBean(PublicMetrics.class);
8080
Collection<Metric<?>> metrics = bean.metrics();
81-
assertMetrics(metrics,
82-
"datasource.tomcat.active", "datasource.tomcat.usage",
81+
assertMetrics(metrics, "datasource.tomcat.active", "datasource.tomcat.usage",
8382
"datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
8483

8584
// Hikari won't work unless a first connection has been retrieved
86-
JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getBean("hikariDS", DataSource.class));
85+
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.context.getBean("hikariDS",
86+
DataSource.class));
8787
jdbcTemplate.execute(new ConnectionCallback<Void>() {
8888
@Override
89-
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
89+
public Void doInConnection(Connection connection) throws SQLException,
90+
DataAccessException {
9091
return null;
9192
}
9293
});
9394

9495
Collection<Metric<?>> anotherMetrics = bean.metrics();
95-
assertMetrics(anotherMetrics,
96-
"datasource.tomcat.active", "datasource.tomcat.usage",
97-
"datasource.hikariDS.active", "datasource.hikariDS.usage",
98-
"datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
96+
assertMetrics(anotherMetrics, "datasource.tomcat.active",
97+
"datasource.tomcat.usage", "datasource.hikariDS.active",
98+
"datasource.hikariDS.usage", "datasource.commonsDbcp.active",
99+
"datasource.commonsDbcp.usage");
99100
}
100101

101102
@Test
102103
public void multipleDataSourcesWithPrimary() {
103104
load(MultipleDataSourcesWithPrimaryConfig.class);
104105
PublicMetrics bean = this.context.getBean(PublicMetrics.class);
105106
Collection<Metric<?>> metrics = bean.metrics();
106-
assertMetrics(metrics,
107-
"datasource.primary.active", "datasource.primary.usage",
107+
assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage",
108108
"datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
109109
}
110110

111111
@Test
112112
public void customPrefix() {
113-
load(MultipleDataSourcesWithPrimaryConfig.class, CustomDataSourcePublicMetrics.class);
113+
load(MultipleDataSourcesWithPrimaryConfig.class,
114+
CustomDataSourcePublicMetrics.class);
114115
PublicMetrics bean = this.context.getBean(PublicMetrics.class);
115116
Collection<Metric<?>> metrics = bean.metrics();
116-
assertMetrics(metrics,
117-
"ds.first.active", "ds.first.usage",
118-
"ds.second.active", "ds.second.usage");
117+
assertMetrics(metrics, "ds.first.active", "ds.first.usage", "ds.second.active",
118+
"ds.second.usage");
119119

120120
}
121121

@@ -138,13 +138,13 @@ private void load(Class<?>... config) {
138138
this.context.refresh();
139139
}
140140

141-
142141
@Configuration
143142
static class MultipleDataSourcesConfig {
144143

145144
@Bean
146145
public DataSource tomcatDataSource() {
147-
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
146+
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
147+
.build();
148148
}
149149

150150
@Bean
@@ -164,7 +164,8 @@ static class MultipleDataSourcesWithPrimaryConfig {
164164
@Bean
165165
@Primary
166166
public DataSource myDataSource() {
167-
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
167+
return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class)
168+
.build();
168169
}
169170

170171
@Bean
@@ -180,17 +181,16 @@ static class CustomDataSourcePublicMetrics {
180181
public DataSourcePublicMetrics myDataSourcePublicMetrics() {
181182
return new DataSourcePublicMetrics() {
182183
@Override
183-
protected String createPrefix(String dataSourceName, DataSource dataSource, boolean primary) {
184+
protected String createPrefix(String dataSourceName,
185+
DataSource dataSource, boolean primary) {
184186
return (primary ? "ds.first." : "ds.second");
185187
}
186188
};
187189
}
188190
}
189191

190192
private static DataSourceBuilder initializeBuilder() {
191-
return DataSourceBuilder.create()
192-
.driverClassName("org.hsqldb.jdbc.JDBCDriver")
193-
.url("jdbc:hsqldb:mem:test")
194-
.username("sa");
193+
return DataSourceBuilder.create().driverClassName("org.hsqldb.jdbc.JDBCDriver")
194+
.url("jdbc:hsqldb:mem:test").username("sa");
195195
}
196196
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceMetadata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
* @author Stephane Nicoll
2525
* @since 1.2.0
2626
*/
27-
public abstract class AbstractDataSourceMetadata<D extends DataSource> implements DataSourceMetadata {
27+
public abstract class AbstractDataSourceMetadata<D extends DataSource> implements
28+
DataSourceMetadata {
2829

2930
private final D dataSource;
3031

@@ -55,7 +56,7 @@ public Float getPoolUsage() {
5556
}
5657

5758
protected final D getDataSource() {
58-
return dataSource;
59+
return this.dataSource;
5960
}
6061

6162
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CommonsDbcpDataSourceMetadata.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import org.apache.commons.dbcp.BasicDataSource;
2020

2121
/**
22-
* A {@link DataSourceMetadata} implementation for the commons dbcp
23-
* data source.
22+
* A {@link DataSourceMetadata} implementation for the commons dbcp data source.
2423
*
2524
* @author Stephane Nicoll
2625
* @since 1.2.0
2726
*/
28-
public class CommonsDbcpDataSourceMetadata extends AbstractDataSourceMetadata<BasicDataSource> {
27+
public class CommonsDbcpDataSourceMetadata extends
28+
AbstractDataSourceMetadata<BasicDataSource> {
2929

3030
public CommonsDbcpDataSourceMetadata(BasicDataSource dataSource) {
3131
super(dataSource);
@@ -50,4 +50,5 @@ public Integer getMinPoolSize() {
5050
public String getValidationQuery() {
5151
return getDataSource().getValidationQuery();
5252
}
53+
5354
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CompositeDataSourceMetadataProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class CompositeDataSourceMetadataProvider implements DataSourceMetadataPr
3535
/**
3636
* Create an instance with an initial collection of delegates to use.
3737
*/
38-
public CompositeDataSourceMetadataProvider(Collection<DataSourceMetadataProvider> providers) {
38+
public CompositeDataSourceMetadataProvider(
39+
Collection<DataSourceMetadataProvider> providers) {
3940
this.providers = providers;
4041
}
4142

@@ -48,8 +49,9 @@ public CompositeDataSourceMetadataProvider() {
4849

4950
@Override
5051
public DataSourceMetadata getDataSourceMetadata(DataSource dataSource) {
51-
for (DataSourceMetadataProvider provider : providers) {
52-
DataSourceMetadata dataSourceMetadata = provider.getDataSourceMetadata(dataSource);
52+
for (DataSourceMetadataProvider provider : this.providers) {
53+
DataSourceMetadata dataSourceMetadata = provider
54+
.getDataSourceMetadata(dataSource);
5355
if (dataSourceMetadata != null) {
5456
return dataSourceMetadata;
5557
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceMetadata.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,48 @@
1919
import javax.sql.DataSource;
2020

2121
/**
22-
* Provide various metadata regarding a {@link DataSource} that
23-
* are shared by most data source types but not accessible in a
24-
* standard manner.
22+
* Provide various metadata regarding a {@link DataSource} that are shared by most data
23+
* source types but not accessible in a standard manner.
2524
*
2625
* @author Stephane Nicoll
2726
* @since 1.2.0
2827
*/
2928
public interface DataSourceMetadata {
3029

3130
/**
32-
* Return the usage of the pool as a double value between
33-
* 0 and 1.
31+
* Return the usage of the pool as a double value between 0 and 1.
3432
* <ul>
35-
* <li>1 means that the maximum number of connections
36-
* have been allocated</li>
33+
* <li>1 means that the maximum number of connections have been allocated</li>
3734
* <li>0 means that no connection is currently active</li>
38-
* <li>-1 means there is not limit to the number of connections
39-
* that can be allocated</li>
35+
* <li>-1 means there is not limit to the number of connections that can be allocated</li>
4036
* </ul>
41-
* This may also return {@code null} if the data source does
42-
* not provide the necessary information to compute the poll usage.
37+
* This may also return {@code null} if the data source does not provide the necessary
38+
* information to compute the poll usage.
4339
*/
4440
Float getPoolUsage();
4541

4642
/**
47-
* Return the current number of active connections that
48-
* have been allocated from the data source or {@code null}
49-
* if that information is not available.
43+
* Return the current number of active connections that have been allocated from the
44+
* data source or {@code null} if that information is not available.
5045
*/
5146
Integer getPoolSize();
5247

5348
/**
54-
* Return the maximum number of active connections that can be
55-
* allocated at the same time or {@code -1} if there is no
56-
* limit. Can also return {@code null} if that information is
57-
* not available.
49+
* Return the maximum number of active connections that can be allocated at the same
50+
* time or {@code -1} if there is no limit. Can also return {@code null} if that
51+
* information is not available.
5852
*/
5953
Integer getMaxPoolSize();
6054

6155
/**
62-
* Return the minimum number of idle connections in the pool
63-
* or {@code null} if that information is not available.
56+
* Return the minimum number of idle connections in the pool or {@code null} if that
57+
* information is not available.
6458
*/
6559
Integer getMinPoolSize();
6660

6761
/**
68-
* Return the query to use to validate that a connection is
69-
* valid or {@code null} if that information is not available.
62+
* Return the query to use to validate that a connection is valid or {@code null} if
63+
* that information is not available.
7064
*/
7165
String getValidationQuery();
7266

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceMetadataProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
public interface DataSourceMetadataProvider {
2828

2929
/**
30-
* Return the {@link DataSourceMetadata} instance able to manage the
31-
* specified {@link DataSource} or {@code null} if the given data
32-
* source could not be handled.
30+
* Return the {@link DataSourceMetadata} instance able to manage the specified
31+
* {@link DataSource} or {@code null} if the given data source could not be handled.
3332
*/
3433
DataSourceMetadata getDataSourceMetadata(DataSource dataSource);
3534

0 commit comments

Comments
 (0)