Package adql.query

Class ClauseSelect

All Implemented Interfaces:
ADQLObject, Iterable<SelectItem>

public class ClauseSelect extends ClauseADQL<SelectItem>

The SELECT clause of an ADQL query.

This ADQL clause is not only a list of ADQL items:

  • The user can specify the maximum number of rows the query must return.
  • He can also ask that all the returned rows are unique according to the first returned column.

Version:
1.4 (09/2017)
Author:
Grégory Mantelet (CDS;ARI)
  • Constructor Details

    • ClauseSelect

      public ClauseSelect()
      Builds an empty SELECT clause.
    • ClauseSelect

      public ClauseSelect(boolean distinctColumns)
      Builds an empty SELECT clause by specifying whether the returned rows are unique (regarding the first returned columns).
      Parameters:
      distinctColumns - true means unique rows (= SELECT DISTINCT), false otherwise (= SELECT or = SELECT ALL).
    • ClauseSelect

      public ClauseSelect(int limit)
      Builds an empty SELECT clause whose the returned rows must be limited to the given number.
      Parameters:
      limit - Maximum number of returned rows (= SELECT TOP limit).
    • ClauseSelect

      public ClauseSelect(boolean distinctColumns, int limit)
      Builds an empty SELECT clause.
      Parameters:
      distinctColumns - true means unique rows (= SELECT DISTINCT), false otherwise (= SELECT or = SELECT ALL).
      limit - Maximum number of returned rows (= SELECT TOP limit).
    • ClauseSelect

      public ClauseSelect(ClauseSelect toCopy) throws Exception
      Builds a SELECT clause by copying the given one.
      Parameters:
      toCopy - The SELECT clause to copy.
      Throws:
      Exception - If there is an error during the copy.
  • Method Details

    • distinctColumns

      public final boolean distinctColumns()
      Tells whether this clause imposes that returned rows are unique (regarding the first returned column).
      Returns:
      true for SELECT DISTINCT, false for SELECT ALL.
    • setDistinctColumns

      public final void setDistinctColumns(boolean distinct)
      Changes the DISTINCT flag of this SELECT clause.
      Parameters:
      distinct - true for SELECY DISTINCT, false for SELECT ALL.
    • hasLimit

      public final boolean hasLimit()
      Indicates whether this SELECT clause imposes a maximum number of rows.
      Returns:
      true this clause has a TOP flag, false otherwise.
    • getLimit

      public final int getLimit()
      Gets the maximum number of rows imposed by this SELECT clause.
      Returns:
      Maximum number of rows the query must return (SELECT TOP limit).
    • setNoLimit

      public final void setNoLimit()
      Sets no maximum number of rows (classic SELECT).
    • setLimit

      public final void setLimit(int limit)
      Changes the maximum number of rows this clause imposes.
      Parameters:
      limit - The maximum number of returned rows (SELECT TOP limit).
    • add

      public boolean add(ADQLOperand operand) throws NullPointerException

      Adds an operand to this SELECT clause.

      IMPORTANT: The given operand will not be added directly ! It will be encapsulated in a SelectItem object which will be then added to the SELECT clause.

      Parameters:
      operand - The operand to add.
      Returns:
      true if the operand has been successfully added, false otherwise.
      Throws:
      NullPointerException - If the given item is null.
      See Also:
    • add

      public void add(int index, ADQLOperand operand) throws NullPointerException, ArrayIndexOutOfBoundsException

      Adds an operand to this SELECT clause at the given position.

      IMPORTANT: The given operand will not be added directly ! It will be encapsulated in a SelectItem object which will be then added to the SELECT clause.

      Parameters:
      index - The position at which the given operand must be added.
      operand - The operand to add.
      Throws:
      NullPointerException - If the given item is null.
      ArrayIndexOutOfBoundsException - If the index is out of range (index < 0 || index > size()).
      See Also:
    • set

      Replaces the specified operand by the given one.

      IMPORTANT: The given operand will not be added directly ! It will be encapsulated in a SelectItem object which will be then added to the SELECT clause.

      Parameters:
      index - The position of the SELECT item to replace.
      operand - The replacer of the specified SELECT item.
      Returns:
      The replaced SELECT item.
      Throws:
      NullPointerException - If the given item is null.
      ArrayIndexOutOfBoundsException - If the index is out of range (index < 0 || index > size()).
    • searchByIndex

      public ADQLOperand searchByIndex(int index) throws ArrayIndexOutOfBoundsException
      Gets the specified operand.
      Parameters:
      index - Index of the operand to retrieve.
      Returns:
      The corresponding operand.
      Throws:
      ArrayIndexOutOfBoundsException - If the index is out of range (index < 0 || index > size()).
    • searchByAlias

      public ADQLOperand searchByAlias(String alias)
      Gets the operand which is associated with the given alias (case sensitive).
      Parameters:
      alias - Alias of the operand to retrieve.
      Returns:
      The corresponding operand or null if none has been found.
      See Also:
    • searchByAlias

      public List<SelectItem> searchByAlias(String alias, boolean caseSensitive)
      Gets all the select items which are associated with the given alias.
      Parameters:
      alias - Alias of the operand to retrieve.
      Returns:
      All the corresponding select items.
    • getCopy

      public ADQLObject getCopy() throws Exception
      Description copied from interface: ADQLObject
      Gets a (deep) copy of this ADQL object.
      Specified by:
      getCopy in interface ADQLObject
      Overrides:
      getCopy in class ClauseADQL<SelectItem>
      Returns:
      The copy of this ADQL object.
      Throws:
      Exception - If there is any error during the copy.
    • toADQL

      public String toADQL()
      Description copied from interface: ADQLObject
      Gets the ADQL expression of this object.
      Specified by:
      toADQL in interface ADQLObject
      Overrides:
      toADQL in class ADQLList<SelectItem>
      Returns:
      The corresponding ADQL expression.