use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata in project java-driver by datastax.
the class GraphSchemaRefreshTest method should_detect_created_keyspace_without_graph_engine.
@Test
public void should_detect_created_keyspace_without_graph_engine() {
DefaultDseKeyspaceMetadata ks2 = newKeyspace("ks2", null);
SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), OLD_KS1, KS_WITH_ENGINE.getName(), KS_WITH_ENGINE, ks2.getName(), ks2));
MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
assertThat(result.newMetadata.getKeyspaces()).hasSize(3);
assertThat(result.events).containsExactly(KeyspaceChangeEvent.created(ks2));
}
use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata in project java-driver by datastax.
the class DseSchemaParser method parseKeyspace.
private DseKeyspaceMetadata 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>>
// )
//
// DSE >= 6.8: same as Cassandra 3 + graph_engine text
CqlIdentifier keyspaceId = CqlIdentifier.fromInternal(keyspaceRow.getString("keyspace_name"));
boolean durableWrites = MoreObjects.firstNonNull(keyspaceRow.getBoolean("durable_writes"), false);
String graphEngine = keyspaceRow.getString("graph_engine");
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 DefaultDseKeyspaceMetadata(keyspaceId, durableWrites, false, graphEngine, replicationOptions, types, parseTables(keyspaceId, types), parseViews(keyspaceId, types), parseFunctions(keyspaceId, types), parseAggregates(keyspaceId, types));
}
use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata in project java-driver by datastax.
the class DseSchemaParser method parseVirtualKeyspace.
private DseKeyspaceMetadata parseVirtualKeyspace(AdminRow keyspaceRow) {
CqlIdentifier keyspaceId = CqlIdentifier.fromInternal(keyspaceRow.getString("keyspace_name"));
boolean durableWrites = MoreObjects.firstNonNull(keyspaceRow.getBoolean("durable_writes"), false);
return new DefaultDseKeyspaceMetadata(keyspaceId, durableWrites, true, null, Collections.emptyMap(), Collections.emptyMap(), parseVirtualTables(keyspaceId), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
}
use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata in project java-driver by datastax.
the class GraphSchemaRefreshTest method should_detect_adding_and_renaming_and_removing_vertex_label.
@Test
public void should_detect_adding_and_renaming_and_removing_vertex_label() {
DefaultDseTableMetadata newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), new DefaultDseVertexMetadata(CqlIdentifier.fromInternal("someLabel")), null);
DefaultDseKeyspaceMetadata ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
assertThat(result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName())).isNotNull();
assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex()).isNotNull();
assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().get().getLabelName().asInternal()).isEqualTo("someLabel");
// now rename the vertex label
newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), new DefaultDseVertexMetadata(CqlIdentifier.fromInternal("someNewLabel")), null);
ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
result = refresh.compute(oldMetadata, false, context);
assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().get().getLabelName().asInternal()).isEqualTo("someNewLabel");
// now remove the vertex label from the table
DefaultMetadata metadataWithVertexLabel = result.newMetadata;
DefaultDseTableMetadata tableWithRemovedLabel = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), null, null);
ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), tableWithRemovedLabel));
refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
result = refresh.compute(metadataWithVertexLabel, false, context);
assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
assertThat(result.events).containsExactly(TableChangeEvent.updated(newTable, tableWithRemovedLabel));
assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().isPresent()).isFalse();
}
use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata in project java-driver by datastax.
the class GraphSchemaRefreshTest method should_detect_created_keyspace_with_graph_engine.
@Test
public void should_detect_created_keyspace_with_graph_engine() {
DefaultDseKeyspaceMetadata ks2 = newKeyspace("ks2", "Core");
SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), OLD_KS1, KS_WITH_ENGINE.getName(), KS_WITH_ENGINE, ks2.getName(), ks2));
MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
assertThat(result.newMetadata.getKeyspaces()).hasSize(3);
assertThat(result.events).containsExactly(KeyspaceChangeEvent.created(ks2));
}
Aggregations