com.sas.storage.olap.embedded
Class ResultSet

com.sas.storage.olap.embedded.ResultSet
All Implemented Interfaces:
ResultSetInterface

public class ResultSet
implements ResultSetInterface

Used for building an in memory multidimensional ResultSet. The MutableResultSet model is designed for a simple definition of multidimensional data. The data is stored in memory within the model. There is no connection or query associated with this model. To use the MutableResultSet model, simply start defining tuples and cells and adding axes with the appropriate data.

Creating an in memory Olap model
 The following example creates a model with Sales For all Dealers of Ford 
 and Chrysler for the months of January through May.
 // Make an instance of the Tuple Interface object
 TupleInterface tuple1 = new Tuple(new TupleElementInterface[] 
                         {new TupleElement("All Dealer"), 
                          new TupleElement("January")});
 TupleInterface tuple2 = new Tuple(new TupleElementInterface[] 
                         {new TupleElement("All Dealer"),
                          new TupleElement("February")});
 TupleInterface tuple3 = new Tuple(new TupleElementInterface[]
                         {new TupleElement("All Dealer"), 
                          new TupleElement("March")});  
 TupleInterface tuple4 = new Tuple(new TupleElementInterface[] 
                         {new TupleElement("All Dealer"),
                          new TupleElement("April")});  
 TupleInterface tuple5 = new Tuple(new TupleElementInterface[] 
                         {new TupleElement("All Dealer"), 
                          new TupleElement("May")});                     

 TupleInterface tuple6 = new Tuple(new TupleElementInterface[] 
                            {new TupleElement("Chrysler")});
 TupleInterface tuple7 = new Tuple(new TupleElementInterface[] 
                         {new TupleElement("Ford")});

 TupleInterface tuple8 = new Tuple(new TupleElementInterface[] 
                            {new TupleElement("Sum of Sales")});

 // Define the Axis for the model
 String[] colHeaders = new String[] {"All:Dealers", "Date"} ;
 String[] rowHeaders = new String[]{"Cars"};
 String[] slicerHeaders = new String[]{"Sum of Sales"};
 AxisInterface columnAxis = new Axis(AxisInterface.COLUMSNAXIS, colHeaders, 
                            new TupleInterface[] {tuple1, tuple2, tuple3, tuple4, tuple5});
 AxisInterface rowAxis    = new  Axis(AxisInterface.ROWSAXIS, rowHeaders, 
                            new TupleInterface[] {tuple6, tuple7});
 AxisInterface slicerAxis = new  Axis(AxisInterface.SLICERSAXIS, slicerHeaders, 
                            new TupleInterface[] {tuple8});
 AxisInterface[] axes = {columnAxis, rowAxis, slicerAxis};
 //create an instance of result set metadata with the axes
 ResultSetMetadata rsma = new ResultSetMetadata(axes);
 // create cell values
 Object[] cells = new Object[] {new Double(20000.0), new Double(47000.0), 
                                new Double(52000.0), new Double(20000.0),
                                new Double(24000.00), new Double(10000.0),
                                new Double(40000.0), new Double(2000.0), 
                                new Double(30000.0), new Double(36000.0)};
  ResultSet rs = new ResultSet();
  rs.setResultSetMetadata(rsma);
  rs.setCells(0, OLAPDataSet.DEFAULT_ENDCELL, cells); 
  
  // create an olap model (that attaches to the viewer) using the result set
  OLAPDataSet OLAPDataSet = new OLAPDataSet(rs);
 

See Also:
OLAPDataSet, ResultSetMetadata

Field Summary
 
Fields inherited from interface com.sas.storage.olap.ResultSetInterface
DEFAULT_END_CELL, DEFAULT_ENDCELL
 
Constructor Summary
ResultSet()
           
ResultSet(ResultSetMetadataInterface rsm)
           
 
Method Summary
 void close()
          Close the ResultSetInterface
 long getCellCount()
          Return the cell count for this result set based on the tuples set.
 java.lang.Object[] getCells(long startCell, long endCell)
          Returns the data beginning with the startCell ordinal and ending with endCell.
 java.lang.String[] getFormattedCells(long startCell, long endCell)
          Returns the data beginning with the startCell ordinal and ending with endCell.
 java.lang.String getQueryStatement()
          Returns the MDX query that defines this MultiDimensional dataset
 ResultSetMetadataInterface getResultSetMetadata()
          Return the resultSetMetadata for this result set
 boolean isReadOnly()
          return the readonly flag
 void removeCells(long startCell, long endCell)
          Remove a block of cells.
 void setCells(long startCell, long endCell, java.lang.Object[] values)
          Add/Replace a block of cell values for the cells based on startOrdinal and endOrdinal.
 void setFormattedCells(long startCell, long endCell, java.lang.String[] values)
          Sets the values for the cells
 void setResultSetMetadata(ResultSetMetadataInterface rsm)
          Set the resultsetmetadata for this result set.
 

