Package org.springframework.cassandra.core.keyspace

Examples of org.springframework.cassandra.core.keyspace.DefaultOption


   * replication strategy class "SimpleStrategy" and with a replication factor equal to that given.
   */
  public static Map<Option, Object> newSimpleReplication(long replicationFactor) {
    return 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();
  }
View Full Code Here


   * replication factors.
   */
  public static Map<Option, Object> newNetworkReplication(DataCenterReplication... dataCenterReplications) {

    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 : dataCenterReplications) {
      builder.entry(new DefaultOption(dcr.dataCenter, Long.class, true, false, false), dcr.replicationFactor);
    }

    return builder.build();
  }
View Full Code Here

public class OptionTest {

  @Test(expected = IllegalArgumentException.class)
  public void testOptionWithNullName() {
    new DefaultOption(null, Object.class, true, true, true);
  }
View Full Code Here

    new DefaultOption(null, Object.class, true, true, true);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testOptionWithEmptyName() {
    new DefaultOption("", Object.class, true, true, true);
  }
View Full Code Here

    new DefaultOption("", Object.class, true, true, true);
  }

  @Test
  public void testOptionWithNullType() {
    new DefaultOption("opt", null, true, true, true);
    new DefaultOption("opt", null, false, true, true);
  }
View Full Code Here

    new DefaultOption("opt", null, false, true, true);
  }

  @Test
  public void testOptionWithNullTypeIsCoerceable() {
    Option op = new DefaultOption("opt", null, true, true, true);
    assertTrue(op.isCoerceable(""));
    assertTrue(op.isCoerceable(null));
  }
View Full Code Here

    Class<?> type = String.class;
    boolean requires = true;
    boolean escapes = true;
    boolean quotes = true;

    Option op = new DefaultOption(name, type, requires, escapes, quotes);

    assertTrue(op.isCoerceable("opt"));
    assertEquals("'opt'", op.toString("opt"));
    assertEquals("'opt''n'", op.toString("opt'n"));

    type = Long.class;
    escapes = false;
    quotes = false;
    op = new DefaultOption(name, type, requires, escapes, quotes);

    String expected = "1";
    for (Object value : new Object[] { 1, "1" }) {
      assertTrue(op.isCoerceable(value));
      assertEquals(expected, op.toString(value));
    }
    assertFalse(op.isCoerceable("x"));
    assertTrue(op.isCoerceable(null));

    type = Long.class;
    escapes = false;
    quotes = true;
    op = new DefaultOption(name, type, requires, escapes, quotes);

    expected = "'1'";
    for (Object value : new Object[] { 1, "1" }) {
      assertTrue(op.isCoerceable(value));
      assertEquals(expected, op.toString(value));
    }
    assertFalse(op.isCoerceable("x"));
    assertTrue(op.isCoerceable(null));

    type = Double.class;
    escapes = false;
    quotes = false;
    op = new DefaultOption(name, type, requires, escapes, quotes);

    String[] expecteds = new String[] { "1", "1.0", "1.0", "1", "1.0", null };
    Object[] values = new Object[] { 1, 1.0F, 1.0D, "1", "1.0", null };
    for (int i = 0; i < values.length; i++) {
      assertTrue(op.isCoerceable(values[i]));
      assertEquals(expecteds[i], op.toString(values[i]));
    }
    assertFalse(op.isCoerceable("x"));
    assertTrue(op.isCoerceable(null));

    type = RetentionPolicy.class;
    escapes = false;
    quotes = false;
    op = new DefaultOption(name, type, requires, escapes, quotes);

    assertTrue(op.isCoerceable(null));
    assertTrue(op.isCoerceable(RetentionPolicy.CLASS));
    assertTrue(op.isCoerceable("CLASS"));
    assertFalse(op.isCoerceable("x"));
    assertEquals("CLASS", op.toString("CLASS"));
    assertEquals("CLASS", op.toString(RetentionPolicy.CLASS));
  }
View Full Code Here

    @Override
    public CreateKeyspaceSpecification specification() {
      keyspace = name;

      replicationMap.put(new DefaultOption("class", String.class, false, false, true), "NetworkTopologyStrategy");
      replicationMap.put(new DefaultOption("dc1", Long.class, false, false, true), 2);
      replicationMap.put(new DefaultOption("dc2", Long.class, false, false, true), 3);

      return CreateKeyspaceSpecification.createKeyspace().name(keyspace)
          .with(KeyspaceOption.REPLICATION, replicationMap).with(KeyspaceOption.DURABLE_WRITES, durableWrites);
    }
View Full Code Here

    CreateKeyspaceSpecification create = new CreateKeyspaceSpecification();
    create.name(name).ifNotExists(ifNotExists).with(KeyspaceOption.DURABLE_WRITES, durableWrites);

    Map<Option, Object> replicationStrategyMap = new HashMap<Option, Object>();
    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) {
      int i = 0;
      for (String datacenter : networkTopologyDataCenters) {
        replicationStrategyMap.put(new DefaultOption(datacenter, Long.class, true, false, false),
            networkTopologyReplicationFactors.get(i++));
      }
    }

    create.with(KeyspaceOption.REPLICATION, replicationStrategyMap);
View Full Code Here

    public Map<Option, Object> replicationMap = new HashMap<Option, Object>();

    @Override
    public AlterKeyspaceSpecification specification() {
      replicationMap.put(new DefaultOption("class", String.class, false, false, true), "SimpleStrategy");
      replicationMap.put(new DefaultOption("replication_factor", Long.class, false, false, true), 1);
      replicationMap.put(new DefaultOption("dc1", Long.class, false, false, true), 2);
      replicationMap.put(new DefaultOption("dc2", Long.class, false, false, true), 3);

      return AlterKeyspaceSpecification.alterKeyspace().name(name).with(KeyspaceOption.REPLICATION, replicationMap)
          .with(KeyspaceOption.DURABLE_WRITES, durableWrites);
    }
View Full Code Here

TOP

Related Classes of org.springframework.cassandra.core.keyspace.DefaultOption

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.