DATACASS-290 - Polishing.

Align declared type of CassandraCqlTemplateFactoryBean to CqlTemplate and the type of CassandraTemplateFactoryBean to CassandraTemplate to report consistent bean types. Add JavaDoc.

Original pull request: #76.
This commit is contained in:
Mark Paluch
2016-07-13 12:11:29 +02:00
parent 7a5104b13f
commit 6a95208bfd
19 changed files with 244 additions and 83 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@ package org.springframework.cassandra.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cassandra.core.CqlOperations;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.util.Assert;
import com.datastax.driver.core.Session;
@@ -26,38 +26,63 @@ import com.datastax.driver.core.Session;
* Factory for configuring a {@link CqlTemplate}.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlOperations>, InitializingBean {
public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>, InitializingBean {
private CqlTemplate template;
private Session session;
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
@Override
public CqlOperations getObject() {
public CqlTemplate getObject() {
return template;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
public Class<? extends CqlOperations> getObjectType() {
return CqlOperations.class;
public Class<CqlTemplate> getObjectType() {
return CqlTemplate.class;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
@Override
public boolean isSingleton() {
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
if (session == null) {
throw new IllegalStateException("session is required");
}
Assert.notNull(session, "Session must not be null");
this.template = new CqlTemplate(session);
}
/**
* Sets the Cassandra {@link Session} to use. The {@link CqlTemplate} will use the logged keyspace of the underlying
* {@link Session}. Don't change the keyspace using CQL but use multiple {@link Session} and
* {@link CqlTemplate} beans.
*
* @param session must not be {@literal null}.
*/
public void setSession(Session session) {
Assert.notNull(session, "Session must not be null");
this.session = session;
}
}

View File

@@ -52,6 +52,9 @@ import com.datastax.driver.core.SocketOptions;
*/
public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -61,11 +64,13 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
return (StringUtils.hasText(id) ? id : DefaultCqlBeanNames.CLUSTER);
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
CassandraCqlClusterFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CassandraCqlClusterFactoryBean.class);
builder.setLazyInit(parserContext.isDefaultLazyInit());
builder.getRawBeanDefinition().setDestroyMethodName("destroy");
@@ -131,11 +136,11 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
List<String> startupScripts = new ArrayList<String>();
List<String> shutdownScripts = new ArrayList<String>();
BeanDefinitionBuilder poolingOptionsBuilder = BeanDefinitionBuilder.genericBeanDefinition(
PoolingOptionsFactoryBean.class);
BeanDefinitionBuilder poolingOptionsBuilder = BeanDefinitionBuilder
.genericBeanDefinition(PoolingOptionsFactoryBean.class);
addOptionalPropertyReference(poolingOptionsBuilder, "initializationExecutor",
element, "initialization-executor-ref");
addOptionalPropertyReference(poolingOptionsBuilder, "initializationExecutor", element,
"initialization-executor-ref");
addOptionalPropertyValue(poolingOptionsBuilder, "heartbeatIntervalSeconds", element, "heartbeat-interval-seconds");
addOptionalPropertyValue(poolingOptionsBuilder, "idleTimeoutSeconds", element, "idle-timeout-seconds");
@@ -148,8 +153,8 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
String name = subElement.getLocalName();
if ("keyspace".equals(name)) {
keyspaceActionSpecificationBeanDefinitions.add(
newKeyspaceActionSpecificationBeanDefinition(subElement, parserContext));
keyspaceActionSpecificationBeanDefinitions
.add(newKeyspaceActionSpecificationBeanDefinition(subElement, parserContext));
} else if ("local-pooling-options".equals(name)) {
parseLocalPoolingOptions(subElement, poolingOptionsBuilder);
} else if ("remote-pooling-options".equals(name)) {
@@ -163,11 +168,10 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
}
}
builder.addPropertyValue("keyspaceSpecifications", newKeyspaceSetFlattenerBeanDefinition(
element, parserContext, keyspaceActionSpecificationBeanDefinitions));
builder.addPropertyValue("keyspaceSpecifications",
newKeyspaceSetFlattenerBeanDefinition(element, parserContext, keyspaceActionSpecificationBeanDefinitions));
builder.addPropertyValue("poolingOptions", getSourceBeanDefinition(
poolingOptionsBuilder, parserContext, element));
builder.addPropertyValue("poolingOptions", getSourceBeanDefinition(poolingOptionsBuilder, parserContext, element));
builder.addPropertyValue("startupScripts", startupScripts);
builder.addPropertyValue("shutdownScripts", shutdownScripts);
@@ -182,15 +186,14 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
*/
BeanDefinition newKeyspaceActionSpecificationBeanDefinition(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
KeyspaceActionSpecificationFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(KeyspaceActionSpecificationFactoryBean.class);
// add required replication defaults
addRequiredPropertyValue(builder, "replicationStrategy",
KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name());
addRequiredPropertyValue(builder, "replicationStrategy", KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name());
addRequiredPropertyValue(builder, "replicationFactor",
String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR));
String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR));
addRequiredPropertyValue(builder, "name", element, "name");
addOptionalPropertyValue(builder, "durableWrites", element, "durable-writes", "false");
@@ -214,10 +217,10 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
if (element != null) {
addOptionalPropertyValue(builder, "replicationStrategy", element, "class",
KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name());
KeyspaceAttributes.DEFAULT_REPLICATION_STRATEGY.name());
addOptionalPropertyValue(builder, "replicationFactor", element, "replication-factor",
String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR));
String.valueOf(KeyspaceAttributes.DEFAULT_REPLICATION_FACTOR));
// DataCenters only apply to NetworkTopologyStrategy
for (Element dataCenter : DomUtils.getChildElementsByTagName(element, "data-center")) {
@@ -241,8 +244,8 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
Object newKeyspaceSetFlattenerBeanDefinition(Element element, ParserContext parserContext,
ManagedSet<BeanDefinition> keyspaceActionSpecificationBeanDefinitions) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
MultiLevelSetFlattenerFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(MultiLevelSetFlattenerFactoryBean.class);
builder.addPropertyValue("multiLevelSet", keyspaceActionSpecificationBeanDefinitions);

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.cassandra.config.xml;
import static org.springframework.cassandra.config.xml.ParsingUtils.addOptionalPropertyReference;
import static org.springframework.cassandra.config.xml.ParsingUtils.addRequiredPropertyReference;
import static org.springframework.cassandra.config.xml.ParsingUtils.addRequiredPropertyValue;
import static org.springframework.cassandra.config.xml.ParsingUtils.*;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -39,11 +37,17 @@ import org.w3c.dom.NamedNodeMap;
*/
public class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return CassandraCqlSessionFactoryBean.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -67,10 +71,13 @@ public class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParse
*/
protected void parseUnhandledSessionElementAttribute(Attr attribute, ParserContext parserContext,
BeanDefinitionBuilder builder) {
throw new IllegalStateException(String.format("encountered unhandled session element attribute [%s]",
attribute.getName()));
throw new IllegalStateException(
String.format("encountered unhandled session element attribute [%s]", attribute.getName()));
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
@@ -108,7 +115,8 @@ public class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParse
}
}
protected void parseSessionChildElements(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
protected void parseSessionChildElements(Element element, ParserContext parserContext,
BeanDefinitionBuilder builder) {
for (Element child : DomUtils.getChildElements(element)) {

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.cassandra.config.xml;
import static org.springframework.cassandra.config.xml.ParsingUtils.addOptionalPropertyReference;
import static org.springframework.cassandra.config.xml.ParsingUtils.*;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -34,11 +34,17 @@ import org.w3c.dom.Element;
*/
public class CassandraCqlTemplateParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return CassandraCqlTemplateFactoryBean.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -47,6 +53,9 @@ public class CassandraCqlTemplateParser extends AbstractSingleBeanDefinitionPars
return StringUtils.hasText(id) ? id : DefaultCqlBeanNames.TEMPLATE;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
addOptionalPropertyReference(builder, "session", element, "session-ref", DefaultCqlBeanNames.SESSION);

View File

@@ -25,6 +25,9 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
*/
public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
*/
@Override
public void init() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2017 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.
@@ -22,7 +22,7 @@ package org.springframework.cassandra.config.xml;
*/
public interface DefaultCqlBeanNames {
public static final String CLUSTER = "cassandraCluster";
public static final String SESSION = "cassandraSession";
public static final String TEMPLATE = "cqlTemplate";
String CLUSTER = "cassandraCluster";
String SESSION = "cassandraSession";
String TEMPLATE = "cqlTemplate";
}

View File

@@ -152,7 +152,7 @@ public class BeanDefinitionUtils {
try {
beanDefinition = registry.getBeanDefinition(name);
} catch (NoSuchBeanDefinitionException x) {
if (FactoryBean.class.isAssignableFrom(type)) { // try unmangled BeanFactory-prefixed name
if (FactoryBean.class.isAssignableFrom(type)) { // try unmanged BeanFactory-prefixed name
name = name.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
} else {
throw x;

View File

@@ -42,7 +42,9 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
protected static final boolean DEFAULT_DROP_UNUSED_TABLES = false;
private CassandraAdminOperations admin;
private CassandraConverter converter;
private SchemaAction schemaAction = SchemaAction.NONE;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 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.
@@ -18,45 +18,84 @@ package org.springframework.data.cassandra.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.util.Assert;
import com.datastax.driver.core.Session;
public class CassandraTemplateFactoryBean implements FactoryBean<CassandraOperations>, InitializingBean {
/**
* Factory for configuring a {@link CassandraTemplate}.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraTemplateFactoryBean implements FactoryBean<CassandraTemplate>, InitializingBean {
protected Session session;
protected CassandraConverter converter;
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(session);
Assert.notNull(converter);
Assert.notNull(session, "Session must not be null");
Assert.notNull(converter, "Converter must not be null");
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
@Override
public CassandraOperations getObject() throws Exception {
public CassandraTemplate getObject() throws Exception {
return new CassandraTemplate(session, converter);
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
public Class<?> getObjectType() {
return CassandraOperations.class;
public Class<CassandraTemplate> getObjectType() {
return CassandraTemplate.class;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
@Override
public boolean isSingleton() {
return true;
}
/**
* Sets the Cassandra {@link Session} to use. The {@link CassandraTemplate} will use the logged keyspace of the
* underlying {@link Session}. Don't change the keyspace using CQL but use multiple {@link Session} and
* {@link CassandraTemplate} beans.
*
* @param session must not be {@literal null}.
*/
public void setSession(Session session) {
Assert.notNull(session);
Assert.notNull(session, "Session must not be null");
this.session = session;
}
/**
* Set the {@link CassandraConverter} to use.
*
* @param converter must not be {@literal null}.
*/
public void setConverter(CassandraConverter converter) {
Assert.notNull(converter);
Assert.notNull(converter, "Converter must not be null");
this.converter = converter;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,13 @@ package org.springframework.data.cassandra.config;
import org.springframework.cassandra.config.xml.DefaultCqlBeanNames;
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
public interface DefaultBeanNames extends DefaultCqlBeanNames {
public static final String DATA_TEMPLATE = "cassandraTemplate";
public static final String CONVERTER = "cassandraConverter";
public static final String CONTEXT = "cassandraMapping";
public static final String USER_TYPE_RESOLVER = "userTypeResolver";
String DATA_TEMPLATE = "cassandraTemplate";
String CONVERTER = "cassandraConverter";
String CONTEXT = "cassandraMapping";
}

View File

@@ -21,12 +21,16 @@ import org.springframework.cassandra.config.xml.CassandraCqlClusterParser;
import org.w3c.dom.Element;
/**
* Spring Data Cassandra XML namespace parser for the &lt;cluster&gt; element.
* Spring Data Cassandra XML namespace parser for the {@code cassandra:cluster} element.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraClusterParser extends CassandraCqlClusterParser {
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlClusterParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors
* Copyright 2013-2017 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.
@@ -41,17 +41,24 @@ import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* Spring Data Cassandra XML namespace parser for the &lt;mapping&gt; element.
* Spring Data Cassandra XML namespace parser for the {@code cassandra:mapping} element.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return BasicCassandraMappingContext.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -61,6 +68,9 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
return (StringUtils.hasText(id) ? id : DefaultBeanNames.CONTEXT);
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
@@ -75,14 +85,13 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
if (StringUtils.hasText(packages)) {
try {
Set<Class<?>> entityClasses = CassandraEntityClassScanner.scan(
StringUtils.commaDelimitedListToStringArray(packages));
Set<Class<?>> entityClasses = CassandraEntityClassScanner
.scan(StringUtils.commaDelimitedListToStringArray(packages));
builder.addPropertyValue("initialEntitySet", entityClasses);
} catch (Exception x) {
throw new IllegalArgumentException(
String.format("encountered exception while scanning for entity classes in package(s) [%s]",
packages), x);
String.format("encountered exception while scanning for entity classes in package(s) [%s]", packages), x);
}
}
@@ -105,7 +114,7 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
builder.addPropertyReference("userTypeResolver", userTypeResolverRef);
}
if (!userTypeResolvers.isEmpty()){
if (!userTypeResolvers.isEmpty()) {
BeanDefinition userTypeResolver = parseUserTypeResolver(userTypeResolvers.get(0));
builder.addPropertyValue("userTypeResolver", userTypeResolver);
}

View File

@@ -26,17 +26,24 @@ import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Spring Data Cassandra XML namespace parser for the &lt;converter&gt; element.
* Spring Data Cassandra XML namespace parser for the {@code cassandra:converter} element.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraMappingConverterParser extends AbstractSingleBeanDefinitionParser {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return MappingCassandraConverter.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -45,6 +52,9 @@ public class CassandraMappingConverterParser extends AbstractSingleBeanDefinitio
return StringUtils.hasText(id) ? id : DefaultBeanNames.CONVERTER;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.config.xml;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
@@ -25,17 +24,22 @@ import org.springframework.data.repository.config.RepositoryBeanDefinitionParser
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
*/
@Override
public void init() {
registerBeanDefinitionParser("cluster", new CassandraClusterParser());
registerBeanDefinitionParser("session", new CassandraSessionParser());
registerBeanDefinitionParser("template", new CassandraTemplateParser());
registerBeanDefinitionParser("converter", new CassandraMappingConverterParser());
registerBeanDefinitionParser("mapping", new CassandraMappingContextParser());
registerBeanDefinitionParser("repositories", new RepositoryBeanDefinitionParser(
new CassandraRepositoryConfigurationExtension()));
registerBeanDefinitionParser("repositories",
new RepositoryBeanDefinitionParser(new CassandraRepositoryConfigurationExtension()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 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.
@@ -15,10 +15,7 @@
*/
package org.springframework.data.cassandra.config.xml;
import static org.springframework.cassandra.config.xml.ParsingUtils.addOptionalPropertyReference;
import static org.springframework.cassandra.config.xml.ParsingUtils.addOptionalPropertyValue;
import static org.springframework.cassandra.config.xml.ParsingUtils.addRequiredPropertyReference;
import static org.springframework.cassandra.config.xml.ParsingUtils.addRequiredPropertyValue;
import static org.springframework.cassandra.config.xml.ParsingUtils.*;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -30,17 +27,24 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Element;
/**
* Spring Data Cassandra XML namespace parser for the &lt;session&gt; element.
* Spring Data Cassandra XML namespace parser for the {@code cassandra:session} element.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraSessionParser extends CassandraCqlSessionParser {
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlSessionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return CassandraSessionFactoryBean.class;
}
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlSessionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
@@ -49,6 +53,9 @@ public class CassandraSessionParser extends CassandraCqlSessionParser {
CassandraMappingXmlBeanFactoryPostProcessorRegistrar.ensureRegistration(element, parserContext);
}
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlSessionParser#parseUnhandledSessionElementAttribute(org.w3c.dom.Attr, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void parseUnhandledSessionElementAttribute(Attr attribute, ParserContext parserContext,
BeanDefinitionBuilder builder) {
@@ -64,6 +71,9 @@ public class CassandraSessionParser extends CassandraCqlSessionParser {
}
}
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlSessionParser#setDefaultProperties(org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void setDefaultProperties(BeanDefinitionBuilder builder) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 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.
@@ -20,31 +20,44 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.cassandra.config.xml.CassandraCqlTemplateParser;
import org.springframework.data.cassandra.config.DefaultBeanNames;
import org.springframework.data.cassandra.config.CassandraTemplateFactoryBean;
import org.springframework.data.cassandra.config.DefaultBeanNames;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Spring Data Cassandra XML namespace parser for the &lt;template&gt; element.
* Spring Data Cassandra XML namespace parser for the {@code cassandra:template} element.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraTemplateParser extends CassandraCqlTemplateParser {
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlTemplateParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return CassandraTemplateFactoryBean.class;
}
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlTemplateParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
// TODO: super.resolveId resolves always to a non-empty id because its fallback is DefaultCqlBeanNames.TEMPLATE.
// This also means that CassandraTemplate is exposed as bean named cqlTemplate. This should change with 2.0
// because 2.0 breaks up inheritance.
String id = super.resolveId(element, definition, parserContext);
return StringUtils.hasText(id) ? id : DefaultBeanNames.DATA_TEMPLATE;
}
/* (non-Javadoc)
* @see org.springframework.cassandra.config.xml.CassandraCqlTemplateParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2017 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.
@@ -29,11 +29,17 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
*/
public class CassandraRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport {
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getAnnotation()
*/
@Override
protected Class<? extends Annotation> getAnnotation() {
return EnableCassandraRepositories.class;
}
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getExtension()
*/
@Override
protected RepositoryConfigurationExtension getExtension() {
return new CassandraRepositoryConfigurationExtension();

View File

@@ -20,9 +20,9 @@ import java.util.Collection;
import java.util.Collections;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.cassandra.config.xml.DefaultCqlBeanNames;
import org.springframework.cassandra.config.xml.ParsingUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.data.cassandra.config.DefaultBeanNames;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.support.CassandraRepositoryFactoryBean;
@@ -44,25 +44,38 @@ public class CassandraRepositoryConfigurationExtension extends RepositoryConfigu
private static final String CASSANDRA_TEMPLATE_REF = "cassandra-template-ref";
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix()
*/
@Override
protected String getModulePrefix() {
return "cassandra";
}
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName()
*/
@Override
public String getRepositoryFactoryClassName() {
return CassandraRepositoryFactoryBean.class.getName();
}
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.XmlRepositoryConfigurationSource)
*/
@Override
public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {
Element element = config.getElement();
// TODO: XML-based configuration uses a different bean name than Java config
ParsingUtils.addOptionalPropertyReference(builder, "cassandraTemplate", element, CASSANDRA_TEMPLATE_REF,
DefaultBeanNames.TEMPLATE);
DefaultCqlBeanNames.TEMPLATE);
}
/* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
*/
@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

View File

@@ -818,7 +818,7 @@ The reference to a UserTypeResolver. UserTypeResolver is required when working w
<xsd:attribute name="cassandra-template-ref" type="cassandraTemplateRef">
<xsd:annotation>
<xsd:documentation><![CDATA[
The reference to a CassandraTemplate. Will default to 'cassandraTemplate'.
The reference to a CassandraTemplate. Will default to 'cqlTemplate'.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>