prefuse.data.io.sql
Class DatabaseDataSource

java.lang.Object
  extended by prefuse.data.io.sql.DatabaseDataSource

public class DatabaseDataSource
extends java.lang.Object

Sends queries to a relational database and processes the results, storing the results in prefuse Table instances. This class should not be instantiated directly. To access a database, the ConnectionFactory class should be used to retrieve an appropriate instance of this class.

Author:
jeffrey heer

Field Summary
protected  java.sql.Connection m_conn
           
protected  SQLDataHandler m_handler
           
protected  java.sql.Statement m_stmt
           
 
Method Summary
 Table getData(java.lang.String query)
          Executes a query and returns the results in a Table instance.
 Table getData(java.lang.String query, java.lang.String keyField)
          Executes a query and returns the results in a Table instance.
 Table getData(Table t, java.lang.String query)
          Executes a query and returns the results in a Table instance.
 Table getData(Table t, java.lang.String query, java.lang.String keyField)
          Executes a query and returns the results in a Table instance.
 Table getData(Table t, java.lang.String query, java.lang.String keyField, java.lang.Object lock)
          Executes a query and returns the results in a Table instance.
protected  int getExistingRow(Table t, java.sql.ResultSet rset, java.lang.String keyField)
          See if a retrieved database row is already represented in the given Table.
 Schema getSchema(java.sql.ResultSetMetaData metadata, SQLDataHandler handler)
          Given the metadata for a SQL result set and a data value handler for that result set, returns a corresponding schema for a prefuse table.
 void loadData(Table t, java.lang.String query)
          Asynchronously executes a query and stores the results in the given table instance.
 void loadData(Table t, java.lang.String query, java.lang.Object lock)
          Asynchronously executes a query and stores the results in the given table instance.
 void loadData(Table t, java.lang.String query, java.lang.String keyField)
          Asynchronously executes a query and stores the results in the given table instance.
 void loadData(Table t, java.lang.String query, java.lang.String keyField, java.lang.Object lock)
          Asynchronously executes a query and stores the results in the given table instance.
 void loadData(Table t, java.lang.String query, java.lang.String keyField, java.lang.Object lock, DataSourceWorker.Listener listener)
          Asynchronously executes a query and stores the results in the given table instance.
protected  Table process(Table t, java.sql.ResultSet rset, java.lang.String key, java.lang.Object lock)
          Process the results of a SQL query, putting retrieved data into a Table instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_conn

protected java.sql.Connection m_conn

m_stmt

protected java.sql.Statement m_stmt

m_handler

protected SQLDataHandler m_handler
Method Detail

getData

public Table getData(java.lang.String query)
              throws DataIOException
Executes a query and returns the results in a Table instance.

Parameters:
query - the text SQL query to execute
Returns:
a Table of the query results
Throws:
DataIOException - if an error occurs while executing the query or adding the query results in a prefuse Table.

getData

public Table getData(java.lang.String query,
                     java.lang.String keyField)
              throws DataIOException
Executes a query and returns the results in a Table instance.

Parameters:
query - the text SQL query to execute
keyField - the field to treat as a primary key, ensuring that this field is indexed in the resulting table instance.
Returns:
a Table of the query results
Throws:
DataIOException - if an error occurs while executing the query or adding the query results in a prefuse Table.

getData

public Table getData(Table t,
                     java.lang.String query)
              throws DataIOException
Executes a query and returns the results in a Table instance.

Parameters:
t - the Table to store the results in. If this value is null, a new table will automatically be created.
query - the text SQL query to execute
Returns:
a Table of the query results
Throws:
DataIOException - if an error occurs while executing the query or adding the query results in a prefuse Table.

getData

public Table getData(Table t,
                     java.lang.String query,
                     java.lang.String keyField)
              throws DataIOException
Executes a query and returns the results in a Table instance.

Parameters:
t - the Table to store the results in. If this value is null, a new table will automatically be created.
query - the text SQL query to execute
keyField - used to determine if the row already exists in the table
Returns:
a Table of the query results
Throws:
DataIOException - if an error occurs while executing the query or adding the query results in a prefuse Table.

