org.sape.carbon.services.sql
Class DefaultStatementFactoryImpl

java.lang.Object
  |
  +--org.sape.carbon.services.sql.DefaultStatementFactoryImpl
All Implemented Interfaces:
Configurable, FunctionalInterface, StatementFactory

public class DefaultStatementFactoryImpl
extends Object
implements StatementFactory, Configurable

The default implementation for the StatementFactory. The configuration interface for this component is SqlFactoryConfiguration. The Component configuration consists of

Sample configuration for the component
 <!-- Component Configuration for a SQLStatementFactory -->
 <Configuration ConfigurationInterface=
        "org.sape.carbon.services.sql.SqlFactoryConfiguration">

     <FunctionalInterface>
            org.sape.carbon.services.sql.StatementFactory
     </FunctionalInterface>
     <FunctionalImplementationClass>
            org.sape.carbon.services.sql.DefaultStatementFactoryImpl
     </FunctionalImplementationClass>
     <ConnectionFactory>
            ref:///sql/connection/test/StandaloneConnectionFactory
     </ConnectionFactory>
     <!-- Default Values for Statement Properties -->
     <ResultSetType>TYPE_SCROLL_SENSITIVE</ResultSetType>
     <ResultSetConcurrency>CONCUR_UPDATABLE</ResultSetConcurrency>
     <MaxRows>5</MaxRows>
     <!-- Statement Definitions -->
     <Statement>
         <!-- Statement Query Name -->
         <QueryName>selectAccounts</QueryName>
         <Query>SELECT * FROM accounts</Query>
         <!-- Overriding Parameters -->
         <MaxRows>10</MaxRows>
     </Statement>
     <Statement>
         <QueryName>Second</QueryName>
         <Query>SELECT * from TEST</Query>
     </Statement>
 </Configuration>
 

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.18 $($Author: dvoet $ / $Date: 2003/05/05 21:21:36 $)
Author:
Vivekanand Kirubanandan, June 2002, Greg Hinkle, December 2002

Field Summary
protected  StatementFactoryConfiguration config
          Holds a reference to this factories configuration.
protected static String CONNECTION_FACTORY_CONFIGURATION_ERROR
          Holds the error message displayed if the user has not properly configured a connection factory.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
protected static String RESULT_SET_CONFIGURATION_ERROR
          Holds the error message displayed if the user has not properly configured the result set type and concurrency.
protected  String statementFactoryName
          The name of this factory.
protected  Map statementsMap
          Holds the map of all query name to StatementConfigurations.
 
Constructor Summary
DefaultStatementFactoryImpl()
           
 
Method Summary
protected  CallableStatement buildCallableStatement(StatementConfiguration statementConfig, Connection connection)
          Builds a callable statement for the given configuration with the connection given.
protected  String buildDebugMessage(StatementConfiguration statementConfig)
          Builds a debug message containg the configuration status of the supplied configured statement.
protected  PreparedStatement buildPreparedStatement(StatementConfiguration statementConfig, Connection connection)
          Builds a prepared statement for the given configuration with the connection given.
 void configure(ComponentConfiguration configuration)
          Configure the component.
protected  Statement configureStatement(Statement statement, StatementConfiguration sqlStatement)
          Configure the statement based on the configuration specified in the sqlStatement or using the default values.
 CallableStatement createCallableStatement(String queryName)
          Creates a callable statement for the given query name using the default connection in the factories configuration.
 CallableStatement createCallableStatement(String queryName, Connection connection)
          Creates a callable statement for the given query name with the connection given.
 PreparedStatement createPreparedStatement(String queryName)
          Creates a prepared statement for the given query name using the default connection in the factories configuration.
 PreparedStatement createPreparedStatement(String queryName, Connection connection)
          Creates a prepared statement for the given query name with the connection given.
protected  StatementConfiguration retrieveConfiguration(String queryName, Class sourceClass)
          Looks up a statement configuration based on the name of the configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


statementFactoryName

protected String statementFactoryName
The name of this factory.


config

protected StatementFactoryConfiguration config
Holds a reference to this factories configuration.


statementsMap

protected Map statementsMap
Holds the map of all query name to StatementConfigurations.


RESULT_SET_CONFIGURATION_ERROR

protected static final String RESULT_SET_CONFIGURATION_ERROR
Holds the error message displayed if the user has not properly configured the result set type and concurrency.

See Also:
Constant Field Values

CONNECTION_FACTORY_CONFIGURATION_ERROR

