com.sas.storage.olap.sasmdx
Class OLAPDataSet

com.sas.storage.olap.sasmdx.OLAPDataSet
All Implemented Interfaces:
OLAPDataSetInterface, ResultSetInterface

public class OLAPDataSet
implements OLAPDataSetInterface

Contains the client side implementation for com.sas.storage.olap.OLAPDataSetInterface and the PerformanceTuningInterface. This implementation uses the IOM/OLAP interfaces provided by the SAS OLAP server.


Field Summary
 
Fields inherited from interface com.sas.storage.olap.OLAPDataSetInterface
DEFAULT_CONTEXT_TYPE, NO_CONTEXT_TYPE
 
Fields inherited from interface com.sas.storage.olap.ResultSetInterface
DEFAULT_END_CELL, DEFAULT_ENDCELL
 
Constructor Summary
OLAPDataSet()
          default constructor
OLAPDataSet(java.lang.Object connection)
          Create a OLAPDataSet object with the connection that is IMDXServer or ISession object
OLAPDataSet(java.lang.Object connection, java.util.Locale locale, java.lang.String queryStatement)
          Create an OLAPDataSet with the passed in connection and query
OLAPDataSet(java.lang.Object connection, java.util.Locale locale, java.lang.String queryStatement, int contextType)
          Create an OLAPDataSet with the passed in connection and query
OLAPDataSet(java.lang.Object connection, java.lang.String queryStatement)
          Create an OLAPDataSet with the passed in connection and query
OLAPDataSet(java.lang.Object connection, java.lang.String queryStatement, int contextType)
          Create an OLAPDataSet with the passed in connection and query
OLAPDataSet(java.lang.Object connection, java.lang.String queryStatement, java.lang.String queryId)
          Create an OLAPDataSet with the passed in connection and query
OLAPDataSet(java.lang.String host, int port, java.lang.String username, java.lang.String password)
          Create an OLAPDataSet with passed in connection properties.
OLAPDataSet(java.lang.String host, int port, java.lang.String username, java.lang.String password, java.util.Locale locale, java.lang.String queryStatement)
          Create an OLAPDataSet with passed in connection properties.
OLAPDataSet(java.lang.String host, int port, java.lang.String username, java.lang.String password, java.lang.String queryStatement)
          Create an OLAPDataSet with passed in connection properties.
 
Method Summary
 void cancelQuery()
           
 void close()
          Closes the result set and clears the cache
 void executeQuery()
          Executes a query that is set, using the setQueryStatement.
 void executeQuery(java.lang.String queryStatement)
          Execute a passed in query.
 void executeQuery(java.lang.String queryStatement, java.lang.String queryId)
          QueryStatement should have queryID appended to it otherwise the id will be ignored.
 long getCellCount()
          Get the number of cells for the query.
 java.lang.Object[] getCells(long startCell, long endCell)
          Get the unformatted cells starting at the start Ordinal upto end ordinal.
 java.lang.Object getConnection()
          Get the connection(IMDXServer) or session(ISession) object set on this class.
 int getContextType()
          Get the context type for this md dataset
 java.lang.String getCubeName()
          Get the cubename for this query.
 MetadataInterface getDatabaseMetadata()
          This method returns an instance of the MetadataInterface which defines all of the Cubes' metadata on the OLAP Server to which the model is connected.
 java.lang.String[] getFormattedCells(long startCell, long endCell)
          Get the formatted cells starting at the start Ordinal upto end ordinal.
 java.util.Locale getLocale()
          Return the locale used to create a session object
 PerformanceTuning getPerformanceTuning()
          This method returns a performanceTuning object on the model.
 java.lang.String getQueryId()
           
 java.lang.String getQueryStatement()
          Returns the most recent query statement.
 ResultSetMetadataInterface getResultSetMetadata()
          Returns the metadata that defines the structure of the ResultSet
 java.lang.String getTotalLabel()
          Get the total label set on the result set elements
 boolean isReadOnly()
          This implementation will always return true.
 void setCells(long startCell, long endCell, java.lang.Object[] cellValues)
          This method is not supported
 void setConnection(java.lang.Object connection)
          This method can use a connection object or a session object associated with a connection.
 void setContextType(int contextType)
          Set the contextType for this dataSet.
 void setFormattedCells(long startCell, long endCell, java.lang.String[] cellValues)
          This is not supported
 void setLocale(java.util.Locale locale)
          Set the Locale used to create the session.
 void setPerformanceTuning(PerformanceTuning performanceTuning)
          Set the PerformanceTuning Object on this model.
 void setQueryStatement(java.lang.String queryStatement)
          Set the query statement.
 void setQueryStatement(java.lang.String queryStatement, java.lang.String queryID)
           
 void setQueryStatement(java.lang.String queryStatement, java.lang.String queryID, java.util.Map<java.lang.String,java.lang.String> measureLabelMap)
          QueryStatement should have queryID appended to it otherwise the id will be ignored.
 void setReadOnly(boolean readOnly)
          The readOnly state may only be set to true.
 void setTotalLabel(java.lang.String label)
          A convenience method to set the Total Label on the resultset element.
 

