Class Query

java.lang.Object
org.olap4j.query.Query

public class Query extends Object
Base query model object.
Since:
May 29, 2007
Author:
jhyde, jdixon, Luc Boudreau
  • Field Details

    • name

      protected final String name
    • axes

      protected Map<Axis,QueryAxis> axes
    • across

      protected QueryAxis across
    • down

      protected QueryAxis down
    • filter

      protected QueryAxis filter
    • unused

      protected QueryAxis unused
    • cube

      protected final Cube cube
    • dimensionMap

      protected Map<String,QueryDimension> dimensionMap
    • selectDefaultMembers

      protected boolean selectDefaultMembers
      Whether or not to select the default hierarchy and default member on a dimension if no explicit selections were performed.
  • Constructor Details

    • Query

      public Query(String name, Cube cube) throws SQLException
      Constructs a Query object.
      Parameters:
      name - Any arbitrary name to give to this query.
      cube - A Cube object against which to build a query.
      Throws:
      SQLException - If an error occurs while accessing the cube's underlying connection.
  • Method Details

    • getSelect

      public SelectNode getSelect()
      Returns the MDX parse tree behind this Query. The returned object is generated for each call to this function. Altering the returned SelectNode object won't affect the query itself.
      Returns:
      A SelectNode object representing the current query structure.
    • getCube

      public Cube getCube()
      Returns the underlying cube object that is used to query against.
      Returns:
      The Olap4j's Cube object.
    • getDimension

      public QueryDimension getDimension(String name)
      Returns the Olap4j's Dimension object according to the name given as a parameter. If no dimension of the given name is found, a null value will be returned.
      Parameters:
      name - The name of the dimension you want the object for.
      Returns:
      The dimension object, null if no dimension of that name can be found.
    • swapAxes

      public void swapAxes()
      Swaps rows and columns axes. Only applicable if there are two axes.
    • getAxis

      public QueryAxis getAxis(Axis axis)
      Returns the query axis for a given axis type.

      If you pass axis=null, returns a special axis that is used to hold all unused hierarchies. (We may change this behavior in future.)

      Parameters:
      axis - Axis type
      Returns:
      Query axis
    • getAxes

      public Map<Axis,QueryAxis> getAxes()
      Returns a map of the current query's axis.

      Be aware that modifications to this list might have unpredictable consequences.

      Returns:
      A standard Map object that represents the current query's axis.
    • getUnusedAxis

      public QueryAxis getUnusedAxis()
      Returns the fictional axis into which all unused dimensions are stored. All dimensions included in this axis will not be part of the query.
      Returns:
      The QueryAxis representing dimensions that are currently not used inside the query.
    • tearDown

      public void tearDown(boolean closeConnection)
      Safely disposes of all underlying objects of this query.
      Parameters:
      closeConnection - Whether or not to call the Connection.close() method of the underlying connection.
    • tearDown

      public void tearDown()
      Safely disposes of all underlying objects of this query and closes the underlying OlapConnection.

      Equivalent of calling Query.tearDown(true).

    • validate

      public void validate() throws OlapException
      Validates the current query structure. If a dimension axis has been placed on an axis but no selections were performed on it, the default hierarchy and default member will be selected. This can be turned off by invoking the setSelectDefaultMembers(boolean) method.
      Throws:
      OlapException - If the query is not valid, an exception will be thrown and it's message will describe exactly what to fix.
    • execute

      public CellSet execute() throws OlapException
      Executes the query against the current OlapConnection and returns a CellSet object representation of the data.
      Returns:
      A proper CellSet object that represents the query execution results.
      Throws:
      OlapException - If something goes sour, an OlapException will be thrown to the caller. It could be caused by many things, like a stale connection. Look at the root cause for more details.
    • getName

      public String getName()
      Returns this query's name. There is no guarantee that it is unique and is set at object instanciation.
      Returns:
      This query's name.
    • getLocale

      public Locale getLocale()
      Returns the current locale with which this query is expressed.
      Returns:
      A standard Locale object.
    • setSelectDefaultMembers

      public void setSelectDefaultMembers(boolean selectDefaultMembers)
      Behavior setter for a query. By default, if a dimension is placed on an axis but no selections are made, the default hierarchy and the default member will be selected when validating the query. This behavior can be turned off by this setter.
      Parameters:
      selectDefaultMembers - Enables or disables the default member and hierarchy selection upon validation.
    • getWithList

      public List<ParseTreeNode> getWithList()
    • setWithList

      public void setWithList(List<ParseTreeNode> withList)
    • addQueryNodeListener

      public void addQueryNodeListener(QueryNodeListener l)
    • removeQueryNodeListener

      public void removeQueryNodeListener(QueryNodeListener l)
    • notifyAdd

      protected void notifyAdd(org.olap4j.query.QueryNode child, int index)
      Subclasses should call this helper method to notify its listeners that a child was added.
      Parameters:
      child - Child that was added
      index - The index at which it was added
    • notifyAdd

      protected void notifyAdd(Map<Integer,org.olap4j.query.QueryNode> children)
      Subclasses should call this helper method to notify it's listeners that children were added.
      Parameters:
      children - A map of indexes and children QueryNode objects that were added
    • notifyRemove

      protected void notifyRemove(org.olap4j.query.QueryNode child, int index)
      Subclasses should call this helper method to notify its listeners that a child was removed.
      Parameters:
      child - Child that was removed
      index - Index of child
    • notifyRemove

      protected void notifyRemove(Map<Integer,org.olap4j.query.QueryNode> children)
      Subclasses should call this helper method to notify its listeners that children were added.
      Parameters:
      children - A map of indexes and children QueryNode objects that were removed
    • notifyChange

      protected void notifyChange(org.olap4j.query.QueryNode child, int index)
      Subclasses should call this helper method to notify its listeners that a child selection object has a new operator value.
      Parameters:
      child - Child that was updated
      index - The index of the child among its siblings
    • notifyChange

      protected void notifyChange(Map<Integer,org.olap4j.query.QueryNode> children)
      Subclasses should call this helper method to notify its listeners that children selections object has a new operator value.
      Parameters:
      children - A map of indexes and children QueryNode objects that were updated