|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cementj.database.SQLResourceBundle
public class SQLResourceBundle
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.
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 |
---|
public SQLResourceBundle()
Method Detail |
---|
public static SQLResourceBundle getBundle(java.lang.String baseName, java.sql.Connection conn) throws java.sql.SQLException, java.io.IOException
_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.
baseName
- conn
-
java.sql.SQLException
java.io.IOException
public static SQLResourceBundle getBundle(java.lang.String baseName, java.sql.Connection conn, java.lang.ClassLoader loader) throws java.sql.SQLException, java.io.IOException
_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.
baseName
- conn
- loader
-
java.sql.SQLException
java.io.IOException
public java.lang.String getString(java.lang.String keyName)
Usage example:
_sqlResourceBundle = SQLResourceBundle.getBundle( DatabaseMetaDataDAO.class.getName(), conn); String tableSQL = _sqlResourceBundle.getString("table.sql");
keyName
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |