Polish
This commit is contained in:
parent
03dad33b0c
commit
4b55144d80
|
|
@ -183,7 +183,7 @@ public class HealthIndicatorAutoConfiguration {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ CouchbaseOperations.class, Bucket.class})
|
||||
@ConditionalOnClass({ CouchbaseOperations.class, Bucket.class })
|
||||
@ConditionalOnBean(CouchbaseOperations.class)
|
||||
@ConditionalOnEnabledHealthIndicator("couchbase")
|
||||
public static class CouchbaseHealthIndicatorConfiguration extends
|
||||
|
|
|
|||
|
|
@ -41,8 +41,10 @@ public class CouchbaseHealthIndicator extends AbstractHealthIndicator {
|
|||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
List<Version> versions = this.couchbaseOperations.getCouchbaseClusterInfo().getAllVersions();
|
||||
builder.up().withDetail("versions", StringUtils.collectionToCommaDelimitedString(versions));
|
||||
List<Version> versions = this.couchbaseOperations.getCouchbaseClusterInfo()
|
||||
.getAllVersions();
|
||||
builder.up().withDetail("versions",
|
||||
StringUtils.collectionToCommaDelimitedString(versions));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -449,7 +449,8 @@ public class HealthIndicatorAutoConfigurationTests {
|
|||
Map<String, HealthIndicator> beans = this.context
|
||||
.getBeansOfType(HealthIndicator.class);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
assertThat(beans.values().iterator().next().getClass()).isEqualTo(CouchbaseHealthIndicator.class);
|
||||
assertThat(beans.values().iterator().next().getClass())
|
||||
.isEqualTo(CouchbaseHealthIndicator.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import javax.validation.Validator;
|
|||
import com.couchbase.client.java.CouchbaseBucket;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
|
|
@ -39,15 +40,14 @@ import org.springframework.data.couchbase.core.query.Consistency;
|
|||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-Configuration} for Couchbase.
|
||||
* {@link EnableAutoConfiguration Auto-Configuration} for Couchbase.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({CouchbaseBucket.class, AbstractCouchbaseConfiguration.class})
|
||||
@ConditionalOnClass({ CouchbaseBucket.class, AbstractCouchbaseConfiguration.class })
|
||||
@Conditional(CouchbaseAutoConfiguration.CouchbaseCondition.class)
|
||||
@EnableConfigurationProperties(CouchbaseProperties.class)
|
||||
public class CouchbaseAutoConfiguration {
|
||||
|
|
@ -107,8 +107,9 @@ public class CouchbaseAutoConfiguration {
|
|||
}
|
||||
|
||||
/**
|
||||
* Determine if Couchbase should be configured. This happens if either the user-configuration
|
||||
* defines a couchbase configuration or if at least the bucket name is specified.
|
||||
* Determine if Couchbase should be configured. This happens if either the
|
||||
* user-configuration defines a couchbase configuration or if at least the bucket name
|
||||
* is specified.
|
||||
*/
|
||||
static class CouchbaseCondition extends AnyNestedCondition {
|
||||
|
||||
|
|
|
|||
|
|
@ -34,15 +34,16 @@ import org.springframework.data.couchbase.core.query.Consistency;
|
|||
public class CouchbaseProperties {
|
||||
|
||||
/**
|
||||
* Automatically create views and indexes. Use the meta-data provided by "@ViewIndexed",
|
||||
* "@N1qlPrimaryIndexed" and "@N1qlSecondaryIndexed".
|
||||
* Automatically create views and indexes. Use the meta-data provided by
|
||||
* "@ViewIndexed", "@N1qlPrimaryIndexed" and "@N1qlSecondaryIndexed".
|
||||
*/
|
||||
private boolean autoIndex;
|
||||
|
||||
/**
|
||||
* Couchbase nodes (host or IP address) to bootstrap from.
|
||||
*/
|
||||
private List<String> bootstrapHosts = new ArrayList<String>(Collections.singletonList("localhost"));
|
||||
private List<String> bootstrapHosts = new ArrayList<String>(
|
||||
Collections.singletonList("localhost"));
|
||||
|
||||
private final Bucket bucket = new Bucket();
|
||||
|
||||
|
|
@ -106,6 +107,7 @@ public class CouchbaseProperties {
|
|||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
|
|||
* @author Eddú Meléndez
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class CouchbaseRepositoriesRegistrar extends AbstractRepositoryConfigurationSourceSupport {
|
||||
public class CouchbaseRepositoriesRegistrar
|
||||
extends AbstractRepositoryConfigurationSourceSupport {
|
||||
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@ public class RedisAutoConfiguration {
|
|||
|
||||
private List<RedisNode> createSentinels(Sentinel sentinel) {
|
||||
List<RedisNode> nodes = new ArrayList<RedisNode>();
|
||||
for (String node : StringUtils.commaDelimitedListToStringArray(sentinel.getNodes())) {
|
||||
for (String node : StringUtils
|
||||
.commaDelimitedListToStringArray(sentinel.getNodes())) {
|
||||
try {
|
||||
String[] parts = StringUtils.split(node, ":");
|
||||
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
|
||||
|
|
@ -190,8 +191,8 @@ public class RedisAutoConfiguration {
|
|||
}
|
||||
|
||||
private JedisConnectionFactory createJedisConnectionFactory() {
|
||||
JedisPoolConfig poolConfig = this.properties.getPool() != null ? jedisPoolConfig()
|
||||
: new JedisPoolConfig();
|
||||
JedisPoolConfig poolConfig = this.properties.getPool() != null
|
||||
? jedisPoolConfig() : new JedisPoolConfig();
|
||||
|
||||
if (getSentinelConfig() != null) {
|
||||
return new JedisConnectionFactory(getSentinelConfig(), poolConfig);
|
||||
|
|
|
|||
|
|
@ -195,8 +195,8 @@ public class RedisProperties {
|
|||
public static class Cluster {
|
||||
|
||||
/**
|
||||
* Comma-separated list of "host:port" pairs to bootstrap from. This represents
|
||||
* an "initial" list of cluster nodes and is required to have at least one entry.
|
||||
* Comma-separated list of "host:port" pairs to bootstrap from. This represents an
|
||||
* "initial" list of cluster nodes and is required to have at least one entry.
|
||||
*/
|
||||
private List<String> nodes;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,10 @@ abstract class DataSourceConfiguration {
|
|||
@ConfigurationProperties("spring.datasource.tomcat")
|
||||
public org.apache.tomcat.jdbc.pool.DataSource dataSource(
|
||||
DataSourceProperties properties) {
|
||||
org.apache.tomcat.jdbc.pool.DataSource dataSource = createDataSource(properties,
|
||||
org.apache.tomcat.jdbc.pool.DataSource.class);
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(properties.determineUrl());
|
||||
org.apache.tomcat.jdbc.pool.DataSource dataSource = createDataSource(
|
||||
properties, org.apache.tomcat.jdbc.pool.DataSource.class);
|
||||
DatabaseDriver databaseDriver = DatabaseDriver
|
||||
.fromJdbcUrl(properties.determineUrl());
|
||||
String validationQuery = databaseDriver.getValidationQuery();
|
||||
if (validationQuery != null) {
|
||||
dataSource.setTestOnBorrow(true);
|
||||
|
|
@ -84,9 +85,10 @@ abstract class DataSourceConfiguration {
|
|||
@ConfigurationProperties("spring.datasource.dbcp")
|
||||
public org.apache.commons.dbcp.BasicDataSource dataSource(
|
||||
DataSourceProperties properties) {
|
||||
org.apache.commons.dbcp.BasicDataSource dataSource = createDataSource(properties,
|
||||
org.apache.commons.dbcp.BasicDataSource.class);
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(properties.determineUrl());
|
||||
org.apache.commons.dbcp.BasicDataSource dataSource = createDataSource(
|
||||
properties, org.apache.commons.dbcp.BasicDataSource.class);
|
||||
DatabaseDriver databaseDriver = DatabaseDriver
|
||||
.fromJdbcUrl(properties.determineUrl());
|
||||
String validationQuery = databaseDriver.getValidationQuery();
|
||||
if (validationQuery != null) {
|
||||
dataSource.setTestOnBorrow(true);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
|
|||
* @since 1.1.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({HttpSolrClient.class, CloudSolrClient.class})
|
||||
@ConditionalOnClass({ HttpSolrClient.class, CloudSolrClient.class })
|
||||
@EnableConfigurationProperties(SolrProperties.class)
|
||||
public class SolrAutoConfiguration {
|
||||
|
||||
|
|
|
|||
|
|
@ -170,8 +170,8 @@ public class ResourceProperties implements ResourceLoaderAware {
|
|||
private boolean htmlApplicationCache = false;
|
||||
|
||||
/**
|
||||
* Enable resolution of already gzipped resources. Checks for a resource
|
||||
* name variant with the *.gz extension.
|
||||
* Enable resolution of already gzipped resources. Checks for a resource name
|
||||
* variant with the {@code *.gz} extension.
|
||||
*/
|
||||
private boolean gzipped = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,18 +65,24 @@ public class CouchbaseAutoConfigurationTests {
|
|||
load(null);
|
||||
assertThat(this.context.getBeansOfType(CouchbaseTemplate.class)).isEmpty();
|
||||
assertThat(this.context.getBeansOfType(Bucket.class)).isEmpty();
|
||||
assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class)).isEmpty();
|
||||
assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bucketNameIsNotRequiredIfCustomConfigurationIsSpecified() throws Exception {
|
||||
public void bucketNameIsNotRequiredIfCustomConfigurationIsSpecified()
|
||||
throws Exception {
|
||||
load(CouchbaseTestConfiguration.class);
|
||||
|
||||
assertThat(this.context.getBeansOfType(AbstractCouchbaseConfiguration.class)).hasSize(1);
|
||||
CouchbaseTestConfiguration configuration = this.context.getBean(CouchbaseTestConfiguration.class);
|
||||
assertThat(this.context.getBean(CouchbaseTemplate.class)).isSameAs(configuration.couchbaseTemplate());
|
||||
assertThat(this.context.getBean(Bucket.class)).isSameAs(configuration.couchbaseClient());
|
||||
assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class)).isEmpty();
|
||||
assertThat(this.context.getBeansOfType(AbstractCouchbaseConfiguration.class))
|
||||
.hasSize(1);
|
||||
CouchbaseTestConfiguration configuration = this.context
|
||||
.getBean(CouchbaseTestConfiguration.class);
|
||||
assertThat(this.context.getBean(CouchbaseTemplate.class))
|
||||
.isSameAs(configuration.couchbaseTemplate());
|
||||
assertThat(this.context.getBean(Bucket.class))
|
||||
.isSameAs(configuration.couchbaseClient());
|
||||
assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -92,7 +98,8 @@ public class CouchbaseAutoConfigurationTests {
|
|||
@Test
|
||||
public void autoIndexIsDisabledByDefault() {
|
||||
load(CouchbaseTestConfiguration.class);
|
||||
CouchbaseTestConfiguration configuration = this.context.getBean(CouchbaseTestConfiguration.class);
|
||||
CouchbaseTestConfiguration configuration = this.context
|
||||
.getBean(CouchbaseTestConfiguration.class);
|
||||
IndexManager indexManager = configuration.indexManager();
|
||||
assertThat(indexManager.isIgnoreViews()).isTrue();
|
||||
assertThat(indexManager.isIgnoreN1qlPrimary()).isTrue();
|
||||
|
|
@ -102,7 +109,8 @@ public class CouchbaseAutoConfigurationTests {
|
|||
@Test
|
||||
public void enableAutoIndex() {
|
||||
load(CouchbaseTestConfiguration.class, "spring.data.couchbase.auto-index=true");
|
||||
CouchbaseTestConfiguration configuration = this.context.getBean(CouchbaseTestConfiguration.class);
|
||||
CouchbaseTestConfiguration configuration = this.context
|
||||
.getBean(CouchbaseTestConfiguration.class);
|
||||
IndexManager indexManager = configuration.indexManager();
|
||||
assertThat(indexManager.isIgnoreViews()).isFalse();
|
||||
assertThat(indexManager.isIgnoreN1qlPrimary()).isFalse();
|
||||
|
|
@ -111,16 +119,21 @@ public class CouchbaseAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void changeConsistency() {
|
||||
load(CouchbaseTestConfiguration.class, "spring.data.couchbase.consistency=eventually-consistent");
|
||||
CouchbaseTestConfiguration configuration = this.context.getBean(CouchbaseTestConfiguration.class);
|
||||
assertThat(configuration.getDefaultConsistency()).isEqualTo(Consistency.EVENTUALLY_CONSISTENT);
|
||||
load(CouchbaseTestConfiguration.class,
|
||||
"spring.data.couchbase.consistency=eventually-consistent");
|
||||
CouchbaseTestConfiguration configuration = this.context
|
||||
.getBean(CouchbaseTestConfiguration.class);
|
||||
assertThat(configuration.getDefaultConsistency())
|
||||
.isEqualTo(Consistency.EVENTUALLY_CONSISTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overrideCouchbaseOperations() {
|
||||
load(CouchbaseTemplateConfiguration.class);
|
||||
CouchbaseTemplateConfiguration configuration = this.context.getBean(CouchbaseTemplateConfiguration.class);
|
||||
assertThat(this.context.getBean(CouchbaseTemplate.class)).isSameAs(configuration.myCouchbaseTemplate());
|
||||
CouchbaseTemplateConfiguration configuration = this.context
|
||||
.getBean(CouchbaseTemplateConfiguration.class);
|
||||
assertThat(this.context.getBean(CouchbaseTemplate.class))
|
||||
.isSameAs(configuration.myCouchbaseTemplate());
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
|
|
@ -146,7 +159,6 @@ public class CouchbaseAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(CouchbaseTestConfiguration.class)
|
||||
static class CouchbaseTemplateConfiguration {
|
||||
|
|
|
|||
|
|
@ -33,13 +33,15 @@ import static org.mockito.Mockito.mock;
|
|||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Configuration
|
||||
public class CouchbaseTestConfiguration extends CouchbaseAutoConfiguration.CouchbaseConfiguration {
|
||||
public class CouchbaseTestConfiguration
|
||||
extends CouchbaseAutoConfiguration.CouchbaseConfiguration {
|
||||
|
||||
@Override
|
||||
public Cluster couchbaseCluster() throws Exception {
|
||||
return mock(CouchbaseCluster.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public ClusterInfo couchbaseClusterInfo() {
|
||||
return mock(ClusterInfo.class);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import org.springframework.context.annotation.Import;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CouchbaseRepositoriesAutoConfiguration}.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class CouchbaseRepositoriesAutoConfigurationTests {
|
||||
|
|
|
|||
|
|
@ -110,9 +110,8 @@ public class RedisAutoConfigurationTests {
|
|||
if (isAtLeastOneNodeAvailable(clusterNodes)) {
|
||||
load("spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
|
||||
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1));
|
||||
assertThat(
|
||||
this.context.getBean(JedisConnectionFactory.class)
|
||||
.getClusterConnection()).isNotNull();
|
||||
assertThat(this.context.getBean(JedisConnectionFactory.class)
|
||||
.getClusterConnection()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ public class DataSourceAutoConfigurationTests {
|
|||
public void hikariValidatesConnectionByDefault() throws Exception {
|
||||
HikariDataSource dataSource = autoConfigureDataSource(HikariDataSource.class,
|
||||
"org.apache.tomcat");
|
||||
assertThat(dataSource.getConnectionTestQuery()).isNull(); // Use Connection#isValid()
|
||||
assertThat(dataSource.getConnectionTestQuery()).isNull(); // Use
|
||||
// Connection#isValid()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -161,7 +162,6 @@ public class DataSourceAutoConfigurationTests {
|
|||
assertThat(dataSource.getUrl()).isEqualTo("jdbc:hsqldb:mem:testdb");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void commonsDbcp2ValidatesConnectionByDefault() throws Exception {
|
||||
org.apache.commons.dbcp2.BasicDataSource dataSource = autoConfigureDataSource(
|
||||
|
|
|
|||
|
|
@ -254,6 +254,7 @@ public class ThymeleafAutoConfigurationTests {
|
|||
public LayoutDialect layoutDialect() {
|
||||
return new LayoutDialect(new GroupingStrategy());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ methods can be removed from your public API, the automatic deprecation hint in t
|
|||
meta-data will go away as well.
|
||||
|
||||
|
||||
|
||||
[[configuration-metadata-hints-attributes]]
|
||||
==== Hint Attributes
|
||||
The JSON object contained in the `hints` array can contain the following attributes:
|
||||
|
|
|
|||
|
|
@ -50,5 +50,4 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ public class SampleCouchbaseApplication implements CommandLineRunner {
|
|||
public void run(String... args) throws Exception {
|
||||
this.userRepository.deleteAll();
|
||||
User user = saveUser();
|
||||
|
||||
System.out.println(this.userRepository.findOne(user.getId()));
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +45,6 @@ public class SampleCouchbaseApplication implements CommandLineRunner {
|
|||
user.setId(UUID.randomUUID().toString());
|
||||
user.setFirstName("Alice");
|
||||
user.setLastName("Smith");
|
||||
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package sample.data.couchbase;
|
||||
|
||||
|
||||
import com.couchbase.client.java.repository.annotation.Field;
|
||||
import com.couchbase.client.java.repository.annotation.Id;
|
||||
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
|
|
@ -59,10 +59,8 @@ public class User {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id='" + this.id + '\'' +
|
||||
", firstName='" + this.firstName + '\'' +
|
||||
", lastName='" + this.lastName + '\'' +
|
||||
'}';
|
||||
return "User{" + "id='" + this.id + '\'' + ", firstName='" + this.firstName + '\''
|
||||
+ ", lastName='" + this.lastName + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -27,4 +27,5 @@ public interface HotelSummary {
|
|||
default Integer getAverageRatingRounded() {
|
||||
return getAverageRating() == null ? null : (int) Math.round(getAverageRating());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -21,4 +21,5 @@ public interface RatingCount {
|
|||
Rating getRating();
|
||||
|
||||
long getCount();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
package sample.data.jpa.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import sample.data.jpa.domain.City;
|
||||
import sample.data.jpa.domain.Hotel;
|
||||
import sample.data.jpa.domain.HotelSummary;
|
||||
import sample.data.jpa.domain.RatingCount;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
|
@ -39,4 +39,5 @@ interface HotelRepository extends Repository<Hotel, Long> {
|
|||
@Query("select r.rating as rating, count(r) as count "
|
||||
+ "from Review r where r.hotel = ?1 group by r.rating order by r.rating DESC")
|
||||
List<RatingCount> findRatingCounts(Hotel hotel);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,20 +127,17 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
|||
for (ConfigurationMetadataHint hint : metadata.getHints()) {
|
||||
ConfigurationMetadataProperty property = allProperties.get(hint.getId());
|
||||
if (property != null) {
|
||||
property.getHints().getValueHints().addAll(hint.getValueHints());
|
||||
property.getHints().getValueProviders().addAll(hint.getValueProviders());
|
||||
addValueHints(property, hint);
|
||||
}
|
||||
else {
|
||||
String id = hint.resolveId();
|
||||
property = allProperties.get(id);
|
||||
if (property != null) {
|
||||
if (hint.isMapKeyHints()) {
|
||||
property.getHints().getKeyHints().addAll(hint.getValueHints());
|
||||
property.getHints().getKeyProviders().addAll(hint.getValueProviders());
|
||||
addMapHints(property, hint);
|
||||
}
|
||||
else {
|
||||
property.getHints().getValueHints().addAll(hint.getValueHints());
|
||||
property.getHints().getValueProviders().addAll(hint.getValueProviders());
|
||||
addValueHints(property, hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -148,6 +145,18 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
|||
return repository;
|
||||
}
|
||||
|
||||
private void addValueHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
property.getHints().getValueHints().addAll(hint.getValueHints());
|
||||
property.getHints().getValueProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
|
||||
private void addMapHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
property.getHints().getKeyHints().addAll(hint.getValueHints());
|
||||
property.getHints().getKeyProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
|
||||
private ConfigurationMetadataSource getSource(RawConfigurationMetadata metadata,
|
||||
ConfigurationMetadataItem item) {
|
||||
if (item.getSourceType() != null) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Hints of an item to provide the list of values and/or the name of the provider
|
||||
* responsible to identify suitable values. If the type of the related item is
|
||||
* a {@link java.util.Map} it can have both key and value hints.
|
||||
* responsible to identify suitable values. If the type of the related item is a
|
||||
* {@link java.util.Map} it can have both key and value hints.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.4.0
|
||||
|
|
@ -39,9 +39,9 @@ public class Hints {
|
|||
|
||||
/**
|
||||
* The list of well-defined keys, if any. Only applicable if the type of the related
|
||||
* item is a {@link java.util.Map}. If no extra {@link ValueProvider provider}
|
||||
* is specified, these values are to be considered a closed-set of the available
|
||||
* keys for the map.
|
||||
* item is a {@link java.util.Map}. If no extra {@link ValueProvider provider} is
|
||||
* specified, these values are to be considered a closed-set of the available keys for
|
||||
* the map.
|
||||
* @return the key hints
|
||||
*/
|
||||
public List<ValueHint> getKeyHints() {
|
||||
|
|
@ -51,8 +51,8 @@ public class Hints {
|
|||
/**
|
||||
* The value providers that are applicable to the keys of this item. Only applicable
|
||||
* if the type of the related item is a {@link java.util.Map}. Only one
|
||||
* {@link ValueProvider} is enabled for a key: the first in the list that is
|
||||
* supported should be used.
|
||||
* {@link ValueProvider} is enabled for a key: the first in the list that is supported
|
||||
* should be used.
|
||||
* @return the key providers
|
||||
*/
|
||||
public List<ValueProvider> getKeyProviders() {
|
||||
|
|
|
|||
|
|
@ -205,38 +205,47 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
|||
contains(source.getProperties(), "spring.map.first", "spring.map.second",
|
||||
"spring.map.keys", "spring.map.values");
|
||||
assertThat(source.getProperties()).hasSize(4);
|
||||
ConfigurationMetadataProperty first = repo.getAllProperties().get("spring.map.first");
|
||||
ConfigurationMetadataProperty first = repo.getAllProperties()
|
||||
.get("spring.map.first");
|
||||
assertThat(first.getHints().getKeyHints()).hasSize(2);
|
||||
assertThat(first.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(first.getHints().getKeyHints().get(0).getValue()).isEqualTo("one");
|
||||
assertThat(first.getHints().getKeyHints().get(0).getDescription()).isEqualTo("First.");
|
||||
assertThat(first.getHints().getKeyHints().get(0).getDescription())
|
||||
.isEqualTo("First.");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getValue()).isEqualTo("two");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getDescription()).isEqualTo("Second.");
|
||||
ConfigurationMetadataProperty second = repo.getAllProperties().get("spring.map.second");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getDescription())
|
||||
.isEqualTo("Second.");
|
||||
ConfigurationMetadataProperty second = repo.getAllProperties()
|
||||
.get("spring.map.second");
|
||||
assertThat(second.getHints().getValueHints()).hasSize(2);
|
||||
assertThat(second.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(second.getHints().getValueHints().get(0).getValue()).isEqualTo("42");
|
||||
assertThat(second.getHints().getValueHints().get(0).getDescription()).isEqualTo("Choose me.");
|
||||
assertThat(second.getHints().getValueHints().get(0).getDescription())
|
||||
.isEqualTo("Choose me.");
|
||||
assertThat(second.getHints().getValueHints().get(1).getValue()).isEqualTo("24");
|
||||
assertThat(second.getHints().getValueHints().get(1).getDescription()).isNull();
|
||||
ConfigurationMetadataProperty keys = repo.getAllProperties().get("spring.map.keys");
|
||||
ConfigurationMetadataProperty keys = repo.getAllProperties()
|
||||
.get("spring.map.keys");
|
||||
assertThat(keys.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(keys.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(keys.getHints().getValueProviders().get(0).getName()).isEqualTo("any");
|
||||
ConfigurationMetadataProperty values = repo.getAllProperties().get("spring.map.values");
|
||||
ConfigurationMetadataProperty values = repo.getAllProperties()
|
||||
.get("spring.map.values");
|
||||
assertThat(values.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(values.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getName()).isEqualTo("handle-as");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters()).hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters().get("target"))
|
||||
.isEqualTo("java.lang.Integer");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getName())
|
||||
.isEqualTo("handle-as");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters())
|
||||
.hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters()
|
||||
.get("target")).isEqualTo("java.lang.Integer");
|
||||
}
|
||||
|
||||
|
||||
private void validatePropertyHints(ConfigurationMetadataProperty property,
|
||||
int valueHints, int valueProviders) {
|
||||
assertThat(property.getHints().getValueHints().size()).isEqualTo(valueHints);
|
||||
assertThat(property.getHints().getValueProviders().size()).isEqualTo(valueProviders);
|
||||
assertThat(property.getHints().getValueProviders().size())
|
||||
.isEqualTo(valueProviders);
|
||||
}
|
||||
|
||||
private void contains(Map<String, ?> source, String... keys) {
|
||||
|
|
|
|||
|
|
@ -389,6 +389,7 @@ public class JarWriter {
|
|||
interface EntryTransformer {
|
||||
|
||||
JarEntry transform(JarEntry jarEntry);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector {
|
|||
List<Class<?>> types = collectClasses(attributes.get("value"));
|
||||
for (Class<?> type : types) {
|
||||
String prefix = extractPrefix(type);
|
||||
String name = (StringUtils.hasText(prefix)
|
||||
? prefix + "-" + type.getName() : type.getName());
|
||||
String name = (StringUtils.hasText(prefix) ? prefix + "-" + type.getName()
|
||||
: type.getName());
|
||||
if (!registry.containsBeanDefinition(name)) {
|
||||
registerBeanDefinition(registry, type, name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import org.springframework.util.StringUtils;
|
|||
* @author Maciej Walkowiak
|
||||
* @author Marten Deinum
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public enum DatabaseDriver {
|
||||
|
||||
|
|
@ -88,8 +88,8 @@ public enum DatabaseDriver {
|
|||
"SELECT 1"),
|
||||
|
||||
/**
|
||||
* jTDS. As it can be used for several databases, there isn't a single product name
|
||||
* we could rely on.
|
||||
* jTDS. As it can be used for several databases, there isn't a single product name we
|
||||
* could rely on.
|
||||
*/
|
||||
JTDS(null, "net.sourceforge.jtds.jdbc.Driver"),
|
||||
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ public class AtomikosProperties {
|
|||
private String logBaseDir;
|
||||
|
||||
/**
|
||||
* Interval between checkpoints. A checkpoint reduces the log file size at the
|
||||
* expense of adding some overhead in the runtime.
|
||||
* Interval between checkpoints. A checkpoint reduces the log file size at the expense
|
||||
* of adding some overhead in the runtime.
|
||||
*/
|
||||
private long checkpointInterval = 500;
|
||||
|
||||
|
|
|
|||
|
|
@ -68,18 +68,27 @@ public class DatabaseDriverTests {
|
|||
|
||||
@Test
|
||||
public void databaseProductNameLookups() throws Exception {
|
||||
assertThat(DatabaseDriver.fromProductName("newone")).isEqualTo(DatabaseDriver.UNKNOWN);
|
||||
assertThat(DatabaseDriver.fromProductName("HSQL Database Engine")).isEqualTo(DatabaseDriver.HSQLDB);
|
||||
assertThat(DatabaseDriver.fromProductName("Oracle")).isEqualTo(DatabaseDriver.ORACLE);
|
||||
assertThat(DatabaseDriver.fromProductName("Apache Derby")).isEqualTo(DatabaseDriver.DERBY);
|
||||
assertThat(DatabaseDriver.fromProductName("newone"))
|
||||
.isEqualTo(DatabaseDriver.UNKNOWN);
|
||||
assertThat(DatabaseDriver.fromProductName("HSQL Database Engine"))
|
||||
.isEqualTo(DatabaseDriver.HSQLDB);
|
||||
assertThat(DatabaseDriver.fromProductName("Oracle"))
|
||||
.isEqualTo(DatabaseDriver.ORACLE);
|
||||
assertThat(DatabaseDriver.fromProductName("Apache Derby"))
|
||||
.isEqualTo(DatabaseDriver.DERBY);
|
||||
assertThat(DatabaseDriver.fromProductName("DB2")).isEqualTo(DatabaseDriver.DB2);
|
||||
assertThat(DatabaseDriver.fromProductName("DB2/LINUXX8664")).isEqualTo(DatabaseDriver.DB2);
|
||||
assertThat(DatabaseDriver.fromProductName("DB2 UDB for AS/400")).isEqualTo(DatabaseDriver.DB2_AS400);
|
||||
assertThat(DatabaseDriver.fromProductName("DB3 XDB for AS/400")).isEqualTo(DatabaseDriver.DB2_AS400);
|
||||
assertThat(DatabaseDriver.fromProductName("DB2/LINUXX8664"))
|
||||
.isEqualTo(DatabaseDriver.DB2);
|
||||
assertThat(DatabaseDriver.fromProductName("DB2 UDB for AS/400"))
|
||||
.isEqualTo(DatabaseDriver.DB2_AS400);
|
||||
assertThat(DatabaseDriver.fromProductName("DB3 XDB for AS/400"))
|
||||
.isEqualTo(DatabaseDriver.DB2_AS400);
|
||||
assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server"))
|
||||
.isEqualTo(DatabaseDriver.INFORMIX);
|
||||
assertThat(DatabaseDriver.fromProductName("Firebird 2.5.WI")).isEqualTo(DatabaseDriver.FIREBIRD);
|
||||
assertThat(DatabaseDriver.fromProductName("Firebird 2.1.LI")).isEqualTo(DatabaseDriver.FIREBIRD);
|
||||
assertThat(DatabaseDriver.fromProductName("Firebird 2.5.WI"))
|
||||
.isEqualTo(DatabaseDriver.FIREBIRD);
|
||||
assertThat(DatabaseDriver.fromProductName("Firebird 2.1.LI"))
|
||||
.isEqualTo(DatabaseDriver.FIREBIRD);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue