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));
}
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());
}
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));
}
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));
}
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));
}
Aggregations