Merge pull request #42 from simonbasle/beanClusterBucket
[2.0] xml configuration for env, cluster, bucket This implements parsers (and FactoryBeans as needed) for the environment, cluster and bucket definitions. Most tunings on the environment are possible through the xml configuration, except a few that are both more complicated to implement and obscure enough not to warrant the possibility (observeIntervalDelay, reconnectDelay, retryDelay, userAgent, packageNameAndVersion, ioPool, scheduler and eventBus).
This commit is contained in:
@@ -22,31 +22,30 @@ package org.springframework.data.couchbase.config;
|
||||
* @author Michael Nitschinger
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
public class BeanNames {
|
||||
class BeanNames {
|
||||
|
||||
/**
|
||||
* Refers to the <couchbase:env /> bean.
|
||||
* Refers to the "<couchbase:env />" bean.
|
||||
*/
|
||||
static final String COUCHBASE_ENV = "couchbaseEnv";
|
||||
/**
|
||||
* Refers to the "<couchbase:cluster />" bean.
|
||||
* Refers to the "<couchbase:cluster />" bean.
|
||||
*/
|
||||
static final String COUCHBASE_CLUSTER = "couchbaseCluster";
|
||||
|
||||
/**
|
||||
* Refers to the "<couchbase:bucket />" bean.
|
||||
* Refers to the "<couchbase:bucket />" bean.
|
||||
*/
|
||||
static final String COUCHBASE_BUCKET = "couchbaseBucket";
|
||||
|
||||
/**
|
||||
* Refers to the "<couchbase:template />" bean.
|
||||
* Refers to the "<couchbase:template />" bean.
|
||||
*/
|
||||
static final String COUCHBASE_TEMPLATE = "couchbaseTemplate";
|
||||
|
||||
/**
|
||||
* Refers to the "<couchbase:translation-service />" bean
|
||||
* Refers to the "<couchbase:translation-service />" bean
|
||||
*/
|
||||
static final String TRANSLATION_SERVICE = "couchbaseTranslationService";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseBucket;
|
||||
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
|
||||
/**
|
||||
* The Factory Bean to help {@link CouchbaseBucketParser} constructing a {@link Bucket} from a given
|
||||
* {@link Cluster} reference.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
public class CouchbaseBucketFactoryBean extends AbstractFactoryBean<Bucket> {
|
||||
|
||||
private final Cluster cluster;
|
||||
private final String bucketName;
|
||||
private final String bucketPassword;
|
||||
|
||||
public CouchbaseBucketFactoryBean(Cluster cluster) {
|
||||
this(cluster, null, null);
|
||||
}
|
||||
|
||||
public CouchbaseBucketFactoryBean(Cluster cluster, String bucketName) {
|
||||
this(cluster, bucketName, null);
|
||||
}
|
||||
|
||||
public CouchbaseBucketFactoryBean(Cluster cluster, String bucketName, String bucketPassword) {
|
||||
this.cluster = cluster;
|
||||
this.bucketName = bucketName;
|
||||
this.bucketPassword = bucketPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return CouchbaseBucket.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bucket createInstance() throws Exception {
|
||||
if (bucketName == null) {
|
||||
return cluster.openBucket();
|
||||
} else if (bucketPassword == null) {
|
||||
return cluster.openBucket(bucketName);
|
||||
} else {
|
||||
return cluster.openBucket(bucketName, bucketPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The parser for XML definition of a {@link Bucket}, to be constructed from a {@link Cluster} reference.
|
||||
* If no reference is given, the default reference <code>{@value BeanNames#COUCHBASE_CLUSTER}</code> is used.
|
||||
*
|
||||
* See attributes {@link #CLUSTER_REF_ATTR}, {@link #BUCKETNAME_ATTR} and {@link #BUCKETPASSWORD_ATTR}.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
public class CouchbaseBucketParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* The <code>cluster-ref</code> attribute in a bucket definition defines the cluster to build from.
|
||||
*/
|
||||
public static final String CLUSTER_REF_ATTR = "cluster-ref";
|
||||
|
||||
/**
|
||||
* The <code>bucketName</code> attribute in a bucket definition defines the name of the bucket to open.
|
||||
*/
|
||||
public static final String BUCKETNAME_ATTR = "bucketName";
|
||||
|
||||
/**
|
||||
* The <code>bucketPassword</code> attribute in a bucket definition defines the password of the bucket to open.
|
||||
*/
|
||||
public static final String BUCKETPASSWORD_ATTR = "bucketPassword";
|
||||
|
||||
/**
|
||||
* Resolve the bean ID and assign a default if not set.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @param definition the bean definition to work with.
|
||||
* @param parserContext encapsulates the parsing state and configuration.
|
||||
* @return the ID to work with.
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(final Element element, final AbstractBeanDefinition definition, final ParserContext parserContext) {
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE_BUCKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the bean class that will be constructed.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @return the class type to instantiate.
|
||||
*/
|
||||
@Override
|
||||
protected Class getBeanClass(final Element element) {
|
||||
return CouchbaseBucketFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the bean definition and build up the bean.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @param builder the builder which builds the bean.
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(final Element element, final BeanDefinitionBuilder builder) {
|
||||
String clusterRef = element.getAttribute(CLUSTER_REF_ATTR);
|
||||
if (!StringUtils.hasText(clusterRef)) {
|
||||
clusterRef = BeanNames.COUCHBASE_CLUSTER;
|
||||
}
|
||||
builder.addConstructorArgReference(clusterRef);
|
||||
|
||||
String bucketName = element.getAttribute(BUCKETNAME_ATTR);
|
||||
if (StringUtils.hasText(bucketName)) {
|
||||
builder.addConstructorArgValue(bucketName);
|
||||
}
|
||||
|
||||
String bucketPassword = element.getAttribute(BUCKETPASSWORD_ATTR);
|
||||
if (StringUtils.hasText(bucketPassword)) {
|
||||
builder.addConstructorArgValue(bucketPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* The XML parser for a {@link Cluster} definition.
|
||||
*
|
||||
* Such a definition can be tuned by either referencing a {@link CouchbaseEnvironment} via
|
||||
* the {@value #CLUSTER_ENVIRONMENT_REF} attribute or define a custom environment inline via
|
||||
* the <{@value #CLUSTER_ENVIRONMENT_TAG}> tag (not recommended, environments should be
|
||||
* shared as possible). If no environment reference or inline description is provided, the
|
||||
* default environment reference {@value BeanNames#COUCHBASE_ENV} is used.
|
||||
*
|
||||
* To bootstrap the connection, one can provide IPs or hostnames of nodes to connect to
|
||||
* via 1 or more <{@value #CLUSTER_NODE_TAG}> tags.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
public class CouchbaseClusterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* The <node> elements in a cluster definition define the bootstrap hosts to use
|
||||
*/
|
||||
public static final String CLUSTER_NODE_TAG = "node";
|
||||
|
||||
/**
|
||||
* The unique <env> element in a cluster definition define the environment customizations.
|
||||
*
|
||||
* @see CouchbaseEnvironmentParser CouchbaseEnvironmentParser for the possible fields.
|
||||
* @see #CLUSTER_ENVIRONMENT_REF CLUSTER_ENVIRONMENT_REF as an alternative (giving a reference to
|
||||
* an env instead of inline description, lower precedence)
|
||||
*/
|
||||
public static final String CLUSTER_ENVIRONMENT_TAG = "env";
|
||||
|
||||
/**
|
||||
* The <env-ref> attribute allows to use a reference to an {@link CouchbaseEnvironment} to
|
||||
* tune the connection.
|
||||
*
|
||||
* @see #CLUSTER_ENVIRONMENT_TAG CLUSTER_ENVIRONMENT_TAG for an inline alternative
|
||||
* (which takes priority over this reference)
|
||||
*/
|
||||
public static final String CLUSTER_ENVIRONMENT_REF = "env-ref";
|
||||
|
||||
/**
|
||||
* Resolve the bean ID and assign a default if not set.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @param definition the bean definition to work with.
|
||||
* @param parserContext encapsulates the parsing state and configuration.
|
||||
* @return the ID to work with.
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(final Element element, final AbstractBeanDefinition definition, final ParserContext parserContext) {
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE_CLUSTER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the bean class that will be constructed.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @return the class type to instantiate.
|
||||
*/
|
||||
@Override
|
||||
protected Class getBeanClass(final Element element) {
|
||||
return CouchbaseCluster.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the bean definition and build up the bean.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @param bean the builder which builds the bean.
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
|
||||
bean.setFactoryMethod("create");
|
||||
bean.setDestroyMethodName("disconnect");
|
||||
|
||||
parseEnvironment(bean, element);
|
||||
|
||||
List<Element> nodes = DomUtils.getChildElementsByTagName(element, CLUSTER_NODE_TAG);
|
||||
if (nodes != null && nodes.size() > 0) {
|
||||
List<String> bootstrapUrls = new ArrayList<String>(nodes.size());
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
bootstrapUrls.add(nodes.get(i).getTextContent());
|
||||
}
|
||||
bean.addConstructorArgValue(bootstrapUrls);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a custom environment was parsed and injected (either reference or inline), false if
|
||||
* the default environment reference was used.
|
||||
*/
|
||||
protected boolean parseEnvironment(BeanDefinitionBuilder clusterBuilder, Element clusterElement) {
|
||||
//any inline environment description would take precedence over a reference
|
||||
Element envElement = DomUtils.getChildElementByTagName(clusterElement, CLUSTER_ENVIRONMENT_TAG);
|
||||
if (envElement != null && envElement.hasAttributes()) {
|
||||
injectEnvElement(clusterBuilder, envElement);
|
||||
return true;
|
||||
}
|
||||
|
||||
//secondly try to see if an env has been referenced
|
||||
String envRef = clusterElement.getAttribute(CLUSTER_ENVIRONMENT_REF);
|
||||
if (StringUtils.hasText(envRef)) {
|
||||
injectEnvReference(clusterBuilder, envRef);
|
||||
return true;
|
||||
}
|
||||
|
||||
//if no custom value provided, consider it a reference to the default bean for Couchbase Environment
|
||||
injectEnvReference(clusterBuilder, BeanNames.COUCHBASE_ENV);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void injectEnvElement(BeanDefinitionBuilder clusterBuilder, Element envElement) {
|
||||
BeanDefinitionBuilder envDefinitionBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(CouchbaseEnvironmentFactoryBean.class);
|
||||
new CouchbaseEnvironmentParser().doParse(envElement, envDefinitionBuilder);
|
||||
|
||||
clusterBuilder.addConstructorArgValue(envDefinitionBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
protected void injectEnvReference(BeanDefinitionBuilder clusterBuilder, String envRef) {
|
||||
clusterBuilder.addConstructorArgReference(envRef);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import com.couchbase.client.core.retry.BestEffortRetryStrategy;
|
||||
import com.couchbase.client.core.retry.FailFastRetryStrategy;
|
||||
import com.couchbase.client.core.retry.RetryStrategy;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
|
||||
/**
|
||||
* Factory Bean to help create a CouchbaseEnvironment (by offering setters for supported tuning methods).
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
/*package*/ class CouchbaseEnvironmentFactoryBean extends AbstractFactoryBean<CouchbaseEnvironment> {
|
||||
|
||||
private static final CouchbaseEnvironment DEFAULT_ENV = DefaultCouchbaseEnvironment.create();
|
||||
public static final String RETRYSTRATEGY_FAILFAST = "FailFast";
|
||||
public static final String RETRYSTRATEGY_BESTEFFORT = "BestEffort";
|
||||
|
||||
private long managementTimeout = DEFAULT_ENV.managementTimeout();
|
||||
private long queryTimeout = DEFAULT_ENV.queryTimeout();
|
||||
private long viewTimeout = DEFAULT_ENV.viewTimeout();
|
||||
private long kvTimeout = DEFAULT_ENV.kvTimeout();
|
||||
private long connectTimeout = DEFAULT_ENV.connectTimeout();
|
||||
private long disconnectTimeout = DEFAULT_ENV.disconnectTimeout();
|
||||
private boolean dnsSrvEnabled = DEFAULT_ENV.dnsSrvEnabled();
|
||||
|
||||
private boolean dcpEnabled = DEFAULT_ENV.dcpEnabled();
|
||||
private boolean sslEnabled = DEFAULT_ENV.sslEnabled();
|
||||
private String sslKeystoreFile = DEFAULT_ENV.sslKeystoreFile();
|
||||
private String sslKeystorePassword = DEFAULT_ENV.sslKeystorePassword();
|
||||
private boolean queryEnabled = DEFAULT_ENV.queryEnabled();
|
||||
private int queryPort = DEFAULT_ENV.queryPort();
|
||||
private boolean bootstrapHttpEnabled = DEFAULT_ENV.bootstrapHttpEnabled();
|
||||
private boolean bootstrapCarrierEnabled = DEFAULT_ENV.bootstrapCarrierEnabled();
|
||||
private int bootstrapHttpDirectPort = DEFAULT_ENV.bootstrapHttpDirectPort();
|
||||
private int bootstrapHttpSslPort = DEFAULT_ENV.bootstrapHttpSslPort();
|
||||
private int bootstrapCarrierDirectPort = DEFAULT_ENV.bootstrapCarrierDirectPort();
|
||||
private int bootstrapCarrierSslPort = DEFAULT_ENV.bootstrapCarrierSslPort();
|
||||
private int ioPoolSize = DEFAULT_ENV.ioPoolSize();
|
||||
private int computationPoolSize = DEFAULT_ENV.computationPoolSize();
|
||||
private int responseBufferSize = DEFAULT_ENV.responseBufferSize();
|
||||
private int requestBufferSize = DEFAULT_ENV.requestBufferSize();
|
||||
private int kvEndpoints = DEFAULT_ENV.kvEndpoints();
|
||||
private int viewEndpoints = DEFAULT_ENV.viewEndpoints();
|
||||
private int queryEndpoints = DEFAULT_ENV.queryEndpoints();
|
||||
private RetryStrategy retryStrategy = DEFAULT_ENV.retryStrategy();
|
||||
private long maxRequestLifetime = DEFAULT_ENV.maxRequestLifetime();
|
||||
private long keepAliveInterval = DEFAULT_ENV.keepAliveInterval();
|
||||
private long autoreleaseAfter = DEFAULT_ENV.autoreleaseAfter();
|
||||
private boolean bufferPoolingEnabled = DEFAULT_ENV.bufferPoolingEnabled();
|
||||
|
||||
//These are tunings that are not practical to be exposed in a xml configuration
|
||||
//or not supposed to be modified that easily:
|
||||
// observeIntervalDelay
|
||||
// reconnectDelay
|
||||
// retryDelay
|
||||
// userAgent
|
||||
// packageNameAndVersion
|
||||
// ioPool
|
||||
// scheduler
|
||||
// eventBus
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return DefaultCouchbaseEnvironment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CouchbaseEnvironment createInstance() throws Exception {
|
||||
return DefaultCouchbaseEnvironment.builder()
|
||||
.managementTimeout(managementTimeout)
|
||||
.queryTimeout(queryTimeout)
|
||||
.viewTimeout(viewTimeout)
|
||||
.kvTimeout(kvTimeout)
|
||||
.connectTimeout(connectTimeout)
|
||||
.disconnectTimeout(disconnectTimeout)
|
||||
.dnsSrvEnabled(dnsSrvEnabled)
|
||||
.dcpEnabled(dcpEnabled)
|
||||
.sslEnabled(sslEnabled)
|
||||
.sslKeystoreFile(sslKeystoreFile)
|
||||
.sslKeystorePassword(sslKeystorePassword)
|
||||
.queryEnabled(queryEnabled)
|
||||
.queryPort(queryPort)
|
||||
.bootstrapHttpEnabled(bootstrapHttpEnabled)
|
||||
.bootstrapCarrierEnabled(bootstrapCarrierEnabled)
|
||||
.bootstrapHttpDirectPort(bootstrapHttpDirectPort)
|
||||
.bootstrapHttpSslPort(bootstrapHttpSslPort)
|
||||
.bootstrapCarrierDirectPort(bootstrapCarrierDirectPort)
|
||||
.bootstrapCarrierSslPort(bootstrapCarrierSslPort)
|
||||
.ioPoolSize(ioPoolSize)
|
||||
.computationPoolSize(computationPoolSize)
|
||||
.responseBufferSize(responseBufferSize)
|
||||
.requestBufferSize(requestBufferSize)
|
||||
.kvEndpoints(kvEndpoints)
|
||||
.viewEndpoints(viewEndpoints)
|
||||
.queryEndpoints(queryEndpoints)
|
||||
.retryStrategy(retryStrategy)
|
||||
.maxRequestLifetime(maxRequestLifetime)
|
||||
.keepAliveInterval(keepAliveInterval)
|
||||
.autoreleaseAfter(autoreleaseAfter)
|
||||
.bufferPoolingEnabled(bufferPoolingEnabled)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link RetryStrategy} to use from an enum-like String value.
|
||||
* Either "FailFast" or "BestEffort" are recognized.
|
||||
*
|
||||
* @param retryStrategy the string value enum from which to choose a strategy.
|
||||
*/
|
||||
public void setRetryStrategy(String retryStrategy) {
|
||||
if (RETRYSTRATEGY_FAILFAST.equals(retryStrategy)){
|
||||
this.retryStrategy = FailFastRetryStrategy.INSTANCE;
|
||||
} else if (RETRYSTRATEGY_BESTEFFORT.equals(retryStrategy)) {
|
||||
this.retryStrategy = BestEffortRetryStrategy.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
//==== SETTERS for the factory bean ====
|
||||
|
||||
public void setManagementTimeout(long managementTimeout) {
|
||||
this.managementTimeout = managementTimeout;
|
||||
}
|
||||
|
||||
public void setQueryTimeout(long queryTimeout) {
|
||||
this.queryTimeout = queryTimeout;
|
||||
}
|
||||
|
||||
public void setViewTimeout(long viewTimeout) {
|
||||
this.viewTimeout = viewTimeout;
|
||||
}
|
||||
|
||||
public void setKvTimeout(long kvTimeout) {
|
||||
this.kvTimeout = kvTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(long connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public void setDisconnectTimeout(long disconnectTimeout) {
|
||||
this.disconnectTimeout = disconnectTimeout;
|
||||
}
|
||||
|
||||
public void setDnsSrvEnabled(boolean dnsSrvEnabled) {
|
||||
this.dnsSrvEnabled = dnsSrvEnabled;
|
||||
}
|
||||
|
||||
public void setDcpEnabled(boolean dcpEnabled) {
|
||||
this.dcpEnabled = dcpEnabled;
|
||||
}
|
||||
|
||||
public void setSslEnabled(boolean sslEnabled) {
|
||||
this.sslEnabled = sslEnabled;
|
||||
}
|
||||
|
||||
public void setSslKeystoreFile(String sslKeystoreFile) {
|
||||
this.sslKeystoreFile = sslKeystoreFile;
|
||||
}
|
||||
|
||||
public void setSslKeystorePassword(String sslKeystorePassword) {
|
||||
this.sslKeystorePassword = sslKeystorePassword;
|
||||
}
|
||||
|
||||
public void setQueryEnabled(boolean queryEnabled) {
|
||||
this.queryEnabled = queryEnabled;
|
||||
}
|
||||
|
||||
public void setQueryPort(int queryPort) {
|
||||
this.queryPort = queryPort;
|
||||
}
|
||||
|
||||
public void setBootstrapHttpEnabled(boolean bootstrapHttpEnabled) {
|
||||
this.bootstrapHttpEnabled = bootstrapHttpEnabled;
|
||||
}
|
||||
|
||||
public void setBootstrapCarrierEnabled(boolean bootstrapCarrierEnabled) {
|
||||
this.bootstrapCarrierEnabled = bootstrapCarrierEnabled;
|
||||
}
|
||||
|
||||
public void setBootstrapHttpDirectPort(int bootstrapHttpDirectPort) {
|
||||
this.bootstrapHttpDirectPort = bootstrapHttpDirectPort;
|
||||
}
|
||||
|
||||
public void setBootstrapHttpSslPort(int bootstrapHttpSslPort) {
|
||||
this.bootstrapHttpSslPort = bootstrapHttpSslPort;
|
||||
}
|
||||
|
||||
public void setBootstrapCarrierDirectPort(int bootstrapCarrierDirectPort) {
|
||||
this.bootstrapCarrierDirectPort = bootstrapCarrierDirectPort;
|
||||
}
|
||||
|
||||
public void setBootstrapCarrierSslPort(int bootstrapCarrierSslPort) {
|
||||
this.bootstrapCarrierSslPort = bootstrapCarrierSslPort;
|
||||
}
|
||||
|
||||
public void setIoPoolSize(int ioPoolSize) {
|
||||
this.ioPoolSize = ioPoolSize;
|
||||
}
|
||||
|
||||
public void setComputationPoolSize(int computationPoolSize) {
|
||||
this.computationPoolSize = computationPoolSize;
|
||||
}
|
||||
|
||||
public void setResponseBufferSize(int responseBufferSize) {
|
||||
this.responseBufferSize = responseBufferSize;
|
||||
}
|
||||
|
||||
public void setRequestBufferSize(int requestBufferSize) {
|
||||
this.requestBufferSize = requestBufferSize;
|
||||
}
|
||||
|
||||
public void setKvEndpoints(int kvEndpoints) {
|
||||
this.kvEndpoints = kvEndpoints;
|
||||
}
|
||||
|
||||
public void setViewEndpoints(int viewEndpoints) {
|
||||
this.viewEndpoints = viewEndpoints;
|
||||
}
|
||||
|
||||
public void setQueryEndpoints(int queryEndpoints) {
|
||||
this.queryEndpoints = queryEndpoints;
|
||||
}
|
||||
|
||||
public void setMaxRequestLifetime(long maxRequestLifetime) {
|
||||
this.maxRequestLifetime = maxRequestLifetime;
|
||||
}
|
||||
|
||||
public void setKeepAliveInterval(long keepAliveInterval) {
|
||||
this.keepAliveInterval = keepAliveInterval;
|
||||
}
|
||||
|
||||
public void setAutoreleaseAfter(long autoreleaseAfter) {
|
||||
this.autoreleaseAfter = autoreleaseAfter;
|
||||
}
|
||||
|
||||
public void setBufferPoolingEnabled(boolean bufferPoolingEnabled) {
|
||||
this.bufferPoolingEnabled = bufferPoolingEnabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import static org.springframework.data.config.ParsingUtils.setPropertyValue;
|
||||
|
||||
import com.couchbase.client.core.retry.RetryStrategy;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Allows creation of a {@link DefaultCouchbaseEnvironment} via spring XML configuration.
|
||||
* <p>
|
||||
* The following properties are supported:<br/><ul>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#managementTimeout(long) managementTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryTimeout(long) queryTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#viewTimeout(long) viewTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#kvTimeout(long) kvTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#connectTimeout(long) connectTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#disconnectTimeout(long) disconnectTimeout}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#dnsSrvEnabled(boolean) dnsSrvEnabled}</li>
|
||||
*
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#dcpEnabled(boolean) dcpEnabled}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslEnabled(boolean) sslEnabled}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslKeystoreFile(String) sslKeystoreFile}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslKeystorePassword(String) sslKeystorePassword}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryEnabled(boolean) queryEnabled}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryPort(int) queryPort}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapHttpEnabled(boolean) bootstrapHttpEnabled}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapCarrierEnabled(boolean) bootstrapCarrierEnabled}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapHttpDirectPort(int) bootstrapHttpDirectPort}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapHttpSslPort(int) bootstrapHttpSslPort}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapCarrierDirectPort(int) bootstrapCarrierDirectPort}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapCarrierSslPort(int) bootstrapCarrierSslPort}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#ioPoolSize(int) ioPoolSize}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#computationPoolSize(int) computationPoolSize}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#responseBufferSize(int) responseBufferSize}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#requestBufferSize(int) requestBufferSize}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#kvEndpoints(int) kvEndpoints}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#viewEndpoints(int) viewEndpoints}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryEndpoints(int) queryEndpoints}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#retryStrategy(RetryStrategy) retryStrategy}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#maxRequestLifetime(long) maxRequestLifetime}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#keepAliveInterval(long) keepAliveInterval}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#autoreleaseAfter(long) autoreleaseAfter}</li>
|
||||
* <li>{@link DefaultCouchbaseEnvironment.Builder#bufferPoolingEnabled(boolean) bufferPoolingEnabled}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* Resolve the bean ID and assign a default if not set.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @param definition the bean definition to work with.
|
||||
* @param parserContext encapsulates the parsing state and configuration.
|
||||
* @return the ID to work with.
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(final Element element, final AbstractBeanDefinition definition, final ParserContext parserContext) {
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
return StringUtils.hasText(id) ? id : BeanNames.COUCHBASE_ENV;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the bean class that will be constructed.
|
||||
*
|
||||
* @param element the XML element which contains the attributes.
|
||||
* @return the class type to instantiate.
|
||||
*/
|
||||
@Override
|
||||
protected Class getBeanClass(final Element element) {
|
||||
return CouchbaseEnvironmentFactoryBean.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the bean definition and build up the bean.
|
||||
*
|
||||
* @param envElement the XML element which contains the attributes.
|
||||
* @param envDefinitionBuilder the builder which builds the bean.
|
||||
*/
|
||||
@Override
|
||||
protected void doParse(final Element envElement, final BeanDefinitionBuilder envDefinitionBuilder) {
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "managementTimeout", "managementTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "queryTimeout", "queryTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "viewTimeout", "viewTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "kvTimeout", "kvTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "connectTimeout", "connectTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "disconnectTimeout", "disconnectTimeout");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "dnsSrvEnabled", "dnsSrvEnabled");
|
||||
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "dcpEnabled", "dcpEnabled");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "sslEnabled", "sslEnabled");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "sslKeystoreFile", "sslKeystoreFile");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "sslKeystorePassword", "sslKeystorePassword");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "queryEnabled", "queryEnabled");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "queryPort", "queryPort");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapHttpEnabled", "bootstrapHttpEnabled");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapCarrierEnabled", "bootstrapCarrierEnabled");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapHttpDirectPort", "bootstrapHttpDirectPort");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapHttpSslPort", "bootstrapHttpSslPort");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapCarrierDirectPort", "bootstrapCarrierDirectPort");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapCarrierSslPort", "bootstrapCarrierSslPort");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "ioPoolSize", "ioPoolSize");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "computationPoolSize", "computationPoolSize");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "responseBufferSize", "responseBufferSize");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "requestBufferSize", "requestBufferSize");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "kvEndpoints", "kvEndpoints");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "viewEndpoints", "viewEndpoints");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "queryEndpoints", "queryEndpoints");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "maxRequestLifetime", "maxRequestLifetime");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "keepAliveInterval", "keepAliveInterval");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "autoreleaseAfter", "autoreleaseAfter");
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "bufferPoolingEnabled", "bufferPoolingEnabled");
|
||||
|
||||
//retry strategy is particular, in the xsd this is an enum (FailFast, BestEffort)
|
||||
setPropertyValue(envDefinitionBuilder, envElement, "retryStrategy", "retryStrategy");
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class CouchbaseJmxParser implements BeanDefinitionParser {
|
||||
*
|
||||
* @param clazz the class type to register.
|
||||
* @param compositeDef component that can hold nested components.
|
||||
* @param refName the reference name to the couchbase client.
|
||||
* @param refName the reference name to the couchbase bucket.
|
||||
* @param eleSource source element to reference.
|
||||
* @param parserContext encapsulates the parsing state and configuration.
|
||||
*/
|
||||
|
||||
@@ -34,8 +34,9 @@ public class CouchbaseNamespaceHandler extends NamespaceHandlerSupport {
|
||||
*/
|
||||
public final void init() {
|
||||
//TODO repositories (CouchbaseRepositoryConfigurationExtension and RepositoryBeanDefinitionParser)
|
||||
//TODO bucket
|
||||
//TODO cluster
|
||||
registerBeanDefinitionParser("env", new CouchbaseEnvironmentParser());
|
||||
registerBeanDefinitionParser("cluster", new CouchbaseClusterParser());
|
||||
registerBeanDefinitionParser("bucket", new CouchbaseBucketParser());
|
||||
registerBeanDefinitionParser("jmx", new CouchbaseJmxParser());
|
||||
registerBeanDefinitionParser("template", new CouchbaseTemplateParser());
|
||||
//TODO translation service
|
||||
|
||||
1
src/main/resources/META-INF/spring.handlers
Normal file
1
src/main/resources/META-INF/spring.handlers
Normal file
@@ -0,0 +1 @@
|
||||
http\://www.springframework.org/schema/data/couchbase=org.springframework.data.couchbase.config.CouchbaseNamespaceHandler
|
||||
4
src/main/resources/META-INF/spring.schemas
Normal file
4
src/main/resources/META-INF/spring.schemas
Normal file
@@ -0,0 +1,4 @@
|
||||
http\://www.springframework.org/schema/data/couchbase/spring-couchbase-1.0.xsd=org/springframework/data/couchbase/config/spring-couchbase-1.0.xsd
|
||||
http\://www.springframework.org/schema/data/couchbase/spring-couchbase-2.0.xsd=org/springframework/data/couchbase/config/spring-couchbase-2.0.xsd
|
||||
http\://www.springframework.org/schema/data/couchbase/spring-couchbase-env-2.0.xsd=org/springframework/data/couchbase/config/spring-couchbase-env-2.0.xsd
|
||||
http\://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd=org/springframework/data/couchbase/config/spring-couchbase-2.0.xsd
|
||||
4
src/main/resources/META-INF/spring.tooling
Normal file
4
src/main/resources/META-INF/spring.tooling
Normal file
@@ -0,0 +1,4 @@
|
||||
# Tooling related information for the Couchbase DB namespace
|
||||
http\://www.springframework.org/schema/data/couchbase@name=Couchbase Namespace
|
||||
http\://www.springframework.org/schema/data/couchbase@prefix=couchbase
|
||||
http\://www.springframework.org/schema/data/couchbase@icon=org/springframework/jdbc/config/spring-jdbc.gif
|
||||
@@ -0,0 +1,200 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/data/couchbase"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:repository="http://www.springframework.org/schema/data/repository"
|
||||
targetNamespace="http://www.springframework.org/schema/data/couchbase"
|
||||
elementFormDefault="qualified" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/context"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/data/repository" schemaLocation="http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd"/>
|
||||
|
||||
<xsd:element name="couchbase" type="couchbaseType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.data.couchbase.core.CouchbaseFactoryBean"><![CDATA[
|
||||
Defines a CouchbaseClient instance used for accessing a Couchbase Cluster.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="com.couchbase.client.CouchbaseClient"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="repositories">
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="repository:repositories">
|
||||
<xsd:attributeGroup ref="couchbase-repository-attributes"/>
|
||||
<xsd:attributeGroup ref="repository:repository-attributes"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="template">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The id of the couchbase definition (by default "couchbaseFactory").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="client-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
The reference to a CouchbaseClient object.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="com.couchbase.client.CouchbaseClient"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="converter-ref" type="converterRef" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to a CouchbaseConverter instance.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.CouchbaseConverter"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="translation-service-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to the Translation Service (by default "translationService").]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.translation.TranslationService"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="translation-service">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The id of the translation-service definition (by default "translationService").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="objectMapper" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to a configured Jackson ObjectMapper.]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="com.fasterxml.jackson.databind.ObjectMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jmx">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a JMX Model MBeans for monitoring a Couchbase cluster'.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="couchbase-ref" type="couchbaseRef" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the Couchbase object that determines what connection to monitor. (by default "couchbase").
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:simpleType name="converterRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.CouchbaseConverter"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="couchbaseTemplateRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.CouchbaseTemplate"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="couchbaseRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.CouchbaseFactoryBean"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:attributeGroup name="couchbase-repository-attributes">
|
||||
<xsd:attribute name="couchbase-template-ref" type="couchbaseTemplateRef" default="couchbaseTemplate">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
The reference to a CouchbaseTemplate. Will default to 'couchbaseTemplate'.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:attributeGroup>
|
||||
|
||||
<xsd:complexType name="couchbaseType">
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the couchbase definition (by default "couchbase").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="bucket" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bucket to connect to. Default is "default".
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="password" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The password of the bucket to connect to. Default is "" (empty).
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="host" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The host to connect to a Couchbase server. Default is localhost.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/data/couchbase"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:repository="http://www.springframework.org/schema/data/repository"
|
||||
targetNamespace="http://www.springframework.org/schema/data/couchbase"
|
||||
elementFormDefault="qualified" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/context"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/data/repository" schemaLocation="http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd"/>
|
||||
|
||||
<xsd:include schemaLocation="spring-couchbase-env-2.0.xsd"/>
|
||||
|
||||
<xsd:element name="env" type="envType" />
|
||||
|
||||
<xsd:element name="cluster">
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="env" type="envType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="node" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="env-ref" type="xsd:string" use="optional"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="bucket">
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attribute name="cluster-ref" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="bucketName" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="bucketPassword" type="xsd:string" use="optional"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="template">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The id of the couchbase definition (by default "couchbaseFactory").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="bucket-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
The reference to a Bucket object.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="com.couchbase.client.java.Bucket"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="converter-ref" type="converterRef" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to a CouchbaseConverter instance.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.CouchbaseConverter"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="translation-service-ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to the Translation Service (by default "translationService").]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.translation.TranslationService"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="translation-service">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The id of the translation-service definition (by default "translationService").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="objectMapper" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The reference to a configured Jackson ObjectMapper.]]>
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="com.fasterxml.jackson.databind.ObjectMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jmx">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a JMX Model MBeans for monitoring a Couchbase cluster'.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="bucket-ref" type="couchbaseBucketRef" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the CouchbaseBucket object that determines what connection to monitor. (by default "couchbaseBucket").
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:simpleType name="converterRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.convert.CouchbaseConverter"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="couchbaseTemplateRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.core.CouchbaseTemplate"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="couchbaseBucketRef">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:assignable-to type="org.springframework.data.couchbase.config.CouchbaseBucketFactoryBean"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/data/couchbase"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
targetNamespace="http://www.springframework.org/schema/data/couchbase"
|
||||
elementFormDefault="qualified" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/context"/>
|
||||
|
||||
|
||||
<xsd:simpleType name="retryStrategyType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="BestEffort"/>
|
||||
<xsd:enumeration value="FailFast"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:complexType name="envType">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attribute name="retryStrategy" type="retryStrategyType"/>
|
||||
|
||||
<xsd:attribute name="managementTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="queryTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="viewTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="kvTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="connectTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="disconnectTimeout" type="xsd:long"/>
|
||||
<xsd:attribute name="dnsSrvEnabled" type="xsd:boolean"/>
|
||||
|
||||
<xsd:attribute name="dcpEnabled" type="xsd:boolean"/>
|
||||
<xsd:attribute name="sslEnabled" type="xsd:boolean"/>
|
||||
<xsd:attribute name="sslKeystoreFile" type="xsd:string"/>
|
||||
<xsd:attribute name="sslKeystorePassword" type="xsd:string"/>
|
||||
<xsd:attribute name="queryEnabled" type="xsd:boolean"/>
|
||||
<xsd:attribute name="queryPort" type="xsd:int"/>
|
||||
<xsd:attribute name="bootstrapHttpEnabled" type="xsd:boolean"/>
|
||||
<xsd:attribute name="bootstrapCarrierEnabled" type="xsd:boolean"/>
|
||||
<xsd:attribute name="bootstrapHttpDirectPort" type="xsd:int"/>
|
||||
<xsd:attribute name="bootstrapHttpSslPort" type="xsd:int"/>
|
||||
<xsd:attribute name="bootstrapCarrierDirectPort" type="xsd:int"/>
|
||||
<xsd:attribute name="bootstrapCarrierSslPort" type="xsd:int"/>
|
||||
<xsd:attribute name="ioPoolSize" type="xsd:int"/>
|
||||
<xsd:attribute name="computationPoolSize" type="xsd:int"/>
|
||||
<xsd:attribute name="responseBufferSize" type="xsd:int"/>
|
||||
<xsd:attribute name="requestBufferSize" type="xsd:int"/>
|
||||
<xsd:attribute name="kvEndpoints" type="xsd:int"/>
|
||||
<xsd:attribute name="viewEndpoints" type="xsd:int"/>
|
||||
<xsd:attribute name="queryEndpoints" type="xsd:int"/>
|
||||
<xsd:attribute name="maxRequestLifetime" type="xsd:long"/>
|
||||
<xsd:attribute name="keepAliveInterval" type="xsd:long"/>
|
||||
<xsd:attribute name="autoreleaseAfter" type="xsd:long"/>
|
||||
<xsd:attribute name="bufferPoolingEnabled" type="xsd:boolean"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class CouchbaseBucketParserTest {
|
||||
|
||||
|
||||
private static DefaultListableBeanFactory factory;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
factory = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
|
||||
int n = reader.loadBeanDefinitions(new ClassPathResource("configurations/couchbaseBucket-bean.xml"));
|
||||
System.out.println(n);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBucketNoCluster() {
|
||||
BeanDefinition def = factory.getBeanDefinition("bucketDefaultNoCluster");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, Object.class);
|
||||
assertThat(holder.getValue(), is(instanceOf(RuntimeBeanReference.class)));
|
||||
|
||||
RuntimeBeanReference clusterRef = (RuntimeBeanReference) holder.getValue();
|
||||
|
||||
assertThat(clusterRef.getBeanName(), is(equalTo(BeanNames.COUCHBASE_CLUSTER)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBucket() throws Exception {
|
||||
BeanDefinition def = factory.getBeanDefinition("bucketDefault");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, Object.class);
|
||||
assertThat(holder.getValue(), is(instanceOf(RuntimeBeanReference.class)));
|
||||
|
||||
RuntimeBeanReference clusterRef = (RuntimeBeanReference) holder.getValue();
|
||||
|
||||
assertThat(clusterRef.getBeanName(), is(equalTo("clusterDefault")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBucketWithName() throws Exception {
|
||||
BeanDefinition def = factory.getBeanDefinition("bucketWithName");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(2)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, Object.class);
|
||||
assertThat(holder.getValue(), is(instanceOf(RuntimeBeanReference.class)));
|
||||
|
||||
RuntimeBeanReference clusterRef = (RuntimeBeanReference) holder.getValue();
|
||||
assertThat(clusterRef.getBeanName(), is(equalTo("clusterDefault")));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder nameHolder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(1, Object.class);
|
||||
assertThat(nameHolder.getValue(), is(instanceOf(String.class)));
|
||||
assertThat(nameHolder.getValue().toString(), is((equalTo("toto"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBucketWithNameAndPassword() throws Exception {
|
||||
BeanDefinition def = factory.getBeanDefinition("bucketWithNameAndPassword");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(3)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, Object.class);
|
||||
assertThat(holder.getValue(), is(instanceOf(RuntimeBeanReference.class)));
|
||||
|
||||
RuntimeBeanReference clusterRef = (RuntimeBeanReference) holder.getValue();
|
||||
assertThat(clusterRef.getBeanName(), is(equalTo("clusterDefault")));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder nameHolder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(1, Object.class);
|
||||
assertThat(nameHolder.getValue(), is(instanceOf(String.class)));
|
||||
assertThat(nameHolder.getValue().toString(), is((equalTo("test"))));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder passwordHolder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(2, Object.class);
|
||||
assertThat(passwordHolder.getValue(), is(instanceOf(String.class)));
|
||||
assertThat(passwordHolder.getValue().toString(), is((equalTo("123"))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class CouchbaseClusterParserTest {
|
||||
|
||||
|
||||
private static DefaultListableBeanFactory factory;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
factory = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
|
||||
int n = reader.loadBeanDefinitions(new ClassPathResource("configurations/couchbaseCluster-bean.xml"));
|
||||
System.out.println(n);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterWithoutSpecificEnv() {
|
||||
BeanDefinition def = factory.getBeanDefinition("clusterDefault");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
assertThat(def.getFactoryMethodName(), is(equalTo("create")));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, CouchbaseEnvironment.class);
|
||||
|
||||
assertThat(holder.getValue(), instanceOf(RuntimeBeanReference.class));
|
||||
RuntimeBeanReference envRef = (RuntimeBeanReference) holder.getValue();
|
||||
|
||||
assertThat(envRef.getBeanName(), is(equalTo("couchbaseEnv")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterWithNodes() {
|
||||
BeanDefinition def = factory.getBeanDefinition("clusterWithNodes");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(2)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
assertThat(def.getFactoryMethodName(), is(equalTo("create")));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(1, List.class);
|
||||
assertThat(holder.getValue(), is(instanceOf(List.class)));
|
||||
List nodes = (List<String>) holder.getValue();
|
||||
|
||||
assertThat(nodes.size(), is(equalTo(2)));
|
||||
assertThat((String) nodes.get(0), is(equalTo("192.1.2.3")));
|
||||
assertThat((String) nodes.get(1), is(equalTo("192.4.5.6")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterWithEnvInline() {
|
||||
BeanDefinition def = factory.getBeanDefinition("clusterWithEnvInline");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, CouchbaseEnvironment.class);
|
||||
GenericBeanDefinition envDef = (GenericBeanDefinition) holder.getValue();
|
||||
|
||||
assertThat(envDef.getBeanClassName(), is(equalTo(CouchbaseEnvironmentFactoryBean.class.getName())));
|
||||
assertThat("unexpected attribute", envDef.getPropertyValues().contains("managementTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterWithEnvRef() {
|
||||
BeanDefinition def = factory.getBeanDefinition("clusterWithEnvRef");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, CouchbaseEnvironment.class);
|
||||
|
||||
assertThat(holder.getValue(), instanceOf(RuntimeBeanReference.class));
|
||||
RuntimeBeanReference envRef = (RuntimeBeanReference) holder.getValue();
|
||||
|
||||
assertThat(envRef.getBeanName(), is(equalTo("someEnv")));
|
||||
}
|
||||
@Test
|
||||
public void testClusterConfigurationPrecedence() {
|
||||
BeanDefinition def = factory.getBeanDefinition("clusterWithAll");
|
||||
|
||||
assertThat(def, is(notNullValue()));
|
||||
assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(2)));
|
||||
assertThat(def.getPropertyValues().size(), is(equalTo(0)));
|
||||
assertThat(def.getFactoryMethodName(), is(equalTo("create")));
|
||||
|
||||
assertThat(def.getConstructorArgumentValues().getIndexedArgumentValues().get(0).getValue(),
|
||||
instanceOf(GenericBeanDefinition.class));
|
||||
assertThat(def.getConstructorArgumentValues().getIndexedArgumentValues().get(1).getValue(),
|
||||
instanceOf(List.class));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holderEnv = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(0, CouchbaseEnvironment.class);
|
||||
GenericBeanDefinition envDef = (GenericBeanDefinition) holderEnv.getValue();
|
||||
|
||||
assertThat(envDef.getBeanClassName(), is(equalTo(CouchbaseEnvironmentFactoryBean.class.getName())));
|
||||
assertThat("unexpected attribute", envDef.getPropertyValues().contains("autoreleaseAfter"));
|
||||
|
||||
ConstructorArgumentValues.ValueHolder holderNodes = def.getConstructorArgumentValues()
|
||||
.getArgumentValue(1, List.class);
|
||||
List nodes = (List<String>) holderNodes.getValue();
|
||||
|
||||
assertThat(nodes.size(), is(equalTo(2)));
|
||||
assertThat((String) nodes.get(0), is(equalTo("2.2.2.2")));
|
||||
assertThat((String) nodes.get(1), is(equalTo("4.4.4.4")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.data.couchbase.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import com.couchbase.client.core.retry.BestEffortRetryStrategy;
|
||||
import com.couchbase.client.core.retry.FailFastRetryStrategy;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class CouchbaseEnvironmentParserTest {
|
||||
|
||||
private static GenericApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("configurations/couchbaseEnv-bean.xml"));
|
||||
context = new GenericApplicationContext(factory);
|
||||
context.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingRetryStrategyFailFast() throws Exception {
|
||||
CouchbaseEnvironment env = context.getBean("envWithFailFast", CouchbaseEnvironment.class);
|
||||
|
||||
assertThat(env.retryStrategy(), is(instanceOf(FailFastRetryStrategy.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingRetryStrategyBestEffort() throws Exception {
|
||||
CouchbaseEnvironment env = context.getBean("envWithBestEffort", CouchbaseEnvironment.class);
|
||||
|
||||
assertThat(env.retryStrategy(), is(instanceOf(BestEffortRetryStrategy.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllDefaultsOverridden() {
|
||||
CouchbaseEnvironment env = context.getBean("envWithNoDefault", CouchbaseEnvironment.class);
|
||||
CouchbaseEnvironment defaultEnv = DefaultCouchbaseEnvironment.create();
|
||||
|
||||
assertThat(env, is(instanceOf(DefaultCouchbaseEnvironment.class)));
|
||||
|
||||
assertThat(env.managementTimeout(), is(equalTo(1L)));
|
||||
assertThat(env.queryTimeout(), is(equalTo(2L)));
|
||||
assertThat(env.viewTimeout(), is(equalTo(3L)));
|
||||
assertThat(env.kvTimeout(), is(equalTo(4L)));
|
||||
assertThat(env.connectTimeout(), is(equalTo(5L)));
|
||||
assertThat(env.disconnectTimeout(), is(equalTo(6L)));
|
||||
assertThat(env.dnsSrvEnabled(), allOf(equalTo(true), not(defaultEnv.dnsSrvEnabled())));
|
||||
|
||||
//TODO activate test when dcp can be enabled on the environment (add it in the xml)
|
||||
// assertThat(env.dcpEnabled(), allOf(equalTo(true), not(defaultEnv.dcpEnabled())));
|
||||
assertThat(env.sslEnabled(), allOf(equalTo(true), not(defaultEnv.sslEnabled())));
|
||||
assertThat(env.sslKeystoreFile(), is(equalTo("test")));
|
||||
assertThat(env.sslKeystorePassword(), is(equalTo("test")));
|
||||
assertThat(env.queryEnabled(), allOf(equalTo(true), not(defaultEnv.queryEnabled())));
|
||||
assertThat(env.queryPort(), is(equalTo(7)));
|
||||
assertThat(env.bootstrapHttpEnabled(), allOf(equalTo(false), not(defaultEnv.bootstrapHttpEnabled())));
|
||||
assertThat(env.bootstrapCarrierEnabled(), allOf(equalTo(false), not(defaultEnv.bootstrapCarrierEnabled())));
|
||||
assertThat(env.bootstrapHttpDirectPort(), is(equalTo(8)));
|
||||
assertThat(env.bootstrapHttpSslPort(), is(equalTo(9)));
|
||||
assertThat(env.bootstrapCarrierDirectPort(), is(equalTo(10)));
|
||||
assertThat(env.bootstrapCarrierSslPort(), is(equalTo(11)));
|
||||
assertThat(env.ioPoolSize(), is(equalTo(12)));
|
||||
assertThat(env.computationPoolSize(), is(equalTo(13)));
|
||||
assertThat(env.responseBufferSize(), is(equalTo(14)));
|
||||
assertThat(env.requestBufferSize(), is(equalTo(15)));
|
||||
assertThat(env.kvEndpoints(), is(equalTo(16)));
|
||||
assertThat(env.viewEndpoints(), is(equalTo(17)));
|
||||
assertThat(env.queryEndpoints(), is(equalTo(18)));
|
||||
assertThat(env.retryStrategy(), is(instanceOf(FailFastRetryStrategy.class)));
|
||||
assertThat(env.maxRequestLifetime(), is(equalTo(19L)));
|
||||
assertThat(env.keepAliveInterval(), is(equalTo(20L)));
|
||||
assertThat(env.autoreleaseAfter(), is(equalTo(21L)));
|
||||
assertThat(env.bufferPoolingEnabled(), allOf(equalTo(false), not(defaultEnv.bufferPoolingEnabled())));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
19
src/test/resources/configurations/couchbaseBucket-bean.xml
Normal file
19
src/test/resources/configurations/couchbaseBucket-bean.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:couchbase="http://www.springframework.org/schema/data/couchbase"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<couchbase:cluster id="clusterDefault" />
|
||||
|
||||
<couchbase:bucket id="bucketDefaultNoCluster" />
|
||||
|
||||
<couchbase:bucket id="bucketDefault" cluster-ref="clusterDefault" />
|
||||
|
||||
<couchbase:bucket id="bucketWithName" cluster-ref="clusterDefault" bucketName="toto" />
|
||||
|
||||
<couchbase:bucket id="bucketWithNameAndPassword" cluster-ref="clusterDefault" bucketName="test" bucketPassword="123" />
|
||||
|
||||
</beans>
|
||||
26
src/test/resources/configurations/couchbaseCluster-bean.xml
Normal file
26
src/test/resources/configurations/couchbaseCluster-bean.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:couchbase="http://www.springframework.org/schema/data/couchbase"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<couchbase:env id="someEnv" retryStrategy="FailFast" />
|
||||
|
||||
<couchbase:cluster id="clusterDefault" />
|
||||
<couchbase:cluster id="clusterWithEnvRef" env-ref="someEnv"/>
|
||||
<couchbase:cluster id="clusterWithEnvInline">
|
||||
<couchbase:env managementTimeout="1"/>
|
||||
</couchbase:cluster>
|
||||
<couchbase:cluster id="clusterWithNodes">
|
||||
<couchbase:node>192.1.2.3</couchbase:node>
|
||||
<couchbase:node>192.4.5.6</couchbase:node>
|
||||
</couchbase:cluster>
|
||||
<couchbase:cluster id="clusterWithAll" env-ref="someEnv">
|
||||
<couchbase:env autoreleaseAfter="8"/>
|
||||
<couchbase:node>2.2.2.2</couchbase:node>
|
||||
<couchbase:node>4.4.4.4</couchbase:node>
|
||||
</couchbase:cluster>
|
||||
|
||||
</beans>
|
||||
48
src/test/resources/configurations/couchbaseEnv-bean.xml
Normal file
48
src/test/resources/configurations/couchbaseEnv-bean.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:couchbase="http://www.springframework.org/schema/data/couchbase"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<couchbase:env id="envWithFailFast" retryStrategy="FailFast" />
|
||||
|
||||
<couchbase:env id="envWithBestEffort" retryStrategy="BestEffort" />
|
||||
|
||||
<couchbase:env id="envWithNoDefault"
|
||||
managementTimeout="1"
|
||||
queryTimeout="2"
|
||||
viewTimeout="3"
|
||||
kvTimeout="4"
|
||||
connectTimeout="5"
|
||||
disconnectTimeout="6"
|
||||
dnsSrvEnabled="true"
|
||||
|
||||
dcpEnabled="false"
|
||||
sslEnabled="true"
|
||||
sslKeystoreFile="test"
|
||||
sslKeystorePassword="test"
|
||||
queryEnabled="true"
|
||||
queryPort="7"
|
||||
bootstrapHttpEnabled="false"
|
||||
bootstrapCarrierEnabled="false"
|
||||
bootstrapHttpDirectPort="8"
|
||||
bootstrapHttpSslPort="9"
|
||||
bootstrapCarrierDirectPort="10"
|
||||
bootstrapCarrierSslPort="11"
|
||||
ioPoolSize="12"
|
||||
computationPoolSize="13"
|
||||
responseBufferSize="14"
|
||||
requestBufferSize="15"
|
||||
kvEndpoints="16"
|
||||
viewEndpoints="17"
|
||||
queryEndpoints="18"
|
||||
retryStrategy="FailFast"
|
||||
maxRequestLifetime="19"
|
||||
keepAliveInterval="20"
|
||||
autoreleaseAfter="21"
|
||||
bufferPoolingEnabled="false"
|
||||
/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user