com.jfw.database
Class ReadDbData

java.lang.Object
  extended by com.jfw.database.ReadDbData

public final class ReadDbData
extends java.lang.Object

Offers methods for read data from a ResultSet. Some methods are explicity create for the Parser. All public methods are static and thread safe.


Field Summary
static java.lang.String ALL_ROWS_KEY
          Key paired with container of data readed from db.
static java.lang.String COLUMN_NAME_KEY
          Key paired with the name of a column.
static java.lang.String COLUMNS_NAMES_KEY
          Key paired with columns names.
static java.lang.String GROUP_BY_ROWS
          Key paired with container of data readed from db.
static java.lang.String GROUP_BY_ROWS_COUNT
          Key paired with number of rows from db.
static java.lang.String GROUP_SUFFIX
          Suffix for readed rows key.
static java.lang.String READED_ROWS_SUFFIX
          Suffix for readed rows key.
static java.lang.String ROW_ODD
          Value for odd rows, used for key ROW_TYPE.
static java.lang.String ROW_PAR
          Value for par rows, used for key ROW_TYPE.
static java.lang.String ROW_TYPE
          Key paired with row type value.
static java.lang.String SKIPPED_ROWS_SUFFIX
          Suffix for readed rows key.
static java.lang.String TOTAL_ROWS_SUFFIX
          Suffix for total rows key.
 
Constructor Summary
ReadDbData()
           
 
Method Summary
static byte[] getBLOB(java.sql.ResultSet resultSet, int index)
          Read a column BLOB.
static byte[] getBLOB(java.sql.ResultSet resultSet, java.lang.String name)
          Read a column BLOB.
static java.lang.StringBuilder getCLOB(java.sql.CallableStatement callable, int index)
          Read a column CLOB.
static java.lang.StringBuilder getCLOB(oracle.sql.CLOB clob)
          Read a column CLOB.
static java.lang.StringBuilder getCLOB(java.sql.ResultSet resultSet, int index)
          Read a column CLOB.
static java.lang.StringBuilder getCLOB(java.sql.ResultSet resultSet, java.lang.String name)
          Read a column CLOB.
static int getColumns(java.sql.ResultSet res, java.util.ArrayList columnsNames, java.lang.String groupBy)
          Get the names of the columns and save them in the columnsNames parameter.
static java.util.ArrayList getColumns4Parser(java.util.ArrayList columnsNames)
          Transform an ArrayList with the names of the columns in an ArrayList of HashMaps with the names of the columns.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer)
          Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer, java.lang.String listName)
          Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer, java.lang.String listName, boolean escape, java.lang.String groupBy)
          Use method result2Hash(ResultSet,HashMap,String,boolean,String,int,int) to read data.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer, java.lang.String listName, boolean escape, java.lang.String groupBy, int rows2Read, int firstRow)
          Save all rows returned by the query in a "data container" compatible with the Parser.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer, java.lang.String listName, int rows2Read, int firstRow)
          Use method result2Hash(ResultSet,HashMap,String,boolean,String,int,int) to read data.
static void result2Hash(java.sql.ResultSet res, java.util.HashMap hashContainer, java.lang.String listName, java.lang.String groupBy)
          Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data.
static void setColumns4Parser(java.util.ArrayList columnsNames, java.util.HashMap hashContainer)
          Set the columns names under key COLUMNS_NAMES_KEY in the HashMap container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROW_TYPE

public static final java.lang.String ROW_TYPE
Key paired with row type value.

See Also:
Constant Field Values

ROW_ODD

public static final java.lang.String ROW_ODD
Value for odd rows, used for key ROW_TYPE.

See Also:
Constant Field Values

ROW_PAR

public static final java.lang.String ROW_PAR
Value for par rows, used for key ROW_TYPE.

See Also:
Constant Field Values

GROUP_BY_ROWS

public static final java.lang.String GROUP_BY_ROWS
Key paired with container of data readed from db.

See Also:
Constant Field Values

GROUP_BY_ROWS_COUNT

public static final java.lang.String GROUP_BY_ROWS_COUNT
Key paired with number of rows from db.

See Also:
Constant Field Values

ALL_ROWS_KEY

public static final java.lang.String ALL_ROWS_KEY
Key paired with container of data readed from db.

See Also:
Constant Field Values

COLUMNS_NAMES_KEY

public static final java.lang.String COLUMNS_NAMES_KEY
Key paired with columns names.

See Also:
Constant Field Values

COLUMN_NAME_KEY

public static final java.lang.String COLUMN_NAME_KEY
Key paired with the name of a column.

See Also:
Constant Field Values

TOTAL_ROWS_SUFFIX

public static final java.lang.String TOTAL_ROWS_SUFFIX
Suffix for total rows key.

See Also:
Constant Field Values

READED_ROWS_SUFFIX

public static final java.lang.String READED_ROWS_SUFFIX
Suffix for readed rows key.

See Also:
Constant Field Values

GROUP_SUFFIX

public static final java.lang.String GROUP_SUFFIX
Suffix for readed rows key.

See Also:
Constant Field Values

SKIPPED_ROWS_SUFFIX

public static final java.lang.String SKIPPED_ROWS_SUFFIX
Suffix for readed rows key.

See Also:
Constant Field Values
Constructor Detail

ReadDbData

public ReadDbData()
Method Detail

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer,
                               java.lang.String listName,
                               boolean escape,
                               java.lang.String groupBy,
                               int rows2Read,
                               int firstRow)
                        throws DatabaseException
