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:
__AUTHOR__
See Also:
DatabaseProxy
, GenericDBProxy

Field Summary
static java.lang.String ABOUT
          Information on the exact CVS version accessible after compilation
static int DB_MSSQLSERVER
           
static java.lang.String DB_NAME_MSSQLSERVER
           
static java.lang.String DB_NAME_ORACLE
           
static java.lang.String DB_NAME_SYBASE_ASA
           
static java.lang.String DB_NAME_SYBASE_ASE
           
static int DB_ORACLE
           
static int DB_SYBASE_ASA
           
static int DB_SYBASE_ASE
           
static int DB_UNKNOWN
           
protected static org.apache.log4j.Logger logger
          The Log4J Category doing the logging.
 
Constructor Summary
DBUtils()
          Default Constructor
 
Method Summary
static java.lang.String addFilter(java.lang.String sql, org.enableit.db.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.StringBuffer addFilters(java.lang.StringBuffer sql, java.util.List filters)
          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.sql.PreparedStatement bindVars(java.sql.PreparedStatement ps, java.util.List parms)
          Binds a List of varables into a SQL statement.
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 getDatabaseProduct(java.sql.DatabaseMetaData dmd)
          Return one of the enumerated database products.
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
static java.lang.Object populateBean(java.lang.Object bean, java.util.Map dataRecord)
          Read data from a Map containing data according to the convention in convertResultToList and populate a JavaBean object with it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger
The Log4J Category doing the logging.


DB_UNKNOWN

public static final int DB_UNKNOWN
See Also:
Constant Field Values

DB_SYBASE_ASA

public static final int DB_SYBASE_ASA
See Also:
Constant Field Values

DB_SYBASE_ASE

public static final int DB_SYBASE_ASE
See Also:
Constant Field Values

DB_ORACLE

public static final int DB_ORACLE
See Also:
Constant Field Values

DB_MSSQLSERVER

public static final int DB_MSSQLSERVER
See Also:
Constant Field Values

DB_NAME_SYBASE_ASA

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

DB_NAME_SYBASE_ASE

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

DB_NAME_ORACLE

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

DB_NAME_MSSQLSERVER

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

ABOUT

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

See Also:
Constant Field Values
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.
DBException

getNextIdUsingSQL

public static int getNextIdUsingSQL(java.lang.String tableName)
                             throws 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 -
DBException

getNextId

public static int getNextId(java.lang.String tableName,
                            boolean spSupported)
                     throws 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
DBException

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,
                                         org.enableit.db.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

addFilters

public static java.lang.StringBuffer addFilters(java.lang.StringBuffer 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

populateBean

public static java.lang.Object populateBean(java.lang.Object bean,
                                            java.util.Map dataRecord)
                                     throws DBException
Read data from a Map containing data according to the convention in convertResultToList and populate a JavaBean object with it.

NB Due to a problem in the beanutils library this will not work with DynaBeans.

Parameters:
bean - The JavaBean to populate
dataRecord - Map of property data to populate into JavaBean.
Returns:
bean The JavaBean now populated with the data
DBException

bindVars

public static java.sql.PreparedStatement bindVars(java.sql.PreparedStatement ps,
                                                  java.util.List parms)
                                           throws DBException
Binds a List of varables into a SQL statement.

DBException

getDatabaseProduct

public static int getDatabaseProduct(java.sql.DatabaseMetaData dmd)
Return one of the enumerated database products.



Copyright © 1999-2004 enableIT.org. All Rights Reserved.