DATACASS-55 : WIP : now parsing XML ok for CREATE & CREATE-DROP

This commit is contained in:
Matthew Adams
2014-01-06 13:00:57 -06:00
parent 0191d38c47
commit 1da819d7db
11 changed files with 463 additions and 32 deletions

View File

@@ -15,9 +15,19 @@
*/
package org.springframework.cassandra.config;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cassandra.core.CassandraTemplate;
import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator;
import org.springframework.cassandra.core.cql.generator.DropKeyspaceCqlGenerator;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
import org.springframework.cassandra.support.CassandraExceptionTranslator;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
@@ -28,6 +38,7 @@ import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.HostDistance;
import com.datastax.driver.core.PoolingOptions;
import com.datastax.driver.core.ProtocolOptions.Compression;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SocketOptions;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.ReconnectionPolicy;
@@ -39,10 +50,11 @@ import com.datastax.driver.core.policies.RetryPolicy;
* @author Alex Shvid
* @author Matthew T. Adams
*/
public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, InitializingBean, DisposableBean,
PersistenceExceptionTranslator {
protected static final Logger log = LoggerFactory.getLogger(CassandraClusterFactoryBean.class);
private static final int DEFAULT_PORT = 9042;
private Cluster cluster;
@@ -64,6 +76,12 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
private final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
private List<CreateKeyspaceSpecification> keyspaceCreations = new ArrayList<CreateKeyspaceSpecification>();
private List<DropKeyspaceSpecification> keyspaceDrops = new ArrayList<DropKeyspaceSpecification>();
private List<String> scripts = new ArrayList<String>();
@Override
public Cluster getObject() throws Exception {
return cluster;
}
@@ -72,6 +90,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
public Class<? extends Cluster> getObjectType() {
return Cluster.class;
}
@@ -80,6 +99,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
@Override
public boolean isSingleton() {
return true;
}
@@ -88,6 +108,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
* (non-Javadoc)
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
*/
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return exceptionTranslator.translateExceptionIfPossible(ex);
}
@@ -96,6 +117,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
if (!StringUtils.hasText(contactPoints)) {
@@ -146,13 +168,72 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
// initialize property
this.cluster = cluster;
processKeyspaceCreations();
executeCqlScripts();
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.DisposableBean#destroy()
*/
protected void processKeyspaceCreations() {
Session system = null;
try {
system = keyspaceCreations.size() > 0 ? cluster.connect() : null;
CassandraTemplate template = system == null ? null : new CassandraTemplate(system);
for (CreateKeyspaceSpecification spec : this.keyspaceCreations) {
String cql = new CreateKeyspaceCqlGenerator(spec).toCql();
if (log.isDebugEnabled()) {
log.info("executing CQL [{}]", cql);
}
template.execute(cql);
}
} finally {
if (system != null) {
system.shutdown();
}
}
}
protected void executeCqlScripts() {
Session system = null;
try {
system = scripts.size() > 0 ? cluster.connect() : null;
CassandraTemplate template = system == null ? null : new CassandraTemplate(system);
for (String cql : this.scripts) {
if (cql.trim().length() == 0) {
continue;
}
template.execute(cql);
}
} finally {
if (system != null) {
system.shutdown();
}
}
}
@Override
public void destroy() throws Exception {
Session system = null;
try {
system = keyspaceDrops.size() > 0 ? cluster.connect() : null;
CassandraTemplate template = new CassandraTemplate(system);
for (DropKeyspaceSpecification spec : this.keyspaceDrops) {
template.execute(new DropKeyspaceCqlGenerator(spec).toCql());
}
} finally {
if (system != null) {
system.shutdown();
}
}
this.cluster.shutdown();
}
@@ -200,6 +281,26 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
this.metricsEnabled = metricsEnabled;
}
public void setKeyspaceCreations(List<CreateKeyspaceSpecification> specifications) {
this.keyspaceCreations = specifications;
}
public List<CreateKeyspaceSpecification> getKeyspaceCreations() {
return keyspaceCreations;
}
public void setKeyspaceDrops(List<DropKeyspaceSpecification> specifications) {
this.keyspaceDrops = specifications;
}
public List<DropKeyspaceSpecification> getKeyspaceDrops() {
return keyspaceDrops;
}
public void setScripts(List<String> scripts) {
this.scripts = scripts;
}
private static Compression convertCompressionType(CompressionType type) {
switch (type) {
case NONE:

View File

@@ -15,7 +15,10 @@
*/
package org.springframework.cassandra.config.xml;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -27,9 +30,15 @@ import org.springframework.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.cassandra.config.CompressionType;
import org.springframework.cassandra.config.PoolingOptionsConfig;
import org.springframework.cassandra.config.SocketOptionsConfig;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.DefaultOption;
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
import org.springframework.cassandra.core.keyspace.Option;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Parser for &lt;cluster;gt; definitions.
@@ -45,10 +54,6 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser {
return CassandraClusterFactoryBean.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 {
@@ -79,6 +84,11 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser {
}
protected void parseChildElements(BeanDefinitionBuilder builder, Element element) {
List<CreateKeyspaceSpecification> creates = new ArrayList<CreateKeyspaceSpecification>();
List<DropKeyspaceSpecification> drops = new ArrayList<DropKeyspaceSpecification>();
List<String> scripts = new ArrayList<String>();
List<Element> elements = DomUtils.getChildElements(element);
// parse nested elements
@@ -91,9 +101,101 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser {
builder.addPropertyValue("remotePoolingOptions", parsePoolingOptions(subElement));
} else if ("socket-options".equals(name)) {
builder.addPropertyValue("socketOptions", parseSocketOptions(subElement));
} else if ("keyspace".equals(name)) {
KeyspaceSpecifications specifications = parseKeyspace(subElement);
if (specifications.create != null) {
creates.add(specifications.create);
}
if (specifications.drop != null) {
drops.add(specifications.drop);
}
} else if ("cql".equals(name)) {
scripts.add(parseScript(subElement));
}
}
builder.addPropertyValue("keyspaceCreations", creates);
builder.addPropertyValue("keyspaceDrops", drops);
builder.addPropertyValue("scripts", scripts);
}
private KeyspaceSpecifications parseKeyspace(Element element) {
CreateKeyspaceSpecification create = null;
DropKeyspaceSpecification drop = null;
String name = element.getAttribute("name");
if (name == null || name.trim().length() == 0) {
name = BeanNames.CASSANDRA_KEYSPACE;
}
boolean durableWrites = Boolean.valueOf(element.getAttribute("durable-writes"));
String action = element.getAttribute("action");
if (action == null || action.trim().length() == 0) {
throw new IllegalArgumentException("attribute action must be given");
}
if (action.startsWith("CREATE")) {
create = CreateKeyspaceSpecification.createKeyspace().name(name)
.with(KeyspaceOption.DURABLE_WRITES, durableWrites);
NodeList nodes = element.getElementsByTagName("replication");
parseReplication((Element) (nodes.getLength() == 1 ? nodes.item(0) : null), create);
}
if (action.equals("CREATE-DROP")) {
drop = DropKeyspaceSpecification.dropKeyspace().name(create.getName());
}
return new KeyspaceSpecifications(create, drop);
}
protected void parseReplication(Element element, CreateKeyspaceSpecification create) {
String strategyClass = null;
if (element != null) {
strategyClass = element.getAttribute("class");
}
if (strategyClass == null || strategyClass.trim().length() == 0) {
strategyClass = "SimpleStrategy";
}
Long replicationFactor = null;
if (element != null) {
String s = element.getAttribute("replication-factor");
replicationFactor = (s == null || s.trim().length() == 0) ? null : Long.parseLong(s);
}
if (replicationFactor == null) {
replicationFactor = 1L;
}
Map<Option, Object> replicationMap = new HashMap<Option, Object>();
replicationMap.put(new DefaultOption("class", String.class, false, false, true), strategyClass);
replicationMap.put(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor);
if (element != null) {
NodeList dataCenters = element.getElementsByTagName("data-center");
int length = dataCenters.getLength();
for (int i = 0; i < length; i++) {
Element dataCenter = (Element) dataCenters.item(i);
replicationMap.put(new DefaultOption(dataCenter.getAttribute("name"), Long.class, false, false, true),
dataCenter.getAttribute("replicas-per-node"));
}
}
create.with(KeyspaceOption.REPLICATION, replicationMap);
}
private String parseScript(Element element) {
return element.getTextContent();
}
private BeanDefinition parsePoolingOptions(Element element) {
@@ -121,4 +223,15 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser {
return builder.getBeanDefinition();
}
private static class KeyspaceSpecifications {
public KeyspaceSpecifications(CreateKeyspaceSpecification create, DropKeyspaceSpecification drop) {
this.create = create;
this.drop = drop;
}
public CreateKeyspaceSpecification create;
public DropKeyspaceSpecification drop;
// TODO: public AlterKeyspaceSpecification alter;
}
}

View File

@@ -26,10 +26,11 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
@Override
public void init() {
registerBeanDefinitionParser("cluster", new CassandraClusterParser());
registerBeanDefinitionParser("session", new CassandraSessionParser());
registerBeanDefinitionParser("template", new CassandraTemplateParser());
}
}
}

View File

@@ -35,6 +35,11 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
return new CreateKeyspaceSpecification();
}
@Override
public CreateKeyspaceSpecification name(String name) {
return (CreateKeyspaceSpecification) super.name(name);
}
@Override
public CreateKeyspaceSpecification with(KeyspaceOption option) {
return (CreateKeyspaceSpecification) super.with(option);

View File

@@ -33,7 +33,7 @@ Defines a Cassandra Session.
<xsd:annotation>
<xsd:documentation
source="org.springframework.cassandra.config.xml.TemplateFactoryBean"><![CDATA[
Defines a Cassandra Templat.
Defines a Cassandra Template.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
@@ -67,6 +67,21 @@ Defines a Cassandra Cluster.
</xsd:element>
<xsd:element name="socket-options" type="socketOptionsType"
maxOccurs="1" minOccurs="0"></xsd:element>
<xsd:element name="keyspace" type="keyspaceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines a Cassandra Keyspace.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="cql" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation><![CDATA[
Arbitrary CQL script to be executed against the system keyspace during bean initialization.
]]></xsd:documentation>
</xsd:annotation>
<!-- TODO: cql could come from a resource via a resource attribute... -->
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
@@ -81,7 +96,7 @@ Defines a Cassandra Cluster.
<xsd:annotation>
<xsd:documentation><![CDATA[
The comma separated list of Cassandra servers. Default is localhost.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="port" type="xsd:string" use="optional"
@@ -89,14 +104,14 @@ The comma separated list of Cassandra servers. Default is localhost.
<xsd:annotation>
<xsd:documentation><![CDATA[
The native CQL port to connect to. Default is 9042.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="compression" default="NONE" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The protocol compression option. Default is 'none'.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
@@ -104,14 +119,14 @@ The protocol compression option. Default is 'none'.
<xsd:annotation>
<xsd:documentation><![CDATA[
No compression.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="SNAPPY">
<xsd:annotation>
<xsd:documentation><![CDATA[
Uses SNAPPY compression algorithm.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
@@ -121,7 +136,7 @@ Uses SNAPPY compression algorithm.
<xsd:annotation>
<xsd:documentation><![CDATA[
AuthInfoProvider implementation.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:annotation>
@@ -138,7 +153,7 @@ AuthInfoProvider implementation.
<xsd:annotation>
<xsd:documentation><![CDATA[
LoadBalancingPolicy implementation.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:annotation>
@@ -156,7 +171,7 @@ LoadBalancingPolicy implementation.
<xsd:annotation>
<xsd:documentation><![CDATA[
ReconnectionPolicy implementation.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:annotation>
@@ -174,7 +189,7 @@ ReconnectionPolicy implementation.
<xsd:annotation>
<xsd:documentation><![CDATA[
RetryPolicy implementation.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:annotation>
@@ -217,28 +232,28 @@ RetryPolicy implementation.
<xsd:annotation>
<xsd:documentation><![CDATA[
if the utilisation of opened connections drops below by this configured threshold, then cassandra drops connections till core-connections.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="max-simultaneous-requests" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
If the utilisation of connections reaches this configurable threshold, then cassandra creates more connections up to max-connections.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="core-connections" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
For each host, the driver keeps a core amount of connections open at all time.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="max-connections" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
More connections are created up to a configurable maximum number of connections.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
@@ -248,54 +263,64 @@ More connections are created up to a configurable maximum number of connections.
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets connection timeout for client socket in milliseconds.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="keep-alive" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_KEEPALIVE socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="reuse-address" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_REUSEADDR socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="so-linger" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_LINGER socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="tcp-no-delay" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_TCPNODELAY socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="receive-buffer-size" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_RCVBUF socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="send-buffer-size" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the SO_SNDBUF socket option.
]]></xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="sessionType">
<xsd:sequence>
<xsd:element name="cql" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation><![CDATA[
Arbitrary CQL script to be executed against the named keyspace (like CREATE TABLE, etc) during bean initialization.
]]></xsd:documentation>
</xsd:annotation>
<!-- TODO: cql could come from a resource via a resource attribute... -->
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -339,4 +364,68 @@ The reference to a Cassandra Session; default is 'cassandra-session'.
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="keyspaceType">
<xsd:sequence>
<xsd:element name="replication" type="replicationType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of this keyspace.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="action" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The keyspace action to take at startup. Value "CREATE" creates this keyspace.
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="CREATE">
<xsd:annotation>
<xsd:documentation><![CDATA[
Action value that causes keyspace creation during bean initialization.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="CREATE-DROP">
<xsd:annotation>
<xsd:documentation><![CDATA[
Action value that causes keyspace creation during bean initialization and keyspace dropping during bean destruction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="durable-writes" type="xsd:boolean"
use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
Whether or not the keyspace supports durable writes.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="replicationType">
<xsd:sequence>
<xsd:element name="data-center" type="datacenterType" minOccurs="0" maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" use="optional" default="SimpleStrategy">
</xsd:attribute>
<xsd:attribute name="replication-factor" type="xsd:integer" use="optional" default="1">
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="datacenterType">
<xsd:attribute name="name" type="xsd:string" use="required">
</xsd:attribute>
<xsd:attribute name="replicas-per-node" type="xsd:integer">
</xsd:attribute>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,33 @@
package org.springframework.cassandra.test.integration.config.xml;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Session;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class FullySpecifiedKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
@Override
protected String keyspace() {
return null;
}
@Inject
Session s;
@Test
public void test() {
IntegrationTestUtils.assertKeyspaceExists("full1", s);
IntegrationTestUtils.assertKeyspaceExists("full2", s);
IntegrationTestUtils.assertKeyspaceExists("script1", s);
IntegrationTestUtils.assertKeyspaceExists("script2", s);
}
}

View File

@@ -0,0 +1,30 @@
package org.springframework.cassandra.test.integration.config.xml;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Session;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MinimalKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
@Override
protected String keyspace() {
return null;
}
@Inject
Session s;
@Test
public void test() {
IntegrationTestUtils.assertKeyspaceExists("minimal", s);
}
}

View File

@@ -56,10 +56,12 @@ public class AlterTableCqlGeneratorTests {
public String dropped = "dropped";
@Override
public AlterTableSpecification specification() {
return AlterTableSpecification.alterTable().name(name).alter(altered, alteredType).add(added, addedType);
}
@Override
public AlterTableCqlGenerator generator() {
return new AlterTableCqlGenerator(specification);
}
@@ -98,6 +100,7 @@ public class AlterTableCqlGeneratorTests {
public Map<Option, Object> compactionMap = new LinkedHashMap<Option, Object>();
public Map<Option, Object> compressionMap = new LinkedHashMap<Option, Object>();
@Override
public AlterTableSpecification specification() {
// Compaction
@@ -108,7 +111,7 @@ public class AlterTableCqlGeneratorTests {
compressionMap.put(CompressionOption.CHUNK_LENGTH_KB, 128);
compressionMap.put(CompressionOption.CRC_CHECK_CHANCE, 0.75);
return (AlterTableSpecification) AlterTableSpecification
return AlterTableSpecification
.alterTable()
.name(name)
// .with(TableOption.COMPACT_STORAGE)

View File

@@ -0,0 +1,39 @@
<?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:cass="http://www.springframework.org/schema/cassandra"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/cassandra http://www.springframework.org/schema/cassandra/spring-cassandra-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties" />
<cass:cluster>
<cass:keyspace action="CREATE-DROP" durable-writes="true"
name="full1">
<cass:replication class="SimpleStrategy"
replication-factor="1">
<cass:data-center name="foo" replicas-per-node="1" />
<cass:data-center name="bar" replicas-per-node="2" />
</cass:replication>
</cass:keyspace>
<cass:keyspace action="CREATE-DROP" durable-writes="true"
name="full2">
<cass:replication class="SimpleStrategy"
replication-factor="1">
<cass:data-center name="foo" replicas-per-node="1" />
<cass:data-center name="bar" replicas-per-node="2" />
</cass:replication>
</cass:keyspace>
<cass:cql><![CDATA[
CREATE KEYSPACE script1 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };
]]></cass:cql>
<cass:cql><![CDATA[
${script2}
]]></cass:cql>
</cass:cluster>
<cass:session keyspace-name="full1" />
</beans>

View File

@@ -0,0 +1 @@
script2=CREATE KEYSPACE script2 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };

View File

@@ -0,0 +1,16 @@
<?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:cass="http://www.springframework.org/schema/cassandra"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/cassandra http://www.springframework.org/schema/cassandra/spring-cassandra-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<cass:cluster>
<cass:keyspace action="CREATE-DROP" durable-writes="true"
name="minimal" />
</cass:cluster>
<cass:session keyspace-name="minimal" />
</beans>