diff --git a/spring-cassandra/pom.xml b/spring-cassandra/pom.xml
index b3afd4fd1..666c35b88 100644
--- a/spring-cassandra/pom.xml
+++ b/spring-cassandra/pom.xml
@@ -41,6 +41,11 @@
org.springframework
spring-tx
+
+ ${project.groupId}
+ spring-data-commons
+ ${springdata.commons}
+
com.datastax.cassandra
cassandra-driver-core
diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/config/CassandraClusterFactoryBean.java b/spring-cassandra/src/main/java/org/springframework/cassandra/config/CassandraClusterFactoryBean.java
index cdd63f6c4..5c7610159 100644
--- a/spring-cassandra/src/main/java/org/springframework/cassandra/config/CassandraClusterFactoryBean.java
+++ b/spring-cassandra/src/main/java/org/springframework/cassandra/config/CassandraClusterFactoryBean.java
@@ -16,8 +16,10 @@
package org.springframework.cassandra.config;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,7 +31,7 @@ import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerat
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.core.keyspace.KeyspaceNameSpecification;
+import org.springframework.cassandra.core.keyspace.KeyspaceActionSpecification;
import org.springframework.cassandra.support.CassandraExceptionTranslator;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
@@ -51,6 +53,7 @@ import com.datastax.driver.core.policies.RetryPolicy;
*
* @author Alex Shvid
* @author Matthew T. Adams
+ * @author David Webb
*/
public class CassandraClusterFactoryBean implements FactoryBean, InitializingBean, DisposableBean,
PersistenceExceptionTranslator {
@@ -62,9 +65,10 @@ public class CassandraClusterFactoryBean implements FactoryBean, Initia
protected static final Logger log = LoggerFactory.getLogger(CassandraClusterFactoryBean.class);
private Cluster cluster;
+ private boolean accumulating = true;
- /**
- * Comma-delimited string of servers.
+ /*
+ * Attributes needed for cluster builder
*/
private String contactPoints = DEFAULT_CONTACT_POINTS;
private int port = CassandraClusterFactoryBean.DEFAULT_PORT;
@@ -77,6 +81,7 @@ public class CassandraClusterFactoryBean implements FactoryBean, Initia
private ReconnectionPolicy reconnectionPolicy;
private RetryPolicy retryPolicy;
private boolean metricsEnabled = DEFAULT_METRICS_ENABLED;
+ private Set> keyspaceSpecifications = new HashSet>();
private List keyspaceCreations = new ArrayList();
private List keyspaceDrops = new ArrayList();
private List startupScripts = new ArrayList();
@@ -152,9 +157,31 @@ public class CassandraClusterFactoryBean implements FactoryBean, Initia
}
cluster = builder.build();
+
+ generateSpecificationsFromFactoryBeans();
+
executeSpecsAndScripts(keyspaceCreations, startupScripts);
}
+ /**
+ * Examines the contents of all the KeyspaceSpecificationFactoryBeans and generates the proper KeyspaceSpecification
+ * from them.
+ */
+ private void generateSpecificationsFromFactoryBeans() {
+
+ for (KeyspaceActionSpecification> spec : keyspaceSpecifications) {
+
+ if (spec instanceof CreateKeyspaceSpecification) {
+ keyspaceCreations.add((CreateKeyspaceSpecification) spec);
+ }
+ if (spec instanceof DropKeyspaceSpecification) {
+ keyspaceDrops.add((DropKeyspaceSpecification) spec);
+ }
+
+ }
+
+ }
+
protected void executeSpecsAndScripts(@SuppressWarnings("rawtypes") List specs, List scripts) {
Session system = null;
@@ -167,7 +194,7 @@ public class CassandraClusterFactoryBean implements FactoryBean, Initia
Iterator> i = specs.iterator();
while (i.hasNext()) {
- KeyspaceNameSpecification> spec = (KeyspaceNameSpecification>) i.next();
+ KeyspaceActionSpecification> spec = (KeyspaceActionSpecification>) i.next();
String cql = (spec instanceof CreateKeyspaceSpecification) ? new CreateKeyspaceCqlGenerator(
(CreateKeyspaceSpecification) spec).toCql() : new DropKeyspaceCqlGenerator(
(DropKeyspaceSpecification) spec).toCql();
@@ -343,4 +370,35 @@ public class CassandraClusterFactoryBean implements FactoryBean, Initia
return socketOptions;
}
+
+ /**
+ * @return Returns the keyspaceSpecifications.
+ */
+ public Set> getKeyspaceSpecifications() {
+ return keyspaceSpecifications;
+ }
+
+ /**
+ * If accumlating is true, we append to the list, otherwise we replace the list.
+ *
+ * @param keyspaceSpecifications The keyspaceSpecifications to set.
+ */
+ public void setKeyspaceSpecifications(Set> keyspaceSpecifications) {
+ log.info("Setter Called");
+ this.keyspaceSpecifications = keyspaceSpecifications;
+ }
+
+ /**
+ * @return Returns the accumulating.
+ */
+ public boolean isAccumulating() {
+ return accumulating;
+ }
+
+ /**
+ * @param accumulating The accumulating to set.
+ */
+ public void setAccumulating(boolean accumulating) {
+ this.accumulating = accumulating;
+ }
}
diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceAction.java b/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceAction.java
new file mode 100644
index 000000000..51f6e93c6
--- /dev/null
+++ b/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceAction.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2010-2012 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.cassandra.config;
+
+/**
+ * Available actions for Keyspace Specifications
+ *
+ * @author David Webb
+ */
+public enum KeyspaceAction {
+ CREATE, CREATE_DROP, ALTER;
+}
diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java b/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java
new file mode 100644
index 000000000..5fb25d3fe
--- /dev/null
+++ b/spring-cassandra/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2011-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.cassandra.config;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+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.keyspace.CreateKeyspaceSpecification;
+import org.springframework.cassandra.core.keyspace.DefaultOption;
+import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
+import org.springframework.cassandra.core.keyspace.KeyspaceActionSpecification;
+import org.springframework.cassandra.core.keyspace.KeyspaceOption;
+import org.springframework.cassandra.core.keyspace.Option;
+import org.springframework.util.Assert;
+
+/**
+ * @author David Webb (dwebb@brightmove.com)
+ *
+ */
+public class KeyspaceActionSpecificationFactoryBean implements FactoryBean>>,
+ InitializingBean, DisposableBean {
+
+ private final static Logger log = LoggerFactory.getLogger(KeyspaceActionSpecificationFactoryBean.class);
+
+ private KeyspaceAction action;
+ private String name;
+ private Map