Constructor Detail

OLAPDataSet

public OLAPDataSet()
            throws OLAPException
default constructor

Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection)
            throws OLAPException
Create a OLAPDataSet object with the connection that is IMDXServer or ISession object

Parameters:
connection - OLAPConnection
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection,
                   java.lang.String queryStatement)
            throws OLAPException
Create an OLAPDataSet with the passed in connection and query

Parameters:
connection - OLAPConnection associated with this OLAPDataSet or ISession associated with the connection
queryStatement - query for this OLAPDataSet
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection,
                   java.lang.String queryStatement,
                   java.lang.String queryId)
            throws OLAPException
Create an OLAPDataSet with the passed in connection and query

Parameters:
connection - OLAPConnection associated with this OLAPDataSet or ISession associated with the connection
queryStatement - query for this OLAPDataSet
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.String host,
                   int port,
                   java.lang.String username,
                   java.lang.String password)
            throws OLAPException
Create an OLAPDataSet with passed in connection properties.

Parameters:
host - connection host
port - connection port
username - connection username
password - connection password
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.String host,
                   int port,
                   java.lang.String username,
                   java.lang.String password,
                   java.lang.String queryStatement)
            throws OLAPException
Create an OLAPDataSet with passed in connection properties.

Parameters:
host - connection host
port - connection port
username - connection username
password - connection password
queryStatement - query for this dataset
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection,
                   java.util.Locale locale,
                   java.lang.String queryStatement)
            throws OLAPException
Create an OLAPDataSet with the passed in connection and query

Parameters:
connection - a connection associated with this OLAPDataSet. The connection can be IMDXServer or ISession object.
Locale - to be used with the connection
queryStatement - query for this OLAPDataSet
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.String host,
                   int port,
                   java.lang.String username,
                   java.lang.String password,
                   java.util.Locale locale,
                   java.lang.String queryStatement)
            throws OLAPException
Create an OLAPDataSet with passed in connection properties.

Parameters:
host - connection host
port - connection port
username - connection username
password - connection password
Locale - to be used with the connection
queryStatement - query for this dataset
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection,
                   java.util.Locale locale,
                   java.lang.String queryStatement,
                   int contextType)
            throws OLAPException
Create an OLAPDataSet with the passed in connection and query

Parameters:
connection - a connection associated with this OLAPDataSet. The connection can be IMDXServer or ISession object.
Locale - to be used with the connection
queryStatement - query for this OLAPDataSet
Throws:
OLAPException

OLAPDataSet

public OLAPDataSet(java.lang.Object connection,
                   java.lang.String queryStatement,
                   int contextType)
            throws OLAPException
Create an OLAPDataSet with the passed in connection and query

Parameters:
connection - OLAPConnection associated with this OLAPDataSet or ISession associated with the connection
queryStatement - query for this OLAPDataSet
Throws:
OLAPException
Method Detail

setContextType

public void setContextType(int contextType)
                    throws OLAPException
Set the contextType for this dataSet. The contextType determines whether to return the tuples with context or without context

Specified by:
setContextType in interface OLAPDataSetInterface
Parameters:
contextType - Currently only two context types defined, DEFAULT_CONTEXT_TYPE and NO_CONTEXT_TYPE
Throws:
OLAPException

getContextType

public int getContextType()
                   throws OLAPException
Get the context type for this md dataset

Specified by:
getContextType in interface OLAPDataSetInterface
Returns:
contextType Currently only two context types defined, DEFAULT_CONTEXT_TYPE and NO_CONTEXT_TYPE
Throws:
OLAPException

setLocale

public void setLocale(java.util.Locale locale)
               throws OLAPException
Set the Locale used to create the session. Setting the Locale after the connection has been established will not take effect until the connection is closed and recreated. If not locale is set, the connection will use the default locale.

Specified by:
setLocale in interface OLAPDataSetInterface
Throws:
OLAPException - if a database error occurs

getLocale

public java.util.Locale getLocale()
                           throws OLAPException
Return the locale used to create a session object

Specified by:
getLocale in interface OLAPDataSetInterface
Returns:
Locale used to create the session object or null if the connection is not established and locale is not set by the user.
Throws:
OLAPException - if a database error occurs

getConnection

public java.lang.Object getConnection()
                               throws OLAPException
Get the connection(IMDXServer) or session(ISession) object set on this class. The get method will return a session object if a session object is passed in, otherwise will return a connection object.

