Class AbstractTableMetadata
- java.lang.Object
-
- com.datastax.driver.core.AbstractTableMetadata
-
- Direct Known Subclasses:
MaterializedViewMetadata,TableMetadata
public abstract class AbstractTableMetadata extends Object
Base class for Tables and Materialized Views metadata.
-
-
Field Summary
Fields Modifier and Type Field Description protected VersionNumbercassandraVersionprotected List<ColumnMetadata>clusteringColumnsprotected List<ClusteringOrder>clusteringOrderprotected Map<String,ColumnMetadata>columnsprotected UUIDidprotected KeyspaceMetadatakeyspaceprotected Stringnameprotected TableOptionsMetadataoptionsprotected List<ColumnMetadata>partitionKey
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTableMetadata(KeyspaceMetadata keyspace, String name, UUID id, List<ColumnMetadata> partitionKey, List<ColumnMetadata> clusteringColumns, Map<String,ColumnMetadata> columns, TableOptionsMetadata options, List<ClusteringOrder> clusteringOrder, VersionNumber cassandraVersion)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringBuilderappendOptions(StringBuilder sb, boolean formatted)StringasCQLQuery()Returns a CQL query representing this table.protected abstract StringasCQLQuery(boolean formatted)StringexportAsString()Returns aStringcontaining CQL queries representing this table and the index on it.List<ColumnMetadata>getClusteringColumns()Returns the list of clustering columns for this table.List<ClusteringOrder>getClusteringOrder()Returns the clustering order for this table.ColumnMetadatagetColumn(String name)Returns metadata on a column of this table.List<ColumnMetadata>getColumns()Returns a list containing all the columns of this table.UUIDgetId()Returns the unique id of this table.KeyspaceMetadatagetKeyspace()Returns the keyspace this table belong to.StringgetName()Returns the name of this table.TableOptionsMetadatagetOptions()Returns the options for this table.List<ColumnMetadata>getPartitionKey()Returns the list of columns composing the partition key for this table.List<ColumnMetadata>getPrimaryKey()Returns the list of columns composing the primary key for this table.booleanisVirtual()Returns whether or not this table is a virtual tableStringtoString()
-
-
-
Field Detail
-
keyspace
protected final KeyspaceMetadata keyspace
-
name
protected final String name
-
id
protected final UUID id
-
partitionKey
protected final List<ColumnMetadata> partitionKey
-
clusteringColumns
protected final List<ColumnMetadata> clusteringColumns
-
columns
protected final Map<String,ColumnMetadata> columns
-
options
protected final TableOptionsMetadata options
-
clusteringOrder
protected final List<ClusteringOrder> clusteringOrder
-
cassandraVersion
protected final VersionNumber cassandraVersion
-
-
Constructor Detail
-
AbstractTableMetadata
protected AbstractTableMetadata(KeyspaceMetadata keyspace, String name, UUID id, List<ColumnMetadata> partitionKey, List<ColumnMetadata> clusteringColumns, Map<String,ColumnMetadata> columns, TableOptionsMetadata options, List<ClusteringOrder> clusteringOrder, VersionNumber cassandraVersion)
-
-
Method Detail
-
getName
public String getName()
Returns the name of this table.- Returns:
- the name of this CQL table.
-
getId
public UUID getId()
Returns the unique id of this table.Note: this id is available in Cassandra 2.1 and above. It will be
nullfor earlier versions.- Returns:
- the unique id of the table.
-
getKeyspace
public KeyspaceMetadata getKeyspace()
Returns the keyspace this table belong to.- Returns:
- the keyspace metadata of the keyspace this table belong to.
-
getColumn
public ColumnMetadata getColumn(String name)
Returns metadata on a column of this table.- Parameters:
name- the name of the column to retrieve (namewill be interpreted as a case-insensitive identifier unless enclosed in double-quotes, seeMetadata.quote(java.lang.String)).- Returns:
- the metadata for the column if it exists, or
nullotherwise.
-
getColumns
public List<ColumnMetadata> getColumns()
Returns a list containing all the columns of this table.The order of the columns in the list is consistent with the order of the columns returned by a
SELECT * FROM thisTable: the first column is the partition key, next are the clustering columns in their defined order, and then the rest of the columns follow in alphabetic order.- Returns:
- a list containing the metadata for the columns of this table.
-
getPrimaryKey
public List<ColumnMetadata> getPrimaryKey()
Returns the list of columns composing the primary key for this table.A table will always at least have a partition key (that may itself be one or more columns), so the returned list at least has one element.
- Returns:
- the list of columns composing the primary key for this table.
-
getPartitionKey
public List<ColumnMetadata> getPartitionKey()
Returns the list of columns composing the partition key for this table.A table always has a partition key so the returned list has at least one element.
- Returns:
- the list of columns composing the partition key for this table.
-
getClusteringColumns
public List<ColumnMetadata> getClusteringColumns()
Returns the list of clustering columns for this table.- Returns:
- the list of clustering columns for this table. If there is no clustering columns, an empty list is returned.
-
getClusteringOrder
public List<ClusteringOrder> getClusteringOrder()
Returns the clustering order for this table.The returned contains the clustering order of each clustering column. The
ith element of the result correspond to the order (ascending or descending) of theith clustering column (seegetClusteringColumns()). Note that a table defined without any particular clustering order is equivalent to one for which all the clustering keys are in ascending order.- Returns:
- a list with the clustering order for each clustering column.
-
getOptions
public TableOptionsMetadata getOptions()
Returns the options for this table.This value will be null for virtual tables.
- Returns:
- the options for this table.
-
isVirtual
public boolean isVirtual()
Returns whether or not this table is a virtual table- Returns:
trueif virtual keyspace,falseotherwise.
-
exportAsString
public String exportAsString()
Returns aStringcontaining CQL queries representing this table and the index on it.In other words, this method returns the queries that would allow you to recreate the schema of this table, along with the indexes and views defined on this table, if any.
Note that the returned String is formatted to be human readable (for some definition of human readable at least).
- Returns:
- the CQL queries representing this table schema as a {code String}.
-
asCQLQuery
public String asCQLQuery()
Returns a CQL query representing this table.This method returns a single 'CREATE TABLE' query with the options corresponding to this table definition.
Note that the returned string is a single line; the returned query is not formatted in any way.
- Returns:
- the 'CREATE TABLE' query corresponding to this table.
- See Also:
exportAsString()
-
asCQLQuery
protected abstract String asCQLQuery(boolean formatted)
-
appendOptions
protected StringBuilder appendOptions(StringBuilder sb, boolean formatted)
-
-