Object Translator

com.informix.ormapper
Class OConnection

java.lang.Object
  |
  +--com.informix.ormapper.OConnection

public class OConnection
extends java.lang.Object

External: This class represents a database connection. When an Object Translator-generated object is instantiated, an OConnection object must be assigned to it before it can be used. The OConnection object can be constructed from a standard JDBC connection URL or directly from a JDBC Connection object. Internally this class wraps around the JDBC connection with some default behaviors for ease of use.


Field Summary
static int DETECT_CHANGEDROW
          Indicates using changed row indicator for optimistic concurrency change detection.
static int DETECT_NONE
          Indicates no change detection for optimistic concurrency.
static int DETECT_QUERIED
          Indicates using all queried attributes for optimistic concurrency change detection.
static int DETECT_UPDATED
          Indicates using all updated attributes for optimistic concurrency change detection.
static int OPTIMISTIC
          Indicates optimistic concurrency locking.
static int PESSIMISTIC
          Indicates pessimistic concurrency locking.
 
Constructor Summary
OConnection(java.sql.Connection conn)
          Constructs a connection object by reusing an existing JDBC connection.
OConnection(java.lang.String url, java.lang.String driverName)
          Constructs a connection object, loads the given driver, and establishes a connection to the given database URL.
OConnection(java.lang.String url, java.lang.String driverName, java.lang.String userName, java.lang.String password)
          Constructs a connection object from a database URL, a driver name, a user name and a password.
 
Method Summary
 void close()
          Releases the connection's database and JDBC resources immediately instead of waiting for them to be automatically released.
 void commit()
          Makes all changes since the previous commit/rollback permanent and releases any database locks currently held by the connection.
 boolean getAutoCommit()
          Gets the current auto-commit state.
 int getDetectType()
          Gets the optimistic concurrency detect type for the connection.
 java.sql.Connection getJdbcConnection()
          Returns the JDBC connection object.
 java.util.Locale getLocale()
          Gets the current locale for the Object Translator runtime.
 int getLockType()
          Gets the concurrency locking type of this connection.
 java.util.Map getTypeMap()
          Gets the custom type map for this connection.
 boolean isClosed()
          Tests to see if the connection is closed.
 boolean isReadOnly()
          Tests to see if the connection is in read-only mode.
 void rollback()
          Drops all changes made since the previous commit/rollback and releases any database locks currently held by the connection.
 void setAutoCommit(boolean autoCommit)
          Sets this connection's auto-commit mode.
 void setDetectType(int type)
          Sets the optimistic concurrency detect type for the connection.
 void setLocale(java.util.Locale locale)
          Sets the current locale for the Object Translator runtime.
 void setLockType(int _lockType)
          Sets the concurrency locking for this connection to OPTIMISTIC, or PESSIMISTIC.
 void setReadOnly(boolean readOnly)
          Sets this connection to read-only mode as a hint to enable database optimizations.
Note: This method cannot be called while in the middle of a transaction.
 void setTypeMap(java.util.Map map)
          Sets a custom type map for this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTIMISTIC

public static final int OPTIMISTIC
Indicates optimistic concurrency locking. Transaction isolation level of the connection is java.sql.Connection.TRANSACTION_READ_COMMITTED. This is the default.

PESSIMISTIC

public static final int PESSIMISTIC
Indicates pessimistic concurrency locking. Depending on the database server support, transaction isolation level of the connection is java.sql.Connection.TRANSACTION_SERIALIZABLE, or TRANSACTION_REPEATABLE_READ.

DETECT_NONE

public static final int DETECT_NONE
Indicates no change detection for optimistic concurrency. This is the default.

DETECT_CHANGEDROW

public static final int DETECT_CHANGEDROW
Indicates using changed row indicator for optimistic concurrency change detection.

DETECT_UPDATED

public static final int DETECT_UPDATED
Indicates using all updated attributes for optimistic concurrency change detection.

DETECT_QUERIED

public static final int DETECT_QUERIED
Indicates using all queried attributes for optimistic concurrency change detection.
Constructor Detail

OConnection

public OConnection(java.sql.Connection conn)
            throws DatabaseException
Constructs a connection object by reusing an existing JDBC connection.
Parameters:
conn - an existing JDBC connection.
Throws:
DatabaseException - if conn is null or closed.

OConnection

public OConnection(java.lang.String url,
                   java.lang.String driverName)
            throws DatabaseException,
                   NoDriverException
Constructs a connection object, loads the given driver, and establishes a connection to the given database URL.
Parameters:
url - a database url of the form jdbc:subprotocol:subname.
driverName - the class name of the database driver to be loaded. If null, the default is com.informix.jdbc.IfxDriver.
Throws:
DatabaseException - if the connection cannot be established.
NoDriverException - if the driver cannot be loaded.

OConnection

public OConnection(java.lang.String url,
                   java.lang.String driverName,
                   java.lang.String userName,
                   java.lang.String password)
            throws DatabaseException,
                   NoDriverException
Constructs a connection object from a database URL, a driver name, a user name and a password.
Parameters:
url - a database url of the form jdbc:subprotocol:subname.
driverName - the class name of the database driver to be loaded. If null, the default is com.informix.jdbc.IfxDriver.
userName - the database user on whose behalf the connection is being made; can be null.
password - the password associated with userName; can be null.
Throws:
DatabaseException - if the connection cannot be established.
NoDriverException - if the driver cannot be loaded.
Method Detail

getJdbcConnection

public java.sql.Connection getJdbcConnection()
Returns the JDBC connection object.
Returns:
the internal JDBC Connection.

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws DatabaseException
Sets this connection to read-only mode as a hint to enable database optimizations.
Note: This method cannot be called while in the middle of a transaction.
Parameters:
readOnly - true enables read-only mode; false disables read-only mode.
Throws:
DatabaseException - if a database access error occurs.

isReadOnly

public boolean isReadOnly()
                   throws DatabaseException
Tests to see if the connection is in read-only mode.
Returns:
true if connection is read-only.
Throws:
DatabaseException - if a database access error occurs.

getLocale

public java.util.Locale getLocale()
Gets the current locale for the Object Translator runtime.
Returns:
current locale

setLocale

public void setLocale(java.util.Locale locale)
Sets the current locale for the Object Translator runtime. This does not affect the CLIENT_LOCALE and DB_LOCALE setting for Informix database connection. They need to be set in the connection URL or properties, if desired.
Parameters:
locale - the new locale

getLockType

public int getLockType()
Gets the concurrency locking type of this connection.
Returns:
OPTIMISTIC, or PESSIMISTIC.

setLockType

public void setLockType(int _lockType)
                 throws DatabaseException
Sets the concurrency locking for this connection to OPTIMISTIC, or PESSIMISTIC. If PESSIMISTIC, transaction isolation level of the connection will be set to java.sql.Connection.TRANSACTION_SERIALIZABLE, or TRANSACTION_REPEATABLE_READ, depending on the highest level of support available from the database server.
Note: This method cannot be called while in the middle of a transaction.
Parameters:
_lockType - OPTIMISTIC, or PESSIMISTIC.

getDetectType

public int getDetectType()
Gets the optimistic concurrency detect type for the connection.
Returns:
DETECT_NONE, DETECT_CHANGEDROW, DETECT_UPDATED, or DETECT_QUERIED

setDetectType

public void setDetectType(int type)
Sets the optimistic concurrency detect type for the connection.
Parameters:
type - DETECT_NONE, DETECT_CHANGEDROW, DETECT_UPDATED, or DETECT_QUERIED

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws DatabaseException
Sets this connection's auto-commit mode. If a connection is in auto-commit mode, then all its SQL statements are executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode. The commit occurs when the statement completes or the next execute occurs, whichever comes first. In the case of statements returning a ResultSet, the statement completes when the last row of the ResultSet has been retrieved or the ResultSet has been closed.
Parameters:
autoCommit - true enables auto-commit; false disables auto-commit.
Throws:
DatabaseException - if a database access error occurs.

getAutoCommit

public boolean getAutoCommit()
                      throws DatabaseException
Gets the current auto-commit state.
Returns:
the current state of auto-commit mode.
Throws:
DatabaseException - if a database access error occurs.
See Also:
setAutoCommit(boolean)

commit

public void commit()
            throws DatabaseException
Makes all changes since the previous commit/rollback permanent and releases any database locks currently held by the connection. This method can be called only when auto-commit mode is disabled.
Throws:
DatabaseException - if a database access error occurs.
See Also:
setAutoCommit(boolean)

rollback

public void rollback()
              throws DatabaseException
Drops all changes made since the previous commit/rollback and releases any database locks currently held by the connection. TThis method can be called only when auto-commit mode is disabled.
Throws:
DatabaseException - if a database access error occurs.
See Also:
setAutoCommit(boolean)

close

public void close()
           throws DatabaseException
Releases the connection's database and JDBC resources immediately instead of waiting for them to be automatically released.
Throws:
DatabaseException - if a database access error occurs.

isClosed

public boolean isClosed()
                 throws DatabaseException
Tests to see if the connection is closed.
Returns:
true if the connection is closed; false if it is still open.
Throws:
DatabaseException - if a database access error occurs.

setTypeMap

public void setTypeMap(java.util.Map map)
                throws DatabaseException
Sets a custom type map for this connection. The type map will be used for custom mapping of opaque type support.
Parameters:
map - the custom type map.
Throws:
DatabaseException - if a database access error occurs.

getTypeMap

public java.util.Map getTypeMap()
                         throws DatabaseException
Gets the custom type map for this connection.
Returns:
the custom type map.
Throws:
DatabaseException - if a database access error occurs.

Object Translator

Copyright © 1999-2000 Informix Software, Inc.