@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); }
/** * 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; }
/** * 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()); }
/** * 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()); }