TableOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) { this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue); }
public void checkValue(@Nullable Object value) { if (takesValue()) { if (value == null) { if (requiresValue) { throw new IllegalArgumentException("Option [" + getName() + "] requires a value"); } return; // doesn't require a value, so null is ok } // else value is not null if (isCoerceable(value)) { return; } // else value is not coerceable into the expected type throw new IllegalArgumentException( "Option [" + getName() + "] takes value coerceable to type [" + getType() + "]"); } // else this option doesn't take a value if (value != null) { throw new IllegalArgumentException("Option [" + getName() + "] takes no value"); } }
public String toString(@Nullable Object value) { if (value == null) { return ""; } checkValue(value); String string = value.toString(); string = escapesValue ? escapeSingle(string) : string; string = quotesValue ? singleQuote(string) : string; return string; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public boolean isCoerceable(Object value) { if (getType().equals(Void.class)) { return true;
CompressionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) { this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue); }
CachingOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) { this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue); }
KeyspaceOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) { this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue); }
CompactionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) { this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue); }
/** * Create replication options represented as {@link Map}. * * @return the replication options represented as {@link Map}. * @since 2.0.1 */ protected Map<Option, Object> getReplication() { Map<Option, Object> replicationStrategyMap = new HashMap<>(); if (hasReplicationOptions()) { 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()); } } } return replicationStrategyMap; }
/** * Returns a map of {@link Option}s suitable as the value of a {@link KeyspaceOption#REPLICATION} option with * 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(); }
/** * 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()); }
/** * Returns a map of {@link Option}s suitable as the value of a {@link KeyspaceOption#REPLICATION} option with * replication strategy class "NetworkTopologyStrategy" and with data centers each with their corresponding * 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.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor()); } return builder.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()); }