Class ColumnDefinitions

  • All Implemented Interfaces:
    Iterable<ColumnDefinitions.Definition>

    public class ColumnDefinitions
    extends Object
    implements Iterable<ColumnDefinitions.Definition>
    Metadata describing the columns returned in a ResultSet or a PreparedStatement.

    A columnDefinitions} instance is mainly a list of ColumnsDefinitions.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 cd contains column fOO, then cd.contains("foo"), cd.contains("fOO") and cd.contains("Foo") will return true.
    • If cd contains both foo and FOO then:
      • cd.getType("foo"), cd.getType("fOO") and cd.getType("FOO") will all match column foo.
      • cd.getType("\"FOO\"") will match column FOO
    Note that the preceding rules mean that if a ColumnDefinitions object 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.
    • Method Detail

      • size

        public int size()
        Returns the number of columns described by this Columns instance.
        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:
        true if this metadata contains the column named name, false otherwise.
      • 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 name in this metadata if contains(name), -1 otherwise.
      • getName

        public String getName​(int i)
        Returns the name of the ith column in this metadata.
        Parameters:
        i - the index in this metadata.
        Returns:
        the name of the ith column in this metadata.
        Throws:
        IndexOutOfBoundsException - if i < 0 or i >= size()
      • getType

        public DataType getType​(int i)
        Returns the type of the ith column in this metadata.

        Note that this method does not set the DataType.isFrozen() flag on the returned object, it will always default to false. Use Cluster.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 - if i < 0 or i >= size()
      • getType

        public DataType getType​(String name)
        Returns the type of the first occurrence of name in this metadata.

        Note that this method does not set the DataType.isFrozen() flag on the returned object, it will always default to false. Use Cluster.getMetadata() to determine if a column is frozen.

        Parameters:
        name - the name of the column.
        Returns:
        the type of (the first occurrence of) name in this metadata.
        Throws:
        IllegalArgumentException - if name is not in this metadata.
      • getKeyspace

        public String getKeyspace​(int i)
        Returns the keyspace of the ith column in this metadata.
        Parameters:
        i - the index in this metadata.
        Returns:
        the keyspace of the ith column in this metadata.
        Throws:
        IndexOutOfBoundsException - if i < 0 or i >= size()
      • getKeyspace

        public String getKeyspace​(String name)
        Returns the keyspace of the first occurrence of name in this metadata.
        Parameters:
        name - the name of the column.
        Returns:
        the keyspace of (the first occurrence of) column name in this metadata.
        Throws:
        IllegalArgumentException - if name is not in this metadata.
      • getTable

        public String getTable​(int i)
        Returns the table of the ith column in this metadata.
        Parameters:
        i - the index in this metadata.
        Returns:
        the table of the ith column in this metadata.
        Throws:
        IndexOutOfBoundsException - if i < 0 or i >= size()
      • getTable

        public String getTable​(String name)
        Returns the table of first occurrence of name in this metadata.
        Parameters:
        name - the name of the column.
        Returns:
        the table of (the first occurrence of) column name in this metadata.
        Throws:
        IllegalArgumentException - if name is not in this metadata.