info.informatica.data
Class SampleDataset

java.lang.Object
  extended by info.informatica.data.SampleDataset
All Implemented Interfaces:
Dataset

public class SampleDataset
extends Object
implements Dataset

Provides a random set of data for a given Metadata.

Author:
Carlos Amengual (amengual at informatica.info)

Constructor Summary
SampleDataset(MetaData md, int maxRows)
           
 
Method Summary
 void close()
          Closes the Dataset.
 Object evaluate(String id)
          Sometimes you want to directly access a field or method and evaluate it, instead of getting the object and then accessing the field or calling the method.
 int findColumn(FieldName name)
          Finds the index of the given column name of the dataset.
 String getCatalogName(int i)
          Gets the designated data item's catalog name.
 int getColumnCount()
           
 FieldName getColumnName(int i)
          Gets the designated data item's column name.
 Date getDate(FieldName id)
          Returns Date of name id.
 Date getDate(int i)
          Returns Date of index i.
 double getDouble(FieldName id)
          Returns double of name id
 double getDouble(int i)
          Returns int of index i
 Map<String,? extends Object> getEnviron()
          Gets a global "environment" Map, if available.
 int getInt(FieldName id)
          Returns int of name id
 int getInt(int i)
          Returns int of index i
 String getLabel()
          Gets the label of this Set, or null if not available.
 long getLong(FieldName id)
          Returns long of name id
 long getLong(int i)
          Returns long of index i
 Map<FieldName,Object> getMap()
          Gets a name -> values map containing the current data row.
 MetaData getMetaData()
          Gets the meta data for this data set.
 Dataset getNestedSet(String datasetName)
          It is allowed to have another Datasets nested to the current Dataset row.
 Object getObject(FieldName id)
          Returns Object of name id
 Object getObject(int i)
          Returns Object of index i
 String getString(FieldName id)
          Returns String of name id.
 String getString(int i)
          Returns String of index i.
 boolean isAfterLast()
          Retrieves wether the dataset is after its last row.
 boolean isEmpty()
           
 boolean isLast()
          Retrieves wether the dataset is on its last row.
 boolean next()
          Positions the Dataset at the next row of data.
 void reset()
          Puts the Dataset cursor in the initial state, regardless of the current cursor state.
 void setEnviron(Map<String,? extends Object> environ)
          Sets a global "environment" Map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleDataset

public SampleDataset(MetaData md,
                     int maxRows)
Method Detail

getDate

public Date getDate(FieldName id)
             throws DatasetException
Description copied from interface: Dataset
Returns Date of name id.

Specified by:
getDate in interface Dataset
Returns:
the Date value of name id.
Throws:
DatasetException - if the data repository produced an error.

getDate

public Date getDate(int i)
             throws DatasetException
Description copied from interface: Dataset
Returns Date of index i.

Specified by:
getDate in interface Dataset
Returns:
the Date value of index i.
Throws:
DatasetException - if the data repository produced an error.

getDouble

public double getDouble(FieldName id)
                 throws DatasetException
Description copied from interface: Dataset
Returns double of name id

Specified by:
getDouble in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getDouble

public double getDouble(int i)
                 throws DatasetException
Description copied from interface: Dataset
Returns int of index i

Specified by:
getDouble in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getInt

public int getInt(FieldName id)
           throws DatasetException
Description copied from interface: Dataset
Returns int of name id

Specified by:
getInt in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getInt

public int getInt(int i)
           throws DatasetException
Description copied from interface: Dataset
Returns int of index i

Specified by:
getInt in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getObject

public Object getObject(FieldName id)
                 throws DatasetException
Description copied from interface: Dataset
Returns Object of name id

Specified by:
getObject in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getObject

public Object getObject(int i)
                 throws DatasetException
Description copied from interface: Dataset
Returns Object of index i

Specified by:
getObject in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getLong

public long getLong(FieldName id)
             throws DatasetException
Description copied from interface: Dataset
Returns long of name id

Specified by:
getLong in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getLong

public long getLong(int i)
             throws DatasetException
Description copied from interface: Dataset
Returns long of index i

Specified by:
getLong in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getString

public String getString(FieldName id)
                 throws DatasetException
Description copied from interface: Dataset
Returns String of name id.

Specified by:
getString in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getString

public String getString(int i)
                 throws DatasetException
Description copied from interface: Dataset
Returns String of index i.

Specified by:
getString in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

evaluate

public Object evaluate(String id)
                throws DatasetException
Description copied from interface: Dataset
Sometimes you want to directly access a field or method and evaluate it, instead of getting the object and then accessing the field or calling the method. The evaluate method provides a way to do that, and when called it will either return a variable named id or a method evaluation of the style package.object.method.

