|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.storage.jdbc.JDBCRowCountAdapter
public abstract class JDBCRowCountAdapter
In many cases it may not be necessary or may be an expensive operation to determine the true row count of a data source. For example, one way to calculate the true row count of a forward only result set is to increment a counter while calling next() on the result set until the end of the result set is reached. This could be inefficient for large result sets.
This class optionally provides an alternative way for calculating the row count, by calculating a "current maximum row count". This value,
specified by the currentMaxRowCount
property is calculated in the calculateCurrentMaxRowCount
method by advancing the result
set cursor ahead of the input specified row, or the currentMaxRowCount
, whichever is greater. The amount the cursor will be advanced is
specified by the readAheadAmount
property. The default read ahead amount is 50 rows. When the end of the result set is reached,
the maxRowsFound
property is set to true, and the currentMaxRowCount
is equal to the true row count.
Field Summary | |
---|---|
protected int |
currentMaxRowCount
The current number of rows that have been read from the data source |
protected boolean |
maxRowsFound
A flag indicating if the true row count has been determined |
static java.lang.String |
RB_KEY
|
protected static int |
READ_AHEAD_AMOUNT
The default number of row to read ahead in the result set |
protected int |
readAheadAmount
The number of rows to read ahead in the data source |
protected boolean |
trueRowCountCalculated
If true, the actual row count is calculated. |
Fields inherited from class com.sas.storage.jdbc.JDBCAdapter |
---|
autoCommit, CLASS_NAME, columnInfoUsed, conn, designTime, displayTransform, forwardOnly, initialized, isRowCountKnown, LABEL, meta, NAME, printWarnings, queryRowCountDisabled, queryStatement, readOnly, result, resultSetRequeryUsed, resultSetType, resultSetUsed, retrieveNumericTypesAsDouble, rowCount, rowCountQueryString, rowNumber, spcs, stmt, trimUsed |
Constructor Summary | |
---|---|
JDBCRowCountAdapter()
Default constructor called when the adapter is made in a webAF project. |
|
JDBCRowCountAdapter(java.sql.Connection conn,
java.lang.String queryStatement)
Constructor used to create an initialized adapter. |
|
JDBCRowCountAdapter(java.sql.ResultSet result)
Constructor used to connect an adapter directly to a previously created ResultSet. |
Method Summary | |
---|---|
protected void |
calculateCurrentMaxRowCount(int requestedRow)
Calculates the currentMaxRowCount by attempting to advance the result set cursor ahead of the requestedRow
or currentMaxRowCount , whichever is greater. |
protected abstract void |
fireModelInsertEvent(int startRow,
int endRow)
Fire a insert event for a model signaling that an insert has occurred. |
int |
getReadAheadAmount()
Returns the number of rows the adapter will read ahead in the result set. |
boolean |
isTrueRowCountCalculated()
Returns true if the true row count is calcualted. |
void |
setConnection(java.sql.Connection conn)
Sets the connection object on the adapter. |
void |
setQueryStatement(java.lang.String queryStatement)
The queryStatement should be any SQL query that is
valid for the JDBC data source. |
void |
setReadAheadAmount(int readAheadAmount)
Sets the amount of rows that the adapter will attempt to read ahead in the result set. |
void |
setTrueRowCountCalculated(boolean trueRowCountCalculated)
Sets whether to calculate the true row count or the current maximum row count. |
Field Detail |
---|
public static final java.lang.String RB_KEY
protected boolean maxRowsFound
protected int currentMaxRowCount
protected int readAheadAmount
protected boolean trueRowCountCalculated
currentMaxRowCount
value will attempt to
be at least the readAheadAmount
number of rows higher than the highest row number retrieved.
protected static final int READ_AHEAD_AMOUNT
Constructor Detail |
---|
public JDBCRowCountAdapter()
public JDBCRowCountAdapter(java.sql.ResultSet result)
result
- ResultSet to use.public JDBCRowCountAdapter(java.sql.Connection conn, java.lang.String queryStatement)
conn
- A java.sql.Connection
object.queryStatement
- A SQL query that is valid for the database
represented by conn
.Method Detail |
---|
public void setTrueRowCountCalculated(boolean trueRowCountCalculated)
The current maximum row count is calculated by attempting to read ahead in the result set by readAheadAmount
rows when a value is retrieved. When the end of the result set is reached the current max row count is equal to the true row
count and the maxRowsFound
is set to true.
trueRowCountCalculated
- true if the true row count should be calculated, false if the current maximum row count should be calculatedisTrueRowCountCalculated()
public boolean isTrueRowCountCalculated()
setTrueRowCountCalculated(boolean)
public int getReadAheadAmount()
setReadAheadAmount(int)
public void setReadAheadAmount(int readAheadAmount)
readAheadAmount
- the number of rows the adapter will read ahead in the result setgetReadAheadAmount()
protected void calculateCurrentMaxRowCount(int requestedRow) throws java.sql.SQLException
currentMaxRowCount
by attempting to advance the result set cursor ahead of the requestedRow
or currentMaxRowCount
, whichever is greater. The amount the cursor will be advanced is specified by
the readAheadAmount
property. When the end of the result set is found, the maxRowsFound
property is
set to true.
requestedRow
- the row number to read ahead of
java.sql.SQLException
public void setQueryStatement(java.lang.String queryStatement)
queryStatement
should be any SQL query that is
valid for the JDBC data source. It is used to extract the desired data
from the database.
Calling this method has no affect if the constructer taking a ResultSet was used to create the adapter and the ResultSet is not a RowSet.
setQueryStatement
in class JDBCAdapter
queryStatement
- The SQL query to apply.public void setConnection(java.sql.Connection conn)
setConnection
in class JDBCAdapter
conn
- A java.sql.Connection object.protected abstract void fireModelInsertEvent(int startRow, int endRow)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |