SPT Core API

com.sptci.echo2.table
Class DatabaseHelper

java.lang.Object
  extended by com.sptci.echo2.table.DatabaseHelper

public class DatabaseHelper
extends Object

A helper class for DatabaseTableModel to abstract JDBC interactions.

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: DatabaseHelper.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2007-09-19

Constructor Summary
DatabaseHelper()
           
 
Method Summary
static RowSet getData(DataSource dataSource, String schema, String table, List<String> primaryKeys, List<String> columns, List<String> orderBy, int page, int pageSize)
          Fetch the data from the specified table.
static RowSet getData(String query, DataSource dataSource, String table, List<String> primaryKeys, int page, int pageSize)
          Fetch the data for the specified SQL statement.
static DataSource getDataSource(String name)
          Return the DataSource identified by the JNDI name specified.
static Collection<String> getPrimaryKeys(DataSource dataSource, String schema, String table)
          Fetch the primary key columns for the specified table in the specified schema.
static RowSet getRow(RowSet table, DatabaseTableModel model)
          Return a RowSet that represents a single record in the database table mapped by the specified DatabaseTableModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseHelper

public DatabaseHelper()
Method Detail

getDataSource

public static DataSource getDataSource(String name)
                                throws NamingException
Return the DataSource identified by the JNDI name specified.

Parameters:
name - The JNDI name to lookup.
Returns:
The configured data source.
Throws:
NamingException - If errors are encountered while fetching the configured resource.

getPrimaryKeys

public static Collection<String> getPrimaryKeys(DataSource dataSource,
                                                String schema,
                                                String table)
                                         throws SQLException
Fetch the primary key columns for the specified table in the specified schema.

Parameters:
dataSource - The data source to use to fetch connections from.
schema - The schema in which the table is defined.
table - The table whose primary key columns are to be retrieved.
Returns:
The collection of primary key column names.
Throws:
SQLException - If errors are encountered while introspecting the table.

getData

public static RowSet getData(String query,
                             DataSource dataSource,
                             String table,
                             List<String> primaryKeys,
                             int page,
                             int pageSize)
                      throws SQLException
Fetch the data for the specified SQL statement. Note that RowSet objects in general require single table data sets.

Parameters:
query - The SQL statement that is to be executed.
dataSource - The data source to use to fetch connection from.
table - The table from which data is to be retrieved.
primaryKeys - The columns that comprise the primary key for the table.
page - The page of data to retrieve from the database.
pageSize - The size of one page of data.
Returns:
The row set representing the results of query execution.
Throws:
SQLException - If errors are encountered while fetch the data.

getData

public static RowSet getData(DataSource dataSource,
                             String schema,
                             String table,
                             List<String> primaryKeys,
                             List<String> columns,
                             List<String> orderBy,
                             int page,
                             int pageSize)
                      throws SQLException
Fetch the data from the specified table.

Note: The RowSet.getMaxRows() method will return the total number of rows available in the table.

Parameters:
dataSource - The data source to use to fetch connection from.
schema - The schema in which the table is defined.
table - The table from which data is to be retrieved.
primaryKeys - The columns that comprise the primary key for the table.
columns - The columns that are to retrieved from the table.
orderBy - The columns by which the data is to be ordered.
page - The page of data to retrieve from the database.
pageSize - The size of one page of data.
Returns:
The row set representing the data in the table.
Throws:
SQLException - If errors are encountered while fetch the data.
See Also:
getQuery(java.lang.String, java.util.List, java.util.List, java.util.List)

getRow

public static RowSet getRow(RowSet table,
                            DatabaseTableModel model)
                     throws NamingException,
                            SQLException
Return a RowSet that represents a single record in the database table mapped by the specified DatabaseTableModel

Parameters:
table - The row set for the current page of data. This row set cursor points to the row required.
model - The table model from which primary key information is retrieved.
Returns:
A row set that represents the selected row. Note that the ResultSet.next() method has been invoked for convenience.
Throws:
NamingException - If errors are encountered while fetching the data source.
SQLException - If errors are encountered while fetching the data.

SPT Core API