Specified by:
evaluate in interface Dataset
Parameters:
id - Fully qualified function name (package.object.function) or fqfn
Returns:
the result given by the function, or the object itself if there is no function (dot not specified in fqfn), or null if the function or method are not available.
Throws:
DatasetException - if the data repository produced an error.

getLabel

public String getLabel()
Description copied from interface: Dataset
Gets the label of this Set, or null if not available.

Specified by:
getLabel in interface Dataset

isEmpty

public boolean isEmpty()
                throws DatasetException
Specified by:
isEmpty in interface Dataset
Returns:
true if the Dataset is empty, false otherwise.
Throws:
DatasetException

next

public boolean next()
             throws DatasetException
Description copied from interface: Dataset
Positions the Dataset at the next row of data.

Specified by:
next in interface Dataset
Returns:
false if there were no more rows, true otherwise.
Throws:
DatasetException - if the data repository produced an error.

getColumnCount

public int getColumnCount()
                   throws DatasetException
Specified by:
getColumnCount in interface Dataset
Returns:
the number of columns of this Dataset.
Throws:
DatasetException - if the data repository produced an error.

getCatalogName

public String getCatalogName(int i)
                      throws DatasetException
Description copied from interface: Dataset
Gets the designated data item's catalog name.

Specified by:
getCatalogName in interface Dataset
Throws:
DatasetException - if the data repository produced an error.

getColumnName

public FieldName getColumnName(int i)
                        throws DatasetException
Description copied from interface: Dataset
Gets the designated data item's column name.

Specified by:
getColumnName in interface Dataset
Throws:
DatasetException

getMetaData

public MetaData getMetaData()
                     throws DataException
Description copied from interface: Dataset
Gets the meta data for this data set.

Specified by:
getMetaData in interface Dataset
Returns:
the meta data for this data set, or null if not available.
Throws:
DataException - if the data repository produced an error.

isAfterLast

public boolean isAfterLast()
                    throws DatasetException
Description copied from interface: Dataset
Retrieves wether the dataset is after its last row.

Specified by:
isAfterLast in interface Dataset
Returns:
true if the dataset is after its last row, false otherwise.
Throws:
DatasetException - if the data repository produced an error.

isLast

public boolean isLast()
               throws DatasetException
Description copied from interface: Dataset
Retrieves wether the dataset is on its last row.

Evaluation of this method could be expensive.

Specified by:
isLast in interface Dataset
Returns:
true if the dataset is on its last row, false otherwise.
Throws:
DatasetException - if the data repository produced an error.

reset

public void reset()
           throws DatasetException
Description copied from interface: Dataset
Puts the Dataset cursor in the initial state, regardless of the current cursor state.

This method allows the reuse of a Dataset object after all rows have been extracted by the use of the next() function.

This method is optional. Implementations are required to throw an UnsupportedOperationException in case they do not implement it.

Specified by:
reset in interface Dataset
Throws:
DatasetException - if an error happened when resetting the data.

close

public void close()
           throws DatasetException
Description copied from interface: Dataset
Closes the Dataset.

No further work is possible with the Dataset after closing it.

Specified by:
close in interface Dataset
Throws:
DatasetException - if an error happens when closing the Dataset.

findColumn

public int findColumn(FieldName name)
               throws DatasetException
Description copied from interface: Dataset
Finds the index of the given column name of the dataset.

Specified by:
findColumn in interface Dataset
Returns:
the index of the given column name of the dataset, or -1 if the column name is not known.
Throws:
DatasetException - if an error happens when accessing the data.

getMap

public Map<FieldName,Object> getMap()
                             throws DatasetException
Description copied from interface: Dataset
Gets a name -> values map containing the current data row.

Optional operation.

Specified by:
getMap in interface Dataset
Returns:
a Map with the current data row. Cannot return null.
Throws:
DatasetException - if an error happens when creating the Map.

setEnviron

public void setEnviron(Map<String,? extends Object> environ)
Description copied from interface: Dataset
Sets a global "environment" Map.

Specified by:
setEnviron in interface Dataset
Parameters:
environ - a Map with the environment.

getEnviron

public Map<String,? extends Object> getEnviron()
Description copied from interface: Dataset
Gets a global "environment" Map, if available.

Specified by:
getEnviron in interface Dataset
Returns:
a Map with the environment, or null if no environment is available.

getNestedSet

public Dataset getNestedSet(String datasetName)
                     throws DatasetException
Description copied from interface: Dataset
It is allowed to have another Datasets nested to the current Dataset row.

This is an optional operation. Datasets not supporting it must throw an UnsupportedOperationException.

Specified by:
getNestedSet in interface Dataset
Parameters:
datasetName - the name of the requested Dataset.
Returns:
the Dataset nested into the current row.
Throws:
DatasetException - if the data repository produced an error.