Constructor Detail

ResultSet

public ResultSet()
          throws OLAPException
Throws:
OLAPException

ResultSet

public ResultSet(ResultSetMetadataInterface rsm)
          throws OLAPException
Throws:
OLAPException
Method Detail

getResultSetMetadata

public final ResultSetMetadataInterface getResultSetMetadata()
                                                      throws OLAPException
Return the resultSetMetadata for this result set

Specified by:
getResultSetMetadata in interface ResultSetInterface
Returns:
the resultset metadata for this result set
Throws:
OLAPException

getQueryStatement

public final java.lang.String getQueryStatement()
                                         throws OLAPException
Returns the MDX query that defines this MultiDimensional dataset

Specified by:
getQueryStatement in interface ResultSetInterface
Returns:
The MDX query that defines this MultiDimensional dataset.
Throws:
OLAPException

getCellCount

public long getCellCount()
                  throws OLAPException
Return the cell count for this result set based on the tuples set. If the cell values are not set, it will return the count based on the tuples set.

Specified by:
getCellCount in interface ResultSetInterface
Returns:
number of cells for this result set
Throws:
OLAPException

getCells

public java.lang.Object[] getCells(long startCell,
                                   long endCell)
                            throws OLAPException
Returns the data beginning with the startCell ordinal and ending with endCell. There is no distinction between formatted and unformatted values for an embedded ResultSet. The same set of cellValues will be returned for both getFormattedCells and getUnformattedCells. This implementation will return a missing value for a cell if the cells are not set, but the tuples associated with it are.

Specified by:
getCells in interface ResultSetInterface
Parameters:
startCell - Ordinal position for starting cell inclusive
endCell - Ordinal position for endCell where -1 means all remaining cells -inclusive
Returns:
The cell data
Throws:
OLAPException - if cannot get the cells

getFormattedCells

public java.lang.String[] getFormattedCells(long startCell,
                                            long endCell)
                                     throws OLAPException
Returns the data beginning with the startCell ordinal and ending with endCell. There is no distinction between formatted and unformatted values for an embedded ResultSet. The same set of cellValues will be returned for both getFormattedCells and getUnformattedCells.

Specified by:
getFormattedCells in interface ResultSetInterface
Parameters:
startCell - Ordinal position for starting cell
endCell - Ordinal position for endCell where -1 means all remaining cells - inclusive
Returns:
The data set on the cells.
Throws:
OLAPException - if a database error occurs

isReadOnly

public boolean isReadOnly()
                   throws OLAPException
return the readonly flag

Specified by:
isReadOnly in interface ResultSetInterface
Returns:
this will return always false, since this result set can be updated
Throws:
OLAPException

setResultSetMetadata

public void setResultSetMetadata(ResultSetMetadataInterface rsm)
                          throws OLAPException
Set the resultsetmetadata for this result set. The resultSetMetadata will also have this resultset set on itself.

Parameters:
resultsetmetadata - for this result set
Throws:
OLAPException

setFormattedCells

public void setFormattedCells(long startCell,
                              long endCell,
                              java.lang.String[] values)
                       throws OLAPException
Sets the values for the cells

Specified by:
setFormattedCells in interface ResultSetInterface
Parameters:
startCell - beginning index
endCellending - cell
values - Set the values for the cells. There is no distinction between formatted and unformatted values for an embedded ResultSet. The same set of cellValues will be returned for both getFormattedCells and getUnformattedCells.
Throws:
OLAPException

setCells

public void setCells(long startCell,
                     long endCell,
                     java.lang.Object[] values)
              throws OLAPException
Add/Replace a block of cell values for the cells based on startOrdinal and endOrdinal. NOTE: ResultSetMetadata has to be set before you can set the cells. The ResultsetMetadata has the axes information which is needed to calculate the ordinals to set the cellls on.

Specified by:
setCells in interface ResultSetInterface
Parameters:
beginning - cell ordinal
ending - cell ordinal
cellValues - Sets the values for the cells. There is no distinction between formatted and unformatted values for an embedded ResultSet. The same set of cellValues will be returned for both getFormattedCells and getUnformattedCells.
Throws:
OLAPException - if the startcell ordinal is not in the result set.

removeCells

public void removeCells(long startCell,
                        long endCell)
                 throws OLAPException
Remove a block of cells. This method can be used to remove a block of cells corresponding to a column or row tuple, when that tuple is removed. i.e. Remove a column or a row from the table. Removing the cells from inbetween without removing the tuple will cause the cells values to move up filling the bottom cells with default value (missing value for now).

Parameters:
startOrdinal - of the cell
endOrdinal - of the cell
Throws:
OLAPException - if the cells cannot be removed

close

public void close()
Description copied from interface: ResultSetInterface
Close the ResultSetInterface

Specified by:
close in interface ResultSetInterface



Copyright © 2009 SAS Institute Inc. All Rights Reserved.