Search in sources :

Example 1 with ImmutableMap

use of com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap in project java-driver by datastax.

the class RelationParser method parseOptions.

protected Map<CqlIdentifier, Object> parseOptions(AdminRow row) {
    ImmutableMap.Builder<CqlIdentifier, Object> builder = ImmutableMap.builder();
    for (Map.Entry<String, TypeCodec<?>> entry : OPTION_CODECS.entrySet()) {
        String name = entry.getKey();
        CqlIdentifier id = CqlIdentifier.fromInternal(name);
        TypeCodec<?> codec = entry.getValue();
        if (name.equals("caching") && row.isString("caching")) {
            // C* <=2.2, caching is stored as a string, and also appears as a string in the WITH clause.
            builder.put(id, row.getString(name));
        } else if (name.equals("compaction_strategy_class")) {
            // C* <=2.2, compaction options split in two columns
            String strategyClass = row.getString(name);
            if (strategyClass != null) {
                builder.put(CqlIdentifier.fromInternal("compaction"), ImmutableMap.<String, String>builder().put("class", strategyClass).putAll(SimpleJsonParser.parseStringMap(row.getString("compaction_strategy_options"))).build());
            }
        } else if (name.equals("compression_parameters")) {
            // C* <=2.2, compression stored as a string
            String compressionParameters = row.getString(name);
            if (compressionParameters != null) {
                builder.put(CqlIdentifier.fromInternal("compression"), ImmutableMap.copyOf(SimpleJsonParser.parseStringMap(row.getString(name))));
            }
        } else if (!isDeprecatedInCassandra4(name)) {
            // Default case, read the value in a generic fashion
            Object value = row.get(name, codec);
            if (value != null) {
                builder.put(id, value);
            }
        }
    }
    return builder.build();
}
Also used : TypeCodec(com.datastax.oss.driver.api.core.type.codec.TypeCodec) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)

Example 2 with ImmutableMap

use of com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap in project java-driver by datastax.

the class DefaultTokenMap method buildReplicationConfigs.

private static Map<CqlIdentifier, Map<String, String>> buildReplicationConfigs(Collection<KeyspaceMetadata> keyspaces, String logPrefix) {
    ImmutableMap.Builder<CqlIdentifier, Map<String, String>> builder = ImmutableMap.builder();
    for (KeyspaceMetadata keyspace : keyspaces) {
        if (!keyspace.isVirtual()) {
            builder.put(keyspace.getName(), keyspace.getReplication());
        }
    }
    ImmutableMap<CqlIdentifier, Map<String, String>> result = builder.build();
    LOG.debug("[{}] Computing keyspace-level data for {}", logPrefix, result);
    return result;
}
Also used : CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) TokenMap(com.datastax.oss.driver.api.core.metadata.TokenMap) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) Map(java.util.Map) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)

Aggregations

CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)2 Map (java.util.Map)2 TokenMap (com.datastax.oss.driver.api.core.metadata.TokenMap)1 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)1 TypeCodec (com.datastax.oss.driver.api.core.type.codec.TypeCodec)1