@Override protected List<CreateKeyspaceSpecification> getKeyspaceCreations() { CreateKeyspaceSpecification specification = CreateKeyspaceSpecification.createKeyspace(keySpace) .ifNotExists() .with(KeyspaceOption.DURABLE_WRITES, true); //.withNetworkReplication(DataCenterReplication.dcr("foo", 1), DataCenterReplication.dcr("bar", 2)); return Arrays.asList(specification); }
/** * Configure simple replication with a replication factor of {@code 1}. * * @return this. */ public CreateKeyspaceSpecification withSimpleReplication() { return withSimpleReplication(1); }
/** * Entry point into the {@link CreateKeyspaceSpecification}'s fluent API given {@code name} to create a keyspace. * Convenient if imported statically. * * @param name must not be {@literal null}. * @return a new {@link CreateKeyspaceSpecification}. */ public static CreateKeyspaceSpecification createKeyspace(KeyspaceIdentifier name) { return new CreateKeyspaceSpecification(name); }
@Override protected List<CreateKeyspaceSpecification> getKeyspaceCreations() { return Collections.singletonList( CreateKeyspaceSpecification.createKeyspace(getKeyspaceName()) .withSimpleReplication()); }
Map<String, Object> options = spec().getOptions(); spec().with(KeyspaceOption.REPLICATION, simpleReplicationMap); spec().with(KeyspaceOption.DURABLE_WRITES, Boolean.TRUE);
/** * Configure simple replication with a {@code replicationFactor}. * * @return this. */ public CreateKeyspaceSpecification withSimpleReplication(long replicationFactor) { return with(KeyspaceOption.REPLICATION, MapBuilder.map(Option.class, Object.class) .entry(new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.SIMPLE_STRATEGY.getValue()) .entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build()); }
/** * Causes the inclusion of an {@code IF NOT EXISTS} clause. * * @return this */ public CreateKeyspaceSpecification ifNotExists() { return ifNotExists(true); }
private void preambleCql(StringBuilder cql) { cql.append("CREATE KEYSPACE ").append(spec().getIfNotExists() ? "IF NOT EXISTS " : "") .append(spec().getName()); }
/** * Configure datacenter replication given {@link DataCenterReplication}. * * @return this. */ public CreateKeyspaceSpecification withNetworkReplication(DataCenterReplication... dcrs) { MapBuilder<Option, Object> builder = MapBuilder.map(Option.class, Object.class).entry( new DefaultOption("class", String.class, true, false, true), ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getValue()); for (DataCenterReplication dcr : dcrs) { builder.entry(new DefaultOption(dcr.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor()); } return with(KeyspaceOption.REPLICATION, builder.build()); }
/** * 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<Option, Object> replication = getReplication(); if (!replication.isEmpty()) { create.with(KeyspaceOption.REPLICATION, replication); } return create; }
/** * Entry point into the {@link CreateKeyspaceSpecification}'s fluent API given {@code name} to create a keyspace. * Convenient if imported statically. * * @param name must not be {@literal null} or empty. * @return a new {@link CreateKeyspaceSpecification}. */ public static CreateKeyspaceSpecification createKeyspace(String name) { return new CreateKeyspaceSpecification(KeyspaceIdentifier.of(name)); }