org.cementj.database
Class SQLResourceBundle

java.lang.Object
  extended by org.cementj.database.SQLResourceBundle

public class SQLResourceBundle
extends java.lang.Object

Resource bundles database specific objects. If your application supports multiple databases and has different versions of a SQL statement to accomodate database-specific SQL syntax, for example.

In this way, you can write code that is platform independent and extensible.

Each resource in the bundle contains the same items, but they differ per database product dialiect. For example, with a resource bundle "MyResources", you could have a "MyResources_Oracle" that contains Oracle-specific SQL, a "MyResources_DB2" that contains DB2-specific SQL, and a "MyResources_MySQL" that contains MySQL-specific syntax SQL.

Entries in the resource confirm to standard Properties syntax (in fact, they are Properties). For example,

                ####  SQL to return table information
                table.sql=select t.owner,t.table_name,c.column_name,\
                        c.column_id,c.data_type,c.data_length,\
                        c.data_precision,c.data_scale,c.nullable \
                        from all_tables t, all_tab_columns c \
                        where t.owner = c.owner and \
                                t.table_name = c.table_name and \
                                t.owner like ? and \
                                t.table_name like ? \
                        order by 1, 2, 4
 

The database-specific extension name comes directly from the getDatabaseProductName() from the JDBC driver DatabaseMetaData.

The properties files associated with the bundle are loaded as resources from the classpath.

Author:
Derek C. Ashmore

Constructor Summary
SQLResourceBundle()
           
 
Method Summary
static SQLResourceBundle getBundle(java.lang.String baseName, java.sql.Connection conn)
          Provides a resource bundle given a database connection and a bundle name.
static SQLResourceBundle getBundle(java.lang.String baseName, java.sql.Connection conn, java.lang.ClassLoader loader)
          Provides a resource bundle given a database connection and a bundle name.
 java.lang.String getString(java.lang.String keyName)
          Returns string for a given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLResourceBundle

public SQLResourceBundle()
Method Detail

getBundle

public static SQLResourceBundle getBundle(java.lang.String baseName,
                                          java.sql.Connection conn)
                                   throws java.sql.SQLException,
                                          java.io.IOException
Provides a resource bundle given a database connection and a bundle name. Typically, the bundle name is the fully-qualified name of the class using it. For example,
                _sqlResourceBundle = SQLResourceBundle.getBundle(
                        DatabaseMetaDataDAO.class.getName(), conn);
                String tableSQL = _sqlResourceBundle.getString("table.sql");
 

By default, the System classloader is used to load the resource from the classpath.

Parameters:
baseName -
conn -
Returns:
SQLResourceBundle
Throws:
java.sql.SQLException
java.io.IOException

getBundle

public static SQLResourceBundle getBundle(java.lang.String baseName,
                                          java.sql.Connection conn,
                                          java.lang.ClassLoader loader)
                                   throws java.sql.SQLException,
                                          java.io.IOException
Provides a resource bundle given a database connection and a bundle name. Typically, the bundle name is the fully-qualified name of the class using it. For example,
                _sqlResourceBundle = SQLResourceBundle.getBundle(
                        DatabaseMetaDataDAO.class.getName(), conn);
                String tableSQL = _sqlResourceBundle.getString("table.sql");
 

The loader provided is used to load the resource from the classpath.

Parameters:
baseName -
conn -
loader -
Returns:
SQLResourceBundle
Throws:
java.sql.SQLException
java.io.IOException

getString

public java.lang.String getString(java.lang.String keyName)
Returns string for a given key.

Usage example:

                _sqlResourceBundle = SQLResourceBundle.getBundle(
                        DatabaseMetaDataDAO.class.getName(), conn);
                String tableSQL = _sqlResourceBundle.getString("table.sql");
 

Parameters:
keyName -
Returns:
value


Copyright © 2003 Delta Vortex Technologies, Inc. All Rights Reserved.