com.sas.storage.jdbc
Class JDBCToListModelAdapter

com.sas.storage.jdbc.JDBCToListModelAdapter
All Implemented Interfaces:
com.sas.table.StaticColumnInfoInterface, com.sas.util.transforms.DisplayTransformInterface, javax.swing.ListModel
Direct Known Subclasses:
JDBCToComboBoxModelAdapter

public class JDBCToListModelAdapter
implements javax.swing.ListModel

The JDBCToListModelAdapter allows JDBC data sources to be displayed in any viewer that requires a model of type javax.swing.ListModel, mainly being a javax.swing.JList.

The adapter requires a java.sql.Connection object and a query statement. They can be passed in on the constructor or set via 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 setTemplateText method can be used to control which column values from the result set are displayed in the list. Multiple column values can be used along with text. The template text uses the default marker, open, and close characters from com.sas.util.SimpleTemplate( "%", "(", and ")" ). The column names must be defined in the template text as all uppercase variables. If no template text is defined, only the values from the first column of the result set are used as list items.

The general form of the template text is:

 text %COL1 more text %COL2
 
 Where COL1 and COL2 are fully uppercased column names. The '%' acts as a delimiter and is not part of the column name. 
 

If more control is desired on what is displayed in the List, then a column values transform can be set on the adapter, via the setColumnValuesTransform method. The retrieveAllColumnValues property must be set to true in order for the column values transform to be used. If a column values transform has been specified and the retrieveAllColumnValues is true, then the adapter will use the specified column values transform to transform the Map containing column names (all uppercased) mapped to column values into a single Object which is returned by the getElementAt method. If the retrieveAllColumnValues property is true, but no column values transform has been set, then the Object returned from the getElementAt method will be a Map containing the column names (all uppercased) mapped to the column values.

The adapter can be configured and used within a webAF project. Add a com.sas.storage.jdbc.JDBCConnection component to your project. Open the customizer and specify the values needed for your JDBC connection.These include driver name and URL. Now open the customizer for the adapter. Specify the value for JDBC Connection using the top combo box. The drop-down list will show all JDBC Connection objects that exist in your project. You can set the properties for query statement, autoCommit, and read-only, as well.


Field Summary
protected  javax.swing.event.EventListenerList listenerList
          List of listeners
protected  com.sas.util.transforms.MapToTemplateStringTransform mapTransform
          Transform used templateText is specified
static java.lang.String RB_KEY
           
protected  java.lang.String templateText
          Template text for output string
 
Fields inherited from class com.sas.storage.jdbc.JDBCColumnValuesAdapter
columnValuesTransform, retrieveAllColumnValues
 
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
JDBCToListModelAdapter()
          Default constructor called when the adapter is made in a webAF project.
JDBCToListModelAdapter(java.sql.Connection conn, java.lang.String queryStatement)
          Constructor used to create an initialized adapter.
JDBCToListModelAdapter(java.sql.ResultSet result)
          Constructor used to connect an adapter directly to a previously created ResultSet.
 
Method Summary
 void addListDataListener(javax.swing.event.ListDataListener l)
          Add a listener to the list that's notified each time a change to the data model occurs.
 void fireCellEvent(int row, int column)
          Fire a specific event for a model signaling that one cell has changed.
 void fireModelEvent()
          Fire a default event for a model signaling the some aspect of the model has changed.
 void fireModelEvent(java.util.EventObject event)
          Fire a specific event for a model signaling that some aspect of the model has changed.
 java.lang.Object getElementAt(int index)
          Returns the value at the specified index.
 java.util.Map getElementsAt(int index)
          Returns a Map containing the column names (all uppercased) mapped to the column values at the specified index in the result set.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this JDBCToListModelAdapter.
 int getSize()
          Returns the length of the list
 java.lang.String getTemplateText()
          Returns the text of the template.
protected  void initializeData()
           
 void removeListDataListener(javax.swing.event.ListDataListener l)
          Remove a listener from the list that's notified each time a change to the data model occurs.
 void setTemplateText(java.lang.String templateText)
          Sets the text to be used for the template, determining what values display in the list.
 
