sqlj.runtime.ConnectionContext interface
The sqlj.runtime.ConnectionContext interface provides a set of methods that manage SQL operations that are performed during a session with a specific data source.
Translation of an SQLJ connection declaration clause causes SQLJ to create a connection context class. A connection context object maintains a JDBC Connection object on which dynamic SQL operations can be performed. A connection context object also maintains a default ExecutionContext object.
Variables
- CLOSE_CONNECTION
- Format:
public static final boolean CLOSE_CONNECTION=true;
A constant that can be passed to the close method. It indicates that the underlying JDBC Connection object should be closed.
- KEEP_CONNECTION
- Format:
public static final boolean KEEP_CONNECTION=false;
A constant that can be passed to the close method. It indicates that the underlying JDBC Connection object should not be closed.
Methods
- close()
- Format:
public abstract void close() throws SQLException
Performs the following functions:
- Releases all resources that are used by the given connection context object
- Closes any open ConnectedProfile objects
- Closes the underlying JDBC Connection object
close() is equivalent to close(CLOSE_CONNECTION).
- close(boolean)
- Format:
public abstract void close (boolean close-connection) throws SQLException
Performs the following functions:- Releases all resources that are used by the given connection context object
- Closes any open ConnectedProfile objects
- Closes the underlying JDBC Connection object, depending on the value of the close-connection parameter
Parameters:
- close-connection
- Specifies whether the underlying JDBC Connection object is closed when a connection context object is closed:
- CLOSE_CONNECTION
- Closes the underlying JDBC Connection object.
- KEEP_CONNECTION
- Does not close the underlying JDBC Connection object.
- getConnectedProfile
- Format:
public abstract ConnectedProfile getConnectedProfile(Object profileKey) throws SQLException
This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.
- getConnection
- Format:
public abstract Connection getConnection()
Returns the underlying JDBC Connection object for the given connection context object.
- getExecutionContext
- Format:
public abstract ExecutionContext getExecutionContext()
Returns the default ExecutionContext object that is associated with the given connection context object.
- isClosed
- Format:
public abstract boolean isClosed()
Returns
true
if the given connection context object has been closed. Returnsfalse
if the connection context object has not been closed.
Constructors
The following constructors are defined in a concrete implementation of the ConnectionContext interface that results from translation of the statement #sql context Ctx;
:
- Ctx(String, boolean)
- Format:
public Ctx(String url, boolean autocommit) throws SQLException
Parameters:
- url
- The representation of a data source, as specified in the JDBC getConnection method.
- autocommit
- Whether autocommit is enabled for the connection. A value of
true
means that autocommit is enabled. A value offalse
means that autocommit is disabled.
- Ctx(String, String, String, boolean)
- Format:
public Ctx(String url, String user, String password, boolean autocommit) throws SQLException
Parameters:
- url
- The representation of a data source, as specified in the JDBC getConnection method.
- user
- The user ID under which the connection to the data source is made.
- password
- The password for the user ID under which the connection to the data source is made.
- autocommit
- Whether autocommit is enabled for the connection. A value of
true
means that autocommit is enabled. A value offalse
means that autocommit is disabled.
- Ctx(String, Properties, boolean)
- Format:
public Ctx(String url, Properties info, boolean autocommit) throws SQLException
Parameters:
- url
- The representation of a data source, as specified in the JDBC getConnection method.
- info
- An object that contains a set of driver properties for the connection. Any of the IBM® Data Server Driver for JDBC and SQLJ properties can be specified.
- autocommit
- Whether autocommit is enabled for the connection. A value of
true
means that autocommit is enabled. A value offalse
means that autocommit is disabled.
- Ctx(Connection)
- Format:
public Ctx(java.sql.Connection JDBC-connection-object) throws SQLException
Parameters:
- JDBC-connection-object
- A previously created JDBC Connection object.
If the constructor call throws an SQLException, the JDBC Connection object remains open.
- Ctx(ConnectionContext)
- Format:
public Ctx(sqlj.runtime.ConnectionContext SQLJ-connection-context-object) throws SQLException
Parameters:
- SQLJ-connection-context-object
- A previously created SQLJ ConnectionContext object.
The following constructors are defined in a concrete implementation of the ConnectionContext interface that results from translation of the statement #sql context Ctx with (dataSource ="jdbc/TestDS");
:
- Ctx()
- Format:
public Ctx() throws SQLException
- Ctx(String, String)
- Format:
public Ctx(String user, String password, ) throws SQLException
Parameters:
- user
- The user ID under which the connection to the data source is made.
- password
- The password for the user ID under which the connection to the data source is made.
- Ctx(Connection)
- Format:
public Ctx(java.sql.Connection JDBC-connection-object) throws SQLException
Parameters:
- JDBC-connection-object
- A previously created JDBC Connection object.
If the constructor call throws an SQLException, the JDBC Connection object remains open.
- Ctx(ConnectionContext)
- Format:
public Ctx(sqlj.runtime.ConnectionContext SQLJ-connection-context-object) throws SQLException
Parameters:
- SQLJ-connection-context-object
- A previously created SQLJ ConnectionContext object.
Additional methods
The following additional methods are generated in a concrete implementation of the ConnectionContext interface that results from translation of the statement #sql context Ctx;
:
- getDefaultContext
- Format:
public static Ctx getDefaultContext()
Returns the default connection context object for the Ctx class.
- getProfileKey
- Format:
public static Object getProfileKey(sqlj.runtime.profile.Loader loader, String profileName) throws SQLException
This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.
- getProfile
- Format:
public static sqlj.runtime.profile.Profile getProfile(Object key)
This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.
- getTypeMap
- Format:
public static java.util.Map getTypeMap()
Returns an instance of a class that implements java.util.Map, which is the user-defined type map that is associated with the ConnectionContext. If there is no associated type map, Java™ null is returned.
This method is used by code that is generated by the SQLJ translator for executable clauses and iterator declaration clauses, but it can also be invoked in an SQLJ application for direct use in JDBC statements.
- SetDefaultContext
- Format:
public static void Ctx setDefaultContext(Ctx default-context)
Sets the default connection context object for the Ctx class.
Recommendation: Do not use this method for multithreaded applications. Instead, use explicit contexts.