org.enableit.db
Class DBUtils

java.lang.Object
  |
  +--org.enableit.db.DBUtils

public class DBUtils
extends java.lang.Object

Provides utilities to be used in conjunction with the database proxies.

Version:
v1.1 Extracted the ResultSet conversion routines from the database proxies.
Author:
chris.pettifer@enableit.org
See Also:
DatabaseProxy
, GenericDBProxy

Field Summary
static java.lang.String about
          Information on the exact CVS version accessible after compilation
protected static org.apache.log4j.Category cat
          The Log4J Category doing the logging.
private static java.lang.String PROC_GET_NEXT_ID
          Name of stored procedure used for getNextId
private static java.lang.String SQL_GET_NEXT_ID
          Dynamic SQL used for getNextId
private static java.lang.String SQL_INIT_ID
          Dynamic SQL used for getNextId, initialises the table if no previous query
private static java.lang.String SQL_SET_NEXT_ID
          Dynamic SQL used for getNextIdUsingSQL to update the id to the next one
 
Constructor Summary
DBUtils()
          Default Constructor
 
Method Summary
static java.lang.String addFilter(java.lang.String sql, DBFilter filter)
          Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value
static java.lang.String addFilter(java.lang.String sql, java.lang.String filterCol, java.lang.String filterVal)
          Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value
static java.lang.String addFilters(java.lang.String sql, java.util.List filters)
          Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value
static java.util.ArrayList convertHashMapToArrayList(java.util.HashMap attributes)
          Converts a set of name-value pairs stored in a java.util.HashMap to values only stored in a java.util.ArrayList
static java.util.ArrayList convertHashtableToArrayList(java.util.Hashtable attributes)
          Converts a set of name-value pairs stored in a java.util.Hashtable to values only stored in a java.util.ArrayList
static java.util.List convertResultToList(java.sql.ResultSet sqlResults)
          Turns a ResultSet into an ArrayList of TreeMaps
static int getNextId(java.lang.String tableName, boolean spSupported)
          Returns the next available id for the specified table
static int getNextIdUsingSQL(java.lang.String tableName)
          Returns the next available id for the specified table
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

protected static org.apache.log4j.Category cat
The Log4J Category doing the logging. Same Category is used throughout the package.

PROC_GET_NEXT_ID

private static final java.lang.String PROC_GET_NEXT_ID
Name of stored procedure used for getNextId

SQL_SET_NEXT_ID

private static final java.lang.String SQL_SET_NEXT_ID
Dynamic SQL used for getNextIdUsingSQL to update the id to the next one

SQL_GET_NEXT_ID

private static final java.lang.String SQL_GET_NEXT_ID
Dynamic SQL used for getNextId

SQL_INIT_ID

private static final java.lang.String SQL_INIT_ID
Dynamic SQL used for getNextId, initialises the table if no previous query

about

public static final java.lang.String about
Information on the exact CVS version accessible after compilation
Constructor Detail

DBUtils

public DBUtils()
Default Constructor
Method Detail

convertHashtableToArrayList

public static java.util.ArrayList convertHashtableToArrayList(java.util.Hashtable attributes)
Converts a set of name-value pairs stored in a java.util.Hashtable to values only stored in a java.util.ArrayList

convertHashMapToArrayList

public static java.util.ArrayList convertHashMapToArrayList(java.util.HashMap attributes)
Converts a set of name-value pairs stored in a java.util.HashMap to values only stored in a java.util.ArrayList

convertResultToList

public static java.util.List convertResultToList(java.sql.ResultSet sqlResults)
                                          throws DBException
Turns a ResultSet into an ArrayList of TreeMaps
Returns:
list An ArrayList of TreeMaps. Each map contains the column heading value pairs for a single result set row.

getNextIdUsingSQL

public static int getNextIdUsingSQL(java.lang.String tableName)
                             throws java.rmi.RemoteException,
                                    DBException

Returns the next available id for the specified table

The implementation makes use of a number fountain in the database to avoid the chance of two EJB onstances attempting to use the same key

Parameters:
tableName -  

getNextId

public static int getNextId(java.lang.String tableName,
                            boolean spSupported)
                     throws java.rmi.RemoteException,
                            DBException

Returns the next available id for the specified table

The implementation makes use of a number fountain in the database to avoid the chance of two EJB onstances attempting to use the same key

Parameters:
tableName -  
spSupported - true - if stored procedures are to be used to execute the queries false - to use dynamic SQL statements

addFilter

public static java.lang.String addFilter(java.lang.String sql,
                                         java.lang.String filterCol,
                                         java.lang.String filterVal)

Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value

If filterCol and / or filterVal are null then no filter is added. This could be modified to allow joins to null values, but presents issues of what datatype to send to the database

Parameters:
sql - The base query to which we wish to add a filter
filterCol - The column to filter on
filterVal - The value to filter on

addFilter

public static java.lang.String addFilter(java.lang.String sql,
                                         DBFilter filter)

Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value

If filter name and / or filter value are null then no filter is added. This could be modified to allow joins to null values, but presents issues of what datatype to send to the database

Parameters:
sql - The base query to which we wish to add a filter
filter - All the encapsulated filter data

addFilters

public static java.lang.String addFilters(java.lang.String sql,
                                          java.util.List filters)

Adds a 'where' or 'and' clause as appropriate to join on the supplied column and value

If filter name and / or filter value are null then no filter is added. This could be modified to allow joins to null values, but presents issues of what datatype to send to the database

Parameters:
sql - The base query to which we wish to add a filter
filter - A java.util.List of DBFilter objects containing the encapsulated filter data


Copyright © enableIT.org 1999,2000,2001,2002 All Rights Reserved.