Class ColumnDefinitions
- java.lang.Object
-
- com.datastax.driver.core.ColumnDefinitions
-
- All Implemented Interfaces:
Iterable<ColumnDefinitions.Definition>
public class ColumnDefinitions extends Object implements Iterable<ColumnDefinitions.Definition>
Metadata describing the columns returned in aResultSetor aPreparedStatement.A
columnDefinitions} instance is mainly a list ofColumnsDefinitions.Definition. The definitions or metadata for a column can be accessed either by:- index (indexed from 0)
- name
When accessed by name, column selection is case insensitive. In case multiple columns only differ by the case of their name, then the column returned with be the first column that has been defined in CQL without forcing case sensitivity (that is, it has either been defined without quotes or is fully lowercase). If none of the columns have been defined in this manner, the first column matching (with case insensitivity) is returned. You can force the case of a selection by double quoting the name.
For example:
- If
cdcontains columnfOO, thencd.contains("foo"),cd.contains("fOO")andcd.contains("Foo")will returntrue. - If
cdcontains bothfooandFOOthen:cd.getType("foo"),cd.getType("fOO")andcd.getType("FOO")will all match columnfoo.cd.getType("\"FOO\"")will match columnFOO
ColumnDefinitionsobject contains multiple occurrences of the exact same name (be it the same column multiple times or columns from different tables with the same name), you will have to use selection by index to disambiguate.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classColumnDefinitions.DefinitionA column definition.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<ColumnDefinitions.Definition>asList()Returns a list containing all the definitions of this metadata in order.booleancontains(String name)Returns whether this metadata contains a given name.intgetIndexOf(String name)The first index in this metadata of the provided name, if present.StringgetKeyspace(int i)Returns the keyspace of theith column in this metadata.StringgetKeyspace(String name)Returns the keyspace of the first occurrence ofnamein this metadata.StringgetName(int i)Returns the name of theith column in this metadata.StringgetTable(int i)Returns the table of theith column in this metadata.StringgetTable(String name)Returns the table of first occurrence ofnamein this metadata.DataTypegetType(int i)Returns the type of theith column in this metadata.DataTypegetType(String name)Returns the type of the first occurrence ofnamein this metadata.Iterator<ColumnDefinitions.Definition>iterator()Returns an iterator over theColumnDefinitions.Definitioncontained in this metadata.intsize()Returns the number of columns described by thisColumnsinstance.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
size
public int size()
Returns the number of columns described by thisColumnsinstance.- Returns:
- the number of columns described by this metadata.
-
contains
public boolean contains(String name)
Returns whether this metadata contains a given name.- Parameters:
name- the name to check.- Returns:
trueif this metadata contains the column namedname,falseotherwise.
-
getIndexOf
public int getIndexOf(String name)
The first index in this metadata of the provided name, if present.- Parameters:
name- the name of the column.- Returns:
- the index of the first occurrence of
namein this metadata ifcontains(name), -1 otherwise.
-
iterator
public Iterator<ColumnDefinitions.Definition> iterator()
Returns an iterator over theColumnDefinitions.Definitioncontained in this metadata.The order of the iterator will be the one of this metadata.
- Specified by:
iteratorin interfaceIterable<ColumnDefinitions.Definition>- Returns:
- an iterator over the
ColumnDefinitions.Definitioncontained in this metadata.
-
asList
public List<ColumnDefinitions.Definition> asList()
Returns a list containing all the definitions of this metadata in order.- Returns:
- a list of the
ColumnDefinitions.Definitioncontained in this metadata.
-
getName
public String getName(int i)
Returns the name of theith column in this metadata.- Parameters:
i- the index in this metadata.- Returns:
- the name of the
ith column in this metadata. - Throws:
IndexOutOfBoundsException- ifi < 0ori >= size()
-
getType
public DataType getType(int i)
Returns the type of theith column in this metadata.Note that this method does not set the
DataType.isFrozen()flag on the returned object, it will always default tofalse. UseCluster.getMetadata()to determine if a column is frozen.- Parameters:
i- the index in this metadata.- Returns:
- the type of the
ith column in this metadata. - Throws:
IndexOutOfBoundsException- ifi < 0ori >= size()
-
getType
public DataType getType(String name)
Returns the type of the first occurrence ofnamein this metadata.Note that this method does not set the
DataType.isFrozen()flag on the returned object, it will always default tofalse. UseCluster.getMetadata()to determine if a column is frozen.- Parameters:
name- the name of the column.- Returns:
- the type of (the first occurrence of)
namein this metadata. - Throws:
IllegalArgumentException- ifnameis not in this metadata.
-
getKeyspace
public String getKeyspace(int i)
Returns the keyspace of theith column in this metadata.- Parameters:
i- the index in this metadata.- Returns:
- the keyspace of the
ith column in this metadata. - Throws:
IndexOutOfBoundsException- ifi < 0ori >= size()
-
getKeyspace
public String getKeyspace(String name)
Returns the keyspace of the first occurrence ofnamein this metadata.- Parameters:
name- the name of the column.- Returns:
- the keyspace of (the first occurrence of) column
namein this metadata. - Throws:
IllegalArgumentException- ifnameis not in this metadata.
-
getTable
public String getTable(int i)
Returns the table of theith column in this metadata.- Parameters:
i- the index in this metadata.- Returns:
- the table of the
ith column in this metadata. - Throws:
IndexOutOfBoundsException- ifi < 0ori >= size()
-
getTable
public String getTable(String name)
Returns the table of first occurrence ofnamein this metadata.- Parameters:
name- the name of the column.- Returns:
- the table of (the first occurrence of) column
namein this metadata. - Throws:
IllegalArgumentException- ifnameis not in this metadata.
-
-