protected static final String CONNECTION_FACTORY_CONFIGURATION_ERROR
Holds the error message displayed if the user has not properly configured a connection factory.

See Also:
Constant Field Values
Constructor Detail

DefaultStatementFactoryImpl

public DefaultStatementFactoryImpl()
Method Detail

buildPreparedStatement

protected PreparedStatement buildPreparedStatement(StatementConfiguration statementConfig,
                                                   Connection connection)
                                            throws SQLException
Builds a prepared statement for the given configuration with the connection given.

Parameters:
statementConfig - configuration to build the statement from
connection - a connection to execute with.
Returns:
a PreparedStatement constructed for the queryName given
Throws:
SQLException - indicates an error creating the CallableStatement

createPreparedStatement

public PreparedStatement createPreparedStatement(String queryName,
                                                 Connection connection)
                                          throws StatementFactoryException
Creates a prepared statement for the given query name with the connection given.

Specified by:
createPreparedStatement in interface StatementFactory
Parameters:
queryName - query to create a CallableStatement for.
connection - a connection to execute with.
Returns:
a PreparedStatement constructed for the queryName given
Throws:
StatementFactoryException - indicates an error creating the CallableStatement

createPreparedStatement

public PreparedStatement createPreparedStatement(String queryName)
                                          throws StatementFactoryException
Creates a prepared statement for the given query name using the default connection in the factories configuration.

When using this interface to create a statement it is important to remember to get back and close the connection that is created. This should be done with:

statement.getConnection().close()

Specified by:
createPreparedStatement in interface StatementFactory
Parameters:
queryName - query to create a CallableStatement for.
Returns:
a PreparedStatement constructed for the queryName given
Throws:
StatementFactoryException - indicates an error creating the CallableStatement

buildCallableStatement

protected CallableStatement buildCallableStatement(StatementConfiguration statementConfig,
                                                   Connection connection)
                                            throws SQLException
Builds a callable statement for the given configuration with the connection given.

Parameters:
statementConfig - configuration to build the statement from
connection - a connection to execute with.
Returns:
a CallableStatement constructed for the queryName given
Throws:
SQLException - indicates an error creating the CallableStatement

createCallableStatement

public CallableStatement createCallableStatement(String queryName,
                                                 Connection connection)
                                          throws StatementFactoryException
Creates a callable statement for the given query name with the connection given.

Specified by:
createCallableStatement in interface StatementFactory
Parameters:
queryName - query to create a CallableStatement for.
connection - a connection to execute with.
Returns:
a CallableStatement constructed for the queryName given
Throws:
StatementFactoryException - indicates an error creating the CallableStatement

createCallableStatement

public CallableStatement createCallableStatement(String queryName)
                                          throws StatementFactoryException
Creates a callable statement for the given query name using the default connection in the factories configuration.

When using this interface to create a statement it is important to remember to get back and close the connection that is created. This should be done with:

statement.getConnection().close()

Specified by:
createCallableStatement in interface StatementFactory
Parameters:
queryName - query to create a CallableStatement for.
Returns:
a CallableStatement constructed for the queryName given
Throws:
StatementFactoryException - indicates an error creating the CallableStatement

retrieveConfiguration

protected StatementConfiguration retrieveConfiguration(String queryName,
                                                       Class sourceClass)
                                                throws StatementNotConfiguredException
Looks up a statement configuration based on the name of the configuration.

Parameters:
queryName - name of the query to lookup
sourceClass - class to use when throwing an exception
Returns:
a StatementConfiguration for the given queryName
Throws:
StatementNotConfiguredException - indicates the queryName had no configured statement associated with it.

configure

public void configure(ComponentConfiguration configuration)
Configure the component. This is preceded and followed by the suspend and resume operations if they are available on the component.

Specified by:
configure in interface Configurable
Parameters:
configuration - A SqlFactoryConfiguration

configureStatement

protected Statement configureStatement(Statement statement,
                                       StatementConfiguration sqlStatement)
                                throws SQLException

Configure the statement based on the configuration specified in the sqlStatement or using the default values.

Parameters:
statement - A PreparedStatement or a CallableStatement>
sqlStatement - The configuration information for the statement.
Returns:
Statement A configured statement
Throws:
SQLException - indicates an error configuring the statement

buildDebugMessage

protected String buildDebugMessage(StatementConfiguration statementConfig)
Builds a debug message containg the configuration status of the supplied configured statement.

Parameters:
statementConfig - statement configuration to build debug message for
Returns:
a debug message describing the statement config


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.