sqlj.runtime.ref
Class DefaultContext

java.lang.Object
  |
  +--sqlj.runtime.ref.ConnectionContextImpl
        |
        +--sqlj.runtime.ref.DefaultContext

public class DefaultContext
extends ConnectionContextImpl
implements ConnectionContext

The default context class provides a complete default implementation of a connection context. This is the same class definition that would have been generated by the reference translator for the clause: #sql public context DefaultContext; The reference implementation defaults to this class when no connection context instance variable exists in an executable sql clause and no other default class name was provided to the translator.


Constructor Summary
DefaultContext(java.sql.Connection conn)
          Creates a new default context instance which uses the passed connection as its underlying connection.
DefaultContext(ConnectionContext other)
          Creates a new default context instance which uses the same underlying connection as the passed connection context instance.
DefaultContext(java.lang.String url, boolean autoCommit)
          Creates a new default context instance whose underlying connection is created based on the passed url.
DefaultContext(java.lang.String url, java.util.Properties info, boolean autoCommit)
          Creates a new default context instance whose underlying connection is created based on the passed url, and properties information.
DefaultContext(java.lang.String url, java.lang.String user, java.lang.String password, boolean autoCommit)
          Creates a new default context instance whose underlying connection is created based on the passed url, user and password.
 
Method Summary
static DefaultContext getDefaultContext()
          Returns the default context instance associated with this context class.
static sqlj.runtime.profile.Profile getProfile(java.lang.Object profileKey)
          Returns a top-level profile associated with profile key returned by an earlier call to getProfileKey in this context class.
static java.lang.Object getProfileKey(sqlj.runtime.profile.Loader loader, java.lang.String profileName)
          Returns a key associated with the profile having the given name.
 java.util.Map getTypeMap()
          Returns the type map on this connection context type.
static void setDefaultContext(DefaultContext ctx)
          Sets the default connection context to be used for this class.
 
Methods inherited from class sqlj.runtime.ref.ConnectionContextImpl
close, close, finalize, getConnectedProfile, getConnection, getExecutionContext, isClosed, loadProps, loadTypeMap
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContext

public DefaultContext(java.sql.Connection conn)
               throws java.sql.SQLException
Creates a new default context instance which uses the passed connection as its underlying connection. The auto commit mode of the connection is used unchanged.

Note that the passed connection will not be closed if a call to this constructor results in an exception

Parameters:
conn - the underlying connection for this context instance.
Throws:
java.sql.SQLException - if an instance could not be constructed

DefaultContext

public DefaultContext(java.lang.String url,
                      java.lang.String user,
                      java.lang.String password,
                      boolean autoCommit)
               throws java.sql.SQLException
Creates a new default context instance whose underlying connection is created based on the passed url, user and password.

Note that if an exception occurs during construction, the underlying connection created during this call will be automatically closed.

Parameters:
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)

DefaultContext

public DefaultContext(java.lang.String url,
                      java.util.Properties info,
                      boolean autoCommit)
               throws java.sql.SQLException
Creates a new default context instance whose underlying connection is created based on the passed url, and properties information.

Note that if an exception occurs during construction, the underlying connection created during this call will be automatically closed.

Parameters:
url - the database url
info - a list of properties for the connection
autoCommit - true if the connection should be created in auto-commit mode, false otherwise
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,java.util.Properties), Connection.setAutoCommit(boolean)

DefaultContext

public DefaultContext(java.lang.String url,
                      boolean autoCommit)
               throws java.sql.SQLException
Creates a new default context instance whose underlying connection is created based on the passed url.

Note that if an exception occurs during construction, the underlying connection created during this call will be automatically closed.

Parameters:
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)

DefaultContext

public DefaultContext(ConnectionContext other)
               throws java.sql.SQLException
Creates a new default context instance which uses the same underlying connection as the passed connection context instance. The auto commit mode of the shared connection is used unchanged.

Note that the passed other ConnectionContext (and its underlying connection) will not be closed if a call to this constructor results in an exception.

Parameters:
other - the context with which to share an underlying connection.
Throws:
java.sql.SQLException - if an instance could not be constructed
See Also:
DefaultContext(Connection), ConnectionContext.getConnection()
Method Detail

getProfileKey

public static java.lang.Object getProfileKey(sqlj.runtime.profile.Loader loader,
                                             java.lang.String profileName)
                                      throws java.sql.SQLException
Returns a key associated with the profile having the given name. If the key for a profile with this name already exists, it is returned. Otherwise, a new profile is registered with the given name and loader and a new key for this profile is returned. An exception is raised a profile cannot be loaded with the given name and loader.
Parameters:
loader - the profile loader from which the profile should be loaded if it doesn't already exist.
profileName - the fully qualified name of the profile.
Returns:
a key for the profile with the given name in this context.
Throws:
java.sql.SQLException - if a profile with this name cannot be loaded.
See Also:
getProfile(Object), ConnectionContext.getConnectedProfile(Object)

getProfile

public static sqlj.runtime.profile.Profile getProfile(java.lang.Object profileKey)
Returns a top-level profile associated with profile key returned by an earlier call to getProfileKey in this context class. Each connection context class maintains a set of profiles that collectively define all possible sql operations that may be performed on this context.
Parameters:
profileKey - the key asscoiated with the desired profile.
Throws:
java.lang.IllegalArgumentException - if the profileKey is null or invalid.
See Also:
getProfileKey(sqlj.runtime.profile.Loader, java.lang.String)

getDefaultContext

public static DefaultContext getDefaultContext()
Returns the default context instance associated with this context class. If a default context has been explicitely installed via a call to setDefaultContext, that context is returned. Otherwise, if a default JDBC connection exists in the current runtime context, a new default context object is created, installed and returned which uses the default JDBC connection as its underlying connection. If no default connection exists in the runtime, null is returned.
See Also:
setDefaultContext(sqlj.runtime.ref.DefaultContext), RuntimeContext.getDefaultConnection()

setDefaultContext

public static void setDefaultContext(DefaultContext ctx)
Sets the default connection context to be used for this class. Any previous default context is replaced.
Parameters:
ctx - the new default context instance.

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Returns the type map on this connection context type. The DefaultContext always returns null.
Specified by:
getTypeMap in interface ConnectionContext