org.teiid.test.client.ctc
Class QueryResults

java.lang.Object
  extended by org.teiid.test.client.ctc.QueryResults
All Implemented Interfaces:
Externalizable, Serializable

public class QueryResults
extends Object
implements Externalizable

This class encapsulates results associated with a query.

Results are conceptually organized as a table of columns and rows, where the columns are the data fields that were specified in the query select statement, and the rows are individual records returned from the data set. The data values are arbitrary Java objects in each field/record cell.

 
  
            Record # |  Field1    Field2    Field3   ...    FieldN
           ----------|---------------------------------------------
              1      |  Value11   Value12   Value13         Value1N
              2      |  Value21   Value22   Value23         Value2N
              :      |     :         :         :               :
              M      |  ValueM1   ValueM2   ValueM3         ValueMN
   
  
 

Methods are provided to access data by:

Results can be specified to be sorted based on a user-provided ordering. The ordering is a List of ElementSymbols, which should match the identifiers for the results fields. This list will typically be in the order that the parameters were specified in the query select statement. If no ordering list is specified, the order is the same as results fields are added to this object.

See Also:
Serialized Form

Nested Class Summary
static class QueryResults.ColumnInfo
          Represents all information about a column.
 
Constructor Summary
QueryResults()
          Construct a default instance of this class.
QueryResults(List fields)
          Construct an instance of this class, specifying the order that the elements should be inserted into the map.
QueryResults(List fields, int numberOfRecords)
          Construct an instance of this class, specifying the fields and the number of records that the result set should hold.
QueryResults(List elements, TupleBatch tupleBatch)
          Construct a QueryResults from a TupleBatch.
 
Method Summary
 void addField(QueryResults.ColumnInfo info)
          Add a new field into this result set.
 void addFields(Collection fields)
          Add a set of fields into this result set.
 int addRecord()
          Add a new record for all fields.
 int addRecord(List record)
          Add a new record for all fields.
 boolean containsField(String field)
          Returns true if the specified field is in the result set.
static List createColumnInfos(List symbols)
          Convert a list of SingleElementSymbols to a List of ColumnInfo objects.
 boolean equals(Object object)
          Compares with another result set
 QueryResults.ColumnInfo getColumnInfo(String columnName)
          Get the column information given the column name.
 int getFieldCount()
          Returns the number of fields in the result set.
 List getFieldIdents()
          Returns all the field identifiers.
 int getIndexOfField(String field)
          Returns the index of the specified field is in the result set.
 int getRecordCount()
          Returns the number of records in the result set.
 List getRecords()
          Get the records contained in this result.
 List getRecordValues(int recordNumber)
          Returns the values for the specified record.
 List getTypes()
           
 Object getValue(String columnName, int recordNumber)
          Get the value for the specified field and record.
 void readExternal(ObjectInput s)
          Implements Externalizable interface to read serialized form
 void setValue(String field, int recordNumber, Object value)
          Set the value at a particular record for a field.
 String toString()
          Returns a string representation of an instance of this class.
 void writeExternal(ObjectOutput s)
          Implements Externalizable interface to write serialized form
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryResults

public QueryResults()
Construct a default instance of this class.

The number of fields returned by the getFieldCount()method will be 0 after this constructor has completed. The number of records returned by the getRecordCount()method will be 0 after this constructor has completed.


QueryResults

public QueryResults(List fields)
Construct an instance of this class, specifying the order that the elements should be inserted into the map. The number of fields returned by the getFieldCount()method will be the same as the number of fields passed in after this constructor has completed. The number of records returned by the getRecordCount()method will be 0 after this constructor has completed.

Parameters:
fields - The set of field identifiers that will be in the result set

QueryResults

public QueryResults(List fields,
                    int numberOfRecords)
Construct an instance of this class, specifying the fields and the number of records that the result set should hold. The fields and number of records are used to pre-allocate memory for all the values that are expected to be indested into the results set.

The number of records returned by the getRecordCount()method will be numberOfRecords after this constructor has completed. The number of fields returned by the getFieldCount()will be the same as the size of the list of fields passed in after this constructor has completed.

Parameters:
fields - The ordered list of variables in select statement
numberOfRecords - The number of blank records to create; records will all contain null values for all the fields
See Also:
addField(org.teiid.test.client.ctc.QueryResults.ColumnInfo)

QueryResults

public QueryResults(List elements,
                    TupleBatch tupleBatch)
Construct a QueryResults from a TupleBatch. Take all rows from the QueryBatch and put them into the QueryResults.

Parameters:
elements - List of SingleElementSymbols
tupleBatch - Batch of rows
Method Detail

getFieldIdents