Specified by:
getConnection in interface OLAPDataSetInterface
Returns:
The connection to the OLAP server
Throws:
OLAPException - if a database error occurs

setConnection

public void setConnection(java.lang.Object connection)
                   throws OLAPException
This method can use a connection object or a session object associated with a connection. The connection type for this implementation is the com.sas.iom.SASMDX.IMDXServer. The session type for this implementation is com.sas.iom.SASMDX.ISession. The get method will return a session object if a session object is passed in, otherwise will return a conmnection object. This defines a connection to the SAS OLAP server.

Specified by:
setConnection in interface OLAPDataSetInterface
Parameters:
connection - the connection can be either IMDXServer or ISession
Throws:
OLAPException - if a database error occurs

getQueryId

public java.lang.String getQueryId()

executeQuery

public void executeQuery(java.lang.String queryStatement,
                         java.lang.String queryId)
                  throws OLAPException
QueryStatement should have queryID appended to it otherwise the id will be ignored.

Parameters:
queryStatement - a complete uery including the id
queryId - queryid to be used by sub queries (ancestor query)
Throws:
OLAPException

executeQuery

public void executeQuery(java.lang.String queryStatement)
                  throws OLAPException
Execute a passed in query. If the query is null, an exception is thrown

Specified by:
executeQuery in interface OLAPDataSetInterface
Parameters:
mdx - statement
Throws:
OLAPException - if a database error occurs

setTotalLabel

public void setTotalLabel(java.lang.String label)
A convenience method to set the Total Label on the resultset element. Default value is null, this is used by the BusunessQueryToOLAPDataSetAdapter to set the Total label set on the businessquery on to the resultset element

Parameters:
label - to use for the Total element

getTotalLabel

public java.lang.String getTotalLabel()
Get the total label set on the result set elements

Returns:

getCubeName

public java.lang.String getCubeName()
                             throws OLAPException
Get the cubename for this query. Currently the assumption is that the query can only conatin one cube name.

Specified by:
getCubeName in interface OLAPDataSetInterface
Returns:
name of the cube
Throws:
OLAPException - if the cubename cannot be

executeQuery

public void executeQuery()
                  throws OLAPException
Executes a query that is set, using the setQueryStatement.

Specified by:
executeQuery in interface OLAPDataSetInterface
Throws:
OLAPException - if a database error occurs

setQueryStatement

public void setQueryStatement(java.lang.String queryStatement)
                       throws OLAPException
Set the query statement. A query is not executed until executeQuery() method is called

Specified by:
setQueryStatement in interface OLAPDataSetInterface
Parameters:
queryStatement - The query to be executed
Throws:
OLAPException - if a database error occurs

setQueryStatement

public void setQueryStatement(java.lang.String queryStatement,
                              java.lang.String queryID)
                       throws OLAPException
Throws:
OLAPException

setQueryStatement

public void setQueryStatement(java.lang.String queryStatement,
                              java.lang.String queryID,
                              java.util.Map<java.lang.String,java.lang.String> measureLabelMap)
                       throws OLAPException
QueryStatement should have queryID appended to it otherwise the id will be ignored.

Parameters:
queryStatement - a complete query including the id
queryId - queryid to be used by sub queries (ancestor query)
measureLabelMap - a map containing measure uniqueName as keys and associated label as value. For example ("[Measures]. [ACTUAL_SALES]"-= "Actual Sales"). Null values are not allowed. The values will be used for the associated query. If the key does not match any measure in the metadata for the cube, the label will be ignored and label from the server will be used.
Throws:
OLAPException - for database error or null values in the measureLabelmap

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws OLAPException
The readOnly state may only be set to true. This implementation does not support updates.

Specified by:
setReadOnly in interface OLAPDataSetInterface
Parameters:
readOnly - The updateable state of the OLAPDataSet.
Throws:
OLAPException - If a database-access error occurs

getResultSetMetadata

public ResultSetMetadataInterface getResultSetMetadata()
                                                throws OLAPException
Description copied from interface: ResultSetInterface
Returns the metadata that defines the structure of the ResultSet

Specified by:
getResultSetMetadata in interface ResultSetInterface
Returns:
The ResultSetMetadata which defines the structure of the ResultSet.
Throws:
OLAPException - if a database error occurs

getQueryStatement

public java.lang.String getQueryStatement()
                                   throws OLAPException
Description copied from interface: ResultSetInterface
Returns the most recent query statement. This value should be used as a hint for the query that may have generated this ResultSet. It's possible that this value could be null or out of date if the ResultSet is not connected. It is also possible that this query is not in sync with the ResultSet. It could have been set, but not executed, in which case the ResultSet is not a product of this query.

