Compoze Software, Inc.

com.compoze.ejb
Class DatabaseConnectionHelper


java.lang.Object

  |

  +--com.compoze.ejb.DatabaseConnectionHelper


public class DatabaseConnectionHelper
extends java.lang.Object

This is a helper class to create database connections and perform common database interactions.


Constructor Summary
DatabaseConnectionHelper()
           
 
Method Summary
static java.sql.Connection getBeanDBConnection(java.lang.ClassLoader classLoader)
          Deprecated. Use getBeanDBConnection(com.compoze.security.User,ClassLoader) instead so that information will be available to select the DataSource at runtime
static java.sql.Connection getBeanDBConnection(User caller)
          Gets the database connection from the database connection factory registered in the current service registry.
static java.sql.Connection getBeanDBConnection(User caller, java.lang.ClassLoader classLoader)
          Gets the database connection from the database connection factory registered in the current service registry.
static com.compoze.ejb.persistence.database.IIdentifierFormat getIdentifierFormat()
          Gets a formatted, comma separated column list from the specified list of columns.
static java.io.InputStream getInputStreamToObject(java.lang.Object obj)
          Gets an InputStream which reads the serialized data of an object.
static java.lang.Object getObjectFromInputStream(java.io.InputStream is)
          Instantiates an object from an InputStream to its serialized data.
static java.lang.String getQuotedColumn(java.lang.String column)
          Gets a formatted, comma separated column list from the specified list of columns.
static java.lang.String getQuotedColumn(java.lang.String[] columns)
          Gets a formatted, comma separated column list from the specified list of columns.
static java.lang.String getQuotedColumn(java.lang.String[] columns, com.compoze.ejb.persistence.database.IIdentifierFormat identifierFormat)
          Gets a formatted, comma separated column list from the specified list of columns.
static java.lang.String getQuotedColumn(java.lang.String column, com.compoze.ejb.persistence.database.IIdentifierFormat identifierFormat)
          Gets a formatted, comma separated column list from the specified list of columns.
static java.lang.Object getSerializableObject(java.sql.ResultSet rs, int iParameterIndex)
          Gets a serializable object from a ResultSet.
static java.lang.Object getSerializableObject(java.sql.ResultSet rs, java.lang.String sColumnName)
          Gets a serializable object from a ResultSet.
static void setSerializableObject(java.sql.PreparedStatement pstmt, int iColumn, java.lang.Object obj)
          Sets a serializable object in a prepared statement using setBinaryStream().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseConnectionHelper


public DatabaseConnectionHelper()
Method Detail

getBeanDBConnection


public static java.sql.Connection getBeanDBConnection(User caller)
                                               throws javax.naming.NamingException,
                                                      java.sql.SQLException,
                                                      java.lang.reflect.InvocationTargetException,
                                                      java.lang.ClassNotFoundException,
                                                      java.lang.NoSuchMethodException,
                                                      java.lang.IllegalAccessException,
                                                      java.lang.InstantiationException
Gets the database connection from the database connection factory registered in the current service registry. Making this call is only valid within the context of an EJB.
Parameters:
caller - the caller or null to use default settings
Returns:
the database connection
Throws:
javax.naming.NamingException - if a naming exception occurred
java.sql.SQLException - if an SQL exception occurred
java.lang.reflect.InvocationTargetException - if a method could not be invoked using introspection
java.lang.ClassNotFoundException - if a class could not be found using introspection
java.lang.NoSuchMethodException - if the constructor on the database connection factory could not be invoked
java.lang.IllegalAccessException - if a field or method could not be accessed using introspection
java.lang.InstantiationException - if the database connection factory could not be instantiated
See Also:
IDatabaseConnectionFactory, EjbServiceRegistry

getBeanDBConnection


public static java.sql.Connection getBeanDBConnection(java.lang.ClassLoader classLoader)
                                               throws javax.naming.NamingException,
                                                      java.sql.SQLException,
                                                      java.lang.reflect.InvocationTargetException,
                                                      java.lang.ClassNotFoundException,
                                                      java.lang.NoSuchMethodException,
                                                      java.lang.IllegalAccessException,
                                                      java.lang.InstantiationException
Deprecated. Use getBeanDBConnection(com.compoze.security.User,ClassLoader) instead so that information will be available to select the DataSource at runtime

Gets the database connection from the database connection factory registered in the current service registry. Making this call is only valid within the context of an EJB.
Parameters:
classLoader - the class loader to look for class in
Returns:
the database connection
Throws:
javax.naming.NamingException - if a naming exception occurred
java.sql.SQLException - if an SQL exception occurred
java.lang.reflect.InvocationTargetException - if a method could not be invoked using introspection
java.lang.ClassNotFoundException - if a class could not be found using introspection
java.lang.NoSuchMethodException - if the constructor on the database connection factory could not be invoked
java.lang.IllegalAccessException - if a field or method could not be accessed using introspection
java.lang.InstantiationException - if the database connection factory could not be instantiated
See Also:
IDatabaseConnectionFactory, EjbServiceRegistry

getBeanDBConnection


public static java.sql.Connection getBeanDBConnection(User caller,
                                                      java.lang.ClassLoader classLoader)
                                               throws javax.naming.NamingException,
                                                      java.sql.SQLException,
                                                      java.lang.reflect.InvocationTargetException,
                                                      java.lang.ClassNotFoundException,
                                                      java.lang.NoSuchMethodException,
                                                      java.lang.IllegalAccessException,
                                                      java.lang.InstantiationException
Gets the database connection from the database connection factory registered in the current service registry. Making this call is only valid within the context of an EJB.
Parameters:
caller - the caller
classLoader - the class loader to look for class in
Returns:
the database connection
Throws:
javax.naming.NamingException - if a naming exception occurred
java.sql.SQLException - if an SQL exception occurred
java.lang.reflect.InvocationTargetException - if a method could not be invoked using introspection
java.lang.ClassNotFoundException - if a class could not be found using introspection
java.lang.NoSuchMethodException - if the constructor on the database connection factory could not be invoked
java.lang.IllegalAccessException - if a field or method could not be accessed using introspection
java.lang.InstantiationException - if the database connection factory could not be instantiated
See Also:
IDatabaseConnectionFactory, EjbServiceRegistry

setSerializableObject


public static void setSerializableObject(java.sql.PreparedStatement pstmt,
                                         int iColumn,
                                         java.lang.Object obj)
                                  throws java.io.IOException,
                                         java.sql.SQLException
Sets a serializable object in a prepared statement using setBinaryStream().
Parameters:
pstmt - the prepared statement
iColumn - the column in the prepared statement to set
obj - the object to set (must implement Serializable)
Throws:
java.io.IOException - if an i/o error occurred
java.sql.SQLException - if a SQL related database error occurred
See Also:
PreparedStatement.setBinaryStream(int, java.io.InputStream, int)

getSerializableObject


public static java.lang.Object getSerializableObject(java.sql.ResultSet rs,
                                                     java.lang.String sColumnName)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException,
                                                     java.sql.SQLException
Gets a serializable object from a ResultSet.
Parameters:
rs - the result set to get the object from
sColumnName - the column to get from
Returns:
the serializable object
Throws:
java.io.IOException - if an i/o error occurred
java.lang.ClassNotFoundException - if a class could not be found
java.sql.SQLException - if a SQL related database error occurred
See Also:
ResultSet.getBinaryStream(String)

getSerializableObject


public static java.lang.Object getSerializableObject(java.sql.ResultSet rs,
                                                     int iParameterIndex)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException,
                                                     java.sql.SQLException
Gets a serializable object from a ResultSet.
Parameters:
rs - the result set to get the object from
iParameterIndex - the parameter index to get from
Returns:
the serializable object
Throws:
java.io.IOException - if an i/o error occurred
java.lang.ClassNotFoundException - if a class could not be found
java.sql.SQLException - if a SQL related database error occurred
See Also:
ResultSet.getBinaryStream(int)

getInputStreamToObject


public static java.io.InputStream getInputStreamToObject(java.lang.Object obj)
                                                  throws java.io.IOException
Gets an InputStream which reads the serialized data of an object. Return null if it could not be obtained. This implementation first creates the serialized data in memory then returns an input stream to that data.
Parameters:
obj - the object to get an input stream to
Returns:
an input stream to the object
Throws:
java.io.IOException - if an i/o error occurred, possibly because the object is not serializable

getObjectFromInputStream


public static java.lang.Object getObjectFromInputStream(java.io.InputStream is)
                                                 throws java.io.IOException,
                                                        java.lang.ClassNotFoundException
Instantiates an object from an InputStream to its serialized data.
Parameters:
is - the input stream to get the object from
Returns:
the object obtained from the stream
Throws:
java.io.IOException - if an i/o error occurred
java.lang.ClassNotFoundException - if the class obtained from the stream could not be found
See Also:
ObjectInputStream

getQuotedColumn


public static java.lang.String getQuotedColumn(java.lang.String column)
                                        throws com.compoze.ejb.persistence.PersistenceException
Gets a formatted, comma separated column list from the specified list of columns. The exact database column names (not Java field names) must be specified. This would be useful when making SQL statements with references to fields in other classes.
Parameters:
column - a column
Returns:
the comma separated column list
Throws:
com.compoze.ejb.persistence.PersistenceException - if the persistence could not be initialized

getIdentifierFormat


public static com.compoze.ejb.persistence.database.IIdentifierFormat getIdentifierFormat()
                                                                                  throws com.compoze.ejb.persistence.PersistenceException
Gets a formatted, comma separated column list from the specified list of columns. The exact database column names (not Java field names) must be specified. This would be useful when making SQL statements with references to fields in other classes.
Parameters:
columns - a list of columns
Returns:
the comma separated column list
Throws:
com.compoze.ejb.persistence.PersistenceException - if the persistence could not be initialized

getQuotedColumn


public static java.lang.String getQuotedColumn(java.lang.String[] columns)
                                        throws com.compoze.ejb.persistence.PersistenceException
Gets a formatted, comma separated column list from the specified list of columns. The exact database column names (not Java field names) must be specified. This would be useful when making SQL statements with references to fields in other classes.
Parameters:
columns - a list of columns
Returns:
the comma separated column list

getQuotedColumn


public static java.lang.String getQuotedColumn(java.lang.String column,
                                               com.compoze.ejb.persistence.database.IIdentifierFormat identifierFormat)
                                        throws com.compoze.ejb.persistence.PersistenceException
Gets a formatted, comma separated column list from the specified list of columns. The exact database column names (not Java field names) must be specified. This would be useful when making SQL statements with references to fields in other classes.
Parameters:
column - a list of column
databaseConfiguration - the database configuration
identifierFormat - the identifier format
Returns:
the comma separated column list

getQuotedColumn


public static java.lang.String getQuotedColumn(java.lang.String[] columns,
                                               com.compoze.ejb.persistence.database.IIdentifierFormat identifierFormat)
                                        throws com.compoze.ejb.persistence.PersistenceException
Gets a formatted, comma separated column list from the specified list of columns. The exact database column names (not Java field names) must be specified. This would be useful when making SQL statements with references to fields in other classes.
Parameters:
columns - a list of columns
databaseConfiguration - the database configuration
identifierFormat - the identifier format
Returns:
the comma separated column list

Compoze Software, Inc.

Copyright ©1999-2001 Compoze Software, Inc. All rights reserved.