ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.xmlconfig
Class DBSourceArray2D

java.lang.Object
  extended by umontreal.iro.lecuyer.xmlconfig.AbstractParam
      extended by umontreal.iro.lecuyer.xmlconfig.DBSourceArray2D
All Implemented Interfaces:
Cloneable, Param, SourceArray2D, StorableParam

public class DBSourceArray2D
extends AbstractParam
implements SourceArray2D, Cloneable, StorableParam

Represents a source array whose data is extracted from a database using JDBC. The elements of the array are obtained by performing a query on a database. Each row of the resulting result set is a row in the source array, while each column corresponding to a field of the result set becomes a column in the array. The JDBC connection is initialized using DBConnectionParam, and the result set is converted into an array of objects using JDBCManager.readObjectData2D(Connection,String). Any numeric object (instances of Number) is converted to the target class while other objects not corresponding to the target class are converted to string before they are passed to String).

In a XML file, the dataQuery attribute of an element representing a database-based source array is used to specify the query on the database. The database nested element is then used to describe the connection to the database.


Constructor Summary
DBSourceArray2D()
           
 
Method Summary
 void addDatabase(DBConnectionParam dbParams1)
          For internal use only.
 DBSourceArray2D clone()
           
 int columns(int row)
          Returns the number of columns in row row of the source array.
 void dispose()
          Clears the data in the source array.
<T> T
get(Class<T> pcls, int row, int column)
          Returns the element at row row and column column of the source array, converted to class pcls.
 DBConnectionParam getDatabase()
          Returns the parameters of the database connection used to obtain data for this source array.
 String getDataQuery()
          Returns the SQL query used to obtain data for the element in the source array.
 String getElementName()
          Returns the name of the XML element representing the type of source array implemented.
 void init()
          Initializes the source array by performing the SQL query.
 int rows()
          Returns the number of rows in the source array.
 void setDatabase(DBConnectionParam dbParams)
          Sets the parameters of the database connection to dbParams.
 void setDataQuery(String dataQuery)
          Sets the SQL query for data to dataQuery.
 Element toElement(ClassFinder finder, Node parent, String elementName, int spc)
          Converts this parameter object to a DOM element using the class finder finder for formatting class names, with parent node parent, element name elementName, and spc spaces for each indentation level.
 
Methods inherited from class umontreal.iro.lecuyer.xmlconfig.AbstractParam
check, createDocument, getId, getXref, setId, setXref, toString, write, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DBSourceArray2D

public DBSourceArray2D()
Method Detail

getDatabase

public DBConnectionParam getDatabase()
Returns the parameters of the database connection used to obtain data for this source array.

Returns:
the database connection parameters.

setDatabase

public void setDatabase(DBConnectionParam dbParams)
Sets the parameters of the database connection to dbParams.

Parameters:
dbParams - the parameters for the database connection.

getDataQuery

public String getDataQuery()
Returns the SQL query used to obtain data for the element in the source array. The query, e.g., SELECT Column FROM Table, is made on the database whose parameters are given by getDatabase().

Returns:
the SQL query for data.

setDataQuery

public void setDataQuery(String dataQuery)
Sets the SQL query for data to dataQuery.

Parameters:
dataQuery - the SQL query for data.

columns

public int columns(int row)
Description copied from interface: SourceArray2D
Returns the number of columns in row row of the source array.

Specified by:
columns in interface SourceArray2D
Parameters:
row - the row to test.
Returns:
the number of columns in the row.

dispose

public void dispose()
Description copied from interface: SourceArray2D
Clears the data in the source array.

Specified by:
dispose in interface SourceArray2D

get

public <T> T get(Class<T> pcls,
                 int row,
                 int column)
      throws UnsupportedConversionException
Description copied from interface: SourceArray2D
Returns the element at row row and column column of the source array, converted to class pcls.

Specified by:
get in interface SourceArray2D
Type Parameters:
T - the target class.
Parameters:
pcls - the target class.
row - the row index.
column - the column index.
Returns:
the element.
Throws:
UnsupportedConversionException

init

public void init()
Initializes the source array by performing the SQL query. This method establishes the connection to the database using JDBC, issues the SQL query, and copies the elements of the result set in an internal 2D array. The resulting internal array, which is the contents of the source array, is a snapshot of the result of the query; it is not updated automatically if the database changes.

Specified by:
init in interface SourceArray2D

rows

public int rows()
Description copied from interface: SourceArray2D
Returns the number of rows in the source array.

Specified by:
rows in interface SourceArray2D
Returns:
the number of rows in the array.

addDatabase

public void addDatabase(DBConnectionParam dbParams1)
For internal use only.


toElement

public Element toElement(ClassFinder finder,
                         Node parent,
                         String elementName,
                         int spc)
Description copied from interface: StorableParam
Converts this parameter object to a DOM element using the class finder finder for formatting class names, with parent node parent, element name elementName, and spc spaces for each indentation level. The method must create an Element instance with name elementName and add it to the node parent of the DOM tree. It is recommended to use DOMUtils helper methods for this. After the element is created, attributes can be set and nested contents can be added. The configured DOM element is then returned.

Specified by:
toElement in interface StorableParam
Parameters:
finder - the class finder used to format class names.
parent - the parent of the new element.
elementName - the name of the constructed element.
spc - the number of spaces for each indentation level.
Returns:
the newly-constructed element.

clone

public DBSourceArray2D clone()
Overrides:
clone in class Object

getElementName

public String getElementName()
Description copied from interface: SourceArray2D
Returns the name of the XML element representing the type of source array implemented.

Specified by:
getElementName in interface SourceArray2D
Returns:
the name of the XML representing the array type.

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.