Search in sources :

Example 1 with DefaultDseVertexMetadata

use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata in project java-driver by datastax.

the class DseTableParser method buildVertex.

private DseVertexMetadata buildVertex(CqlIdentifier tableId, Multimap<CqlIdentifier, AdminRow> keyspaceVertices) {
    if (keyspaceVertices == null) {
        return null;
    }
    Collection<AdminRow> tableVertices = keyspaceVertices.get(tableId);
    if (tableVertices == null || tableVertices.isEmpty()) {
        return null;
    }
    AdminRow row = tableVertices.iterator().next();
    return new DefaultDseVertexMetadata(getLabel(row));
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) DefaultDseVertexMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata)

Example 2 with DefaultDseVertexMetadata

use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata 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();
}
Also used : DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) DseGraphTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata) DefaultMetadata(com.datastax.oss.driver.internal.core.metadata.DefaultMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) DefaultDseTableMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) DefaultDseVertexMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata) Test(org.junit.Test)

Aggregations

DefaultDseVertexMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata)2 DseGraphTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata)1 DefaultDseKeyspaceMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata)1 DefaultDseTableMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata)1 AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)1 DefaultMetadata (com.datastax.oss.driver.internal.core.metadata.DefaultMetadata)1 MetadataRefresh (com.datastax.oss.driver.internal.core.metadata.MetadataRefresh)1 SchemaRefresh (com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh)1 Test (org.junit.Test)1