sqlj.runtime.ref
Class ConnectionContextImpl

java.lang.Object
  |
  +--sqlj.runtime.ref.ConnectionContextImpl
Direct Known Subclasses:
DefaultContext

public abstract class ConnectionContextImpl
extends java.lang.Object
implements ConnectionContext

The connection context impl class is an abstract implementation of the connection context interface. It does not implement the connection context interface directly, but rather just defines the connection context method implementations. Subclasses must be defined which provide the static methods and constructors described in the connection context documentation.

Generated context classes will extend this class and implement the connection context interface.

See Also:
ConnectionContext

Constructor Summary
protected ConnectionContextImpl(ProfileGroup profiles, java.sql.Connection conn)
          Creates a new connection context impl class with the given profile group and connection.
protected ConnectionContextImpl(ProfileGroup profiles, ConnectionContext other)
          Creates a new connection context impl class with the given profile group which uses the same connection as that of the passed context.
protected ConnectionContextImpl(ProfileGroup profiles, java.lang.String dsname)
          Creates a new connection context impl class with the given profile group which uses the default datasource connection.
protected ConnectionContextImpl(ProfileGroup profiles, java.lang.String url, boolean autoCommit)
          Creates a new connection context impl class with the given profile group and creates a new connection using the passed url.
protected ConnectionContextImpl(ProfileGroup profiles, java.lang.String url, java.util.Properties info, boolean autoCommit)
          Creates a new connection context impl class with the given profile group and creates a new connection using the passed url and properties.
protected ConnectionContextImpl(ProfileGroup profiles, java.lang.String dsname, java.lang.String user, java.lang.String password)
          Creates a new connection context impl class with the given profile group which uses the a datasource connection with particular username and password.
protected ConnectionContextImpl(ProfileGroup profiles, java.lang.String url, java.lang.String user, java.lang.String password, boolean autoCommit)
          Creates a new connection context impl class with the given profile group and creates a new connection using the passed url, user and password.
 
Method Summary
 void close()
          closes the context, its underlying connection and connected profiles.
 void close(boolean closeConnection)
          Releases all resources used in maintaining database state on this context.
protected  void finalize()
          Calls the finalize method of the super and closes this context if it has not already been closed.
 sqlj.runtime.profile.ConnectedProfile getConnectedProfile(java.lang.Object profileKey)
          Returns the connected profile associated with a profileKey for this connection context instance.
 java.sql.Connection getConnection()
          Returns the underlying connection for this connection context.
 ExecutionContext getExecutionContext()
          Returns the default execution context used by this connection context.
 boolean isClosed()
          Returns true if this context has been closed, false otherwise.
static java.util.Properties loadProps(java.lang.Class loadCtx, java.lang.String propName)
          Read a properties file.
static java.util.Hashtable loadTypeMap(java.lang.Class loadCtx, java.lang.String propList)
          Utility function to load the type map into a hastable.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.sql.Connection conn)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group and connection. The auto commit mode of the connection is used unchanged. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
conn - the underlying connection for this context instance.
Throws:
java.sql.SQLException - if the passed connection is null

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.lang.String url,
                                java.lang.String user,
                                java.lang.String password,
                                boolean autoCommit)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group and creates a new connection using the passed url, user and password. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
url - the database url
user - the username
password - the user password
autoCommit - true if the connection should be created in auto-commit mode, false otherwise.
Throws:
java.sql.SQLException - the underlying connection could not be created.
See Also:
DriverManager.getConnection(String,String,String), Connection.setAutoCommit(boolean)

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.lang.String url,
                                java.util.Properties info,
                                boolean autoCommit)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group and creates a new connection using the passed url and properties. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
url - the database url
properties - the properties for creating a connection
autoCommit - true if the connection should be created in auto-commit mode, false otherwise.
Throws:
java.sql.SQLException - the underlying connection could not be created.
See Also:
Connection.setAutoCommit(boolean), DriverManager.getConnection(String,java.util.Properties)

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.lang.String url,
                                boolean autoCommit)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group and creates a new connection using the passed url. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
