com.codestudio.util
Class SQLUtil

java.lang.Object
  |
  +--com.codestudio.util.SQLUtil

public class SQLUtil
extends java.lang.Object

A utility class that is capable of performing any sql operation. All results from queries are returned as Hashtable arrays, where each Hashtable represents one row (record) of data (key=column_name, value=data).

If the sql is an update, insert, or delete, then the Hashtable array contains only one slice, and the value of that first Hashtable contains a description of the number of rows affected.

Results are cached by query that refreshes itself perdiocially, at a configurable interval that defaults to five minutes.

If you wish to force the cache to refresh before this interval, you should either update the cacheRefresh parameter in the poolman.props file or invoke the executeSql(String sql, boolean usecache) method with the second argument set to 'false'. If the second argument is set to true or ommitted, the cache will be used. The cache updates are handled internally by a separate thread of execution.

For specific usage examples, take a look at Sample.java in the samples directory of the distribution.


Field Summary
static int MAX_ATTEMPTS
           
 java.lang.String propsfilename
           
 
Method Summary
 java.util.Hashtable[] doJDBC(java.lang.String dbname, java.lang.String sql, boolean goNative)
          This method is called by the cache thread in SQLCache.
protected  java.util.Hashtable[] doJDBC(java.lang.String dbname, java.lang.String sql, java.sql.Connection con)
          Executes a statement and returns results in the form of a Hashtable array.
protected  java.util.Hashtable[] doJDBC(java.lang.String dbname, java.lang.String sql, java.sql.Connection con, boolean goNative)
          Executes a statement and returns results in the form of a Hashtable array.
 SQLResult execute(java.lang.String sql)
           
 SQLResult execute(java.lang.String dbname, java.lang.String sql)
           
 java.util.Hashtable[] executeSql(java.lang.String sql)
          Simply executes executeSql(sql, true).
 java.util.Hashtable[] executeSql(java.lang.String dbname, java.lang.String sql)
          Begins the actual database operation by preparing resources.
 java.util.Enumeration getAllPoolnames()
          Get a Vector containing all the names of the database pools currently in use.
static SQLUtil getInstance()
          The default method used to retrieve an instance of SQLUtil, based on the properties file SQLManager.DEFAULT_PROPSFILE, which must be in your CLASSPATH.
static SQLUtil getInstance(java.util.Properties p)
          An alternative method to retrieve an instance of SQLUtil, using a Properties object.
static SQLUtil getInstance(java.lang.String propsfilename)
          An alternative method to retrieve an instance of SQLUtil, using a specified props file.
 JDBCPool getPool(java.lang.String dbname)
           
static void main(java.lang.String[] args)
           
protected  SQLResult makeResult(java.util.Hashtable[] h)
          Wraps an array of Hashtables into a more convenient data structure, called a SQLResult.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ATTEMPTS

public static final int MAX_ATTEMPTS

propsfilename

public java.lang.String propsfilename
Method Detail

main

public static void main(java.lang.String[] args)

getInstance

public static SQLUtil getInstance()
The default method used to retrieve an instance of SQLUtil, based on the properties file SQLManager.DEFAULT_PROPSFILE, which must be in your CLASSPATH.

getInstance

public static SQLUtil getInstance(java.lang.String propsfilename)
An alternative method to retrieve an instance of SQLUtil, using a specified props file.

getInstance

public static SQLUtil getInstance(java.util.Properties p)
An alternative method to retrieve an instance of SQLUtil, using a Properties object.

execute

public SQLResult execute(java.lang.String sql)
                  throws java.sql.SQLException

execute

public SQLResult execute(java.lang.String dbname,
                         java.lang.String sql)
                  throws java.sql.SQLException

executeSql

public java.util.Hashtable[] executeSql(java.lang.String sql)
                                 throws java.sql.SQLException
Simply executes executeSql(sql, true).

makeResult

protected SQLResult makeResult(java.util.Hashtable[] h)
                        throws java.sql.SQLException
Wraps an array of Hashtables into a more convenient data structure, called a SQLResult.

getAllPoolnames

public java.util.Enumeration getAllPoolnames()
Get a Vector containing all the names of the database pools currently in use.

getPool

public JDBCPool getPool(java.lang.String dbname)
Returns:
JDBCPool The pool requested by name.

executeSql

public java.util.Hashtable[] executeSql(java.lang.String dbname,
                                        java.lang.String sql)
                                 throws java.sql.SQLException
Begins the actual database operation by preparing resources. It calls doJDBC() to perform the actual operation.

doJDBC

public java.util.Hashtable[] doJDBC(java.lang.String dbname,
                                    java.lang.String sql,
                                    boolean goNative)
                             throws java.sql.SQLException
This method is called by the cache thread in SQLCache.

doJDBC

protected java.util.Hashtable[] doJDBC(java.lang.String dbname,
                                       java.lang.String sql,
                                       java.sql.Connection con)
                                throws java.sql.SQLException
Executes a statement and returns results in the form of a Hashtable array.

doJDBC

protected java.util.Hashtable[] doJDBC(java.lang.String dbname,
                                       java.lang.String sql,
                                       java.sql.Connection con,
                                       boolean goNative)
                                throws java.sql.SQLException
Executes a statement and returns results in the form of a Hashtable array.


Copyright © 1999-2001 The Code Studio. All Rights Reserved.