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
This commit is contained in:
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,9 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.data;
|
package org.springframework.boot.autoconfigure.data;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
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.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -41,74 +38,36 @@ import com.couchbase.client.CouchbaseClient;
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase
|
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase
|
||||||
* Repositories.
|
* Repositories.
|
||||||
*
|
*
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
|
* @since 1.1.0
|
||||||
|
* @see CouchbaseProperties
|
||||||
* @see EnableCouchbaseRepositories
|
* @see EnableCouchbaseRepositories
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ CouchbaseClient.class, CouchbaseRepository.class })
|
@ConditionalOnClass({ CouchbaseClient.class, CouchbaseRepository.class })
|
||||||
|
@Import(CouchbaseRepositoriesAutoConfigureRegistrar.class)
|
||||||
|
@EnableConfigurationProperties(CouchbaseProperties.class)
|
||||||
public class CouchbaseRepositoriesAutoConfiguration {
|
public class CouchbaseRepositoriesAutoConfiguration {
|
||||||
|
|
||||||
@Import(CouchbaseRepositoriesAutoConfigureRegistrar.class)
|
@Autowired
|
||||||
@Configuration
|
private CouchbaseProperties properties;
|
||||||
@EnableConfigurationProperties(CouchbaseProperties.class)
|
|
||||||
protected static class CouchbaseRepositoriesConfiguration {
|
|
||||||
|
|
||||||
@Autowired
|
@PreDestroy
|
||||||
private CouchbaseProperties config;
|
public void close() throws URISyntaxException, IOException {
|
||||||
|
couchbaseClient().shutdown();
|
||||||
@PreDestroy
|
|
||||||
public void close() throws URISyntaxException, IOException {
|
|
||||||
couchbaseClient().shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(CouchbaseClient.class)
|
|
||||||
CouchbaseClient couchbaseClient() throws URISyntaxException, IOException {
|
|
||||||
return this.config.couchbaseClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(CouchbaseTemplate.class)
|
|
||||||
CouchbaseTemplate couchbaseTemplate(CouchbaseClient couchbaseClient) {
|
|
||||||
return new CouchbaseTemplate(couchbaseClient);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "spring.data.couchbase")
|
@Bean
|
||||||
public static class CouchbaseProperties {
|
@ConditionalOnMissingBean(CouchbaseClient.class)
|
||||||
|
CouchbaseClient couchbaseClient() throws URISyntaxException, IOException {
|
||||||
private String host = "127.0.0.1";
|
return this.properties.createClient();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,22 +16,22 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.data;
|
package org.springframework.boot.autoconfigure.data;
|
||||||
|
|
||||||
|
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.CouchbaseRepositoryConfigurationExtension;
|
||||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase
|
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase
|
||||||
* Repositories.
|
* Repositories.
|
||||||
*
|
*
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
class CouchbaseRepositoriesAutoConfigureRegistrar extends
|
class CouchbaseRepositoriesAutoConfigureRegistrar extends
|
||||||
AbstractRepositoryConfigurationSourceSupport {
|
AbstractRepositoryConfigurationSourceSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends Annotation> getAnnotation() {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link CouchbaseRepositoriesAutoConfiguration}.
|
* Tests for {@link CouchbaseRepositoriesAutoConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
*/
|
*/
|
||||||
public class CouchbaseRepositoriesAutoConfigurationTests {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,14 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.data.couchbase;
|
package org.springframework.boot.autoconfigure.data.couchbase;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.couchbase.core.mapping.Document;
|
import org.springframework.data.couchbase.core.mapping.Document;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Michael Nitschinger
|
|
||||||
*/
|
|
||||||
@Document
|
@Document
|
||||||
public class City implements Serializable {
|
public class City implements Serializable {
|
||||||
|
|
||||||
|
@ -31,8 +28,11 @@ public class City implements Serializable {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String state;
|
private String state;
|
||||||
|
|
||||||
private String country;
|
private String country;
|
||||||
|
|
||||||
private String map;
|
private String map;
|
||||||
|
|
||||||
public City(String id, String name, String country) {
|
public City(String id, String name, String country) {
|
||||||
|
@ -42,7 +42,7 @@ public class City implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
|
@ -50,7 +50,7 @@ public class City implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
|
@ -58,7 +58,7 @@ public class City implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return this.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
|
@ -66,7 +66,7 @@ public class City implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCountry() {
|
public String getCountry() {
|
||||||
return country;
|
return this.country;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCountry(String country) {
|
public void setCountry(String country) {
|
||||||
|
@ -74,10 +74,11 @@ public class City implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMap() {
|
public String getMap() {
|
||||||
return map;
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMap(String map) {
|
public void setMap(String map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,5 @@ package org.springframework.boot.autoconfigure.data.couchbase;
|
||||||
|
|
||||||
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
import org.springframework.data.couchbase.repository.CouchbaseRepository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Michael Nitschinger
|
|
||||||
*/
|
|
||||||
public interface CityRepository extends CouchbaseRepository<City, String> {
|
public interface CityRepository extends CouchbaseRepository<City, String> {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue