com.sas.storage.jdbc
Class JDBCAdapter

com.sas.storage.jdbc.JDBCAdapter
All Implemented Interfaces:
com.sas.table.StaticColumnInfoInterface, com.sas.util.transforms.DisplayTransformInterface
Direct Known Subclasses:
JDBCColumnValuesAdapter, JDBCRowCountAdapter, JDBCToDataTableAdapter

public abstract class JDBCAdapter
implements com.sas.util.transforms.DisplayTransformInterface, com.sas.table.StaticColumnInfoInterface

The JDBCAdapter is an abstract class that provides common methods that assist in displaying JDBC data sources in a viewer.

Two ways have been provided to create an adapter. The first is to supply a java.sql.Connection and a query statement, either through the constructor, or through set methods. The setConnection() method will apply the connection object. The setQueryStatement() method will apply the SQL query statement. When non-null values for both connection and query statement have been applied, the adapter is initialized and ready to use. The query statement must be a SQL query that is valid for the JDBC data source. This may include a blank statement, if valid.

The other way to create an adapter is to use the constructor taking a java.sql.ResultSet object as a parameter. In this case, calling the setConnection() methods will have no affect. If the result set is an instance of a RowSet, then calling the The setQueryStatement() method will set the command on the row set, otherwise it will do nothing.

If autoCommit is true when any setXXX method is used, an updateRow() method will be called upon the ResultSet so that the value(s) passed by the setXXX method are updated to the data source. If autoCommit is false, it is necessary to call the commitRow() method to commit changes to the data source.

This adapter works best with JDBC drivers that can create scrollable result sets. Table viewers usually need to read backwards to support scrolling the viewer. However, the adapter can support using scrolling viewers with forward-only result sets (ResultSet.TYPE_FORWARD_ONLY). This is accomplished by re-executing the query statement to obtain a new result set whenever there is a need to read a row before the current row. There is a performance penalty for this because the server must be requeried and the adapter re-initializes. If you want to turn off this feature, call setResultSetRequeryUsed(false). This option is not available when the adapter is created with a ResultSet object directly because the query cannot be executed again in this case unless the result set is a RowSet object.

This table shows the constants from the java.sql.Types class and whether this adapter supports getting those types. It also shows whether the adapter supports setting those types with either a "setXXX" or "setFormattedXXX" method. A viewer will call a "setFormattedXXX" method on the adapter when there is a change made to a value shown in the viewer.

JDBC Type get set setFormatted
BIT X X X
TINYINT X X X
SMALLINT X X X
INTEGER X X X
BIGINT X X X
FLOAT X X X
REAL X X X
DOUBLE X X X
NUMERIC X X X
DECIMAL X X X
CHAR X X X
VARCHAR X X X
LONGVARCHAR X    
DATE X X X
TIME X X X
TIMESTAMP X X X
BINARY X X  
VARBINARY X X  
LONGVARBINARY X    
NULL      
OTHER      
JAVA_OBJECT X X  
DISTINCT      
STRUCT X X  
ARRAY X    
BLOB X    
CLOB X    
REF X    


Field Summary
protected  boolean autoCommit
          If true, updates will be automatically committed to the database.
static java.lang.String CLASS_NAME
          One of the valid values for getColumnInfo.
protected  java.lang.String columnInfoUsed
          The value passed in by setColumInfoUsed.
protected  java.sql.Connection conn
          The Connection object supplied by the constructor or setModel method.
protected  boolean designTime
          True if the class is used at webAF design time.
protected  com.sas.util.transforms.TransformInterface displayTransform
          The transform used on the data.
protected  boolean forwardOnly
          If true, the adapter is connected to a result set that is ResultSet.TYPE_FORWARD_ONLY.
protected  boolean initialized
          True if the adapter is initialized with a Connection object and queryStatement.
protected  boolean isRowCountKnown
          Indicates if the number of rows in the result set is known
static java.lang.String LABEL
          One of the valid values for setColumnInfoUsed.
protected  java.sql.ResultSetMetaData meta
          The ResultSetMetaData object created from the Statement object when queryStatement is supplied.
static java.lang.String NAME
          One of the valid values for setColumnInfoUsed.
protected  boolean printWarnings
          True if the adapter should print SQLWarning messages.
protected  boolean queryRowCountDisabled
          Indicates if the row count should be determined by executing a "count" query or the rowCountQueryString if one is provided.
protected  java.lang.String queryStatement
          The SQL query statement.
static java.lang.String RB_KEY
           
protected  boolean readOnly
          True if the adapter is read-only.
protected  java.sql.ResultSet result
          The ResultSet object created from the Statement object when queryStatement is supplied.
protected  boolean resultSetRequeryUsed
          If the adapter is connected to a result set that is ResultSet.TYPE_FORWARD_ONLY this property controls whether the result set can be requeried to permit a simulation of scrolling backwards.
protected  int resultSetType
          The type of the ResultSet.
protected  boolean resultSetUsed
          If true, no connections or queries will be used to remake a previously created result set
protected  boolean retrieveNumericTypesAsDouble
          Indicates if numeric JDBC types will be retrieved from the ResultSet with the getDouble method
protected  int rowCount
          Used with counting rows in the result set in the calculateRowCount method.
protected  java.lang.String rowCountQueryString
          The query string used to determine the number of rows in the result set
protected  int rowNumber
          Indicates the row number the result set cursor is currently positioned on.
protected  javax.swing.event.SwingPropertyChangeSupport spcs
          Used to support property changes in the webAF customizer
protected  java.sql.Statement stmt
          The Statement object created from the Connection.
protected  boolean trimUsed
          If true, all character string data returned from the data source will be trimmed of whitespace according to String.trim().
 
Constructor Summary
JDBCAdapter()
          Default constructor called when the adapter is made in a webAF project.
JDBCAdapter(java.sql.Connection conn, java.lang.String queryStatement)
          Constructor used to create an initialized adapter.
JDBCAdapter(java.sql.ResultSet result)
          Constructor used to connect an adapter directly to a previously created ResultSet.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
protected  int calculateRowCount()
          Counts the number of rows when the underlying result set is not scrollable (TYPE_FORWARD_ONLY) and resultSetRequeryUsed is true.
 void close()
          Closes the statement and the result set.
protected  boolean doAbsolute(int index)
          For scrollable result sets, the absolute() method is called on the result set.
protected  int doCountColumns(int maxCount)
          The number of columns known to be available.
protected  void doUpdateCell(int col, java.lang.Object value)
          This method is called by public "setter" methods.
protected  void finalize()
          Closes the JDBC objects
protected abstract  void fireCellEvent(int row, int column)
          Fire a specific event for a model signaling that one cell has changed.
protected abstract  void fireModelEvent()
          Fire a default event for a model signaling the some aspect of the model has changed.
protected abstract  void fireModelEvent(java.util.EventObject event)
          Fire a specific event for a model signaling that some aspect of the model has changed.
 boolean getAutoCommit()
          Gets the value of autoCommit.
 java.lang.Object getColumnInfo(int index, java.lang.String columnInfoName)
          Returns the named information for a column.
 java.lang.String[] getColumnInfoNames()
          Returns an array of the named information that can be returned for the columns.
 java.sql.Connection getConnection()
          Gets the connection object used as the adapter's model.
 com.sas.util.transforms.TransformInterface getDisplayTransform()
          Return current transform, which can be null
 java.sql.Connection getModel()
          Returns the connection object attached to the adapter when the adapter is part of a webAF project.
 boolean getPrintWarnings()
          Returns whether or not to print SQL warnings to System.out.
 java.lang.String getQueryStatement()
          Returns the SQL query that has been applied to the JDBC data source.
protected  int getResultSetConcurrency()
           
protected  int getResultSetRowCount()
          This method finds the number of rows in a JDBC ResultSet using the standard JDBC technique.
 int getResultSetType()
          The resultSetType value returned at design time reflects the value that was set by calling the setResultSetType method, or the default value of ResultSet.TYPE_SCROLL_SENSITIVE.
protected  int getRowCountByCountFunction()
          This method attempts to find the number of rows in a JDBC ResultSet by using the SQL count function.
 java.lang.String getRowCountQueryString()
          Returns the query String used to determine the row count when the queryRowCountDisabled is set to false.
protected  void init()
          Creates the Statement, ResultSet, and ResultSetMetaData objects using the queryStatement whenever the initialized field is false.
protected  void initializeData()
           
 boolean isQueryRowCountDisabled()
          Indicates if the row count should be determined by executing a "count" query.
 boolean isReadOnly()
          The value returned at design time reflects the value that was set by calling the setReadOnly method, or the default value of true.
 boolean isResultSetRequeryUsed()
          Gets the value of resultSetRequeryUsed.
 boolean isRetrieveNumericTypesAsDouble()
          Returns a value indicating whether to retrieve numeric JDBC types with the ResultSet getDouble method.
 boolean isTrimUsed()
          Returns the value of trimUsed.
protected  void printSQLWarning(java.sql.SQLWarning w)
          Prints message, SQL state and vendor error code from SQLWarning objects if printWarnings is true.
protected  void putColumnInfoUsed(java.lang.String info)
          Sets the column information that is currently being used as the column label.
protected  void putValueAt(java.lang.Object value, int rowIndex, int columnIndex)
          Updates value into the cell at rowIndex, columnIndex.
 void refresh()
          Reinitializes the result set and fires a model event.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
protected  java.lang.Class retrieveColumnClass(int index)
          Returns the class of a column.
protected  int retrieveColumnCount()
          Returns the number of columns in the result set.
protected  int retrieveColumnIndex(java.lang.String name)
          Returns the column index for a column name.
protected  java.lang.String retrieveColumnInfoUsed()
          Returns the column information that is currently being used as the column label.
protected  java.lang.String retrieveColumnLabel(int index)
          If columnInfoUsed is "LABEL", gets the suggested column title provided by ResultSetMetaData object for the column at the given index.
protected  java.lang.Object retrieveValueAt(int row, int col)
          Returns value of a cell in the JDBC data type of the cell.
protected  java.lang.Object retrieveValueAt(int col, java.sql.ResultSet result)
          Returns value of a cell in the JDBC data type of the cell.
 void setAutoCommit(boolean autoCommit)
          Sets the value of autoCommit.
 void setConnection(java.sql.Connection conn)
          Sets the connection object on the adapter.
 void setDisplayTransform(com.sas.util.transforms.TransformInterface newTransform)
          Set transform to given transform, which can be null
 void setModel(java.sql.Connection conn)
          Enables attaching a connection object to the adapter when the adapter is part of a webAF project.
 void setPrintWarnings(boolean printWarnings)
          Sets whether or not to print warnings from methods that generate SQLWarning objects.
 void setQueryRowCountDisabled(boolean queryRowCountDisabled)
          Sets a value indicating if the row count should be determined by executing a "count" query.
 void setQueryStatement(java.lang.String queryStatement)
          The queryStatement should be any SQL query that is valid for the JDBC data source.
 void setReadOnly(boolean readOnly)
          Attempts to change the adapter's readOnly field between true and false.
 void setResultSetRequeryUsed(boolean resultSetRequeryUsed)
          In order to simulate scrolling in drivers that do not support scrollable result sets, the resultSetRequeryUsed property may be set to true to allow the adapter to re-execute the query and obtain a new result set.
 void setResultSetType(int type)
          Changes the type of the result set to determine whether it can be scrolled and whether changes to column values made to the underlying data base are ever shown in the result set.
 void setRetrieveNumericTypesAsDouble(boolean retrieveAsDouble)
          Indicates whether to retrieve numeric JDBC types with the ResultSet getDouble method.
 void setRowCountQueryString(java.lang.String rowCountQueryString)
          Sets the query String used to determine the row count when the queryRowCountDisabled is set to false.
 void setTrimUsed(boolean trimUsed)
          Set the value of trimUsed.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
One of the valid values for setColumnInfoUsed.

See Also:
Constant Field Values

LABEL

public static final java.lang.String LABEL
One of the valid values for setColumnInfoUsed. This is the default value.

See Also:
Constant Field Values

CLASS_NAME

public static final java.lang.String CLASS_NAME
One of the valid values for getColumnInfo.

See Also:
Constant Field Values

initialized

protected boolean initialized
True if the adapter is initialized with a Connection object and queryStatement.


readOnly

protected boolean readOnly
True if the adapter is read-only. It initializes to true.


resultSetType

protected int resultSetType
The type of the ResultSet.


autoCommit

protected boolean autoCommit
If true, updates will be automatically committed to the database. It initializes to true.


printWarnings

protected boolean printWarnings
True if the adapter should print SQLWarning messages. It initializes to false.


forwardOnly

protected boolean forwardOnly
If true, the adapter is connected to a result set that is ResultSet.TYPE_FORWARD_ONLY.


resultSetRequeryUsed

protected boolean resultSetRequeryUsed
If the adapter is connected to a result set that is ResultSet.TYPE_FORWARD_ONLY this property controls whether the result set can be requeried to permit a simulation of scrolling backwards. It initializes to true.


trimUsed

protected boolean trimUsed
If true, all character string data returned from the data source will be trimmed of whitespace according to String.trim().


resultSetUsed

protected boolean resultSetUsed
If true, no connections or queries will be used to remake a previously created result set


conn

protected java.sql.Connection conn
The Connection object supplied by the constructor or setModel method.


stmt

protected java.sql.Statement stmt
The Statement object created from the Connection.


result

protected java.sql.ResultSet result
The ResultSet object created from the Statement object when queryStatement is supplied.


meta

protected java.sql.ResultSetMetaData meta
The ResultSetMetaData object created from the Statement object when queryStatement is supplied.


queryStatement

protected java.lang.String queryStatement
The SQL query statement.


displayTransform

protected com.sas.util.transforms.TransformInterface displayTransform
The transform used on the data.


designTime

protected boolean designTime
True if the class is used at webAF design time.


spcs

protected javax.swing.event.SwingPropertyChangeSupport spcs
Used to support property changes in the webAF customizer


columnInfoUsed

protected java.lang.String columnInfoUsed
The value passed in by setColumInfoUsed.


rowCountQueryString

protected java.lang.String rowCountQueryString
The query string used to determine the number of rows in the result set


queryRowCountDisabled

protected boolean queryRowCountDisabled
Indicates if the row count should be determined by executing a "count" query or the rowCountQueryString if one is provided.


isRowCountKnown

protected boolean isRowCountKnown
Indicates if the number of rows in the result set is known


rowNumber

protected int rowNumber
Indicates the row number the result set cursor is currently positioned on. Used in the doAbsolute method.


rowCount

protected int rowCount
Used with counting rows in the result set in the calculateRowCount method. Is the actual row count when isRowCountKnown is true.


retrieveNumericTypesAsDouble

protected boolean retrieveNumericTypesAsDouble
Indicates if numeric JDBC types will be retrieved from the ResultSet with the getDouble method

Constructor Detail

JDBCAdapter

public JDBCAdapter()
Default constructor called when the adapter is made in a webAF project.


JDBCAdapter

public JDBCAdapter(java.sql.ResultSet result)
Constructor used to connect an adapter directly to a previously created ResultSet. In order for the adapter to work properly, the ResultSet should be scrollable.

Parameters:
result - ResultSet to use.

JDBCAdapter

public JDBCAdapter(java.sql.Connection conn,
                   java.lang.String queryStatement)
Constructor used to create an initialized adapter.

Parameters:
conn - A java.sql.Connection object.
queryStatement - A SQL query that is valid for the database represented by conn.
Method Detail

initializeData

protected void initializeData()

init

protected void init()
Creates the Statement, ResultSet, and ResultSetMetaData objects using the queryStatement whenever the initialized field is false.

Throws:
java.lang.IllegalStateException - If the Connection or queryStatement are null.

getResultSetConcurrency

protected int getResultSetConcurrency()

isReadOnly

public boolean isReadOnly()
The value returned at design time reflects the value that was set by calling the setReadOnly method, or the default value of true. At run time, the value returned is the actual concurrency of the ResultSet object. It should be noted that this value may be different from what was passed to the setReadOnly method. This is because a driver may return a result set with a concurrency different than what was requested depending on if the requested type is supported.

If any SQL warnings have been generated, they will have been printed if printWarnings() was set to true.

Returns:
true if the adapter is read-only.

setReadOnly

public void setReadOnly(boolean readOnly)
Attempts to change the adapter's readOnly field between true and false. This causes initialization or re-initialization of the adapter. This attempts to create a new result set with the desired concurrency if the adapter was created with a java.sql.Connection.

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. If it was instantiated with a RowSet, then the concurrency property will be set on the rowset object and it will be reinitialized.

If readOnly is false, it will use ResultSet.CONCUR_UPDATABLE when making the result set. If any SQL warnings have been generated, they will be printed if printWarnings() has been set to true.

Parameters:
readOnly - Sets to true or false.

setResultSetType

public void setResultSetType(int type)
Changes the type of the result set to determine whether it can be scrolled and whether changes to column values made to the underlying data base are ever shown in the result set. Valid values are ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE. If the value of type changes from current value, a new statement object is created and the query statement is executed again.

Parameters:
type - the type of result set desired
Throws:
java.lang.IllegalArgumentException - if invalid result set type

getResultSetType

public int getResultSetType()
The resultSetType value returned at design time reflects the value that was set by calling the setResultSetType method, or the default value of ResultSet.TYPE_SCROLL_SENSITIVE. At run time, the value returned is the actual type of the ResultSet object. It should be noted that this value may be different from what was passed to the setResultSetType method. This is because a driver may return a result set with a different type than what was requested depending on if the requested type is supported.

If any SQL warnings have been generated, they will have been printed if printWarnings() was set to true.

Returns:
one of the following ResultSet constants, indicating the type: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, or TYPE_SCROLL_SENSITIVE

getAutoCommit

public boolean getAutoCommit()
Gets the value of autoCommit. If the value is true, the setXXX methods will call an updateRow on the result set so that the new value(s) will be committed to the database. If false, it will be necessary to use commitRow to commit changes.

Returns:
True or false.

setAutoCommit

public void setAutoCommit(boolean autoCommit)
Sets the value of autoCommit. If the value is true, the setXXX methods will call an updateRow on the result set so that the new value(s) will be committed to the database. If false, it will be necessary to use commitRow to commit changes.

Parameters:
autoCommit - True or false.

getConnection

public java.sql.Connection getConnection()
Gets the connection object used as the adapter's model.

Returns:
A java.sql.Connection object.

setConnection

public void setConnection(java.sql.Connection conn)
Sets the connection object on the adapter.

Parameters:
conn - A java.sql.Connection object.

getModel

public java.sql.Connection getModel()
Returns the connection object attached to the adapter when the adapter is part of a webAF project. return The java.sql.Connection object (the same as returned by getConnection).


setModel

public void setModel(java.sql.Connection conn)
Enables attaching a connection object to the adapter when the adapter is part of a webAF project.

Parameters:
conn - A java.sql.Connection object.

getQueryStatement

public java.lang.String getQueryStatement()
Returns the SQL query that has been applied to the JDBC data source.

Returns:
The query.

setQueryStatement

public void setQueryStatement(java.lang.String queryStatement)
The 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.

Parameters:
queryStatement - The SQL query to apply.

isResultSetRequeryUsed

public boolean isResultSetRequeryUsed()
Gets the value of resultSetRequeryUsed.

Returns:
true or false.

setResultSetRequeryUsed

public void setResultSetRequeryUsed(boolean resultSetRequeryUsed)
In order to simulate scrolling in drivers that do not support scrollable result sets, the resultSetRequeryUsed property may be set to true to allow the adapter to re-execute the query and obtain a new result set. This will allow the adapter to scroll through the rows again. This behavior will incur a performance penalty, but it will then be possible to use such data sources with more kinds of viewers and with the SAS chart controls. If false, the adapter may only scroll forward until there are no more rows.

This property is initialized to true except in the case where the adapter is instantiated with a ResultSet object that is not a RowSet, since the query cannot be re-executed in this case. Setting the resultSetRequeryUsed property to true in this case will cause an IllegalArgumentException to be thrown.

Parameters:
resultSetRequeryUsed - true or false.

isTrimUsed

public boolean isTrimUsed()
Returns the value of trimUsed.

Returns:
True or false.

setTrimUsed

public void setTrimUsed(boolean trimUsed)
Set the value of trimUsed. If true, all character strings returned from the data source will be trimmed of whitespace according to String.trim().

Parameters:
trimUsed - True or false.

getDisplayTransform

public com.sas.util.transforms.TransformInterface getDisplayTransform()
Return current transform, which can be null

Specified by:
getDisplayTransform in interface com.sas.util.transforms.DisplayTransformInterface
Returns:
current transform

setDisplayTransform

public void setDisplayTransform(com.sas.util.transforms.TransformInterface newTransform)
Set transform to given transform, which can be null

Specified by:
setDisplayTransform in interface com.sas.util.transforms.DisplayTransformInterface
Parameters:
newTransform - transform to be set

setRetrieveNumericTypesAsDouble

public void setRetrieveNumericTypesAsDouble(boolean retrieveAsDouble)
Indicates whether to retrieve numeric JDBC types with the ResultSet getDouble method. If true then the following java.sql.Types will be retrieved from the result set with the java.sql.ResultSet getDouble method: Types.INTEGER, Types.DOUBLE, Types.TINYINT, Types.SMALLINT, Types.BIGINT, Types.REAL, Types.FLOAT. If false, then these sql Types will be retrieved by the JDBC recommended method for that type.

Parameters:
retrieveAsDouble - boolean value indicating whether to retrieve numeric JDBC types with the ResultSet getDouble method

isRetrieveNumericTypesAsDouble

public boolean isRetrieveNumericTypesAsDouble()
Returns a value indicating whether to retrieve numeric JDBC types with the ResultSet getDouble method. Default value is true.

See Also:
setRetrieveNumericTypesAsDouble(boolean)

doAbsolute

protected boolean doAbsolute(int index)
                      throws java.sql.SQLException
For scrollable result sets, the absolute() method is called on the result set. This method can simulate scrolling backwards for forward-only result sets, if the resultSetRequeryUsed property is set to true(the default). In this case the forward-only result sets will be requeried as needed to return to prior row(s). If it returns false, an attempt to move past the last row will throw an exception.

Parameters:
index - The row number to move to.
Returns:
true if it was possible to move to the given row index or false if the cursor is before the first row or after the last row.
Throws:
java.sql.SQLException - If index is greater than the number of rows.
IlegalStateException - If trying to scroll backward in a forward-only result set and resultSetRequeryUsed is false, or the end of the result set has been reached and resultSetRequeryUsed is false.

retrieveColumnInfoUsed

protected java.lang.String retrieveColumnInfoUsed()
Returns the column information that is currently being used as the column label. The method will return either NAME or LABEL if the field has been set.

Returns:
The type of information used as the column header.

putColumnInfoUsed

protected void putColumnInfoUsed(java.lang.String info)
Sets the column information that is currently being used as the column label. Valid values are "name" and "label". They are not case-sensitive.

Parameters:
info - The type of information to use in column labels.

retrieveColumnLabel

protected java.lang.String retrieveColumnLabel(int index)
                                        throws java.sql.SQLException
If columnInfoUsed is "LABEL", gets the suggested column title provided by ResultSetMetaData object for the column at the given index. If columnInfoUsed is "NAME", gets the name of the column at the given index. If no label exists for a column, the name is returned.

Parameters:
index - A one-based index that identifies the column.
Returns:
The label.
Throws:
java.sql.SQLException - - Thrown if the ResultSetMetaData throws a SQLException.

retrieveColumnIndex

protected int retrieveColumnIndex(java.lang.String name)
                           throws java.sql.SQLException
Returns the column index for a column name.

Parameters:
name - The column name.
Returns:
The column index.
Throws:
java.sql.SQLException - If column name is not found.

close

public void close()
Closes the statement and the result set. Sets a flag that initialization is false. If other methods are called later, they may reinitialize the statement and the result set unless the adapter was instantiated with a ResultSet, in which case it cannot be reinitialized.


refresh

public void refresh()
Reinitializes the result set and fires a model event.


finalize

protected void finalize()
Closes the JDBC objects

Overrides:
finalize in class java.lang.Object

retrieveColumnClass

protected java.lang.Class retrieveColumnClass(int index)
                                       throws java.sql.SQLException,
                                              java.lang.ClassNotFoundException
Returns the class of a column. The column is identified by the given index.

Parameters:
index - - A one-based index that identifies the column.
Returns:
The specified column's class.
Throws:
java.sql.SQLException - Thrown if ResultSetMetaData throws a SQLException.
java.lang.ClassNotFoundException - Thrown if the class of the given column cannot be loaded.

doCountColumns

protected int doCountColumns(int maxCount)
                      throws java.sql.SQLException
The number of columns known to be available. The maxCount parameter is ignored and the result of retrieveColumnCount is returned.

Parameters:
maxCount - Maximum number of columns to read, or 0 to read indefinitely. Thus maxCount is only used as a limiting factor when the implementation has to actually do computation (e.g. fetch observations).
Returns:
The number of columns.
Throws:
java.sql.SQLException - Thrown if ResultSetMetaData throws a SQLException.

retrieveColumnCount

protected int retrieveColumnCount()
                           throws java.sql.SQLException
Returns the number of columns in the result set.

Returns:
The number of columns.
Throws:
java.sql.SQLException - Thrown if ResultSetMetaData throws a SQLException.

calculateRowCount

protected int calculateRowCount()
                         throws java.sql.SQLException
Counts the number of rows when the underlying result set is not scrollable (TYPE_FORWARD_ONLY) and resultSetRequeryUsed is true. Otherwise, the result of retrieveRowCount() is returned.

Returns:
The number of rows in the result set or -1.
Throws:
java.sql.SQLException - Thrown if ResultSetMetaData throws an SQLException.

getRowCountQueryString

public java.lang.String getRowCountQueryString()
Returns the query String used to determine the row count when the queryRowCountDisabled is set to false. The rowCountQueryString is not used when the adapter is instantiated with a ResultSet.


setRowCountQueryString

public void setRowCountQueryString(java.lang.String rowCountQueryString)
Sets the query String used to determine the row count when the queryRowCountDisabled is set to false. The rowCountQueryString is not used when the adapter is instantiated with a ResultSet. If no rowCountQueryString has been set, then the adapter will create a query containing the sql count function to execute to obtain the row count for the result set.

Parameters:
rowCountQueryString - the query String used to determine the row count when the queryRowCountDisabled is set to false.

isQueryRowCountDisabled

public boolean isQueryRowCountDisabled()
Indicates if the row count should be determined by executing a "count" query.

Returns:
a value indicating how the result set row count is determined.
See Also:
setQueryRowCountDisabled(boolean)

setQueryRowCountDisabled

public void setQueryRowCountDisabled(boolean queryRowCountDisabled)
Sets a value indicating if the row count should be determined by executing a "count" query. If false, the row count is determined by the getRowCountByCountFunction method. Otherwise, the row count is determined by the getResultSetRowCount method. The default value of this property is false.

If the adapter is instantiated with a ResultSet, this property is ignored and the row count is determined by the getResultSetRowCount method.

Parameters:
queryRowCountDisabled - a value indicating how the row count is calculated.
See Also:
getRowCountByCountFunction(), getResultSetRowCount()

getRowCountByCountFunction

protected int getRowCountByCountFunction()
This method attempts to find the number of rows in a JDBC ResultSet by using the SQL count function. If a rowCountQueryString has been set, then it will be executed to get the row count. Otherwise, the sql select statement will be altered to include the sql count function. For example, the select statement would be changed from "select a, b, c, d from table" to "select count(*) from table". This query is exectued on a Statement object which returns a ResultSet containing one row/column that holds the row count.

A value of -1 is returned if the adapter has not been initialized, or an SQLException is thrown while attempting to find the row count.


getResultSetRowCount

protected int getResultSetRowCount()
                            throws java.sql.SQLException
This method finds the number of rows in a JDBC ResultSet using the standard JDBC technique. That is, for scrollable result sets, positioning the result set cursor on the last row and getting its row number. For forward only result sets this is done by incrementing a counter while moving through the result set using the next() method. The initialized flag will be set to false after finding the count of a forward only result set so that it can be re-initialized later.

A value of -1 is returned if the adapter has not been initialized, or an SQLException is thrown while attempting to find the row count.

Throws:
java.sql.SQLException

putValueAt

protected void putValueAt(java.lang.Object value,
                          int rowIndex,
                          int columnIndex)
                   throws java.sql.SQLException
Updates value into the cell at rowIndex, columnIndex. If autoCommit is true, it also updates the row in the result set. If autoCommit is false, use commitRow to update the row.

Parameters:
rowIndex - A one-based index that identifies the cell's row.
columnIndex - A one-based index that identifies the cell's column.
value - The cell's new value.
Throws:
SqlException - Thrown if ResultSet throws a SQLException.
java.lang.IllegalStateException - Thrown if the operation cannot be completed (e.g. read-only).
java.sql.SQLException

retrieveValueAt

protected java.lang.Object retrieveValueAt(int row,
                                           int col)
                                    throws java.sql.SQLException
Returns value of a cell in the JDBC data type of the cell. It calls the ResultSet getXXX method recommended in the JDBC API for that data type. The cell is identified by the given row and column indices.

Parameters:
row - A one-based index that identifies the cell's row.
col - A one-based index that identifies the cell's column.
Returns:
The specified cell's value.
Throws:
java.sql.SQLException - Thrown if ResultSet throws a SQLException.

retrieveValueAt

protected java.lang.Object retrieveValueAt(int col,
                                           java.sql.ResultSet result)
                                    throws java.sql.SQLException
Returns value of a cell in the JDBC data type of the cell. It calls the ResultSet getXXX method recommended in the JDBC API for that data type. The cell is identified by the column index of the current row.

Parameters:
col - A one-based index that identifies the cell's column.
result - ResultSet in which to get values.
Returns:
The specified cell's value.
Throws:
java.sql.SQLException - Thrown if ResultSet throws a SQLException.

doUpdateCell

protected void doUpdateCell(int col,
                            java.lang.Object value)
                     throws java.sql.SQLException
This method is called by public "setter" methods. It obtains the column's JDBC type and then calls the correct JDBC updateXXX method. It takes the column number and a value to update into the cell. Value will be a String, if being called from a viewer via setFormattedCell(), etc. It must be possible to convert the Object into the correct type required by the updateXXX method.

Parameters:
the - one-based column number
the - value to be updated into the cell
Throws:
java.sql.SQLException - if a JDBC method throws a SQLException.

getColumnInfo

public java.lang.Object getColumnInfo(int index,
                                      java.lang.String columnInfoName)
                               throws com.sas.table.TableException
Returns the named information for a column. The column is identified by the given index.

Specified by:
getColumnInfo in interface com.sas.table.StaticColumnInfoInterface
Parameters:
index - the index identifies the column, needs to be one-based
columnInfoName - the name of the information a user wants to query for, the valid values are returned from a call to getColumnInfoNames().
Returns:
the named information for the column.
Throws:
com.sas.util.UncheckedException - thrown if a call to the model yields an exception
java.lang.IllegalArgumentException - if columnInfoName is not a valid column information value
com.sas.table.TableException
See Also:
getColumnInfoNames(), StaticColumnInfoInterface

getColumnInfoNames

public java.lang.String[] getColumnInfoNames()
                                      throws com.sas.table.TableException
Returns an array of the named information that can be returned for the columns. Values returned are NAME and LABEL, and CLASS_NAME.

Specified by:
getColumnInfoNames in interface com.sas.table.StaticColumnInfoInterface
Returns:
an array of strings of the type of information the columns can be queried for
Throws:
com.sas.table.TableException
See Also:
StaticColumnInfoInterface

printSQLWarning

protected void printSQLWarning(java.sql.SQLWarning w)
Prints message, SQL state and vendor error code from SQLWarning objects if printWarnings is true. This method is called from init() where SQL warnings may be generated.

Parameters:
w - a SQLWarning object

getPrintWarnings

public boolean getPrintWarnings()
Returns whether or not to print SQL warnings to System.out.

Returns:
true if warnings will be printed, false otherwise

setPrintWarnings

public void setPrintWarnings(boolean printWarnings)
Sets whether or not to print warnings from methods that generate SQLWarning objects. If true, messages, SQL state codes, and vendor error codes will go to System.out.

Parameters:
printWarnings - true to print warnings, false to suppress printing

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)

fireCellEvent

protected abstract void fireCellEvent(int row,
                                      int column)
Fire a specific event for a model signaling that one cell has changed. Subclasses must override this method to fire specific events for their model.

Parameters:
row - row number of the cell that has been modified
column - column number of the cell that has been modified

fireModelEvent

protected abstract void fireModelEvent(java.util.EventObject event)
Fire a specific event for a model signaling that some aspect of the model has changed. Subclasses must override this method to fire specific events for their model.

Parameters:
event - Event that must be cast that should be fired

fireModelEvent

protected abstract void fireModelEvent()
Fire a default event for a model signaling the some aspect of the model has changed. Subclasses must override this method to fire a default events for their model.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.