Package org.olap4j.query
Class Query
- java.lang.Object
-
- org.olap4j.query.Query
-
public class Query extends java.lang.Object
Base query model object.- Since:
- May 29, 2007
- Author:
- jhyde, jdixon, Luc Boudreau
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addQueryNodeListener(QueryNodeListener l)
CellSet
execute()
Executes the query against the current OlapConnection and returns a CellSet object representation of the data.java.util.Map<Axis,QueryAxis>
getAxes()
Returns a map of the current query's axis.QueryAxis
getAxis(Axis axis)
Returns the query axis for a given axis type.Cube
getCube()
Returns the underlying cube object that is used to query against.QueryDimension
getDimension(java.lang.String name)
Returns the Olap4j's Dimension object according to the name given as a parameter.java.util.Locale
getLocale()
Returns the current locale with which this query is expressed.java.lang.String
getName()
Returns this query's name.SelectNode
getSelect()
Returns the MDX parse tree behind this Query.QueryAxis
getUnusedAxis()
Returns the fictional axis into which all unused dimensions are stored.void
removeQueryNodeListener(QueryNodeListener l)
void
setSelectDefaultMembers(boolean selectDefaultMembers)
Behavior setter for a query.void
swapAxes()
Swaps rows and columns axes.void
tearDown()
Safely disposes of all underlying objects of this query and closes the underlyingOlapConnection
.void
tearDown(boolean closeConnection)
Safely disposes of all underlying objects of this query.void
validate()
Validates the current query structure.
-
-
-
Constructor Detail
-
Query
public Query(java.lang.String name, Cube cube) throws java.sql.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:
java.sql.SQLException
- If an error occurs while accessing the cube's underlying connection.
-
-
Method Detail
-
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(java.lang.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 java.util.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 theConnection.close()
method of the underlying connection.
-
tearDown
public void tearDown()
Safely disposes of all underlying objects of this query and closes the underlyingOlapConnection
.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 thesetSelectDefaultMembers(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 java.lang.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 java.util.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.
-
addQueryNodeListener
public void addQueryNodeListener(QueryNodeListener l)
-
removeQueryNodeListener
public void removeQueryNodeListener(QueryNodeListener l)
-
-