Polish couchbase support

Polish couchbase support to:
- Extract properties into its own class
- Remove unnecessary inner configuration class
- Add since tags
- Format code and add `this.` references
pull/733/merge
Phillip Webb 11 years ago
parent fba08e7811
commit 2adf30950e

@ -0,0 +1,72 @@
/*
* Copyright 2012-2014 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.data;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.couchbase.client.CouchbaseClient;
/**
* Couchbase properties.
*
* @author Michael Nitschinger
* @since 1.1.0
*/
@ConfigurationProperties(prefix = "spring.data.couchbase")
public class CouchbaseProperties {
private String host = "127.0.0.1";
private String bucket = "default";
private String password = "";
public String getHost() {
return this.host;
}
public void setHost(String host) {
this.host = host;
}
public String getBucket() {
return this.bucket;
}
public void setBucket(String bucket) {
this.bucket = bucket;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public CouchbaseClient createClient() throws URISyntaxException, IOException {
return new CouchbaseClient(Arrays.asList(new URI("http://" + getHost()
+ ":8091/pools")), getBucket(), getPassword());
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -17,9 +17,7 @@
package org.springframework.boot.autoconfigure.data;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import javax.annotation.PreDestroy;
@ -27,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -41,74 +38,36 @@ import com.couchbase.client.CouchbaseClient;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase
* Repositories.
*
*
* @author Michael Nitschinger
* @since 1.1.0
* @see CouchbaseProperties
* @see EnableCouchbaseRepositories
*/
@Configuration
@ConditionalOnClass({ CouchbaseClient.class, CouchbaseRepository.class })
@Import(CouchbaseRepositoriesAutoConfigureRegistrar.class)
@EnableConfigurationProperties(CouchbaseProperties.class)
public class CouchbaseRepositoriesAutoConfiguration {
@Import(CouchbaseRepositoriesAutoConfigureRegistrar.class)
@Configuration
@EnableConfigurationProperties(CouchbaseProperties.class)
protected static class CouchbaseRepositoriesConfiguration {
@Autowired
private CouchbaseProperties config;
@PreDestroy
public void close() throws URISyntaxException, IOException {
couchbaseClient().shutdown();
}
@Bean
@ConditionalOnMissingBean(CouchbaseClient.class)
CouchbaseClient couchbaseClient() throws URISyntaxException, IOException {
return this.config.couchbaseClient();
}
@Autowired
private CouchbaseProperties properties;
@Bean
@ConditionalOnMissingBean(CouchbaseTemplate.class)
CouchbaseTemplate couchbaseTemplate(CouchbaseClient couchbaseClient) {
return new CouchbaseTemplate(couchbaseClient);
}
@PreDestroy
public void close() throws URISyntaxException, IOException {
couchbaseClient().shutdown();
}
@ConfigurationProperties(prefix = "spring.data.couchbase")
public static class CouchbaseProperties {
private String host = "127.0.0.1";
private String bucket = "default";
private String password = "";
public CouchbaseClient couchbaseClient() throws URISyntaxException, IOException {
return new CouchbaseClient(Arrays.asList(new URI("http://" + getHost()
+ ":8091/pools")), getBucket(), getPassword());
}
public String getHost() {
return this.host;
}
public void setHost(String host) {
this.host = host;
}
public String getBucket() {
return this.bucket;
}
public void setBucket(String bucket) {
this.bucket = bucket;
}
public String getPassword() {
return this.password;
}
@Bean
@ConditionalOnMissingBean(CouchbaseClient.class)
CouchbaseClient couchbaseClient() throws URISyntaxException, IOException {
return this.properties.createClient();
}
public void setPassword(String password) {
this.password = password;
}
@Bean
@ConditionalOnMissingBean(CouchbaseTemplate.class)
CouchbaseTemplate couchbaseTemplate(CouchbaseClient couchbaseClient) {
return new CouchbaseTemplate(couchbaseClient);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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,22 +16,22 @@
package org.springframework.boot.autoconfigure.data;
import org.springframework.data.couchbase.repository.config.CouchbaseRepositoryConfigurationExtension;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import java.lang.annotation.Annotation;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.data.couchbase.repository.config.CouchbaseRepositoryConfigurationExtension;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase
* Repositories.
*
*
* @author Michael Nitschinger
* @since 1.1.0
*/
class CouchbaseRepositoriesAutoConfigureRegistrar extends
AbstractRepositoryConfigurationSourceSupport {
AbstractRepositoryConfigurationSourceSupport {
@Override
protected Class<? extends Annotation> getAnnotation() {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -32,7 +32,7 @@ import static org.mockito.Mockito.mock;
/**
* Tests for {@link CouchbaseRepositoriesAutoConfiguration}.
*
*
* @author Michael Nitschinger
*/
public class CouchbaseRepositoriesAutoConfigurationTests {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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,14 +16,11 @@
package org.springframework.boot.autoconfigure.data.couchbase;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import java.io.Serializable;
/**
* @author Michael Nitschinger
*/
@Document
public class City implements Serializable {
@ -31,8 +28,11 @@ public class City implements Serializable {
private String id;
private String name;
private String state;
private String country;
private String map;
public City(String id, String name, String country) {
@ -42,7 +42,7 @@ public class City implements Serializable {
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {
@ -50,7 +50,7 @@ public class City implements Serializable {
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@ -58,7 +58,7 @@ public class City implements Serializable {
}
public String getState() {
return state;
return this.state;
}
public void setState(String state) {
@ -66,7 +66,7 @@ public class City implements Serializable {
}
public String getCountry() {
return country;
return this.country;
}
public void setCountry(String country) {
@ -74,10 +74,11 @@ public class City implements Serializable {
}
public String getMap() {
return map;
return this.map;
}
public void setMap(String map) {
this.map = map;
}
}

@ -18,8 +18,5 @@ package org.springframework.boot.autoconfigure.data.couchbase;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
/**
* @author Michael Nitschinger
*/
public interface CityRepository extends CouchbaseRepository<City, String> {
}

Loading…
Cancel
Save