本文整理匯總了Java中com.datastax.driver.core.KeyspaceMetadata.getTables方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyspaceMetadata.getTables方法的具體用法?Java KeyspaceMetadata.getTables怎麽用?Java KeyspaceMetadata.getTables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.KeyspaceMetadata
的用法示例。
在下文中一共展示了KeyspaceMetadata.getTables方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTableMetadata
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
private TableMetadata getTableMetadata(SchemaTableName schemaTableName)
{
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
if (tableMetadata != null) {
return tableMetadata;
}
for (TableMetadata table : keyspaceMetadata.getTables()) {
if (table.getName().equalsIgnoreCase(tableName)) {
return table;
}
}
throw new TableNotFoundException(schemaTableName);
}
示例2: createTableIfNecessary
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
private void createTableIfNecessary( RetentionTable table, KeyspaceMetadata metadata ) {
for ( TableMetadata meta : metadata.getTables()) {
log.debug( "Comparing " + meta.getName() + " with " + table.tableName() );
if ( meta.getName().equalsIgnoreCase( table.tableName() )) {
return;
}
}
StringBuilder query = new StringBuilder();
query.append( "CREATE TABLE " ).append( table.tableName() ).append( " (" );
query.append( COL_NAME ).append( " text, " );
query.append( COL_TIME ).append( " bigint, " );
query.append( COL_VALUE ).append( " double, " );
query.append( "PRIMARY KEY (" ).append( COL_NAME ).append( ", " ).append( COL_TIME ).append( ")");
query.append( ");" );
log.debug( "Creating table with query: <" + query.toString() + ">");
try {
session.execute( query.toString() );
} catch( AlreadyExistsException e ) {
// Some other gatherer might have already created the same table.
}
}
示例3: marshallKeyspaces
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static JSONArray marshallKeyspaces(List<KeyspaceMetadata> keyspaces, boolean flatten)
throws UnsupportedEncodingException {
JSONArray keyspaceJson = new JSONArray();
if (flatten) {
for (KeyspaceMetadata keyspace : keyspaces) {
for (TableMetadata table : keyspace.getTables()) {
JSONObject json = new JSONObject();
json.put("keyspace", keyspace.getName());
json.put("columnFamily", table.getName());
keyspaceJson.add(json);
}
}
}
return keyspaceJson;
}
示例4: detectSchema
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
/**
* Performs an analysis of the given keyspace in a Cassandra cluster
* {@link Cluster} instance and detects the cassandra types structure based
* on the metadata provided by the datastax cassandra java client.
*
* @see #detectTable(TableMetadata)
*
* @param cluster
* the cluster to inspect
* @param keyspaceName
* @return a mutable schema instance, useful for further fine tuning by the
* user.
*/
public static SimpleTableDef[] detectSchema(Cluster cluster, String keyspaceName) {
final Metadata metadata = cluster.getMetadata();
final KeyspaceMetadata keyspace = metadata.getKeyspace(keyspaceName);
if (keyspace == null) {
throw new IllegalArgumentException("Keyspace '" + keyspaceName + "' does not exist in the database");
}
final Collection<TableMetadata> tables = keyspace.getTables();
final SimpleTableDef[] result = new SimpleTableDef[tables.size()];
int i = 0;
for (final TableMetadata tableMetaData : tables) {
final SimpleTableDef table = detectTable(tableMetaData);
result[i] = table;
i++;
}
return result;
}
示例5: clean
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public void clean() {
log.info("Cleaning all tables");
for (KeyspaceMetadata keyspaceMetadata : session.getCluster().getMetadata().getKeyspaces()) {
String keyspace = keyspaceMetadata.getName();
if (keyspace.startsWith("system")) {
continue;
}
for (TableMetadata metadata : keyspaceMetadata.getTables()) {
String statement = "TRUNCATE TABLE " + keyspace + "." + metadata.getName();
session.execute(statement);
}
}
}
示例6: getAllTables
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public List<String> getAllTables(String schema)
throws SchemaNotFoundException
{
KeyspaceMetadata meta = getCheckedKeyspaceMetadata(schema);
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (TableMetadata tableMeta : meta.getTables()) {
builder.add(tableMeta.getName());
}
return builder.build();
}
示例7: execute
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
/**
* Execute when shCQL is DESCRIBE KEYSPACE anyvalue
* @param metaData
* @return table
*/
@Override
public Table execute(Metadata metaData) {
KeyspaceMetadata keySpaceMetada = metaData.getKeyspace(param);
FunctionalList<TableMetadata,RowData> functionalList = new FunctionalList<>(new ArrayList<>(keySpaceMetada.getTables()));
List<RowData> rows = functionalList.map(new TableMetadataToRowDataFunction());
rows.add(0,buildFirst(keySpaceMetada.toString()));
return new Table(new ListUtils<String>().buildList(),rows);
}
示例8: transform
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
/**
*
* @param keyspaceMetadata
* @return ransform KeySpacetables to CellData with tableName
*/
@Override
public RowData transform(KeyspaceMetadata keyspaceMetadata) {
List<TableMetadata> tables = new ArrayList<>(keyspaceMetadata.getTables());
FunctionalList<TableMetadata,CellData> functional = new FunctionalList<>(tables);
List<CellData> cells = new ListUtils<CellData>().buildList(new CellData(buildTable(keyspaceMetadata.getName(),functional)));
return new RowData(cells);
}
示例9: list
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
/**
* {@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);
}
}
示例10: listNames
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public List<QualifiedName> listNames(
@Nonnull @NonNull final ConnectorRequestContext context,
@Nonnull @NonNull final QualifiedName name,
@Nullable final QualifiedName prefix,
@Nullable final Sort sort,
@Nullable final Pageable pageable
) {
final String catalog = name.getCatalogName();
final String keyspace = name.getDatabaseName();
log.debug("Attempting to list table names 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<QualifiedName> tableNames = Lists.newArrayList();
for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
final String tableName = tableMetadata.getName();
if (prefix != null && !tableName.startsWith(prefix.getTableName())) {
continue;
}
tableNames.add(QualifiedName.ofTable(catalog, keyspace, tableName));
}
// Sort
if (sort != null) {
final Comparator<QualifiedName> tableNameComparator = Comparator.comparing(QualifiedName::getTableName);
ConnectorUtils.sort(tableNames, sort, tableNameComparator);
}
// Paging
final List<QualifiedName> paged = ConnectorUtils.paginate(tableNames, pageable);
log.debug("Listed {} table names in Cassandra keyspace {} for request {}", paged.size(), keyspace, context);
return paged;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
示例11: makeTables
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public CassandraMetadataResultSet makeTables(CassandraStatement statement, String schemaPattern, String tableNamePattern) throws SQLException
{
// 1. TABLE_CAT String => table catalog (may be null)
// 2. TABLE_SCHEM String => table schema (may be null)
// 3. TABLE_NAME String => table name
// 4. TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
// 5. REMARKS String => explanatory comment on the table
// 6. TYPE_CAT String => the types catalog (may be null)
// 7. TYPE_SCHEM String => the types schema (may be null)
// 8. TYPE_NAME String => type name (may be null)
// 9. SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null)
// 10. REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null)
final ArrayList<MetadataRow> schemas = Lists.newArrayList();
List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces();
for(KeyspaceMetadata keyspace:keyspaces){
if ("%".equals(schemaPattern)) schemaPattern = null;
if((schemaPattern==null?keyspace.getName():schemaPattern).equals(keyspace.getName())){
Collection<TableMetadata> tables = keyspace.getTables();
if ("%".equals(tableNamePattern)) tableNamePattern = null;
for(TableMetadata table:tables){
if((tableNamePattern==null?table.getName():tableNamePattern).equals(table.getName())){
MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog())
.addEntry("TABLE_SCHEM", keyspace.getName())
.addEntry("TABLE_NAME", table.getName())
.addEntry("TABLE_TYPE", TABLE_CONSTANT)
.addEntry("REMARKS", table.getOptions().getComment())
.addEntry("TYPE_CAT", null)
.addEntry("TYPE_SCHEM", null)
.addEntry("TYPE_NAME", null)
.addEntry("SELF_REFERENCING_COL_NAME", null)
.addEntry("REF_GENERATION", null);
schemas.add(row);
}
}
}
}
CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas));
return result;
}
示例12: makeIndexes
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public CassandraMetadataResultSet makeIndexes(CassandraStatement statement, String schema, String tableName, boolean unique, boolean approximate) throws SQLException
{
final ArrayList<MetadataRow> schemas = Lists.newArrayList();
List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces();
for(KeyspaceMetadata keyspace:keyspaces){
if(schema.equals(keyspace.getName())){
Collection<TableMetadata> tables = keyspace.getTables();
for(TableMetadata table:tables){
if(tableName.equals(table.getName())){
for(IndexMetadata index:table.getIndexes()){
MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog())
.addEntry("TABLE_SCHEM", keyspace.getName())
.addEntry("TABLE_NAME", table.getName())
.addEntry("NON_UNIQUE", true+"")
.addEntry("INDEX_QUALIFIER", statement.connection.getCatalog())
.addEntry("INDEX_NAME", index.getName())
.addEntry("TYPE", DatabaseMetaData.tableIndexHashed+"")
.addEntry("ORDINAL_POSITION", 1+"")
.addEntry("COLUMN_NAME", index.getTarget())
.addEntry("ASC_OR_DESC", null)
.addEntry("CARDINALITY", -1+"")
.addEntry("PAGES", -1+"")
.addEntry("FILTER_CONDITION", null);
schemas.add(row);
}
}
}
}
}
CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas));
return result;
//1.TABLE_CAT String => table catalog (may be null)
//2.TABLE_SCHEM String => table schema (may be null)
//3.TABLE_NAME String => table name
//4.NON_UNIQUE boolean => Can index values be non-unique. false when TYPE is tableIndexStatistic
//5.INDEX_QUALIFIER String => index catalog (may be null); null when TYPE is tableIndexStatistic
//6.INDEX_NAME String => index name; null when TYPE is tableIndexStatistic
//7.TYPE short => index type: - tableIndexStatistic - this identifies table statistics that are returned in conjuction with a table's index descriptions
//- tableIndexClustered - this is a clustered index
//- tableIndexHashed - this is a hashed index
//- tableIndexOther - this is some other style of index
//
//8.ORDINAL_POSITION short => column sequence number within index; zero when TYPE is tableIndexStatistic
//9.COLUMN_NAME String => column name; null when TYPE is tableIndexStatistic
//10.ASC_OR_DESC String => column sort sequence, "A" => ascending, "D" => descending, may be null if sort sequence is not supported; null when TYPE is tableIndexStatistic
//11.CARDINALITY int => When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique values in the index.
//12.PAGES int => When TYPE is tableIndexStatisic then this is the number of pages used for the table, otherwise it is the number of pages used for the current index.
//13.FILTER_CONDITION String => Filter condition, if any. (may be null)
/* StringBuilder query = new StringBuilder("SELECT keyspace_name, columnfamily_name, column_name, component_index, index_name, index_options, index_type FROM system.schema_columns");*/
}
示例13: makePrimaryKeys
import com.datastax.driver.core.KeyspaceMetadata; //導入方法依賴的package包/類
public CassandraMetadataResultSet makePrimaryKeys(CassandraStatement statement, String schema, String tableName) throws SQLException
{
final ArrayList<MetadataRow> schemas = Lists.newArrayList();
List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces();
for(KeyspaceMetadata keyspace:keyspaces){
if(schema.equals(keyspace.getName())){
Collection<TableMetadata> tables = keyspace.getTables();
for(TableMetadata table:tables){
if(tableName.equals(table.getName())){
int seq=0;
for(ColumnMetadata col:table.getPrimaryKey()){
MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog())
.addEntry("TABLE_SCHEM", keyspace.getName())
.addEntry("TABLE_NAME", table.getName())
.addEntry("COLUMN_NAME", col.getName())
.addEntry("KEY_SEQ", seq+"")
.addEntry("PK_NAME", null);
schemas.add(row);
seq++;
}
}
}
}
}
CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas));
return result;
//1.TABLE_CAT String => table catalog (may be null)
//2.TABLE_SCHEM String => table schema (may be null)
//3.TABLE_NAME String => table name
//4.COLUMN_NAME String => column name
//5.KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
//6.PK_NAME String => primary key name (may be null)
}