use of com.datastax.driver.core.KeyspaceMetadata in project fallout by datastax.
the class FalloutAppExtensionBase method maybeCleanDatabase.
private void maybeCleanDatabase() {
if (getCassandraDriverManager() != null) {
KeyspaceMetadata metadata = getSession().getCluster().getMetadata().getKeyspace(CASSANDRA_KEYSPACE);
metadata.getTables().forEach(table -> {
getSession().execute(String.format("TRUNCATE %s.%s;", CASSANDRA_KEYSPACE, table.getName()));
});
TestRunDAO.addFinishedTestRunEndStop(CASSANDRA_KEYSPACE, getCassandraDriverManager().getMappingManager());
}
}
use of com.datastax.driver.core.KeyspaceMetadata in project scalardb by scalar-labs.
the class ClusterManagerTest method getMetadata_TableNotExists_ShouldReturnNull.
@Test
public void getMetadata_TableNotExists_ShouldReturnNull() {
// Arrange
Metadata metadata = mock(Metadata.class);
KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
when(cluster.getMetadata()).thenReturn(metadata);
when(metadata.getKeyspace(anyString())).thenReturn(keyspaceMetadata);
when(keyspaceMetadata.getTable(anyString())).thenReturn(null);
// Act
TableMetadata actual = manager.getMetadata(ANY_KEYSPACE_NAME, ANY_TABLE_NAME);
// Assert
assertThat(actual).isNull();
}
use of com.datastax.driver.core.KeyspaceMetadata in project scalardb by scalar-labs.
the class ClusterManagerTest method getMetadata_WithReservedKeywordsExistingKeyspaceAndTableGiven_ShouldReturnMetadata.
@Test
public void getMetadata_WithReservedKeywordsExistingKeyspaceAndTableGiven_ShouldReturnMetadata() {
// Arrange
String keyspace = "keyspace";
String table = "table";
Metadata metadata = mock(Metadata.class);
KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
TableMetadata tableMetadata = mock(TableMetadata.class);
when(cluster.getMetadata()).thenReturn(metadata);
when(metadata.getKeyspace(quote(keyspace))).thenReturn(keyspaceMetadata);
when(keyspaceMetadata.getTable(quote(table))).thenReturn(tableMetadata);
// Act
TableMetadata actual = manager.getMetadata(keyspace, table);
// Assert
assertThat(actual).isEqualTo(tableMetadata);
}
use of com.datastax.driver.core.KeyspaceMetadata in project metacat by Netflix.
the class CassandraConnectorTableService method list.
/**
* {@inheritDoc}
*/
@Override
public List<TableInfo> list(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
final String keyspace = name.getDatabaseName();
log.debug("Attempting to list tables in Cassandra keyspace {} for request {}", keyspace, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
// TODO: Should we include views?
final List<TableInfo> tables = Lists.newArrayList();
for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
if (prefix != null && !tableMetadata.getName().startsWith(prefix.getTableName())) {
continue;
}
tables.add(this.getTableInfo(name, tableMetadata));
}
// Sort
if (sort != null) {
final Comparator<TableInfo> tableComparator = Comparator.comparing((t) -> t.getName().getTableName());
ConnectorUtils.sort(tables, sort, tableComparator);
}
// Paging
final List<TableInfo> pagedTables = ConnectorUtils.paginate(tables, pageable);
log.debug("Listed {} tables in Cassandra keyspace {} for request {}", pagedTables.size(), keyspace, context);
return pagedTables;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
use of com.datastax.driver.core.KeyspaceMetadata in project metacat by Netflix.
the class CassandraConnectorTableService method exists.
/**
* {@inheritDoc}
*/
@Override
public boolean exists(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name) {
final String keyspace = name.getDatabaseName();
final String table = name.getTableName();
log.debug("Checking if Cassandra table {}.{} exists for request {}", keyspace, table, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
return false;
}
final boolean exists = keyspaceMetadata.getTable(table) != null;
log.debug("Cassandra table {}.{} {} for request {}", keyspace, table, exists ? "exists" : "doesn't exist", context);
return exists;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
Aggregations