public List getFieldIdents()
Returns all the field identifiers. If the parameters in the query select statement have been provided, then the set of field identifiers should be a subset of them, and ordered the same.

This method will never return null. The list of identifiers returned is not mutable -- changes made to this list will not affect the QueryResults object.

Returns:
The field identifiers

getColumnInfo

public QueryResults.ColumnInfo getColumnInfo(String columnName)
Get the column information given the column name.

Parameters:
columnName - The name of the column.
Returns:
Column information

getFieldCount

public int getFieldCount()
Returns the number of fields in the result set.

Returns:
The number of fields

getRecordCount

public int getRecordCount()
Returns the number of records in the result set.

Returns:
The number of records

getValue

public Object getValue(String columnName,
                       int recordNumber)
                throws IllegalArgumentException,
                       IndexOutOfBoundsException
Get the value for the specified field and record.

The value returned is not mutable -- changes made to this value will not affect the QueryResults object.

Note that results must be retrieved with the same type of data node identifier that was specified in the select statement.

Parameters:
columnName - The unique data element identifier for the field
recordNumber - The record number
Returns:
The data value at the specified field and record
Throws:
IllegalArgumentException - If field is not in result set
IndexOutOfBoundsException - If record is not in result set

getRecordValues

public List getRecordValues(int recordNumber)
                     throws IndexOutOfBoundsException
Returns the values for the specified record. The values are ordered the same as the field identifiers in the result set, which will be the same as the order of the query select parameters if they have been provided.

The list of values returned is not mutable -- changes made to this list will not affect the QueryResults object.

Parameters:
recordNumber - The record number
Returns:
A list containing the field values for the specified record, ordered according to the original select parameters, if defined
Throws:
IndexOutOfBoundsException

getRecords

public List getRecords()
Get the records contained in this result. The records are returned as a list of field values (a list of lists).

Returns:
A list of lists contains the field values for each row.

containsField

public boolean containsField(String field)
Returns true if the specified field is in the result set.

Parameters:
field - Unique identifier for a data element specified in result set

getTypes

public List getTypes()

addField

public void addField(QueryResults.ColumnInfo info)
Add a new field into this result set. The field will be inserted in the order of the parameters in the select statement if those parameters were specified upon construction of the result set; otherwise, the field will be appended to the result set.

Parameters:
info - The column information.

addFields

public void addFields(Collection fields)
Add a set of fields into this result set. The fields will be inserted in the order of the parameters in the select statement if those parameters were specified upon construction of the result set; otherwise, the field will be appended to the result set.

Parameters:
fields - The field identifiers.

addRecord

public int addRecord()
Add a new record for all fields. The record is populated with all null values, which act as placeholders for subsequent setValue calls.

Before this method is called, the fields must already be defined.

Returns:
The updated number of records

addRecord

public int addRecord(List record)
Add a new record for all fields. The record must contain the same number of values as there are fields.

Before this method is called, the fields must already be defined.

Returns:
The updated number of records

setValue

public void setValue(String field,
                     int recordNumber,
                     Object value)
              throws IllegalArgumentException,
                     IndexOutOfBoundsException
Set the value at a particular record for a field.

The specified field and record must already exist in the data set, or an exception will be thrown. The addField(ColumnInfo)method can be used to append values or new records for fields.

Parameters:
field - The unique data element identifier for the field
recordNumber - The record number
Throws:
IndexOutOfBoundsException - If the specified record does not exist
IllegalArgumentException

getIndexOfField

public int getIndexOfField(String field)
                    throws IllegalArgumentException
Returns the index of the specified field is in the result set. An exception is thrown if the field is not in the set.

Parameters:
field - Unique identifier for a data element specified in result set
Returns:
The index of the field in the set of fields
Throws:
IllegalArgumentException - If field is not in result set

createColumnInfos

public static List createColumnInfos(List symbols)
Convert a list of SingleElementSymbols to a List of ColumnInfo objects.

Parameters:
symbols - List of SingleElementSymbols
Returns:
List of ColumnInfos

equals

public boolean equals(Object object)
Compares with another result set

Overrides:
equals in class Object

toString

public String toString()
Returns a string representation of an instance of this class.

Overrides:
toString in class Object

readExternal

public void readExternal(ObjectInput s)
                  throws ClassNotFoundException,
                         IOException
Implements Externalizable interface to read serialized form

Specified by:
readExternal in interface Externalizable
Parameters:
s - Input stream to serialize from
Throws:
ClassNotFoundException
IOException

writeExternal

public void writeExternal(ObjectOutput s)
                   throws IOException
Implements Externalizable interface to write serialized form

Specified by:
writeExternal in interface Externalizable
Parameters:
s - Output stream to serialize to
Throws:
IOException


Copyright © 2012. All Rights Reserved.