org.springframework.data.cassandra.config.KeyspaceActionSpecificationFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-cassandra Show documentation
Show all versions of spring-data-cassandra Show documentation
Cassandra support for Spring Data
/*
* Copyright 2017-2018 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.AlterKeyspaceSpecification;
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.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;
/**
* 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