From df045de2fa24350ed1c29136f2a31a6b441be281 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 1 Aug 2017 14:58:33 +0200 Subject: [PATCH] DATACASS-482 - Refactor KeyspaceActionSpecificationBean to produce KeyspaceActions. Remove indirection via MultiLevelSetFlattenerFactoryBean and create a KeyspaceActions wrapper that encapsulates the actual actions. Introduce KeyspaceActionSpecificationFactory for keyspace action creation. --- .../config/CassandraClusterFactoryBean.java | 83 ++++++-- .../data/cassandra/config/KeyspaceAction.java | 5 +- .../KeyspaceActionSpecificationFactory.java | 186 ++++++++++++++++++ ...eyspaceActionSpecificationFactoryBean.java | 105 ++++------ .../cassandra/config/KeyspaceActions.java | 43 ++++ .../MultiLevelSetFlattenerFactoryBean.java | 75 ------- .../core/cql/KeyspaceIdentifier.java | 13 +- .../keyspace/AlterKeyspaceSpecification.java | 2 +- .../keyspace/CreateKeyspaceSpecification.java | 2 +- .../keyspace/DropKeyspaceSpecification.java | 2 +- 10 files changed, 349 insertions(+), 167 deletions(-) create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactory.java create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActions.java delete mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/MultiLevelSetFlattenerFactoryBean.java diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java index 8052e5efb..8ef41bc48 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java @@ -16,7 +16,10 @@ package org.springframework.data.cassandra.config; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -52,6 +55,34 @@ import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; /** * {@link org.springframework.beans.factory.FactoryBean} for configuring a Cassandra {@link Cluster}. + *

+ * This factory bean allows configuration and creation of {@link Cluster} bean. Most options default to {@literal null}. + * Unsupported options are configured via {@link ClusterBuilderConfigurer}. + *

+ * The factory bean initializes keyspaces, if configured, accoording to its lifecycle. Keyspaces can be created after + * {@link #afterPropertiesSet() initialization} and dropped when this factory is {@link #destroy() destroyed}. Keyspace + * actions can be configured via {@link #setKeyspaceActions(List) XML} and {@link #setKeyspaceCreations(List) + * programatically}. Additional {@link #getStartupScripts()} and {@link #getShutdownScripts()} are executed after + * running keyspace actions. + *

+ * XML configuration + * + *

+     
+		
+		
+		
+		
+	
+ * 
* * @author Alex Shvid * @author Matthew T. Adams @@ -102,6 +133,7 @@ public class CassandraClusterFactoryBean private List keyspaceCreations = new ArrayList<>(); private List keyspaceDrops = new ArrayList<>(); private Set keyspaceSpecifications = new HashSet<>(); + private List keyspaceActions = new ArrayList<>(); private List startupScripts = new ArrayList<>(); private List shutdownScripts = new ArrayList<>(); @@ -260,7 +292,13 @@ public class CassandraClusterFactoryBean */ private void generateSpecificationsFromFactoryBeans() { - keyspaceSpecifications.forEach(keyspaceActionSpecification -> { + generateSpecifications(keyspaceSpecifications); + keyspaceActions.forEach(actions -> generateSpecifications(actions.getActions())); + } + + private void generateSpecifications(Collection specifications) { + + specifications.forEach(keyspaceActionSpecification -> { if (keyspaceActionSpecification instanceof CreateKeyspaceSpecification) { keyspaceCreations.add((CreateKeyspaceSpecification) keyspaceActionSpecification); @@ -272,17 +310,17 @@ public class CassandraClusterFactoryBean }); } - protected void executeSpecsAndScripts(List kepspaceActionSpecifications, + private void executeSpecsAndScripts(List keyspaceActionSpecifications, List scripts, Cluster cluster) { - if (!CollectionUtils.isEmpty(kepspaceActionSpecifications) || !CollectionUtils.isEmpty(scripts)) { + if (!CollectionUtils.isEmpty(keyspaceActionSpecifications) || !CollectionUtils.isEmpty(scripts)) { Session session = cluster.connect(); try { CqlTemplate template = new CqlTemplate(session); - kepspaceActionSpecifications + keyspaceActionSpecifications .forEach(keyspaceActionSpecification -> template.execute(toCql(keyspaceActionSpecification))); scripts.forEach(template::execute); @@ -429,6 +467,23 @@ public class CassandraClusterFactoryBean this.metricsEnabled = metricsEnabled; } + /** + * @return the {@link List} of {@link KeyspaceActions}. + */ + public List getKeyspaceActions() { + return Collections.unmodifiableList(keyspaceActions); + } + + /** + * Set a {@link List} of {@link KeyspaceActions} to be executed on initialization. Keyspace actions may contain create + * and drop specifications. + * + * @param keyspaceActions the {@link List} of {@link KeyspaceActions}. + */ + public void setKeyspaceActions(List keyspaceActions) { + this.keyspaceActions = new ArrayList<>(keyspaceActions); + } + /** * Set a {@link List} of {@link CreateKeyspaceSpecification create keyspace specifications} that are executed when * this factory is {@link #afterPropertiesSet() initialized}. {@link CreateKeyspaceSpecification Create keyspace @@ -438,14 +493,14 @@ public class CassandraClusterFactoryBean * @param specifications the {@link List} of {@link CreateKeyspaceSpecification create keyspace specifications}. */ public void setKeyspaceCreations(List specifications) { - this.keyspaceCreations = specifications; + this.keyspaceCreations = new ArrayList<>(specifications); } /** * @return {@link List} of {@link CreateKeyspaceSpecification create keyspace specifications}. */ public List getKeyspaceCreations() { - return keyspaceCreations; + return Collections.unmodifiableList(keyspaceCreations); } /** @@ -456,14 +511,14 @@ public class CassandraClusterFactoryBean * @param specifications the {@link List} of {@link DropKeyspaceSpecification drop keyspace specifications}. */ public void setKeyspaceDrops(List specifications) { - this.keyspaceDrops = specifications; + this.keyspaceDrops = new ArrayList<>(specifications); } /** * @return the {@link List} of {@link DropKeyspaceSpecification drop keyspace specifications}. */ public List getKeyspaceDrops() { - return keyspaceDrops; + return Collections.unmodifiableList(keyspaceDrops); } /** @@ -474,14 +529,14 @@ public class CassandraClusterFactoryBean * @param scripts the scripts to execute on startup */ public void setStartupScripts(List scripts) { - this.startupScripts = scripts; + this.startupScripts = new ArrayList<>(scripts); } /** * @return the startup scripts */ public List getStartupScripts() { - return startupScripts; + return Collections.unmodifiableList(startupScripts); } /** @@ -492,28 +547,28 @@ public class CassandraClusterFactoryBean * @param scripts the scripts to execute on shutdown */ public void setShutdownScripts(List scripts) { - this.shutdownScripts = scripts; + this.shutdownScripts = new ArrayList<>(scripts); } /** * @return the shutdown scripts */ public List getShutdownScripts() { - return shutdownScripts; + return Collections.unmodifiableList(shutdownScripts); } /** * @param keyspaceSpecifications The {@link KeyspaceActionSpecification} to set. */ public void setKeyspaceSpecifications(Set keyspaceSpecifications) { - this.keyspaceSpecifications = keyspaceSpecifications; + this.keyspaceSpecifications = new LinkedHashSet<>(keyspaceSpecifications); } /** * @return the {@link KeyspaceActionSpecification} associated with this factory. */ public Set getKeyspaceSpecifications() { - return keyspaceSpecifications; + return Collections.unmodifiableSet(keyspaceSpecifications); } /** diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceAction.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceAction.java index 4fdcf87de..8926e9992 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceAction.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceAction.java @@ -16,10 +16,11 @@ package org.springframework.data.cassandra.config; /** - * Available actions for Keyspace Specifications + * Available actions for Keyspace Specifications. * * @author David Webb + * @author Mark Paluch */ public enum KeyspaceAction { - CREATE, CREATE_DROP, ALTER + NONE, CREATE, CREATE_DROP, ALTER } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactory.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactory.java new file mode 100644 index 000000000..8d9f6e4e3 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactory.java @@ -0,0 +1,186 @@ +/* + * Copyright 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. + * 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.cassandra.config; + +import lombok.RequiredArgsConstructor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier; +import org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification; +import org.springframework.data.cassandra.core.cql.keyspace.DataCenterReplication; +import org.springframework.data.cassandra.core.cql.keyspace.DefaultOption; +import org.springframework.data.cassandra.core.cql.keyspace.DropKeyspaceSpecification; +import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption; +import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption.ReplicationStrategy; +import org.springframework.data.cassandra.core.cql.keyspace.Option; + +/** + * Factory to create {@link CreateKeyspaceSpecification} and {@link DropKeyspaceSpecification}. + * + * @author Mark Paluch + * @since 2.0 + */ +@RequiredArgsConstructor +class KeyspaceActionSpecificationFactory { + + private final KeyspaceIdentifier name; + + private final List replications; + + private final ReplicationStrategy replicationStrategy; + + private final long replicationFactor; + + private final boolean durableWrites; + + /** + * Create a new {@link KeyspaceActionSpecificationFactoryBuilder} to configure a new + * {@link KeyspaceActionSpecificationFactory}. + * + * @param keyspaceName must not be {@literal null} or empty. + * @return the new {@link KeyspaceActionSpecificationFactoryBuilder} for {@code keyspaceName}. + */ + public static KeyspaceActionSpecificationFactoryBuilder builder(String keyspaceName) { + return builder(KeyspaceIdentifier.of(keyspaceName)); + } + + /** + * Create a new {@link KeyspaceActionSpecificationFactoryBuilder} to configure a new + * {@link KeyspaceActionSpecificationFactory}. + * + * @param keyspaceName must not be {@literal null} or empty. + * @return the new {@link KeyspaceActionSpecificationFactoryBuilder} for {@code keyspaceName}. + */ + public static KeyspaceActionSpecificationFactoryBuilder builder(KeyspaceIdentifier keyspaceName) { + return new KeyspaceActionSpecificationFactoryBuilder(keyspaceName); + } + + /** + * Generate a {@link CreateKeyspaceSpecification} for the keyspace. + * + * @param ifNotExists {@literal true} to include {@code IF NOT EXISTS} rendering in the create statement. + * @return the {@link CreateKeyspaceSpecification}. + */ + public CreateKeyspaceSpecification create(boolean ifNotExists) { + + CreateKeyspaceSpecification create = CreateKeyspaceSpecification.createKeyspace(name).ifNotExists(ifNotExists) + .with(KeyspaceOption.DURABLE_WRITES, durableWrites); + + Map replicationStrategyMap = new HashMap<>(); + replicationStrategyMap.put(new DefaultOption("class", String.class, true, false, true), + replicationStrategy.getValue()); + + if (replicationStrategy == ReplicationStrategy.SIMPLE_STRATEGY) { + replicationStrategyMap.put(new DefaultOption("replication_factor", Long.class, true, false, false), + replicationFactor); + } + + if (replicationStrategy == ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY) { + for (DataCenterReplication datacenter : replications) { + replicationStrategyMap.put(new DefaultOption(datacenter.getDataCenter(), Long.class, true, false, false), + datacenter.getReplicationFactor()); + } + } + + create.with(KeyspaceOption.REPLICATION, replicationStrategyMap); + + return create; + } + + /** + * Generate a {@link DropKeyspaceSpecification} for the keyspace. + * + * @param ifExists {@literal true} to include {@code IF EXISTS} rendering in the drop statement. + * @return the {@link DropKeyspaceSpecification}. + */ + public DropKeyspaceSpecification drop(boolean ifExists) { + return DropKeyspaceSpecification.dropKeyspace(name).ifExists(ifExists); + } + + static class KeyspaceActionSpecificationFactoryBuilder { + + private final KeyspaceIdentifier name; + + private final List replications = new ArrayList<>(); + + private ReplicationStrategy replicationStrategy = ReplicationStrategy.SIMPLE_STRATEGY; + + private long replicationFactor; + + private boolean durableWrites = false; + + private KeyspaceActionSpecificationFactoryBuilder(KeyspaceIdentifier name) { + this.name = name; + } + + /** + * Configure simple replication scheme for the keyspace action factory. + * + * @param replicationFactor the replication factor. + * @return this. + */ + KeyspaceActionSpecificationFactoryBuilder simpleReplication(int replicationFactor) { + + this.replicationFactor = replicationFactor; + + return replicationStrategy(ReplicationStrategy.SIMPLE_STRATEGY); + } + + /** + * Configure datacenter replication scheme for the keyspace action factory. + * + * @param replication the replication configuration. + * @return this. + */ + KeyspaceActionSpecificationFactoryBuilder withDataCenter(DataCenterReplication replication) { + + replicationStrategy(ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY); + this.replications.add(replication); + return this; + } + + private KeyspaceActionSpecificationFactoryBuilder replicationStrategy(ReplicationStrategy strategy) { + + this.replicationStrategy = strategy; + return this; + } + + /** + * Configure durable writes for the keyspace action factory. + * + * @param durableWrites {@literal true} to enable durable writes. + * @return this. + */ + KeyspaceActionSpecificationFactoryBuilder durableWrites(boolean durableWrites) { + + this.durableWrites = durableWrites; + return this; + } + + /** + * @return a new {@link KeyspaceActionSpecificationFactory}. + */ + public KeyspaceActionSpecificationFactory build() { + + return new KeyspaceActionSpecificationFactory(name, new ArrayList<>(replications), replicationStrategy, + replicationFactor, durableWrites); + } + } +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactoryBean.java index 6bdd374f1..27623f36a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActionSpecificationFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 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,23 +15,16 @@ */ package org.springframework.data.cassandra.config; -import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; -import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification; -import org.springframework.data.cassandra.core.cql.keyspace.DefaultOption; -import org.springframework.data.cassandra.core.cql.keyspace.DropKeyspaceSpecification; +import org.springframework.data.cassandra.config.KeyspaceActionSpecificationFactory.KeyspaceActionSpecificationFactoryBuilder; +import org.springframework.data.cassandra.core.cql.keyspace.DataCenterReplication; import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceActionSpecification; -import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption; import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption.ReplicationStrategy; -import org.springframework.data.cassandra.core.cql.keyspace.Option; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -41,39 +34,27 @@ import org.springframework.util.Assert; * {@link KeyspaceActionSpecification} required to satisfy the configuration action. * * @author David Webb + * @author Mark Paluch */ -public class KeyspaceActionSpecificationFactoryBean - implements FactoryBean>, InitializingBean, DisposableBean { +public class KeyspaceActionSpecificationFactoryBean implements FactoryBean, InitializingBean { - private @Nullable KeyspaceAction action; + private KeyspaceAction action = KeyspaceAction.NONE; private @Nullable String name; private List networkTopologyDataCenters = new LinkedList<>(); private List networkTopologyReplicationFactors = new LinkedList<>(); - private @Nullable ReplicationStrategy replicationStrategy; - private long replicationFactor; + private ReplicationStrategy replicationStrategy = ReplicationStrategy.SIMPLE_STRATEGY; + + private int replicationFactor; private boolean durableWrites = false; private boolean ifNotExists = false; - private Set specs = new HashSet<>(); - - /* (non-Javadoc) - * @see org.springframework.beans.factory.DisposableBean#destroy() - */ - @Override - public void destroy() { - action = null; - name = null; - networkTopologyDataCenters = new LinkedList<>(); - networkTopologyReplicationFactors = new LinkedList<>(); - replicationStrategy = null; - specs = new HashSet<>(); - } + private @Nullable KeyspaceActions actions; /* (non-Javadoc) * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() @@ -84,65 +65,45 @@ public class KeyspaceActionSpecificationFactoryBean Assert.hasText(name, "Keyspace Name is required for a Keyspace Action"); Assert.notNull(action, "Keyspace Action is required for a Keyspace Action"); - switch (action) { - case CREATE_DROP: - specs.add(generateDropKeyspaceSpecification()); - case CREATE: - // Assert.notNull(replicationStrategy, "Replication Strategy is required to create a Keyspace"); - specs.add(generateCreateKeyspaceSpecification()); - break; - case ALTER: - break; - } - } - - /** - * Generate a {@link CreateKeyspaceSpecification} for the keyspace. - * - * @return The {@link CreateKeyspaceSpecification} - */ - private CreateKeyspaceSpecification generateCreateKeyspaceSpecification() { - - CreateKeyspaceSpecification create = CreateKeyspaceSpecification.createKeyspace(name).ifNotExists(ifNotExists) - .with(KeyspaceOption.DURABLE_WRITES, durableWrites); - - Map replicationStrategyMap = new HashMap<>(); - replicationStrategyMap.put(new DefaultOption("class", String.class, true, false, true), - replicationStrategy.getValue()); + KeyspaceActionSpecificationFactoryBuilder builder = KeyspaceActionSpecificationFactory.builder(name) + .durableWrites(durableWrites); if (replicationStrategy == ReplicationStrategy.SIMPLE_STRATEGY) { - replicationStrategyMap.put(new DefaultOption("replication_factor", Long.class, true, false, false), - replicationFactor); + builder.simpleReplication(replicationFactor); } if (replicationStrategy == ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY) { + int i = 0; for (String datacenter : networkTopologyDataCenters) { - replicationStrategyMap.put(new DefaultOption(datacenter, Long.class, true, false, false), - networkTopologyReplicationFactors.get(i++)); + builder.withDataCenter( + DataCenterReplication.of(datacenter, Integer.parseInt(networkTopologyReplicationFactors.get(i++)))); } } - create.with(KeyspaceOption.REPLICATION, replicationStrategyMap); + KeyspaceActionSpecificationFactory factory = builder.build(); - return create; - } - - /** - * Generate a {@link DropKeyspaceSpecification} for the keyspace. - * - * @return The {@link DropKeyspaceSpecification} - */ - private DropKeyspaceSpecification generateDropKeyspaceSpecification() { - return DropKeyspaceSpecification.dropKeyspace(getName()); + switch (action) { + case NONE: + this.actions = new KeyspaceActions(); + break; + case CREATE_DROP: + this.actions = new KeyspaceActions(factory.create(ifNotExists), factory.drop(ifNotExists)); + break; + case CREATE: + this.actions = new KeyspaceActions(factory.create(ifNotExists)); + break; + default: + throw new IllegalStateException(String.format("KeyspaceAction %s not supported", action)); + } } /* (non-Javadoc) * @see org.springframework.beans.factory.FactoryBean#getObject() */ @Override - public Set getObject() { - return specs; + public KeyspaceActions getObject() { + return actions; } /* (non-Javadoc) @@ -272,7 +233,7 @@ public class KeyspaceActionSpecificationFactoryBean /** * @param replicationFactor The replicationFactor to set. */ - public void setReplicationFactor(long replicationFactor) { + public void setReplicationFactor(int replicationFactor) { this.replicationFactor = replicationFactor; } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActions.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActions.java new file mode 100644 index 000000000..fdc645b71 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/KeyspaceActions.java @@ -0,0 +1,43 @@ +/* + * Copyright 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. + * 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.cassandra.config; + +import lombok.Value; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceActionSpecification; + +/** + * Collection of {@link KeyspaceActionSpecification}s. Wraps none, one or multiple keyspace actions (creates, drops). + * + * @author Mark Paluch + * @since 2.0 + */ +@Value +public class KeyspaceActions { + + private final List actions; + + public KeyspaceActions(KeyspaceActionSpecification... actions) { + this(Arrays.asList(actions)); + } + + public KeyspaceActions(List actions) { + this.actions = actions; + } +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/MultiLevelSetFlattenerFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/MultiLevelSetFlattenerFactoryBean.java deleted file mode 100644 index 8494a4fc9..000000000 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/MultiLevelSetFlattenerFactoryBean.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - * 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.cassandra.config; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.FactoryBean; - -/** - * Given Set of Sets where all child Sets contain the same class, then a single level Set of is generated. - * - * @author David Webb - * @param TODO: Remove me - */ -public class MultiLevelSetFlattenerFactoryBean implements FactoryBean> { - - private static final Logger log = LoggerFactory.getLogger(MultiLevelSetFlattenerFactoryBean.class); - - private Set> multiLevelSet; - - @Override - public Set getObject() throws Exception { - Set set = new HashSet<>(); - - multiLevelSet.stream().flatMap(Collection::stream).forEach(t -> { - log.debug(t.toString()); - log.debug("Set contains -> " + set.contains(t)); - set.add(t); - }); - - return set; - } - - @Override - public Class getObjectType() { - return Set.class; - } - - @Override - public boolean isSingleton() { - return true; - } - - /** - * @return Returns the multiLevelSet. - */ - public Set> getMultiLevelSet() { - return multiLevelSet; - } - - /** - * @param multiLevelSet The multiLevelSet to set. - */ - public void setMultiLevelSet(Set> multiLevelSet) { - this.multiLevelSet = multiLevelSet; - } - -} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/KeyspaceIdentifier.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/KeyspaceIdentifier.java index 066097ad1..21a4d8fca 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/KeyspaceIdentifier.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/KeyspaceIdentifier.java @@ -55,11 +55,22 @@ public final class KeyspaceIdentifier implements Comparable /** * Factory method for {@link KeyspaceIdentifier}. Convenient if imported statically. + * + * @deprecated since 2.0, use {@link #of(CharSequence)}. */ public static KeyspaceIdentifier ksId(CharSequence identifier) { return new KeyspaceIdentifier(identifier); } + /** + * Factory method for {@link KeyspaceIdentifier}. Convenient if imported statically. + * + * @since 2.0 + */ + public static KeyspaceIdentifier of(CharSequence identifier) { + return new KeyspaceIdentifier(identifier); + } + /** * Returns {@code true} if the given {@link CharSequence} is a legal keyspace identifier. */ @@ -114,7 +125,7 @@ public final class KeyspaceIdentifier implements Comparable } KeyspaceIdentifier other = (that instanceof KeyspaceIdentifier) ? (KeyspaceIdentifier) that - : ksId((CharSequence) that); + : of((CharSequence) that); return this.identifier.equals(other.identifier); } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java index 907e99416..f7a1575d1 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java @@ -39,7 +39,7 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification