| java.lang.Object com.knowgate.dataobjs.DBSubset
DBSubset | final public class DBSubset (Code) | | A bidimensional array representing data readed from a database table.
The DBSubset object is used for reading a collection of registers from the database
and kept them in memory for inmediate access.
As hipergate reuses database connections by recycling them at the
JDCConnectionPool ,
it is a good programming practice to read just the needed number of registers in a single
step operation and then free the connection as soon as possible for being used by another processs.
Another reason for this "read fast and leave" tactic is that some JDBC drivers have problems
managing multiple open resultsets with pending results in a single connection.
author: Sergio Montoro Ten version: 3.0 |
Constructor Summary | |
public | DBSubset(String sTableName, String sColumnList, String sFilterClause, int iFetchSize) Contructs a DBSubset.
Parameters: sTableName - Base table or tables, ie. |
Method Summary | |
public int | call(JDCConnection oConn) | public int | call(JDCConnection oConn, int iSkip) | public int | call(JDCConnection oConn, Object[] aFilterValues) Execute a stored procedure returning a ResultSet
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. | public int | call(JDCConnection oConn, Object[] aFilterValues, int iSkip) | public int | clear(Connection oConn, Object[] aFilterValues) | public void | ensureCapacity(int nCols, int nRows) | public boolean | eof() | public int | find(int iCol, Object oVal) Find a value in a given column
Value is searched by brute force from the begining to the end of the column.
Trying to find a null value is allowed.
Find is case sensitive. | public Object | get(int iCol, int iRow) | public Object | get(String sCol, int iRow) | public boolean | getBoolean(int iCol, int iRow) | public List | getColumnAsList(int iCol) | public int | getColumnCount() | public String | getColumnDelimiter() | public String[] | getColumnNames() | public int | getColumnPosition(String sColumnName) Parameters: sColumnName - Name of column witch position is to be returned. | public java.util.Date | getDate(int iCol, int iRow) | public java.util.Date | getDate(String sCol, int iRow) | public String | getDateFormated(int iCol, int iRow, String sFormat) | public String | getDateShort(int iCol, int iRow) | public String | getDateTime(int iCol, int iRow) | public String | getDateTime24(int iCol, int iRow) | public BigDecimal | getDecimal(int iCol, int iRow) Get pre-loaded value and tries to convert it into a BigDecimal
If column is NULL then null value is returned.
If base columnn is of type String then thsi function will try to parse the
value into a BigDecimal. | public BigDecimal | getDecimal(String sCol, int iRow) | public String | getDecimalFormated(int iCol, int iRow, String sPattern) | public String | getDecimalFormated(String sCol, int iRow, String sPattern) | public double | getDouble(int iCol, int iRow) | public float | getFloat(int iCol, int iRow) | public float | getFloat(String sCol, int iRow) | public float | getFloat(int iCol, int iRow, int iDecimals) | public float | getFloat(String sCol, int iRow, int iDecimals) | public int | getInt(int iCol, int iRow) | public int | getInt(String sCol, int iRow) | public Integer | getInteger(int iCol, int iRow) | public Integer | getInteger(String sCol, int iRow) | public long | getIntervalMilis(int iCol, int iRow) Return interval value in miliseconds
This method is only for PostgreSQL 8.0 or later
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] long Interval in miliseconds. | public int | getMaxRows() | public Money | getMoney(int iCol, int iRow) | public Money | getMoney(String sCol, int iRow) | public int | getQueryTimeout() | public List | getRowAsList(int iRow) | public Map | getRowAsMap(int iRow) | public Vector | getRowAsVector(int iRow) | public int | getRowCount() | public String | getRowDelimiter() | public java.sql.Date | getSQLDate(int iCol, int iRow) | public java.sql.Date | getSQLDate(String sCol, int iRow) | public java.sql.Time | getSQLTime(int iCol, int iRow) | public java.sql.Time | getSQLTime(String sCol, int iRow) | public short | getShort(int iCol, int iRow) | public String | getString(int iCol, int iRow) | public String | getString(String sCol, int iRow) | public String | getStringNull(int iCol, int iRow, String sDef) | public String | getStringNull(String sCol, int iRow, String sDef) | public String | getTextQualifier() | public long | getTimeMilis(int iCol, int iRow) | public Time | getTimeOfDay(int iCol, int iRow) | public Timestamp | getTimestamp(int iCol, int iRow) | public boolean | isNull(int iCol, int iRow) | public boolean | isNull(String sCol, int iRow) | public int | load(JDCConnection oConn) | public int | load(JDCConnection oConn, int iSkip) Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: iSkip - Number of rows to be skipped before reading. | public int | load(JDCConnection oConn, Object[] aFilterValues) Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. | public int | load(JDCConnection oConn, Object[] aFilterValues, int iSkip) Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. Parameters: iSkip - Number of rows to be skipped before reading. | public void | parseCSV(String sFilePath, String sCharSet) Parse a delimited text file into DBSubset bi-dimensional array
The parsed file must have the same column structure as the column list set when the DBSubset constructor was called. | public void | parseCSV(String sFilePath) Parse a delimited text file into DBSubset bi-dimensional array
The parsed file must have the same column structure as the column list set when the DBSubset constructor was called. | public void | parseCSV(char[] aData, String sCharSet) Parse character data into DBSubset bi-dimensional array
The parsed file must have the same column structure as the column list set when the DBSubset constructor was called. | public void | parseCSV(char[] aData) Parse character data into DBSubset bi-dimensional array
The parsed file must have the same column structure as the column list set when the DBSubset constructor was called. | public void | print(Connection oConn, OutputStream oOutStrm) Print DBSubset to an output stream
This method is quite different in behavior from toString() and toXML(). | public void | setColumnDelimiter(String sDelim) | public void | setElementAt(Object oObj, int iCol, int iRow) | public void | setElementAt(Object oObj, String sCol, int iRow) | public void | setMaxRows(int iMax) Maximum number of rows to be readed from database
The exact behavior of this property depends on the RDBMS used.
For PostgreSQL [LIMIT n] clause is appended to DBSubset query and all returned rows are readed.
For Microsoft SQL Server [OPTION FAST(n)] clause is appended to DBSubset query
and then the number of readed rows is limited at client side fetching.
For Oracle there is no standard way of limiting the resultset size. | public void | setQueryTimeout(int iMaxSeconds) | public void | setRowDelimiter(String sDelim) | public void | setTextQualifier(String sQualifier) | public void | sortBy(int iCol) Sort in memory an already loaded ResultSet by a given column
A modified bubble sort algorithm is used. | public SQLException[] | store(JDCConnection oConn, Class oDBPersistSubclass, boolean bStopOnError) Store full contents of this DBSubset at base table
This method takes all the dat contained in memory for this DBSubsets and
stores it at the database. | public Object | sum(int iCol) | public String | toString() | public String | toXML(String sIdent, String sNode, String sDateFormat, String sDecimalFormat) Write DBSubset to an XML string
Parameters: sIdent - Initial space identations on the left for fields Parameters: sNode - Name of top parent node. | public String | toXML(String sIdent, String sNode) Write DBSubset to an XML string
Use default output format for date values: yyyy-MM-dd'T'hh:mm:ss
Parameters: sIdent - Initial space identations on the left for fields Parameters: sNode - Name of top parent node. | public void | union(DBSubset oDbs) |
DBSubset | public DBSubset(String sTableName, String sColumnList, String sFilterClause, int iFetchSize)(Code) | | Contructs a DBSubset.
Parameters: sTableName - Base table or tables, ie. "k_products" or "k_products p, k_x_cat_objs x" Parameters: sColumnList - Column list to be retirved from base tables i.e "p.gu_product,p.nm_product" Parameters: sFilterClause - SQL filter clause or null if there is no filter clause to be applied. Parameters: iFetchSize - Space for number of rows initailly allocated. Is DBSubset later loads more rowsthe buffer is automatically expanded. This parameter may also have a great effect on reducingnetwork round trips as the ResultSet.setFetchSize(iFetchSize) method is called prior to fetchingrows. Fetching rows in batches is much faster than doing so one by one. When iFetchSize is set,the JDBC driver may optimize accesses to fetched rows by reading bursts andcaching rows at client side. |
call | public int call(JDCConnection oConn, Object[] aFilterValues) throws SQLException(Code) | | Execute a stored procedure returning a ResultSet
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. Number of rows retrieved throws: SQLException - |
clear | public int clear(Connection oConn, Object[] aFilterValues) throws SQLException(Code) | | Delete rows from base table
Parameters: oConn - Connection Parameters: aFilterValues - Object[] Parameters for sFilter parameter specified at constructor int Number of rows deleted throws: SQLException - |
ensureCapacity | public void ensureCapacity(int nCols, int nRows)(Code) | | Pre-allocate a given number of empty rows and columns
Parameters: nCols - Number of columns per row Parameters: nRows - Number of rows to allocate since: 2.2 |
eof | public boolean eof()(Code) | | true if call() or load() methods readed all available rows,false if more rows where pending of reading when getMaxRows() wasreached. Also, after calling store(), eof() is true if all rows were storedsuccessfully or false if any row failed to be inserted or updated. |
find | public int find(int iCol, Object oVal)(Code) | | Find a value in a given column
Value is searched by brute force from the begining to the end of the column.
Trying to find a null value is allowed.
Find is case sensitive.
Parameters: iCol - Column to be searched [0..getColumnCount()-1] Parameters: oVal - Value searched Row where seached value was found or -1 is value was not found. |
getColumnCount | public int getColumnCount()(Code) | | Number of columns retrieved. |
getColumnDelimiter | public String getColumnDelimiter()(Code) | | Column delimiter for print() and toString() methods. |
getColumnNames | public String[] getColumnNames()(Code) | | Get column names
String[] An array with names of columns from the most recently SQL SELECT sentence. since: 3.0 |
getColumnPosition | public int getColumnPosition(String sColumnName)(Code) | | Parameters: sColumnName - Name of column witch position is to be returned. Column names are case insensitive. Column position or -1 if no column with such name exists. |
getDateShort | public String getDateShort(int iCol, int iRow)(Code) | | Get pre-loaded value for a Date field formated as a short Date "yyyy-MM-dd"
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] String with format "yyyy-MM-dd" or null. throws: ClassCastException - |
getDateTime24 | public String getDateTime24(int iCol, int iRow)(Code) | | Get pre-loaded value for a Date field formated as a DateTime "yyyy-MM-dd HH:mm:ss"
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] String with format "yyyy-MM-dd HH:mm:ss" or null. throws: ClassCastException - since: 2.1 |
getDecimal | public BigDecimal getDecimal(int iCol, int iRow) throws java.lang.ClassCastException, java.lang.NumberFormatException(Code) | | Get pre-loaded value and tries to convert it into a BigDecimal
If column is NULL then null value is returned.
If base columnn is of type String then thsi function will try to parse the
value into a BigDecimal. A single dot '.' is used as decimal delimiter no
matter which is the current locale. All comma characters ',' are removed
before parsing String into BigDecimal.
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] Field value converted to BigDecimal or null if field was NULL. throws: java.lang.ClassCastException - throws: java.lang.NumberFormatException - |
getInteger | public Integer getInteger(int iCol, int iRow) throws ArrayIndexOutOfBoundsException(Code) | | Get pre-loaded value and tries to convert it into an Integer
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] Field value converted to Integer or null if field was NULL. |
getIntervalMilis | public long getIntervalMilis(int iCol, int iRow) throws ArrayIndexOutOfBoundsException, ClassCastException(Code) | | Return interval value in miliseconds
This method is only for PostgreSQL 8.0 or later
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] long Interval in miliseconds. If interval is null then zero is returned. For Postgres 7.4 and earlier versions this method always return zeroeven if the interval column is not null. throws: ArrayIndexOutOfBoundsException - throws: ClassCastException - since: v2.2 |
getMaxRows | public int getMaxRows()(Code) | | Maximum number of rows to be readed from database |
getQueryTimeout | public int getQueryTimeout()(Code) | | Maximum amount of time in seconds that a query may run before being cancelled. |
getRowCount | public int getRowCount()(Code) | | number of rows retrieved by last call() or load() method invocation. |
getRowDelimiter | public String getRowDelimiter()(Code) | | Row delimiter for print() and toString() methods. |
getStringNull | public String getStringNull(int iCol, int iRow, String sDef) throws ArrayIndexOutOfBoundsException(Code) | | Get toString() form of pre-loaded value
Parameters: iCol - Column position [0..getColumnCount()-1] Parameters: iRow - Row position [0..getRowCount()-1] Parameters: sDef - Default value Field value converted to String default value sDef if field was NULL. |
getTextQualifier | public String getTextQualifier()(Code) | | Text qualifier for quoting fields in print() and toString() methods. |
load | public int load(JDCConnection oConn, int iSkip) throws SQLException, IllegalArgumentException, ArrayIndexOutOfBoundsException, NullPointerException(Code) | | Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: iSkip - Number of rows to be skipped before reading. On database systems that support anOFFSET clause (such as PostgreSQL) the native offset feature of the DBMS is used, in case thatthe DBMS does not provide offset capabilities, the data is fetched and discarded at client sidebefore returning the DBSubset. Care must be taken when skipping a large number of rows in clientside mode as it may cause heavy network traffic and round trips to the database. Number of rows retrievedthe maximum number of rows to be retrieved is determined by calling methodsetMaxRows(), if setMaxRows() is not called before call() then all rows existing are retrieved. throws: SQLException - throws: IllegalArgumentException - if iSkip<0 throws: ArrayIndexOutOfBoundsException - throws: NullPointerException - |
load | public int load(JDCConnection oConn, Object[] aFilterValues) throws SQLException, ArrayIndexOutOfBoundsException, NullPointerException(Code) | | Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. Number of rows retrievedthe maximum number of rows to be retrieved is determined by calling methodsetMaxRows(), if setMaxRows() is not called before call() then all rows existing are retrieved. throws: SQLException - |
load | public int load(JDCConnection oConn, Object[] aFilterValues, int iSkip) throws SQLException, IllegalArgumentException, ArrayIndexOutOfBoundsException, NullPointerException(Code) | | Execute a JDBC Statement and load query ResultSet in an internal bidimensional matrix
Parameters: oConn - Database Connection Parameters: aFilterValues - Values to be binded and JDBC PreparedStatement query paramenters. Parameters: iSkip - Number of rows to be skipped before reading. On database systems that support anOFFSET clause (such as PostgreSQL) the native offset feature of the DBMS is used, in case thatthe DBMS does not provide offset capabilities, the data is fetched and discarded at client sidebefore returning the DBSubset. Care must be taken when skipping a large number of rows in clientside mode as it may cause heavy network traffic and round trips to the database. Number of rows retrievedthe maximum number of rows to be retrieved is determined by calling methodsetMaxRows(), if setMaxRows() is not called before call() then all rows existing are retrieved. throws: SQLException - throws: IllegalArgumentException - if iSkip<0 |
print | public void print(Connection oConn, OutputStream oOutStrm) throws SQLException(Code) | | Print DBSubset to an output stream
This method is quite different in behavior from toString() and toXML().
In toString() and toXML() methods data is first pre-loaded by invoking
call() or load() methods and then written to a string buffer.
For toString() and toXML() memory consumption depends on how many rows
are pre-loaded in memory.
print() method directly writes readed data to the output stream without creating
the bidimimensional internal array for holding readed data.
This way data is directly piped from database to output stream.
Parameters: oConn - Database Connection Parameters: oOutStrm - Output Stream throws: SQLException - |
setColumnDelimiter | public void setColumnDelimiter(String sDelim)(Code) | | Parameters: sDelim - Column delimiter for print() and toString() methods.The default delimiter is '`' character |
setMaxRows | public void setMaxRows(int iMax)(Code) | | Maximum number of rows to be readed from database
The exact behavior of this property depends on the RDBMS used.
For PostgreSQL [LIMIT n] clause is appended to DBSubset query and all returned rows are readed.
For Microsoft SQL Server [OPTION FAST(n)] clause is appended to DBSubset query
and then the number of readed rows is limited at client side fetching.
For Oracle there is no standard way of limiting the resultset size.
The number of readed rows is just limited at client side fetching.
|
setQueryTimeout | public void setQueryTimeout(int iMaxSeconds)(Code) | | Maximum number of seconds that a query can be executing before raising a timeout exception
Parameters: iMaxSeconds - |
setRowDelimiter | public void setRowDelimiter(String sDelim)(Code) | | Parameters: sDelim - Row delimiter for print() and toString() methods.The default delimiter is '¨' character |
setTextQualifier | public void setTextQualifier(String sQualifier)(Code) | | Parameters: sQualifier - Text qualifier for quoting fields in print() and toString() methods. |
store | public SQLException[] store(JDCConnection oConn, Class oDBPersistSubclass, boolean bStopOnError) throws SQLException, IllegalAccessException, InstantiationException, ArrayIndexOutOfBoundsException(Code) | | Store full contents of this DBSubset at base table
This method takes all the dat contained in memory for this DBSubsets and
stores it at the database. For each row, if it does not exist then it is
inserted, if it exists then it is updated.
Parameters: oConn - JDBC Database Connection Parameters: oDBPersistSubclass - DBPersist subclass for rows. DBSubset will call theproper DBPersist.store() derived method for each row, executing specific codefor the subclass such as automatic GUID at modification date generation. Parameters: bStopOnError - true if process should stop if any SQLException isthrown, false if process must continue upon an SQLException and leavereturn addional information throught SQLException[] array. An array with a SQLException object per stored row, if no SQLExceptionwas trown for a row then the entry at the array for that row is null. eof() property is set to true if all rows were inserted successfully,and, thus, all entries of the returned SQLException array are null; if any rowfailed to be inserted or updated then eof() is set to false throws: SQLException - Only if bStopOnError is true throws: IllegalAccessException - throws: InstantiationException - |
toString | public String toString()(Code) | | Write DBSubset to a delimited text string using the column and row delimiters
stablished at setColumnDelimiter() and setRowDelimiter() properties.
String dump of the whole DBSubset pre-loaded data. |
toXML | public String toXML(String sIdent, String sNode, String sDateFormat, String sDecimalFormat)(Code) | | Write DBSubset to an XML string
Parameters: sIdent - Initial space identations on the left for fields Parameters: sNode - Name of top parent node. If null then main table namefor this DBSubset is used. Parameters: sDateFormat - Output format for date values Parameters: sDecimalFormat - Output format for decimal and floating point values XML string dump of the whole DBSubset pre-loaded data. |
toXML | public String toXML(String sIdent, String sNode)(Code) | | Write DBSubset to an XML string
Use default output format for date values: yyyy-MM-dd'T'hh:mm:ss
Parameters: sIdent - Initial space identations on the left for fields Parameters: sNode - Name of top parent node. If null then main table namefor this DBSubset is used. XML string dump of the whole DBSubset pre-loaded data. |
|
|