Search in sources :

Example 1 with DefaultKeyspaceMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata in project java-driver by datastax.

the class SchemaRefreshTest method should_detect_top_level_change_and_children_changes.

@Test
public void should_detect_top_level_change_and_children_changes() {
    // Drop one type, modify the other and add a third one
    UserDefinedType newT2 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks1"), CqlIdentifier.fromInternal("t2")).withField(CqlIdentifier.fromInternal("i"), DataTypes.TEXT).build();
    UserDefinedType t3 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks1"), CqlIdentifier.fromInternal("t3")).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).build();
    // Also disable durable writes
    DefaultKeyspaceMetadata newKs1 = newKeyspace("ks1", false, newT2, t3);
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), newKs1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces().get(OLD_KS1.getName())).isEqualTo(newKs1);
    assertThat(result.events).containsExactly(KeyspaceChangeEvent.updated(OLD_KS1, newKs1), TypeChangeEvent.dropped(OLD_T1), TypeChangeEvent.updated(OLD_T2, newT2), TypeChangeEvent.created(t3));
}
Also used : DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.Test)

Example 2 with DefaultKeyspaceMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata in project java-driver by datastax.

the class CassandraSchemaParser method parseVirtualKeyspace.

private KeyspaceMetadata parseVirtualKeyspace(AdminRow keyspaceRow) {
    CqlIdentifier keyspaceId = CqlIdentifier.fromInternal(keyspaceRow.getString("keyspace_name"));
    boolean durableWrites = MoreObjects.firstNonNull(keyspaceRow.getBoolean("durable_writes"), false);
    Map<String, String> replicationOptions = Collections.emptyMap();
    ;
    Map<CqlIdentifier, UserDefinedType> types = parseTypes(keyspaceId);
    return new DefaultKeyspaceMetadata(keyspaceId, durableWrites, true, replicationOptions, types, parseVirtualTables(keyspaceId, types), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
}
Also used : DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 3 with DefaultKeyspaceMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata in project java-driver by datastax.

the class CassandraSchemaParser method parseKeyspace.

private KeyspaceMetadata parseKeyspace(AdminRow keyspaceRow) {
    // Cassandra <= 2.2
    // CREATE TABLE system.schema_keyspaces (
    // keyspace_name text PRIMARY KEY,
    // durable_writes boolean,
    // strategy_class text,
    // strategy_options text
    // )
    // 
    // Cassandra >= 3.0:
    // CREATE TABLE system_schema.keyspaces (
    // keyspace_name text PRIMARY KEY,
    // durable_writes boolean,
    // replication frozen<map<text, text>>
    // )
    CqlIdentifier keyspaceId = CqlIdentifier.fromInternal(keyspaceRow.getString("keyspace_name"));
    boolean durableWrites = MoreObjects.firstNonNull(keyspaceRow.getBoolean("durable_writes"), false);
    Map<String, String> replicationOptions;
    if (keyspaceRow.contains("strategy_class")) {
        String strategyClass = keyspaceRow.getString("strategy_class");
        Map<String, String> strategyOptions = SimpleJsonParser.parseStringMap(keyspaceRow.getString("strategy_options"));
        replicationOptions = ImmutableMap.<String, String>builder().putAll(strategyOptions).put("class", strategyClass).build();
    } else {
        replicationOptions = keyspaceRow.getMapOfStringToString("replication");
    }
    Map<CqlIdentifier, UserDefinedType> types = parseTypes(keyspaceId);
    return new DefaultKeyspaceMetadata(keyspaceId, durableWrites, false, replicationOptions, types, parseTables(keyspaceId, types), parseViews(keyspaceId, types), parseFunctions(keyspaceId, types), parseAggregates(keyspaceId, types));
}
Also used : DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 4 with DefaultKeyspaceMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata in project java-driver by datastax.

the class SchemaRefreshTest method should_detect_updated_children_in_keyspace.

@Test
public void should_detect_updated_children_in_keyspace() {
    // Drop one type, modify the other and add a third one
    UserDefinedType newT2 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks1"), CqlIdentifier.fromInternal("t2")).withField(CqlIdentifier.fromInternal("i"), DataTypes.TEXT).build();
    UserDefinedType t3 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks1"), CqlIdentifier.fromInternal("t3")).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).build();
    DefaultKeyspaceMetadata newKs1 = newKeyspace("ks1", true, newT2, t3);
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), newKs1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces().get(OLD_KS1.getName())).isEqualTo(newKs1);
    assertThat(result.events).containsExactly(TypeChangeEvent.dropped(OLD_T1), TypeChangeEvent.updated(OLD_T2, newT2), TypeChangeEvent.created(t3));
}
Also used : DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.Test)

Example 5 with DefaultKeyspaceMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata in project java-driver by datastax.

the class SchemaRefreshTest method should_detect_top_level_update_in_keyspace.

@Test
public void should_detect_top_level_update_in_keyspace() {
    // Change only one top-level option (durable writes)
    DefaultKeyspaceMetadata newKs1 = newKeyspace("ks1", false, OLD_T1, OLD_T2);
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), newKs1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(1);
    assertThat(result.events).containsExactly(KeyspaceChangeEvent.updated(OLD_KS1, newKs1));
}
Also used : DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) Test(org.junit.Test)

Aggregations

DefaultKeyspaceMetadata (com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata)6 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)4 MetadataRefresh (com.datastax.oss.driver.internal.core.metadata.MetadataRefresh)4 Test (org.junit.Test)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)2