|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
* Copyright 2012-2017 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,17 +16,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.data.couchbase;
|
|
|
|
package org.springframework.boot.autoconfigure.data.couchbase;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.couchbase.client.java.Cluster;
|
|
|
|
|
|
|
|
import com.couchbase.client.java.cluster.ClusterInfo;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
|
|
|
|
import org.springframework.boot.autoconfigure.domain.EntityScanner;
|
|
|
|
import org.springframework.boot.autoconfigure.domain.EntityScanner;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.data.annotation.Persistent;
|
|
|
|
import org.springframework.data.annotation.Persistent;
|
|
|
|
import org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration;
|
|
|
|
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
|
|
|
import org.springframework.data.couchbase.config.BeanNames;
|
|
|
|
import org.springframework.data.couchbase.config.BeanNames;
|
|
|
|
import org.springframework.data.couchbase.config.CouchbaseConfigurer;
|
|
|
|
import org.springframework.data.couchbase.config.CouchbaseConfigurer;
|
|
|
|
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
|
|
|
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
|
|
@ -41,24 +46,53 @@ import org.springframework.data.couchbase.repository.support.IndexManager;
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnMissingBean(AbstractCouchbaseDataConfiguration.class)
|
|
|
|
@ConditionalOnMissingBean(AbstractCouchbaseConfiguration.class)
|
|
|
|
@ConditionalOnBean(CouchbaseConfigurer.class)
|
|
|
|
@ConditionalOnBean(CouchbaseConfigurer.class)
|
|
|
|
class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfiguration {
|
|
|
|
class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private final ApplicationContext applicationContext;
|
|
|
|
private final ApplicationContext applicationContext;
|
|
|
|
|
|
|
|
|
|
|
|
private final CouchbaseDataProperties properties;
|
|
|
|
private final CouchbaseProperties properties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final CouchbaseDataProperties dataProperties;
|
|
|
|
|
|
|
|
|
|
|
|
private final CouchbaseConfigurer couchbaseConfigurer;
|
|
|
|
private final CouchbaseConfigurer couchbaseConfigurer;
|
|
|
|
|
|
|
|
|
|
|
|
SpringBootCouchbaseDataConfiguration(ApplicationContext applicationContext,
|
|
|
|
SpringBootCouchbaseDataConfiguration(ApplicationContext applicationContext,
|
|
|
|
CouchbaseDataProperties properties,
|
|
|
|
CouchbaseProperties properties,
|
|
|
|
|
|
|
|
CouchbaseDataProperties dataProperties,
|
|
|
|
ObjectProvider<CouchbaseConfigurer> couchbaseConfigurer) {
|
|
|
|
ObjectProvider<CouchbaseConfigurer> couchbaseConfigurer) {
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
this.properties = properties;
|
|
|
|
this.properties = properties;
|
|
|
|
|
|
|
|
this.dataProperties = dataProperties;
|
|
|
|
this.couchbaseConfigurer = couchbaseConfigurer.getIfAvailable();
|
|
|
|
this.couchbaseConfigurer = couchbaseConfigurer.getIfAvailable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected List<String> getBootstrapHosts() {
|
|
|
|
|
|
|
|
return this.properties.getBootstrapHosts();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected String getBucketName() {
|
|
|
|
|
|
|
|
return this.properties.getBucket().getName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected String getBucketPassword() {
|
|
|
|
|
|
|
|
return this.properties.getBucket().getPassword();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Cluster couchbaseCluster() throws Exception {
|
|
|
|
|
|
|
|
return couchbaseConfigurer().couchbaseCluster();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public ClusterInfo couchbaseClusterInfo() throws Exception {
|
|
|
|
|
|
|
|
return couchbaseConfigurer().couchbaseClusterInfo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected CouchbaseConfigurer couchbaseConfigurer() {
|
|
|
|
protected CouchbaseConfigurer couchbaseConfigurer() {
|
|
|
|
return this.couchbaseConfigurer;
|
|
|
|
return this.couchbaseConfigurer;
|
|
|
@ -66,7 +100,7 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Consistency getDefaultConsistency() {
|
|
|
|
protected Consistency getDefaultConsistency() {
|
|
|
|
return this.properties.getConsistency();
|
|
|
|
return this.dataProperties.getConsistency();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -93,7 +127,7 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
|
|
|
|
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
|
|
|
|
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
|
|
|
|
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
|
|
|
|
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
|
|
|
|
public IndexManager indexManager() {
|
|
|
|
public IndexManager indexManager() {
|
|
|
|
if (this.properties.isAutoIndex()) {
|
|
|
|
if (this.dataProperties.isAutoIndex()) {
|
|
|
|
return new IndexManager(true, true, true);
|
|
|
|
return new IndexManager(true, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new IndexManager(false, false, false);
|
|
|
|
return new IndexManager(false, false, false);
|
|
|
|