Methods inherited from class com.sas.storage.jdbc.JDBCColumnValuesAdapter
getColumnValuesMap, getColumnValuesTransform, isRetrieveAllColumnValues, retrieveColumnValueAt, retrieveValueAt, setColumnValuesTransform, setRetrieveAllColumnValues
 
Methods inherited from class com.sas.storage.jdbc.JDBCAdapter
addPropertyChangeListener, addPropertyChangeListener, calculateRowCount, close, doAbsolute, doCountColumns, doUpdateCell, finalize, getAutoCommit, getColumnInfo, getColumnInfoNames, getConnection, getDisplayTransform, getModel, getPrintWarnings, getQueryStatement, getResultSetConcurrency, getResultSetRowCount, getResultSetType, getRowCountByCountFunction, getRowCountQueryString, init, isQueryRowCountDisabled, isReadOnly, isResultSetRequeryUsed, isRetrieveNumericTypesAsDouble, isTrimUsed, printSQLWarning, putColumnInfoUsed, putValueAt, refresh, removePropertyChangeListener, removePropertyChangeListener, retrieveColumnClass, retrieveColumnCount, retrieveColumnIndex, retrieveColumnInfoUsed, retrieveColumnLabel, retrieveRawSASNumericValue, retrieveRawSASNumericValue, retrieveValueAt, setAutoCommit, setConnection, setDisplayTransform, setModel, setPrintWarnings, setQueryRowCountDisabled, setQueryStatement, setReadOnly, setResultSetRequeryUsed, setResultSetType, setRetrieveNumericTypesAsDouble, setRowCountQueryString, setTrimUsed
 

Field Detail

RB_KEY

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

listenerList

protected javax.swing.event.EventListenerList listenerList
List of listeners


templateText

protected java.lang.String templateText
Template text for output string


mapTransform

protected com.sas.util.transforms.MapToTemplateStringTransform mapTransform
Transform used templateText is specified

Constructor Detail

JDBCToListModelAdapter

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


JDBCToListModelAdapter

public JDBCToListModelAdapter(java.sql.ResultSet result)
Constructor used to connect an adapter directly to a previously created ResultSet.

Parameters:
result - ResultSet to use.

JDBCToListModelAdapter

public JDBCToListModelAdapter(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()
Overrides:
initializeData in class JDBCAdapter

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener l)
Add a listener to the list that's notified each time a change to the data model occurs.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
l - The ListDataListener

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener l)
Remove a listener from the list that's notified each time a change to the data model occurs.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
l - The ListDataListener

getSize

public int getSize()
Returns the length of the list

Specified by:
getSize in interface javax.swing.ListModel

getElementAt

public java.lang.Object getElementAt(int index)
Returns the value at the specified index. If no templateText is provided, only the data in the first column will be returned as the value. If templateText is provided, the data will be formatted based upon the templateText and will be returned as the value.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - the index to return the value of

getElementsAt

public java.util.Map getElementsAt(int index)
                            throws java.sql.SQLException
Returns a Map containing the column names (all uppercased) mapped to the column values at the specified index in the result set.

Throws:
java.sql.SQLException

getTemplateText

public java.lang.String getTemplateText()
Returns the text of the template.


setTemplateText

public void setTemplateText(java.lang.String templateText)
Sets the text to be used for the template, determining what values display in the list. If no text is provided, only the data in the first column will be returned as the element for each row. Any text provided will be used as the template for all data. Column names used as variables in the template text must be fully uppercased.

Parameters:
templateText - text to be set for the template
See Also:
SimpleTemplate

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this JDBCToListModelAdapter.


fireCellEvent

public 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.

Specified by:
fireCellEvent in class JDBCAdapter
Parameters:
row - row number of the cell that has been modified
column - column number of the cell that has been modified

fireModelEvent

public 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.

Specified by:
fireModelEvent in class JDBCAdapter
Parameters:
event - Event that must be cast that should be fired

fireModelEvent

public 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.

Specified by:
fireModelEvent in class JDBCAdapter



Copyright © 2009 SAS Institute Inc. All Rights Reserved.