url - the database url
autoCommit - true if the connection should be created in auto-commit mode, false otherwise.
Throws:
java.sql.SQLException - the underlying connection could not be created.
See Also:
DriverManager.getConnection(String), Connection.setAutoCommit(boolean)

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                ConnectionContext other)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group which uses the same connection as that of the passed context. The auto commit mode of the shared connection is unchanged. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
other - a connection context instance with which to share a connection.
Throws:
java.sql.SQLException - if the underlying connection is null
See Also:
ConnectionContext.getConnection()

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.lang.String dsname)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group which uses the default datasource connection. The auto commit mode of the datasource connection is used. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
dsname - name of the data source
Throws:
java.sql.SQLException - if no connection can be established
See Also:
ConnectionContext.getConnection()

ConnectionContextImpl

protected ConnectionContextImpl(ProfileGroup profiles,
                                java.lang.String dsname,
                                java.lang.String user,
                                java.lang.String password)
                         throws java.sql.SQLException
Creates a new connection context impl class with the given profile group which uses the a datasource connection with particular username and password. The auto commit mode of the datasource connection is used. Each subclass must define its own profile group that will manage the set of profiles associated with that context class.
Parameters:
profiles - the profile group for the context subclass.
dsname - name of the data source
Throws:
java.sql.SQLException - if no connection can be established
See Also:
ConnectionContext.getConnection()
Method Detail

getConnectedProfile

public sqlj.runtime.profile.ConnectedProfile getConnectedProfile(java.lang.Object profileKey)
                                                          throws java.sql.SQLException
Returns the connected profile associated with a profileKey for this connection context instance.
Specified by:
getConnectedProfile in interface ConnectionContext
Parameters:
profileKey - the key asscoiated with the desired profile.
Throws:
java.lang.IllegalArgumentException - if the profileKey is null or invalid.
java.sql.SQLException - if a connected profile instance could not be created
See Also:
ConnectionContext.getConnectedProfile(Object)

close

public void close()
           throws java.sql.SQLException
closes the context, its underlying connection and connected profiles.
Specified by:
close in interface ConnectionContext
Throws:
java.sql.SQLException - if an error occurs while closing
See Also:
ConnectionContext.close()

isClosed

public boolean isClosed()
Returns true if this context has been closed, false otherwise.
Specified by:
isClosed in interface ConnectionContext
See Also:
ConnectionContext.isClosed()

getConnection

public java.sql.Connection getConnection()
Returns the underlying connection for this connection context.
Specified by:
getConnection in interface ConnectionContext
See Also:
ConnectionContext.getConnection()

close

public void close(boolean closeConnection)
           throws java.sql.SQLException
Releases all resources used in maintaining database state on this context.

Note: A context is automatically closed when it is garbage collected. A context closed in such a way does not close the underlying JDBC connection since it will also be automatically closed when it is garbage collected.

Specified by:
close in interface ConnectionContext
Parameters:
closeConnection - is true if the underlying Connection should also be closed.
Throws:
java.sql.SQLException - if unable to close the context
See Also:
ConnectionContext.close(boolean)

getExecutionContext

public ExecutionContext getExecutionContext()
Returns the default execution context used by this connection context. The default execution context is the execution context used if no explicit context is supplied during the execution of a particular sql operation.
Specified by:
getExecutionContext in interface ConnectionContext
Returns:
the default excution context

loadProps

public static java.util.Properties loadProps(java.lang.Class loadCtx,
                                             java.lang.String propName)
Read a properties file. If the propertyFile starts with "/", then it is used as is, otherwise we look in a path relative to the package of the class.
Throws:
java.sql.SQLException - if no appropriate properties file could be found.

loadTypeMap

public static java.util.Hashtable loadTypeMap(java.lang.Class loadCtx,
                                              java.lang.String propList)
Utility function to load the type map into a hastable.
Parameters:
loadCtx - class that describes the loading context for the type map
propList - string that designates the name of the resource containing the type map

finalize

protected void finalize()
                 throws java.lang.Throwable
Calls the finalize method of the super and closes this context if it has not already been closed. The underlying connection is not closed.
Throws:
java.lang.Throwable - if an error occurs during finalization
Overrides:
finalize in class java.lang.Object