Specified by:
getQueryStatement in interface ResultSetInterface
Returns:
The most recent query statement.
Throws:
OLAPException - if a database error occurs

isReadOnly

public boolean isReadOnly()
                   throws OLAPException
This implementation will always return true. The OLAPDataSet is not updateable.

Specified by:
isReadOnly in interface ResultSetInterface
Returns:
Indicates whether this OLAPDataSet is updateable
Throws:
OLAPException - If a database-access error occurs

getCells

public java.lang.Object[] getCells(long startCell,
                                   long endCell)
                            throws OLAPException
Get the unformatted cells starting at the start Ordinal upto end ordinal. Since this returns a block of cells, the number of cells may not be the same as requested.

Specified by:
getCells in interface ResultSetInterface
Parameters:
startCell - A zero-based ordinal position for the starting cell.
endCell - A zero-based ordinal position for the ending cell where DEFAULT_ENDCELL can be used to indicate all remaining cells
Returns:
The data in its raw format.
Throws:
OLAPException - if a database error occurs

getFormattedCells

public java.lang.String[] getFormattedCells(long startCell,
                                            long endCell)
                                     throws OLAPException
Get the formatted cells starting at the start Ordinal upto end ordinal. Since this returns a block of cells, the number of cells may not be the same as requested.

Specified by:
getFormattedCells in interface ResultSetInterface
Parameters:
startCell - A zero-based ordinal position for the starting cell.
endCell - A zero-based ordinal position for the ending cell where DEFAULT_ENDCELL can be used to indicate all remaining cells
Returns:
The formatted data.
Throws:
OLAPException - if a database error occurs

getCellCount

public long getCellCount()
                  throws OLAPException
Get the number of cells for the query.

Specified by:
getCellCount in interface ResultSetInterface
Returns:
The total number of cells defined in the ResultSet.
Throws:
OLAPException - if a database error occurs

setCells

public void setCells(long startCell,
                     long endCell,
                     java.lang.Object[] cellValues)
              throws OLAPException
This method is not supported

Specified by:
setCells in interface ResultSetInterface
Parameters:
startCell - A zero-based ordinal position for the starting cell.
endCell - A zero-based ordinal position for the ending cell.
cellValues - Sets the values for the cells.
Throws:
OLAPException - if a database error occurs

setFormattedCells

public void setFormattedCells(long startCell,
                              long endCell,
                              java.lang.String[] cellValues)
                       throws OLAPException
This is not supported

Specified by:
setFormattedCells in interface ResultSetInterface
Parameters:
startCell - A zero-based ordinal position for the starting cell.
endCell - A zero-based ordinal position for the ending cell.
cellValues - Sets the formatted values for the cells.
Throws:
OLAPException - if a database error occurs

close

public void close()
           throws OLAPException
Closes the result set and clears the cache

Specified by:
close in interface ResultSetInterface
Throws:
OLAPException - if a database error occurs

getPerformanceTuning

public PerformanceTuning getPerformanceTuning()
                                       throws OLAPException
This method returns a performanceTuning object on the model. This can be null if the query has not been set. User can create a new PerformanceTuning object and set it on the model. The returned object may be a different than the set object, in case of it being set on multiple models. The model checks for an existence of model (property) on the passed in object and if there is one, it makes a copy of the passed in object and sets it on this model. In other words there is one to one relationship between model and the performance tuning object.

Specified by:
getPerformanceTuning in interface OLAPDataSetInterface
Returns:
performanceTuning object
Throws:
OLAPException

setPerformanceTuning

public void setPerformanceTuning(PerformanceTuning performanceTuning)
                          throws OLAPException
Set the PerformanceTuning Object on this model. Nothing will happen if the object is null. Since each instance of model has its own performance tuning, if this object is derived from another model or it is already set on another model, a copy of the perfroamnceTuning object will be made before setting it on this model. In other words, a get may not return the same object as the set.

Specified by:
setPerformanceTuning in interface OLAPDataSetInterface
Parameters:
perfromanceTuning - An Object that has performanceTuning properties set on it. Null will not have any effect.
Throws:
OLAPException

getDatabaseMetadata

public MetadataInterface getDatabaseMetadata()
                                      throws OLAPException
Description copied from interface: OLAPDataSetInterface
This method returns an instance of the MetadataInterface which defines all of the Cubes' metadata on the OLAP Server to which the model is connected. Implementations which do not support this MetadataInterface should return null.

Specified by:
getDatabaseMetadata in interface OLAPDataSetInterface
Returns:
metadata An instance of the MetadataInterface that shares the same connection as the Data Model
Throws:
OLAPException - If a database error occurs

cancelQuery

public void cancelQuery()
                 throws OLAPException
Throws:
OLAPException



Copyright © 2009 SAS Institute Inc. All Rights Reserved.