getData

public Table getData(Table t,
                     java.lang.String query,
                     java.lang.String keyField,
                     java.lang.Object lock)
              throws DataIOException
Executes a query and returns the results in a Table instance.

Parameters:
t - the Table to store the results in. If this value is null, a new table will automatically be created.
query - the text SQL query to execute
keyField - used to determine if the row already exists in the table
lock - an optional Object to use as a lock when performing data processing. This lock will be synchronized on whenever the Table is modified.
Returns:
a Table of the query results
Throws:
DataIOException - if an error occurs while executing the query or adding the query results in a prefuse Table.

loadData

public void loadData(Table t,
                     java.lang.String query)
Asynchronously executes a query and stores the results in the given table instance. All data processing is done in a separate thread of execution.

Parameters:
t - the Table in which to store the results
query - the query to execute

loadData

public void loadData(Table t,
                     java.lang.String query,
                     java.lang.String keyField)
Asynchronously executes a query and stores the results in the given table instance. All data processing is done in a separate thread of execution.

Parameters:
t - the Table in which to store the results
query - the query to execute
keyField - the primary key field, comparisons on this field are performed to recognize data records already present in the table.

loadData

public void loadData(Table t,
                     java.lang.String query,
                     java.lang.Object lock)
Asynchronously executes a query and stores the results in the given table instance. All data processing is done in a separate thread of execution.

Parameters:
t - the Table in which to store the results
query - the query to execute
lock - an optional Object to use as a lock when performing data processing. This lock will be synchronized on whenever the Table is modified.

loadData

public void loadData(Table t,
                     java.lang.String query,
                     java.lang.String keyField,
                     java.lang.Object lock)
Asynchronously executes a query and stores the results in the given table instance. All data processing is done in a separate thread of execution.

Parameters:
t - the Table in which to store the results
query - the query to execute
keyField - the primary key field, comparisons on this field are performed to recognize data records already present in the table.
lock - an optional Object to use as a lock when performing data processing. This lock will be synchronized on whenever the Table is modified.

loadData

public void loadData(Table t,
                     java.lang.String query,
                     java.lang.String keyField,
                     java.lang.Object lock,
                     DataSourceWorker.Listener listener)
Asynchronously executes a query and stores the results in the given table instance. All data processing is done in a separate thread of execution.

Parameters:
t - the Table in which to store the results
query - the query to execute
keyField - the primary key field, comparisons on this field are performed to recognize data records already present in the table. A null value will result in no key checking.
lock - an optional Object to use as a lock when performing data processing. This lock will be synchronized on whenever the Table is modified. A null value will result in no locking.
listener - an optional listener that will provide notifications before the query has been issued and after the query has been processed. This is most useful for post-processing operations.

process

protected Table process(Table t,
                        java.sql.ResultSet rset,
                        java.lang.String key,
                        java.lang.Object lock)
                 throws DataIOException
Process the results of a SQL query, putting retrieved data into a Table instance. If a null table is provided, a new table with the appropriate schema will be created.

Parameters:
t - the Table to store results in
rset - the SQL query result set
Returns:
a Table containing the query results
Throws:
DataIOException

getExistingRow

protected int getExistingRow(Table t,
                             java.sql.ResultSet rset,
                             java.lang.String keyField)
                      throws java.sql.SQLException
See if a retrieved database row is already represented in the given Table.

Parameters:
t - the prefuse Table to check for an existing row
rset - the ResultSet, set to a particular row, which may or may not have a matching row in the prefuse Table
keyField - the key field to look up to check for an existing row
Returns:
the index of the existing row, or -1 if no match is found
Throws:
java.sql.SQLException

getSchema

public Schema getSchema(java.sql.ResultSetMetaData metadata,
                        SQLDataHandler handler)
                 throws java.sql.SQLException
Given the metadata for a SQL result set and a data value handler for that result set, returns a corresponding schema for a prefuse table.

Parameters:
metadata - the SQL result set metadata
handler - the data value handler
Returns:
the schema determined by the metadata and handler
Throws:
java.sql.SQLException - if an error occurs accessing the metadata


Copyright 2007 Regents of the University of California