Save all rows returned by the query in a "data container" compatible with the Parser.
Every row is saved in an HashMap (the names of the keys are the names of the returned columns in uppercase). Every HashMap is added in an ArrayList.
In the HashMap hashContainer are also saved:
  1. under key listName_count the number of readed groups
  2. under key listName_total_count the number of readed rows
  3. under key listName_skipped_rows the number of skipped rows
  4. under key listName_total_rows the number of all rows in result set

Parameters:
res - a ResultSet object.
hashContainer - the HasMap containing the ArrayList of HashMaps. The default key to use, if parameter listName is null, is ALL_ROWS_KEY.
listName - the key value for the ArrayList of HashMaps.
escape - if true the data are escapedusing the method escape(java.lang.String).
groupBy - the column name to group by.
rows2Read - max number of rows to read. If the value is -1 then all the available rows will be read.
firstRow - the first row to read. The first row index is 1.
Throws:
DatabaseException

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer,
                               java.lang.String listName,
                               boolean escape,
                               java.lang.String groupBy)
                        throws DatabaseException
Use method result2Hash(ResultSet,HashMap,String,boolean,String,int,int) to read data.
The value of parameter escape is false.
The value of parameter groupBy is null. The value of parameter rows2Read is -1. The value of parameter firstRow is 1.

Throws:
DatabaseException

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer,
                               java.lang.String listName,
                               int rows2Read,
                               int firstRow)
                        throws DatabaseException
Use method result2Hash(ResultSet,HashMap,String,boolean,String,int,int) to read data.
The value of parameter escape is false.
The value of parameter groupBy is null.

Throws:
DatabaseException

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer,
                               java.lang.String listName)
                        throws DatabaseException
Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data.
The value of parameter escape is false.
The value of parameter groupBy is null.

Throws:
DatabaseException

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer)
                        throws DatabaseException
Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data.
The value of parameter listName is ALL_ROWS_KEY.
The value of parameter escape is false.
The value of parameter groupBy is null.

Throws:
DatabaseException

result2Hash

public static void result2Hash(java.sql.ResultSet res,
                               java.util.HashMap hashContainer,
                               java.lang.String listName,
                               java.lang.String groupBy)
                        throws DatabaseException
Use method result2Hash(ResultSet,HashMap,String,boolean,String) to read data. The value of parameter escape is false.

Throws:
DatabaseException

getColumns

public static int getColumns(java.sql.ResultSet res,
                             java.util.ArrayList columnsNames,
                             java.lang.String groupBy)
                      throws java.lang.Exception
Get the names of the columns and save them in the columnsNames parameter. Also, return the position of the group by column.

Parameters:
res - a ResultSet object.
columnsNames - the names of the columns in uppercase. The position 0 of the array is always the blank space(""). The parameter mustn't be null.
groupBy - the name of column to groyp by.
Returns:
If parameter groupBy has a value not null the returned value will be the position in the ArrayList of the column to group by. If the group by column not found or groupBy is null then return -1.
Throws:
java.lang.Exception

getColumns4Parser

public static java.util.ArrayList getColumns4Parser(java.util.ArrayList columnsNames)
Transform an ArrayList with the names of the columns in an ArrayList of HashMaps with the names of the columns.

Parameters:
columnsNames - the ArrayList with the names of the columns.
Returns:
an ArrayList of HashMaps with the names of the columns. The name is paired with key COLUMN_NAME_KEY

setColumns4Parser

public static void setColumns4Parser(java.util.ArrayList columnsNames,
                                     java.util.HashMap hashContainer)
Set the columns names under key COLUMNS_NAMES_KEY in the HashMap container.

Parameters:
columnsNames - ArrayList of HashMaps with the names of the columns.
hashContainer - the container of the data.

getCLOB

public static java.lang.StringBuilder getCLOB(oracle.sql.CLOB clob)
                                       throws DatabaseException
Read a column CLOB.

Parameters:
clob - the CLOB object to read.
Returns:
a StringBuilder with the CLOB chars readed.
Throws:
DatabaseException

getCLOB

public static java.lang.StringBuilder getCLOB(java.sql.ResultSet resultSet,
                                              int index)
                                       throws DatabaseException
Read a column CLOB.

Parameters:
resultSet - a ResultSet object.
index - the position on ResultSet of the CLOB column.
Returns:
a StringBuilder with the CLOB chars readed.
Throws:
DatabaseException

getCLOB

public static java.lang.StringBuilder getCLOB(java.sql.CallableStatement callable,
                                              int index)
                                       throws DatabaseException
Read a column CLOB.

Parameters:
callable - a CallableStatement object.
index - the position on ResultSet of the CLOB column.
Returns:
a StringBuilder with the CLOB chars readed.
Throws:
DatabaseException

getCLOB

public static java.lang.StringBuilder getCLOB(java.sql.ResultSet resultSet,
                                              java.lang.String name)
                                       throws DatabaseException
Read a column CLOB.

Parameters:
resultSet - a ResultSet object.
name - the name on ResultSet of the CLOB column.
Returns:
a StringBuilder with the CLOB chars readed.
Throws:
DatabaseException

getBLOB

public static byte[] getBLOB(java.sql.ResultSet resultSet,
                             java.lang.String name)
                      throws DatabaseException
Read a column BLOB.

Parameters:
resultSet - a ResultSet object.
name - the name on ResultSet of the BLOB column.
Returns:
a array of bytes with the BLOB bytes readed.
Throws:
DatabaseException

getBLOB

public static byte[] getBLOB(java.sql.ResultSet resultSet,
                             int index)
                      throws DatabaseException
Read a column BLOB.

Parameters:
resultSet - a ResultSet object.
index - the index on ResultSet of the BLOB column.
Returns:
a array of bytes with the BLOB bytes readed.
Throws:
DatabaseException