Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 2 (11.1.2.0.0)

E17483-01

oracle.jbo.server
Class DBTransactionImpl

java.lang.Object
  extended by oracle.jbo.server.DBTransactionImpl
All Implemented Interfaces:
ExprWrappable, PCollManagerHelper, JboTransAttrValidationManager, JboTransValidationManager, DBTransaction, ValidationManager, Transaction
Direct Known Subclasses:
DBTransactionImpl2

public class DBTransactionImpl
extends java.lang.Object
implements DBTransaction, PCollManagerHelper, JboTransValidationManager, JboTransAttrValidationManager

The superclass of classes representing connections of middle-tier objects to databases.

Instances encapsulate the JDBC connection, provide commit() and rollback() operations, and maintain various internal framework states, events and caches of entity data.

Advanced applications can provide custom subclass implementations using DatabaseTransactionFactory.

From 9.0.3 onwards, this class is no longer used to represent a connected transaction. The connected state, by default, is now represented by DBTransactionImpl2. Applications using custom DBTransactionImpl and/or NullDBTransactionImpl subclass(es) should now subclass DBTransactionImpl2 instead.

Applications requiring backward compatibility must set the jbo.server.useNullDbTransaction property to true in appmodule configuration, initial context environment or as a System property to continue using this class as the default implementation for representing connected DBTransaction.

Using Anonymous View Objects

The DBTransactionImpl class has these methods for creating View Objects:

In contrast to the "create View Object" methods on the ApplicationModuleImpl class, the methods on DBTransaction do not take a String voNname parameter. These methods create anonymous View Objects on the database transaction. Anonymous View Objects do not require an Application Module. An anonymous View Object is a View Object to which you do not give a name and that is usually used locally. For example, you could use an anonymous View Object when you want to perform a query (for example, a look-up) through a View Object, then remove it.

Anonymous View Objects should not be passed around between Application Modules. As soon as the anonymous View Object has performed its task, it should be discarded with the View Object remove() method.

Using anonymous View Objects also lets you avoid name clashes between View Objects. For example, if one Entity Object developer builds some code that is expecting to create a View Object in its own Application Module with a name like "temp" and another unrelated Entity Object developer builds some code that is expecting to work with a View Object in its own Application Module named "temp" (but which is for a totally different View Object), then if an application required both of these Application Modules to works as peers, name clashes could result.

The method getDBTransaction().createViewObject() creates a View Object from a definition created at design time which can be based on Entity Objects just like the ones you might have been creating with the createViewObject from the ApplicationModule class.

The DBTransactionImpl class also has createViewObjectFromQueryStmt and createViewObjectFromQueryClauses just like the Application Module class does; all of the same functionality is available to the Entity Object business logic writer.

The only difference is that the DBTransactionImpl class approach forces the Entity Object business logic writer to not pre-select an "instance" name for the View Object being used (the equivalent of calling the Application Module-level methods with a null instance name argument) so that the system ensures the "instance" names are unique and no unintended clashes occur.

To illustrate the differences between using the create View Object methods on the Application Module class versus the DBTransaction class, consider the following code snippets. Assume you have a method called doSomething() on an Entity Object to implement some operation. Two possible implementations are:

  // Implementation 1
 public void doSomething() {
     DBTransaction txn = this.getDBTransaction();
     ViewObject vo1 =
 txn.createViewObject("myPackage.MyFirstViewObject");
     ViewObject vo2 =
 txn.createViewObject("myPackage.MySecondViewObject");

     // Do something here...

     vo1.remove();
     vo2.remove();
 }

 // Implementation 2
 public void doSomething() {
     DBTransaction txn = this.getDBTransaction();
     MyApplicationModule am =
 txn.createApplicationModule("myPackage.MyAppModule");
     ViewObject vo1 = am.getMyFirstViewObject();
     ViewObject vo2 = am.getMySecondViewObject();

     // Do the same something here...

     am.remove();
 }
 
The following lists compare the advantages and disadvangages of each implementation.

Implementation 1:

Implementation 2:

Generally, the motivation for separating code out into an Application Module would be the same as the general motivation for separating code out into a different a class.

In that sense, you may choose to take your example one step further and move the "Do Something Here" code into the Application Module class:

 // Implementation 3
 public void doSomething() {
     DBTransaction txn = this.getDBTransaction();
     MyApplicationModule am = (MyApplicationModule)
 txn.createApplicationModule("myPackage.MyAppModule");
     am.doSomethingThere(...);
     am.remove();
 }
  
Implementations 1 and 2 are both correct approaches. Creating a nested Application Module is good for multi-View Object data models, and DbTransaction is good for simple one-off queries. If your application is using one-off queries most of the time, you might find that the extra overhead of creating an Application Module "container" might not add sufficient value.

Since:
JDevloper 3.0

Field Summary
static int MAX_CURSORS_UNINITIALIZED
           
protected  ConnectionCredentials mConnectionCredentials
           
protected  int mDMLOperationTimeOut
           
protected  ConnectionCredentials mInternalCredentials
           
protected  java.util.List mLongRunningDMLOperationHandles
           
protected  SQLBuilder mSQLBuilder
          The SQLBuilder instance used to interact with JDBC in this transaction.
protected  java.util.ArrayList mTxnListeners
           
static int POST_ABORT_ON_FIRST_EXCEPTION
           
static int POST_ALL_NO_RESET_ON_EXCEPTION
           
static int POST_ALL_RESET_ON_EXCEPTION
           
 
Fields inherited from interface oracle.jbo.server.DBTransaction
DEFAULT
 
Fields inherited from interface oracle.jbo.Transaction
DML_OPERATION_TIMEOUT_WAIT_FOREVER, LOCK_NONE, LOCK_OPTIMISTIC, LOCK_OPTUPDATE, LOCK_PESSIMISTIC
 
Constructor Summary
DBTransactionImpl(java.sql.Connection connection)
          Creates an instance from an existing JDBC connection.
DBTransactionImpl(javax.sql.DataSource ds)
           
DBTransactionImpl(javax.sql.DataSource ds, java.lang.String user, java.lang.String passwd)
           
DBTransactionImpl(java.lang.String url)
          Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.
DBTransactionImpl(java.lang.String url, java.util.Properties info)
          Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.
DBTransactionImpl(java.lang.String url, java.lang.String user, java.lang.String password)
          Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.
DBTransactionImpl(java.lang.String url, java.lang.String user, java.lang.String password, java.util.Properties info)
          Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.
 
Method Summary
 void addLongRunningDMLOperationHandle(LongRunningStatementHandle handle)
           
 void addToValidationListeners(ValidationListener entity)
          Adds an entity validation listener.
 void addTransactionListener(TransactionListener listener)
          Adds a listener to the transaction's list.
 void addTransactionListenerNoCheck(TransactionListener listener)
          Internal: Applications should not call this method.
 void addTransactionPostListener(TransactionPostListener listener)
          Adds a subscriber to the transaction's post-events list.
 void addTransactionPostListenerNoCheck(TransactionPostListener listener)
          Internal: Applications should not use this method.
 void addTransactionStateListener(TransactionStateListener target)
          Add this TransactionListener to the list and notify all such listeners whenever commit and rollback occurs in this transaction.
 void addViewClearCacheListener(ViewClearCacheListener target)
           
 void addWarning(JboWarning warn)
          Adds a warning to the root Application Module warning stack.
 void applyChangeSet(int id)
          Applies the changes committed by another transaction in order to synchronize caches between root Application Module instances.
 boolean cancelDMLOperations()
          Cancels the currently running Entity Object DML operations.
protected  void checkConnected()
           
 void clearEntityCache(java.lang.String entityName)
          Clears the cache of the specified Entity Object.
 void closeTransaction()
          Internal: Applications should not use this method.
 void commit()
          Commits all changes in this transaction to the database, making them visible to other users and transactions.
 int commitAndSaveChangeSet()
          Commits the transaction and writes updated EntityImpls to the persistent store.
 void connect(java.sql.Connection sqlConnection)
          Deprecated.  
 void connect(java.lang.String url)
          Uses this JDBC Connection object to connect to the database for all operations via this transaction.
 void connect(java.lang.String url, java.util.Properties info)
          Internal: Applications should not use this method.
 void connect(java.lang.String url, java.lang.String user, java.lang.String password)
          Internal: Applications should not use this method.
 void connectToDataSource(javax.sql.DataSource ds, boolean isJTAbased)
           
 void connectToDataSource(javax.sql.DataSource ds, java.lang.String user, java.lang.String passwd, boolean isJTAbased)
           
 void connectToDataSource(java.util.Hashtable env, java.lang.String dsName, boolean isJTABased)
          Looks up a datasource from a jndi tree and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String passwd) method.
 void connectToDataSource(java.util.Hashtable env, java.lang.String dsName, java.lang.String user, java.lang.String passwd, boolean isJTABased)
          Looks up a datasource from a jndi tree and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String passwd) method.
 void connectToDataSource(java.lang.String nsUrl, java.lang.String nsUser, java.lang.String nsPasswd, java.lang.String dsUrl)
          Looks up a datasource from Oracle 8i namespace using the jdbc_access protocol and acquires the default jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection() method.
 void connectToDataSource(java.lang.String nsUrl, java.lang.String nsUser, java.lang.String nsPasswd, java.lang.String dsUrl, java.lang.String user, java.lang.String passwd)
          Looks up a datasource from Oracle 8i namespace using the jdbc_access protocol and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String password) method.
 ApplicationModule createApplicationModule(java.lang.String defName)
          Creates an anonymous Application Module.
 ApplicationModule createApplicationModule(java.lang.String amName, java.lang.String defName)
          Creates an instance of an nested Application Module within this Transaction For example,
 java.sql.CallableStatement createCallableStatement(java.lang.String str, int noRowsPrefetch)
          Creates a JDBC CallableStatement instance.
 EntityImpl createEntityInstance(EntityDefImpl entityDef, AttributeList al)
          Creates an EntityImpl object based on the given defintion, in the context of the root Application Module.
 EntityImpl createEntityInstance(java.lang.String entityDefName, AttributeList al)
          Creates an EntityImpl object based on the given defintion, in the context of the root Application Module.
 java.sql.PreparedStatement createPreparedStatement(java.lang.String str, int noRowsPrefetch)
          Creates a JDBC PreparedStatement instance.
 java.lang.Object createRef(java.lang.String structName, byte[] data)
          Internal: Applications should not use this method.
 java.sql.Statement createStatement(int noRowsPrefetch)
          Creates a JDBC Statement instance.
 ViewLink createViewLink(java.lang.String viewLinkDefName, ViewObject master, ViewObject detail)
          Creates an anonymous View Link.
 ViewLink createViewLinkBetweenViewObjects(java.lang.String accessorName, ViewObject master, AttributeDef[] srcAttrs, ViewObject detail, AttributeDef[] destAttrs, java.lang.String assocClause)
          Creates an anonymous View Link.
 ViewLink createViewLinkFromEntityAssocName(java.lang.String entityAssocName, ViewObject master, ViewObject detail)
          Creates a View Link.
 ViewObject createViewObject(java.lang.String voDefName)
          Creates an anonymous query definition from the name of a ViewObject class.
 ViewObject createViewObjectFromQueryClauses(java.lang.String eoName, java.lang.String selectClause, java.lang.String fromClause, java.lang.String whereClause, java.lang.String orderByClause)
          Creates an updatable query definition.
 ViewObject createViewObjectFromQueryStmt(java.lang.String sqlStatement)
          Creates an anonymous query definition from an SQL statement.
 ViewObject createViewObjectFromQueryStmt(java.lang.String sqlStatement, java.lang.String voImplClassName)
          Creates an anonymous query definition from an SQL statement.
static java.lang.String diagCleanURL(java.lang.String url)
           
 void disconnect()
          Closes the JDBC connection object and removes this transaction from the root application module.
 void disconnect(boolean retainState)
          Closes the JDBC connection object.
 void doAfterCommit()
           
 void doBeforeCommit()
           
protected  void doCommit()
          Called by the commit method to issue the commit call.
protected  void doRollback()
          Called by the rollback method to issue the rollback call.
 void doValidatePostChanges()
          invoke validate() and postChanges() iteratively based on validateThreshold and postThreshold setting.
 void dumpEntityCaches(java.io.Writer out)
          Iterates over the currently populated caches of entities, and write a representation of them to a charater stream.
 java.lang.String dumpQueryResult(java.lang.String query, java.lang.String dumpClassName, java.lang.String[] data)
          Writes the result of the query to a (potentially very long) string.
 int executeCommand(java.lang.String command)
          Executes a SQL command using a JDBC Statement under the current transaction.
 ApplicationModule findApplicationModule(java.lang.String amName)
          Returns the named Application Module.
 EntityImpl findByPrimaryKey(EntityDefImpl entityDef, Key key)
          Finds an Entity Object in this transaction given an EntityDef object and a Primary Key.
 EntityImpl findByPrimaryKey(java.lang.String entityDefName, Key key)
          Finds an Entity Object in this transaction given the String name of the EntityDef and a Primary Key.
 EntityCache findEntityCache(EntityDefImpl source)
          Finds a Cache table for the entity.
 ViewObject findViewObject(java.lang.String voName)
          Find a view object with the specified name.
protected  java.util.Set<ApplicationModuleImpl> getActiveApplicationModuleImpls()
           
 int getBatchPostExceptionThreshold()
          In case of batch mode post operation, try to post the batched set of entities for each entity type and post operation (Insert/Update/Delete) for this many number of exceptions.
 ConnectionMetadata getConnectionMetadata()
          Returns a metdata structure that describes the transaction's JDBC connection.
 java.sql.Timestamp getCurrentDbTime()
           
 int getDMLOperationTimeOut()
          Returns the current Entity Object DML operation time out value.
 EntityCache getEntityCache(EntityDefImpl source)
           
protected  java.sql.Connection getJdbcConnection()
          Returns the JDBC connection for this transaction.
 int getLockingMode()
          Returns the preferred locking mode for this Transaction.
 java.sql.Connection getPersistManagerConnection()
          Internal: Applications should not use this api. Returns the connection used by PersistentCollection apis.
 int getPostChangesFlag()
          Internal: Applications should not use this method.
 int getPostThreshold()
          Gets the threshold value for the commit-cycle's post phase.
 ApplicationModule getRootApplicationModule()
          Returns the root appmodule that owns this transaction.
 Session getSession()
          Gets the session information.
 SQLBuilder getSQLBuilder()
          Internal: Applications should not use this method.
 java.lang.Object getSyncLock()
           
 TransactionHandler getTransactionHandler()
          Internal: Applications should not use this method.
protected  java.util.ArrayList getTransactionListenersList()
           
protected  java.util.ArrayList getTransactionPostListenersList()
           
protected  int getTransactionState()
           
 java.util.ArrayList getTransAttrValidationList()
           
 JboTransAttrValidationManager getTransAttrValidationManager()
           
 java.util.HashMap getTransAttrValidations()
           
 java.util.ArrayList getTransValidationList()
           
 JboTransValidationManager getTransValidationManager()
           
 java.util.HashMap getTransValidations()
           
protected  ApplicationModuleImpl getTxnApplicationModuleImpl()
          Gets the root Application Module to which this transaction belongs.
protected  java.util.ArrayList getValidationListenersList()
           
 int getValidationThreshold()
          Gets the threshold value for the commit-cycle's validation phase.
protected  boolean hasRollbackSavePoint()
           
 boolean isBundledExceptionMode()
           
 boolean isClearCacheOnCommit()
          Returns the flag indicating whether all Entity Object caches will be cleared after the transaction is committed.
 boolean isClearCacheOnRollback()
          Returns the flag indicating whether all Entity Object caches will be cleared after the transaction is rolled back.
 boolean isConnected()
          Checks if the transaction is connected to the database.
 boolean isConnected(boolean pingDatabase)
           
 boolean isDirty()
          This method is typically called before an attempt is made to post the data.
 boolean isForceDeferValidation()
           
 boolean isLockOptimistic()
          Returns true if the lock mode for this transaction is optimistic.
 boolean isTrackNewAndModifiedRowsOnly()
          Deprecated. since 9.0.5.1
 EntityCache lookupEntityCache(EntityDefImpl source)
           
 void postChanges()
          Synchronizes the changes in the middle-tier transaction-cache with the database.
protected  void postChanges(TransactionEvent te)
          Internal: Applications should not use this method.
 void putTransAttrValEntry(JboTransValidatorInterface validator, JboValidatorContext valCtx)
           
 void putTransValEntry(JboTransValidatorInterface validator, JboValidatorContext valCtx)
           
 void reconnect()
          Reconnect the ApplicationModule to the database, using previously supplied database credentials.
 void reconnect(boolean force)
          Reconnect the Application Module to the database, if necessary, using previously supplied database credentials.
 void removeChangeSet(int id)
          Removes the change set that defines the changes to EntityImpls within a transaction.
 void removeEntityCache(EntityDefImpl source)
           
 void removeEntityCacheByName(java.lang.String name)
           
 void removeLongRunningDMLOperationHandle(LongRunningStatementHandle handle)
           
 void removeTransactionListener(TransactionListener listener)
          Removes a subscriber from the transaction's events list.
 void removeTransactionPostListener(TransactionPostListener listener)
          Removes a subscriber from the transaction's post-events list.
 void removeTransactionStateListener(TransactionStateListener target)
          Remove this transaction listener (if it exists) from this transaction.
 void removeViewClearCacheListener(ViewClearCacheListener target)
           
 void rollback()
          Discards all modifications made in this transaction.
 void setBatchModeForEntity(EntityDefImpl def, boolean mode)
          Sets the updatebatching (Batch post operations) mode on or off for a given entity type in this transaction.
 void setBatchPostExceptionThreshold(int count)
          Set this value to 0 to let all the modified entities be posted for each entity type and entity-DML operation to collect possible exceptions for all such entities.
 void setBundledExceptionMode(boolean flag)
          Set this transaction into bundled exception mode.
 void setClearCacheOnCommit(boolean val)
          Sets the value of the flag indicating whether all Entity Object caches will be cleared after the transaction is committed.
 void setClearCacheOnRollback(boolean val)
          Sets the value of the flag indicating whether all Entity Object caches will be cleared after the transaction is rolled back.
 void setDMLOperationTimeOut(int timeOutMills)
          Sets the query time out value for the Entity Object's DML operations.
 void setForceDeferValidation(boolean bForceDefer)
           
 void setLockingMode(int mode)
          Sets the preferred locking mode for this Transaction.
 void setPostChangesFlag(int flag)
          The given flag modifies the behavior of postChanges method.
 void setPostThreshold(int count)
          Sets the threshold value for the commit-cycle's post phase.
 void setTrackNewAndModifiedRowsOnly(boolean flag)
          Deprecated. since 9.0.5.1. This behavior is not optional anymore.
 void setTransactionHandler(TransactionHandler txnHandler)
          Internal: Applications should not use this method.
 void setValidationThreshold(int count)
          Sets the threshold value for the commit-cycle's validation phase.
 void showCursorUsage(java.io.Writer out)
          Internal: Applications should not use this method.
 void validate()
          Starts the validation cycle and validates all subscribers in the ValidationListener list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CURSORS_UNINITIALIZED

public static final int MAX_CURSORS_UNINITIALIZED
See Also:
Constant Field Values

mSQLBuilder

protected SQLBuilder mSQLBuilder
The SQLBuilder instance used to interact with JDBC in this transaction.


mConnectionCredentials

protected ConnectionCredentials mConnectionCredentials

mInternalCredentials

protected ConnectionCredentials mInternalCredentials

mTxnListeners

protected java.util.ArrayList mTxnListeners

POST_ALL_NO_RESET_ON_EXCEPTION

public static int POST_ALL_NO_RESET_ON_EXCEPTION

POST_ALL_RESET_ON_EXCEPTION

public static int POST_ALL_RESET_ON_EXCEPTION

POST_ABORT_ON_FIRST_EXCEPTION

public static int POST_ABORT_ON_FIRST_EXCEPTION

mDMLOperationTimeOut

protected int mDMLOperationTimeOut

mLongRunningDMLOperationHandles

protected java.util.List mLongRunningDMLOperationHandles
Constructor Detail

DBTransactionImpl

public DBTransactionImpl(javax.sql.DataSource ds)

DBTransactionImpl

public DBTransactionImpl(javax.sql.DataSource ds,
                         java.lang.String user,
                         java.lang.String passwd)

DBTransactionImpl

public DBTransactionImpl(java.sql.Connection connection)
Creates an instance from an existing JDBC connection. This constructor is used when applications supply their own JDBC connection to an Application Module's transaction.

Parameters:
connection - an existing connection.

DBTransactionImpl

public DBTransactionImpl(java.lang.String url)
Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.

Attempts to establish a connection to a database through the given URL. The driver manager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database URL of the form JDBC:subprotocol:subname.
See Also:
DBTransactionImpl2

DBTransactionImpl

public DBTransactionImpl(java.lang.String url,
                         java.util.Properties info)
Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.

Attempts to establish a connection to a database through the given URL. The driver manager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database URL of the form JDBC:subprotocol:subname.
info - a list of arbitrary string tag/value pairs as connection arguments; normally at least "user" and "password" tags should be included.
See Also:
DBTransactionImpl2

DBTransactionImpl

public DBTransactionImpl(java.lang.String url,
                         java.lang.String user,
                         java.lang.String password)
Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.

Attempts to establish a connection to a database through the given URL. The driver manager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database URL of the form JDBC:subprotocol:subname.
user - the database user on whose behalf the connection is being made.
password - the user's password.
See Also:
DBTransactionImpl2

DBTransactionImpl

public DBTransactionImpl(java.lang.String url,
                         java.lang.String user,
                         java.lang.String password,
                         java.util.Properties info)
Deprecated. Since 9.0.3. This constructor is no longer called to create a connected DBTransaction instance. Instead, DBTransactionImpl2 instance, created by create(), migrates from disconnected to connected state.

Internal: Applications should not use this constructor.

Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the Connection is being made
password - the user's password
info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included
See Also:
DBTransactionImpl2
Method Detail

getSyncLock

public final java.lang.Object getSyncLock()

diagCleanURL

public static java.lang.String diagCleanURL(java.lang.String url)

isLockOptimistic

public boolean isLockOptimistic()
Returns true if the lock mode for this transaction is optimistic.

Specified by:
isLockOptimistic in interface DBTransaction
Returns:
true if the locking mode is LOCK_OPTIMISTIC or LOCK_OPTUPDATE.

getPersistManagerConnection

public java.sql.Connection getPersistManagerConnection()
Internal: Applications should not use this api. Returns the connection used by PersistentCollection apis.

Specified by:
getPersistManagerConnection in interface PCollManagerHelper

closeTransaction

public void closeTransaction()
Internal: Applications should not use this method.

Closes this transaction's JDBC connection.

Performs rollback on the current transaction to reset all the data in the cache to their initial states and then drops the JDBC connection. This method is invoked by disconnect to terminate the JDBC connection. Applications should use disconnect() instead of closeTransaction() to properly release JDBC resources.

Specified by:
closeTransaction in interface DBTransaction

setBundledExceptionMode

public void setBundledExceptionMode(boolean flag)
Description copied from interface: Transaction
Set this transaction into bundled exception mode. In this mode, all exceptions thrown during updates to rows will be cached by the entity-cache. However when the rows are validated either by explicit validation call or when the transaction is committed, these exceptions will be thrown bundled in a RowValException. When in bundledException mode, validation code in setXXX methods on the Entity will be executed and if a ValidationException is thrown from these methods, they're cached by the Entity and thrown later as a detail of RowValException when the Entity is eventually validated.

Specified by:
setBundledExceptionMode in interface Transaction

isBundledExceptionMode

public final boolean isBundledExceptionMode()
Specified by:
isBundledExceptionMode in interface Transaction

getSQLBuilder

public SQLBuilder getSQLBuilder()
Internal: Applications should not use this method.

Identifies the SQLBuilder that is used by this driver. In the runtime, the SQLBuilder that is used depends on whether the JDBC driver is Oracle-specific or non-Oracle-specific.

Specified by:
getSQLBuilder in interface DBTransaction
Returns:
the SQLBuilder used by the current JDBC driver.

isClearCacheOnCommit

public boolean isClearCacheOnCommit()
Returns the flag indicating whether all Entity Object caches will be cleared after the transaction is committed.

After the transaction is committed, the value of this flag is used to determine whether the Entity Object caches are cleared or not. If this flag value is false, the cache contents are kept. In this case, the cache may contain data that is stale in that it does not match the newest data (changes made by another user and committed).

If this flag is true, the caches are cleared after the transaction is committed. When the user brings in data by traversing row collection, the latest data from the database will be brought into Entity caches.

Specified by:
isClearCacheOnCommit in interface Transaction
Returns:
the current value of clear-cache-on-commit flag.
See Also:
RowSet.executeQuery(), setClearCacheOnCommit(boolean val), Transaction.isClearCacheOnCommit(), Transaction.setClearCacheOnCommit(boolean val)

setClearCacheOnCommit

public void setClearCacheOnCommit(boolean val)
Sets the value of the flag indicating whether all Entity Object caches will be cleared after the transaction is committed.

The initial value of this flag is retrieved from the Application Module definition of the root Application Module (an XML attribute value named "ClearCacheOnCommit" in the Application Module definition's XML file). If the Application Module definition does not contain the initial value, the default value is false, i.e., the caches are kept after commit.

The user can override the value of this flag for this Transaction by calling this method. Calling this method does not affect the initial value in the Application Module definition.

Specified by:
setClearCacheOnCommit in interface Transaction
Parameters:
val - the new value of the clear-cache-on-commit flag. true indicates that the Entity Object caches will be cleared after commit.
See Also:
isClearCacheOnCommit(), Transaction.isClearCacheOnCommit(), Transaction.setClearCacheOnCommit(boolean)

isClearCacheOnRollback

public boolean isClearCacheOnRollback()
Returns the flag indicating whether all Entity Object caches will be cleared after the transaction is rolled back.

After the transaction is rolled back, the value of this flag is used to determine whether the Entity Object caches are cleared or not. If this flag value is false, the cache contents are kept. In this case, the cache may contain data that is not in sync with database in that uncommitted changes made this by user (before the transaction was rolled back) will be kept.

If this flag is true, the caches are cleared after the transaction is rolled back. When the user brings in data by traversing row collection, the latest data from the database will be brought into Entity caches.

Specified by:
isClearCacheOnRollback in interface Transaction
Returns:
the current value of clear-cache-on-roll-back flag.
See Also:
RowSet.executeQuery(), setClearCacheOnRollback(boolean val), Transaction.isClearCacheOnCommit(), Transaction.setClearCacheOnCommit(boolean val)

setClearCacheOnRollback

public void setClearCacheOnRollback(boolean val)
Sets the value of the flag indicating whether all Entity Object caches will be cleared after the transaction is rolled back.

The initial value of this flag is retrieved from the Application Module definition of the root Application Module (an XML attribute value named "ClearCacheOnRollback" in the Application Module definition's XML file). If the Application Module definition does not contain the initial value, the default value is true, i.e., the caches are cleared after rollback.

The user can override the value of this flag for this Transaction by calling this method. Calling this method does not affect the initial value in the Application Module definition.

Specified by:
setClearCacheOnRollback in interface Transaction
Parameters:
val - the new value of the clear-cache-on-roll-back flag. true indicates that the Entity Object caches will be cleared after rollback, and will be refreshed with new data from the database.
See Also:
isClearCacheOnRollback(), Transaction.setClearCacheOnRollback(boolean), Transaction.isClearCacheOnRollback()

doValidatePostChanges

public void doValidatePostChanges()
invoke validate() and postChanges() iteratively based on validateThreshold and postThreshold setting.


doBeforeCommit

public void doBeforeCommit()

doAfterCommit

public void doAfterCommit()

commit

public void commit()
Commits all changes in this transaction to the database, making them visible to other users and transactions. This method is called on the Application Module's transaction. For example:

     appMod.getTransaction().commit();
 
When the commit process begins multiple attempts are made to validate all objects in the list of validation listeners, depending on the setting of the validation threshold. After each attempt, top-level entities that are still invalid will remain in the list. If any remain after the last attempt, a failure exception is thrown.

Each listed TransactionPostListener is notified to post any changes to the database using the postChanges method. Non-transient listeners are notified first, followed by transient listeners. The post phase is repeated, the number of repetitions depending on the setting of the validation threshold. If any invalid objects remain after the last repetition, a failure exception is thrown.

Following validation, no further changes to data should be made until the commit operation is completed.

Finally, beforeCommit events are posted to the listeners, the data is committed, afterCommit events are posted, and transient listeners are deleted from the transaction. For both beforeCommit and afterCommit events, non-transient listeners preceed transient listeners.

Note, if your Application Module is an EJB session bean, a new transaction is started for you automatically after calling commit. You do not have to explicitly start a new transaction.

Specified by:
commit in interface Transaction
See Also:
TransactionListener.beforeCommit(TransactionEvent), TransactionListener.afterCommit(TransactionEvent), DBTransaction, postChanges()

commitAndSaveChangeSet

public int commitAndSaveChangeSet()
Description copied from interface: Transaction
Commits the transaction and writes updated EntityImpls to the persistent store.

This method (along with applyChangeSet and removeChangeSet is used to synchronize the cache between root Application Module instances in an Application Module pool.

commitAndSaveChangeSet commits the transaction, but during the commit process, writes out "changed" EntityImpls to the persistent store. These changes are stored as a "change set". The change set can then be applied to other transactions (that is, to the Entity caches of other root Application Modules).

The integer value returned by this method identifies the change set that is stored in persistent store.

To apply the changes to another transaction (or Application Module cache), call Transaction.applyChangeSet(int) where int is the integer value returned by commitAndSaveChangeSet that represents the change set.

For example, assume you have two root Application Modules, named am1 and am2, in an Application Module pool.

  // The line below commits the transaction in am1 and writes the change
  // set to persistent store (database table).  The returning snapId
  // identifies the (persistent) change set.

  int snapId = am1.getTransaction().commitAndSaveChangeSet();

  // Use that change set and apply the changes to the other Application
  // Module, am2.  That is, apply changes from am1 to am2.

  am2.getTransaction().applyChangeSet(snapId);

  // When you are done with the change set, remove (free) it.

  am1.getTransaction().removeChangeSet(snapId);
 

Specified by:
commitAndSaveChangeSet in interface Transaction
Returns:
an integer representing an EntityImpl change set in persistent store.
See Also:
Transaction.applyChangeSet(int), Transaction.removeChangeSet(int)

applyChangeSet

public void applyChangeSet(int id)
Description copied from interface: Transaction
Applies the changes committed by another transaction in order to synchronize caches between root Application Module instances.

This method (along with commitAndSaveChangeSet and removeChangeSet is used to synchronize the cache between root Application Module instances in an Application Module pool.

Call applyChangeSet to apply changes commited by another transaction. The integer id parameter (returned by commitAndSaveChangeSet) identifies the change set to be found in the persistent store.

After this call, this transaction's cache is synchronized with the changes from the change set.

For an example of how to use applyChangeSet, see commitAndSaveChangeSet.

Specified by:
applyChangeSet in interface Transaction
Parameters:
id - an integer representing the change set to apply to the transaction.
See Also:
Transaction.commitAndSaveChangeSet(), Transaction.removeChangeSet(int)

removeChangeSet

public void removeChangeSet(int id)
Description copied from interface: Transaction
Removes the change set that defines the changes to EntityImpls within a transaction.

This method (along with commitAndSaveChangeSet and applyChangeSet is used to synchronize the cache between root Application Module instances in an Application Module pool.

For an example of how to use removeChangeSet, see commitAndSaveChangeSet.

Specified by:
removeChangeSet in interface Transaction
Parameters:
id - an integer representing the change set to remove from the persistent store.
See Also:
Transaction.commitAndSaveChangeSet(), Transaction.applyChangeSet(int)

rollback

public void rollback()
Discards all modifications made in this transaction. This method is called on the Application Module's transaction. For example:

     appMod.getTransaction().rollback();
 
When this method is invoked, beforeRollback events are posted to the listeners, the changes are discarded, afterRollback events are posted, and transient listeners are deleted from the transaction. For both events, non-transient listeners preceed transient listeners.

In the following example, a method named updateAttr has been implemented to update a row of a View Object vo with the value newAttrVal. If updateAttr succeeds (returns true), the code commits the transaction; otherwise, it rolls the transaction back:

 // Assume that appMod has been declared and initialized elsewhere.
   try {  if (updateAttr(vo, newAttrVal)) {
       // Commit changes to the database, making
       // updated data available to other Application Modules.
       appMod.getTransaction().commit();
       System.out.println("\n Transaction committed. \n");
     }
   else {
       appMod.getTransaction().rollback();
       System.out.println("\n Transaction rolled back. \n");
    }
 } catch (Exception e) {
       e.printStackTrace();
 }
 

Note, if your Application Module is an EJB session bean, a new transaction is started for you automatically after calling rollback. You do not have to explicitly start a new transaction.

Specified by:
rollback in interface Transaction
See Also:
DBTransaction, TransactionListener.afterRollback(TransactionEvent), TransactionListener.beforeRollback(TransactionEvent)

addTransactionListener

public void addTransactionListener(TransactionListener listener)
Adds a listener to the transaction's list.

Listeners are notified of the commit and rollback events generated by the commit and rollback methods. The framework adds modified top-level Entity Objects to this list.

This method is available only on the middle tier; it is not available on the client.

This method should not be overridden.

Specified by:
addTransactionListener in interface DBTransaction
Parameters:
listener - the subscriber to be added.
See Also:
commit(), rollback()

addTransactionListenerNoCheck

public void addTransactionListenerNoCheck(TransactionListener listener)
Internal: Applications should not call this method.

Adds a listener to the transaction's list, without checking whether the listener was present.

Listeners are notified of the commit and rollback events generated by the commit and rollback methods. The framework adds modified top-level Entity Objects to this list.

Specified by:
addTransactionListenerNoCheck in interface DBTransaction
Parameters:
listener - the subscriber to be added.

removeTransactionListener

public void removeTransactionListener(TransactionListener listener)
Removes a subscriber from the transaction's events list.

Specified by:
removeTransactionListener in interface DBTransaction
Parameters:
listener - the subscriber to be removed.

getTransactionListenersList

protected java.util.ArrayList getTransactionListenersList()

getTransactionPostListenersList

protected java.util.ArrayList getTransactionPostListenersList()

getValidationListenersList

protected java.util.ArrayList getValidationListenersList()

addTransactionPostListener

public void addTransactionPostListener(TransactionPostListener listener)
Adds a subscriber to the transaction's post-events list.

When postChanges is invoked, each listed TransactionPostListener is notified to post any changes to the database.

Specified by:
addTransactionPostListener in interface DBTransaction
Parameters:
listener - the subscriber to be added.
See Also:
postChanges()

addTransactionPostListenerNoCheck

public void addTransactionPostListenerNoCheck(TransactionPostListener listener)
Internal: Applications should not use this method.

Adds a subscriber to the transaction's post-events list, without checking if it is already present.

When postChanges() is invoked, each listed TransactionPostListener is notified to post any changes to the database.

Specified by:
addTransactionPostListenerNoCheck in interface DBTransaction
Parameters:
listener - the subscriber to be added.
See Also:
postChanges()

removeTransactionPostListener

public void removeTransactionPostListener(TransactionPostListener listener)
Removes a subscriber from the transaction's post-events list.

Specified by:
removeTransactionPostListener in interface DBTransaction
Parameters:
listener - the subscriber to be removed.

postChanges

public void postChanges()
Synchronizes the changes in the middle-tier transaction-cache with the database.

This method bypasses the validation cycle and can allow invalid data to be posted to the database. As a side effect of this method, database triggers or other constraints might be fired as a result of posting data. However, invalid changes cannot be committed, as the commit() method validates all changes before committing them.

Typically, applications should call this method if they must execute SQL operations or queries with the current cached-state of data, before validating the changes.

Specified by:
postChanges in interface Transaction
See Also:
commit()

setBatchModeForEntity

public void setBatchModeForEntity(EntityDefImpl def,
                                  boolean mode)
Sets the updatebatching (Batch post operations) mode on or off for a given entity type in this transaction.

Parameters:
def - - Def for the desired entity type
mode - - whether to turn batch updates on or off. if false rest of the arguments are ignored. If attribute list is null or has no elements, then Def is consulted for any default setting in the def for AttributeLists for these purposes. If Def does not have an attribute list then ALL attributes participate in the concerned operation.

postChanges

protected void postChanges(TransactionEvent te)
Internal: Applications should not use this method.

Synchronizes all the changes in this transaction-cache with the database. These changes are still not visible to other users/transaction.

Executes a savepoint before starting to post any changes. Then, all non-transient and transient TransactionPostListeners are notified to post their changes, in that order. In case of any exception, rollsback the transaction to the savepoint. and throws DMLException.

For Entity types that are marked to use batch update in case of oracle jdbc, first a maximal-attribute-changed-set is collected for each entity-type so that batch statements could be created for all changes. Then postChanges() is called on all the entities in the transaction just like in the normal case, but entity does not execute the dml, instead simply adds the DML to a batched statement which is executed after all entities are done adding their changes to the batch. Then for each entity type that has batched statements executes the batches (deletes first, followed by inserts and then updates). On any eror during the batch operations, the entire transaction is rolled back to the savepoint as described earlier.


hasRollbackSavePoint

protected boolean hasRollbackSavePoint()

createStatement

public java.sql.Statement createStatement(int noRowsPrefetch)
Description copied from interface: DBTransaction
Creates a JDBC Statement instance.

Applications may use this method to create a JDBC statement object to execute application specific SQL statements directly, so that the modifications are committed to the database in a single transaction through this object.

Specified by:
createStatement in interface DBTransaction
Parameters:
noRowsPrefetch - the number of rows to prefetch when executing this statement's query.
Returns:
a JDBC Statement instance.

createCallableStatement

public java.sql.CallableStatement createCallableStatement(java.lang.String str,
                                                          int noRowsPrefetch)
Description copied from interface: DBTransaction
Creates a JDBC CallableStatement instance.

Applications may use this method to create a JDBC callable statement object to execute application-specific SQL statements directly, so that the modifications are committed to the database in a single transaction through this object.

Specified by:
createCallableStatement in interface DBTransaction
Parameters:
str - the CallableStatement instance's SQL statement.
noRowsPrefetch - the number of rows to prefetch when executing this statement's query. If this parameter is set to DBTransaction.DEFAULT, then the default value from the jdbc driver is used.
Returns:
a JDBC CallableStatement instance.

createPreparedStatement

public java.sql.PreparedStatement createPreparedStatement(java.lang.String str,
                                                          int noRowsPrefetch)
Description copied from interface: DBTransaction
Creates a JDBC PreparedStatement instance.

Applications may use this method to create a JDBC callable statement object to execute application specific SQL statements directly, so that the modifications are committed to the database in a single transaction through this object.

Specified by:
createPreparedStatement in interface DBTransaction
Parameters:
str - the PreparedStatement instance's SQL statement.
noRowsPrefetch - the number of rows to prefetch when executing this statement's query. If this parameter is set to DBTransaction.DEFAULT, then the default value from the jdbc driver is used.
Returns:
a JDBC PreparedStatement instance.

executeCommand

public int executeCommand(java.lang.String command)
Executes a SQL command using a JDBC Statement under the current transaction. Applications should use this method to execute application-specific JDBC statements.

This method provides a way of bypassing the framework to query the database directly. Internally, the method passes the specified SQL command to a statement on the JDBC connection and executes it.

The following code example uses executeCommand. The SQL string is designed to update the EMP table. This example passes the string to executeCommand, then prints a message to report how many rows were actually updated.

 public static void demoUpdateColumn(ApplicationModule appMod) {
     String sqlStr = "UPDATE EMP " +
                     "SET MGR=7007 " +
                     "WHERE MGR=7698 ";

     int n = appMod.getTransaction().executeCommand(sqlStr);
     System.out.println("Updated " + n + " rows.");
   }
 

Be careful when using executeCommand, because it will execute any valid SQL statement. For example, you could perform an operation like the following DDL command:

 appMod.getTransaction().executeCommand("DROP TABLE MYTEMPTABLE");
 

A pending database transaction could be committed inadvertently due to the implicit commit performed by DDL operations, as well as having any row locks released.

Specified by:
executeCommand in interface Transaction
Parameters:
command - a valid SQL statement.
Returns:
the number of rows affected.
Throws:
InvalidParamException - if command is empty.
SQLStmtException - if command fails.

dumpQueryResult

public java.lang.String dumpQueryResult(java.lang.String query,
                                        java.lang.String dumpClassName,
                                        java.lang.String[] data)
Writes the result of the query to a (potentially very long) string. It takes three parameters: the first is the SQL query statement. The second is the class that dumps the result to a string. This class must implement the oracle.jbo.server.QueryDump interface. The implementation of this class decides what to do with the third, data parameter (which can be null). This is a utility method for testing and debugging queries and applications.

The following code example uses dumpQueryResult.

 public static void demoSimpleFetch(ApplicationModule appMod) {
       // Define and execute a simple SQL statement.
       String sqlStr = "SELECT Emp.ename FROM EMP Emp ";
       // dumpQueryResult is a utility method for testing queries.
       String result = appMod.getTransaction().dumpQueryResult(sqlStr,
                                    "oracle.jbo.server.QueryDumpTab",
                                      null);

 System.out.println(sqlStr);
 System.out.println(result);  }
 

Specified by:
dumpQueryResult in interface Transaction
Parameters:
query - the SQL query statement.
dumpClassName - the class that dumps the result to a string.
data - an array of data items.

getLockingMode

public int getLockingMode()
Returns the preferred locking mode for this Transaction. For example:

 am.getTransaction().getLockingMode();
 
The possible return values are:

If not set by setLockingMode(), the locking mode defaults to LOCK_PESSIMISTIC.

Specified by:
getLockingMode in interface Transaction
Returns:
an integer representing the preferred locking mode. The values can be LOCK_NONE, LOCK_PESSIMISTIC (default), or LOCK_OPTIMISTIC.

setLockingMode

public void setLockingMode(int mode)
Sets the preferred locking mode for this Transaction. The possible values are:

Changing the locking mode affects only subsequent locks. Current locks are not affected.

Specified by:
setLockingMode in interface Transaction
Parameters:
mode - one of LOCK_PESSIMISTIC, LOCK_OPTIMISTIC or LOCK_NONE.

lookupEntityCache

public EntityCache lookupEntityCache(EntityDefImpl source)

findEntityCache

public EntityCache findEntityCache(EntityDefImpl source)
Finds a Cache table for the entity. This method will find the internal EntityCache object which is allocated to cache the Entity information. If one is not already present for the type of Entity, then it will be created and returned.

Returns:
the EntityCache for the Entity in this Transaction.

getEntityCache

public EntityCache getEntityCache(EntityDefImpl source)

removeEntityCache

public void removeEntityCache(EntityDefImpl source)

removeEntityCacheByName

public void removeEntityCacheByName(java.lang.String name)

clearEntityCache

public void clearEntityCache(java.lang.String entityName)
Description copied from interface: Transaction
Clears the cache of the specified Entity Object. A value of null clears the caches of all Entities. If a View Object uses the Entity Object, the View Object's cache will be cleared as well.

Specified by:
clearEntityCache in interface Transaction
Parameters:
entityName - the name of the entity whose cache is to be cleared. If null, caches for all entities are cleared.

addToValidationListeners

public void addToValidationListeners(ValidationListener entity)
Adds an entity validation listener.

The entity listener will be notified to perform its own validation when this validation manager is validated.

This method overrides the ValidationManager.addToValidationListeners(ValidationListener) method.

Specified by:
addToValidationListeners in interface ValidationManager
Parameters:
entity - an entity validation listener.

getTransValidationManager

public JboTransValidationManager getTransValidationManager()

getTransValidations

public java.util.HashMap getTransValidations()
Specified by:
getTransValidations in interface JboTransValidationManager

getTransValidationList

public java.util.ArrayList getTransValidationList()
Specified by:
getTransValidationList in interface JboTransValidationManager

getTransAttrValidationManager

public JboTransAttrValidationManager getTransAttrValidationManager()

getTransAttrValidations

public java.util.HashMap getTransAttrValidations()
Specified by:
getTransAttrValidations in interface JboTransAttrValidationManager

getTransAttrValidationList

public java.util.ArrayList getTransAttrValidationList()
Specified by:
getTransAttrValidationList in interface JboTransAttrValidationManager

putTransValEntry

public void putTransValEntry(JboTransValidatorInterface validator,
                             JboValidatorContext valCtx)
Specified by:
putTransValEntry in interface JboTransValidationManager

putTransAttrValEntry

public void putTransAttrValEntry(JboTransValidatorInterface validator,
                                 JboValidatorContext valCtx)
Specified by:
putTransAttrValEntry in interface JboTransAttrValidationManager

validate

public void validate()
Starts the validation cycle and validates all subscribers in the ValidationListener list. Typically all top-level entities which were invalidated through the framework will be in this list. Listeners are removed as they are validated.

The advantage of calling validate() is that the data stays in the middle tier. Data is not posted to the database, thus avoiding the possible firing of database triggers or constraints.

Specified by:
validate in interface ValidationManager
Specified by:
validate in interface Transaction

setValidationThreshold

public void setValidationThreshold(int count)
Description copied from interface: DBTransaction
Sets the threshold value for the commit-cycle's validation phase.

When commit() is invoked the framework attempts to validate the transaction's modifications, making count attempts before failing with an exception. This mechanism allows applications to update data in the cache within the validation phase, and validate them before they are posted.

Specified by:
setValidationThreshold in interface DBTransaction
Parameters:
count - the new threshold value.

getValidationThreshold

public int getValidationThreshold()
Description copied from interface: DBTransaction
Gets the threshold value for the commit-cycle's validation phase.

Specified by:
getValidationThreshold in interface DBTransaction

setPostThreshold

public void setPostThreshold(int count)
Description copied from interface: DBTransaction
Sets the threshold value for the commit-cycle's post phase.

When commit() is invoked the framework attempts to post the transaction's modifications, making count attempts before failing with an exception. This mechanism allows applications to update data in the cache within the post phase, and commit all changes.

Specified by:
setPostThreshold in interface DBTransaction
Parameters:
count - the new threshold value.

getPostThreshold

public int getPostThreshold()
Description copied from interface: DBTransaction
Gets the threshold value for the commit-cycle's post phase.

Specified by:
getPostThreshold in interface DBTransaction

getBatchPostExceptionThreshold

public int getBatchPostExceptionThreshold()
In case of batch mode post operation, try to post the batched set of entities for each entity type and post operation (Insert/Update/Delete) for this many number of exceptions.

Specified by:
getBatchPostExceptionThreshold in interface DBTransaction
See Also:
setBatchPostExceptionThreshold(int)

setBatchPostExceptionThreshold

public void setBatchPostExceptionThreshold(int count)
Set this value to 0 to let all the modified entities be posted for each entity type and entity-DML operation to collect possible exceptions for all such entities. Set this number to a postive integer to set a limit on number of exceptions to collect for each entity type and DML operation before aborting the post operation.

Specified by:
setBatchPostExceptionThreshold in interface DBTransaction

isDirty

public boolean isDirty()
This method is typically called before an attempt is made to post the data. For example, this method can be called when the user at the client attempts to close an application. If there is unsaved data, this method can return true. In response, the client can prompt the user to save before closing the application.

Specified by:
isDirty in interface Transaction
Returns:
trueif any data within this Application Module has been modified but not yet committed; false otherwise.

dumpEntityCaches

public void dumpEntityCaches(java.io.Writer out)
Iterates over the currently populated caches of entities, and write a representation of them to a charater stream. Internal: Applications should not use this method.


showCursorUsage

public void showCursorUsage(java.io.Writer out)
Internal: Applications should not use this method.


doCommit

protected void doCommit()
Called by the commit method to issue the commit call. This method is called just before the transaction is committed on the JDBC connection. Override this method to provide your own handler for the commit operation.


doRollback

protected void doRollback()
Called by the rollback method to issue the rollback call. This method is called just before the transaction is rolled back on the JDBC connection. Override this method to provide your own handler for the rollback operation.


connect

public void connect(java.sql.Connection sqlConnection)
Deprecated. 

Uses this JDBC Connection object to connect to the database for all operations via this transaction. ApplicationModule calls this method on the transaction object. Internal: Applications should not use this method.

Specified by:
connect in interface DBTransaction
Since:
5.0

connect

public void connect(java.lang.String url)
Uses this JDBC Connection object to connect to the database for all operations via this transaction. ApplicationModule calls this method on the transaction object. Internal: Applications should not use this method.

Use the connect method on the Transaction interface instead.

Specified by:
connect in interface Transaction
Parameters:
url - a database url of the form jdbc:subprotocol:subname.

connect

public void connect(java.lang.String url,
                    java.util.Properties info)
Internal: Applications should not use this method.

Use the connect method on the Transaction interface instead.

Specified by:
connect in interface Transaction
Parameters:
url - a database url of the form jdbc:subprotocol:subname.
info - a list of arbitrary string tag/value pairs to be used as connection arguments. Normally, at least "user" and "password" properties should be included.

connect

public void connect(java.lang.String url,
                    java.lang.String user,
                    java.lang.String password)
Internal: Applications should not use this method.

Use the connect method on the Transaction interface instead.

Specified by:
connect in interface Transaction
Parameters:
url - a database url of the form jdbc:subprotocol:subname.
user - the database user on whose behalf the connection is being made.
password - the user's password.

connectToDataSource

public void connectToDataSource(java.lang.String nsUrl,
                                java.lang.String nsUser,
                                java.lang.String nsPasswd,
                                java.lang.String dsUrl)
Description copied from interface: Transaction
Looks up a datasource from Oracle 8i namespace using the jdbc_access protocol and acquires the default jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection() method.

Specified by:
connectToDataSource in interface Transaction
Parameters:
nsUrl - Url to the jndi namespace where the datasource is bound
nsUser - User name that is used to access the namespace.
nsPasswd - nsUsers' passwd
dsUrl - Datasource name as bound in the namespace. Name can be the fully qaultified url such as jdbc_access://test/ds/db1 otherwise the the url prefix jdbc_acess:// is prepended to the datasource name for lookup.

connectToDataSource

public void connectToDataSource(java.lang.String nsUrl,
                                java.lang.String nsUser,
                                java.lang.String nsPasswd,
                                java.lang.String dsUrl,
                                java.lang.String user,
                                java.lang.String passwd)
Description copied from interface: Transaction
Looks up a datasource from Oracle 8i namespace using the jdbc_access protocol and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String password) method.

Specified by:
connectToDataSource in interface Transaction
Parameters:
nsUrl - Url to the jndi namespace where the datasource is bound
nsUser - User name that is used to access the namespace.
nsPasswd - nsUsers' passwd
dsUrl - Datasource name as bound in the namespace. Name can be the fully qaultified url such as jdbc_access://test/ds/db1 otherwise the the url prefix jdbc_acess:// is prepended to the datasource name for lookup.
user - Username for which the connection is acquired from the datasource
passwd - User's password.

connectToDataSource

public void connectToDataSource(javax.sql.DataSource ds,
                                boolean isJTAbased)
Specified by:
connectToDataSource in interface DBTransaction

connectToDataSource

public void connectToDataSource(javax.sql.DataSource ds,
                                java.lang.String user,
                                java.lang.String passwd,
                                boolean isJTAbased)
Specified by:
connectToDataSource in interface DBTransaction

connectToDataSource

public void connectToDataSource(java.util.Hashtable env,
                                java.lang.String dsName,
                                java.lang.String user,
                                java.lang.String passwd,
                                boolean isJTABased)
Description copied from interface: Transaction
Looks up a datasource from a jndi tree and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String passwd) method.

Specified by:
connectToDataSource in interface Transaction
Parameters:
env - Envirionment used the create initial context. May be null.
dsName - Datasource name as bound in the namespace.
user - Username for which the connection is acquired from the datasource
passwd - User's password.
isJTABased - True if datasource is XADataSource implementation. If true, the tranasction is assumed to be controlled by an external transaction manager.

connectToDataSource

public void connectToDataSource(java.util.Hashtable env,
                                java.lang.String dsName,
                                boolean isJTABased)
Description copied from interface: Transaction
Looks up a datasource from a jndi tree and acquires the jdbc connection from the looked up datasource using the javax.sql.Datasource.getConnection(String user, String passwd) method.

Specified by:
connectToDataSource in interface Transaction
Parameters:
env - Envirionment used the create initial context. May be null.
dsName - Datasource name as bound in the namespace.
isJTABased - True if datasource is XADataSource implementation. If true, the tranasction is assumed to be controlled by an external transaction manager.

getConnectionMetadata

public ConnectionMetadata getConnectionMetadata()
Description copied from interface: Transaction
Returns a metdata structure that describes the transaction's JDBC connection.

Specified by:
getConnectionMetadata in interface Transaction

isConnected

public boolean isConnected()
Checks if the transaction is connected to the database. In a three-tier scenario, clients can call this method to check if the middle tier is connected to the database.

Specified by:
isConnected in interface Transaction
Returns:
true if connected; false if disconnected.

disconnect

public void disconnect(boolean retainState)
Closes the JDBC connection object. If disconnect is invoked with retainState equal to false then the JDBC connection will be closed and this transaction will be removed* from the root application module.

If disconnect is invoked with retainState equal to true then this transaction's JDBC connection will be closed but, the root application module will continue to reference this transaction and its state. The transaction state may include unposted database changes and cached result sets. In the middle tier, reconnect on the DBTransaction interface may be invoked to re-establish a JDBC connection for this transaction. If connection pooling is enabled for this middle tier instance this connection may represent a recycled connection.

The developer should take measures to ensure that the following requirements are met before attempting to disconnect a JDBC connection and retain application module state. All of these validations are not currently performed by the disconnection implementation because of performance considerations:

All non-forward only view objects should have fetched in all data

If pessimistic locking is enabled, all pending changes should be commited/rolled back.

All changes that have been posted to the database should be commited/rolled back>/p>

Specified by:
disconnect in interface DBTransaction
Specified by:
disconnect in interface Transaction

reconnect

public void reconnect()
Reconnect the ApplicationModule to the database, using previously supplied database credentials. This method should only be invoked if the transaction has been previously disconnected using disconnect(boolean) with the retainState parameter equal to true or, if a previous isConnected() request had discovered a stale JDBC connection. If it is invoked otherwise the method will do nothing.

Specified by:
reconnect in interface DBTransaction
Specified by:
reconnect in interface Transaction
See Also:
disconnect(boolean)

reconnect

public void reconnect(boolean force)
Reconnect the Application Module to the database, if necessary, using previously supplied database credentials. If the parameter is true, then a database disconnect and reconnect is performed, whatever the current connection state. If false, the connect is only performed if the connection has disappeared.

Specified by:
reconnect in interface Transaction
Parameters:
force - force a reconnect, should usually be false.

disconnect

public void disconnect()
Closes the JDBC connection object and removes this transaction from the root application module.

As an alternative, you can also use the disconnect method on the Transaction interface.

Specified by:
disconnect in interface Transaction

getTransactionHandler

public TransactionHandler getTransactionHandler()
Internal: Applications should not use this method.

Specified by:
getTransactionHandler in interface DBTransaction

setTransactionHandler

public void setTransactionHandler(TransactionHandler txnHandler)
Internal: Applications should not use this method.

Specified by:
setTransactionHandler in interface DBTransaction

getTxnApplicationModuleImpl

protected ApplicationModuleImpl getTxnApplicationModuleImpl()
Gets the root Application Module to which this transaction belongs.

Returns:
the root Application Module.

getActiveApplicationModuleImpls

protected java.util.Set<ApplicationModuleImpl> getActiveApplicationModuleImpls()

getRootApplicationModule

public ApplicationModule getRootApplicationModule()
Returns the root appmodule that owns this transaction.

Specified by:
getRootApplicationModule in interface DBTransaction

createEntityInstance

public EntityImpl createEntityInstance(EntityDefImpl entityDef,
                                       AttributeList al)
Creates an EntityImpl object based on the given defintion, in the context of the root Application Module. Passes the attribute list, al, to the create method on the EntityImpl.

Specified by:
createEntityInstance in interface DBTransaction
Parameters:
entityDef - the EntityDef defintion to use to create the EntityImpl.
al - attribute list to pass to the create() method on the EntityImpl.
Returns:
the new EntityImpl instance.

createEntityInstance

public EntityImpl createEntityInstance(java.lang.String entityDefName,
                                       AttributeList al)
Creates an EntityImpl object based on the given defintion, in the context of the root Application Module. Passes the attribute list, al, to the create method on the EntityImpl.

Specified by:
createEntityInstance in interface DBTransaction
Parameters:
entityDefName - the String name of entity defintion to use to create the EntityImpl.
al - attribute list to pass to the create method on the EntityImpl.
Returns:
the new EntityImpl instance.

findByPrimaryKey

public EntityImpl findByPrimaryKey(EntityDefImpl entityDef,
                                   Key key)
Finds an Entity Object in this transaction given an EntityDef object and a Primary Key.

Given the EntityDef object and the table's primary key, this method returns the associated Entity Object. If the Entity has not already been brought into the cache by any of the View Objects, this method will cause the Entity to be fetched from the database. This method returns null if the Entity Object is not found.

For example, use this method to create a set of Entity Objects based on a relational schema without the need to create any Application Modules or View Objects. To do this, use findByPrimaryKey to locate a specific object and then traverse association accessors to get to all the other objects.

Specified by:
findByPrimaryKey in interface DBTransaction
Parameters:
entityDef - the Entity Def object to to be used to find the instance.
key - the Primary Key.
Returns:
the Entity Object matching Key, or null if not found.

findByPrimaryKey

public EntityImpl findByPrimaryKey(java.lang.String entityDefName,
                                   Key key)
Finds an Entity Object in this transaction given the String name of the EntityDef and a Primary Key.

Given the String name of the EntityDef and the table's primary key, this method returns the associated Entity Object. If the Entity has not already been brought into the cache by any of the View Objects, this method will cause the Entity to be fetched from the database.

This method returns null if the Entity Object is not found.

For example, use this method to create a set of Entity Objects based on a relational schema without the need to create any Application Modules or View Objects. To do this, use findByPrimaryKey to locate a specific object and then traverse association accessors to get to all the other objects.

Specified by:
findByPrimaryKey in interface DBTransaction
Parameters:
entityDefName - the name of the defintion to to be used to find the instance.
key - the Primary Key.
Returns:
the Entity Object matching Key, or null if not found.

createApplicationModule

public ApplicationModule createApplicationModule(java.lang.String amName,
                                                 java.lang.String defName)
Creates an instance of an nested Application Module within this Transaction For example,

 oracle.jbo.ApplicationModule nestedAM =
 dbtxn.createApplicationModule("subAppMod", "PackageName.AppModuleName");
 

This application module can control the namespace of objects that are contained within it.

Specified by:
createApplicationModule in interface DBTransaction
Parameters:
amName - the name to be given to the Application Module. If amName is empty, a name is generated.
defName - the name of the Application Module definition to be used. If null a default definition is used.
Returns:
a new Application Module.

findApplicationModule

public ApplicationModule findApplicationModule(java.lang.String amName)
Returns the named Application Module. This method assumes that the Application Module has already been created in this Transaction. The following example returns the Application Module KpiAM:

 oracle.jbo.ApplicationModule am = dbTxn.findApplicationModule("KpiAM");
 

Specified by:
findApplicationModule in interface DBTransaction
Parameters:
amName - the name of the Application Module.
Returns:
the Application Module.
Throws:
InvalidObjNameException - if the name cannot be found.

createViewObject

public ViewObject createViewObject(java.lang.String voDefName)
Creates an anonymous query definition from the name of a ViewObject class. For more information on anonymous View Objects, see Using Anonymous View Objects

Calling method should also call remove() for the View Object to be properly garbage-collected.

Specified by:
createViewObject in interface DBTransaction
Parameters:
voDefName - the name of the ViewObject class.
Returns:
the new ViewObject instance.

createViewObjectFromQueryClauses

public ViewObject createViewObjectFromQueryClauses(java.lang.String eoName,
                                                   java.lang.String selectClause,
                                                   java.lang.String fromClause,
                                                   java.lang.String whereClause,
                                                   java.lang.String orderByClause)
Creates an updatable query definition.

Creates an anonymous query definition from an Entity Object and parts of a SQL statement. For more information on anonymous View Objects, see Using Anonymous View Objects

Calling method should also call remove() for the View Object to be properly garbage-collected.

Specified by:
createViewObjectFromQueryClauses in interface DBTransaction
Parameters:
eoName - the name of a EntityObject beaninfo class.
selectClause - an SQL statement SELECT clause.
fromClause - an SQL statement FROM clause.
whereClause - an SQL statement WHERE clause.
orderByClause - an SQL statement ORDERBY clause.

createViewObjectFromQueryStmt

public ViewObject createViewObjectFromQueryStmt(java.lang.String sqlStatement)
Creates an anonymous query definition from an SQL statement. For more information on anonymous View Objects, see Using Anonymous View Objects

Calling method should also call remove() for the View Object to be properly garbage-collected.

The following example creates a View Object that queries for the system date:

  ViewObject vo = tx.createViewObjectFromQueryStmt("select sysdate
   from dual");
         Row row = vo.first();
         Date now = (Date) row.getAttribute(0);
         System.out.println("The date/time is now: "+now);
         oracle.sql.DATE nextMonth = now.addMonths(1);
         System.out.println("The date/time is now: "+nextMonth);
 

Specified by:
createViewObjectFromQueryStmt in interface DBTransaction
Parameters:
sqlStatement - a SQL statement.

createViewObjectFromQueryStmt

public ViewObject createViewObjectFromQueryStmt(java.lang.String sqlStatement,
                                                java.lang.String voImplClassName)
Creates an anonymous query definition from an SQL statement. The returned ViewObject is an instance of the Class name that is passed in as the argument. This allows for custom logic in a subclass of the framework provided oracle.jbo.server.ViewObjectImpl class.

Specified by:
createViewObjectFromQueryStmt in interface DBTransaction
Parameters:
sqlStatement - a SQL statement.
voImplClassName - the name of a subclass of oracle.jbo.server.ViewObjectImpl
Returns:
the ViewObject instance of the Class name passed as the argument

findViewObject

public ViewObject findViewObject(java.lang.String voName)
Find a view object with the specified name. The name passed in the argument should either be relative to the root Application Module of the transaction or a fully-qualified path when nested Application Modules are involved.

Specified by:
findViewObject in interface DBTransaction
Parameters:
voName - the name of the view object.
Returns:
the view object. null if the view object is not found.
Throws:
NoObjException - if an AM-qualified name was specified and the containing application module could not be found.
InvalidObjNameException - if voName is an invalid name. voName must be a vaild Java name.

createApplicationModule

public ApplicationModule createApplicationModule(java.lang.String defName)
Creates an anonymous Application Module. This method is useful for Entity Object middle-tier routines or for creating a sandbox for a service or utility object. With this method, View Objects can be created within the "scope" of that Application Module; then the application module can be passed around. The code in the Application Module can, for example, make assumptions about what View Objects are available and contain code for customizing them. It can control the namespace of objects that are contained within it. For example, the Entity Object middle-tier routine can call:

    getDbTransaction().createApplicationModule()
 

then use that Application Module as its local scratchpad. The routine can pass that Application Module around to others. The anonymous Application Module provides a temporary namespace and can be discarded with one .remove() call to clean-up just the things that the Entity Object needed temporarily.

Specified by:
createApplicationModule in interface DBTransaction
Parameters:
defName - the name of the Application Module definition to be used. If null a default definition is used.
Returns:
a new application module.

createViewLink

public ViewLink createViewLink(java.lang.String viewLinkDefName,
                               ViewObject master,
                               ViewObject detail)
Creates an anonymous View Link.

Specified by:
createViewLink in interface DBTransaction
Parameters:
viewLinkDefName - the name of the definition to be used to create the link. If empty a default definition will be used.
master - the link's source.
detail - the link's destination.
Throws:
InvalidParamException - if master or detail are invalid.
InvalidObjNameException - if viewLinkName is invalid.
NameClashException - if viewLinkName already exists.

createViewLinkFromEntityAssocName

public ViewLink createViewLinkFromEntityAssocName(java.lang.String entityAssocName,
                                                  ViewObject master,
                                                  ViewObject detail)
Creates a View Link.

Specified by:
createViewLinkFromEntityAssocName in interface DBTransaction
Parameters:
entityAssocName - the entity association that the View Link will represent.
master - the link's source.
detail - the link's destination.
Throws:
InvalidParamException - if master, detail, or entityAssocName are invalid.
InvalidObjNameException - if viewLinkName is invalid.
NameClashException - if viewLinkName already exists.

createViewLinkBetweenViewObjects

public ViewLink createViewLinkBetweenViewObjects(java.lang.String accessorName,
                                                 ViewObject master,
                                                 AttributeDef[] srcAttrs,
                                                 ViewObject detail,
                                                 AttributeDef[] destAttrs,
                                                 java.lang.String assocClause)
Creates an anonymous View Link.

Specified by:
createViewLinkBetweenViewObjects in interface DBTransaction
Parameters:
accessorName - the name to be given to the View Link's accessor.
master - the link's source.
srcAttrs - link attributes taken from the master View Object.
detail - the link's destination.
destAttrs - link attributes taken from the detail View Object.
assocClause -
Throws:
InvalidParamException - if master or detail are invalid.
InvalidObjNameException - if viewLinkName or accessorName are invalid.
NameClashException - if viewLinkName or accessorName already exist.

addWarning

public void addWarning(JboWarning warn)
Adds a warning to the root Application Module warning stack.

Specified by:
addWarning in interface DBTransaction
Parameters:
warn - a warning message.

getSession

public Session getSession()
Gets the session information.

Specified by:
getSession in interface DBTransaction
Returns:
the session.
Throws:
java.lang.IllegalStateException - if the session information cannot be found.

getJdbcConnection

protected java.sql.Connection getJdbcConnection()
Returns the JDBC connection for this transaction.


createRef

public java.lang.Object createRef(java.lang.String structName,
                                  byte[] data)
Internal: Applications should not use this method.

Specified by:
createRef in interface Transaction

addTransactionStateListener

public void addTransactionStateListener(TransactionStateListener target)
Add this TransactionListener to the list and notify all such listeners whenever commit and rollback occurs in this transaction.

Specified by:
addTransactionStateListener in interface Transaction

removeTransactionStateListener

public void removeTransactionStateListener(TransactionStateListener target)
Remove this transaction listener (if it exists) from this transaction.

Specified by:
removeTransactionStateListener in interface Transaction

addViewClearCacheListener

public void addViewClearCacheListener(ViewClearCacheListener target)
Specified by:
addViewClearCacheListener in interface Transaction

removeViewClearCacheListener

public void removeViewClearCacheListener(ViewClearCacheListener target)
Specified by:
removeViewClearCacheListener in interface Transaction

getCurrentDbTime

public java.sql.Timestamp getCurrentDbTime()

setTrackNewAndModifiedRowsOnly

public void setTrackNewAndModifiedRowsOnly(boolean flag)
Deprecated. since 9.0.5.1. This behavior is not optional anymore.

Internal: Applications should not use this method.

Specified by:
setTrackNewAndModifiedRowsOnly in interface DBTransaction

isTrackNewAndModifiedRowsOnly

public boolean isTrackNewAndModifiedRowsOnly()
Deprecated. since 9.0.5.1

Internal: Applications should not use this method.

Specified by:
isTrackNewAndModifiedRowsOnly in interface DBTransaction

setPostChangesFlag

public final void setPostChangesFlag(int flag)
The given flag modifies the behavior of postChanges method. Valid values for the flag are:


getPostChangesFlag

public final int getPostChangesFlag()
Internal: Applications should not use this method.


checkConnected

protected void checkConnected()
                       throws NotConnectedException
Throws:
NotConnectedException

isConnected

public boolean isConnected(boolean pingDatabase)
Specified by:
isConnected in interface DBTransaction

getTransactionState

protected int getTransactionState()

getDMLOperationTimeOut

public int getDMLOperationTimeOut()
Description copied from interface: Transaction
Returns the current Entity Object DML operation time out value. The default is DML_OPERATION_TIMEOUT_WAIT_FOREVER.

Specified by:
getDMLOperationTimeOut in interface Transaction
Returns:
the current Entity Object DML operation time out value.

setDMLOperationTimeOut

public void setDMLOperationTimeOut(int timeOutMills)
Description copied from interface: Transaction
Sets the query time out value for the Entity Object's DML operations. The default is DML_OPERATION_TIMEOUT_WAIT_FOREVER (-1), which means that the DML operations will not time out. The user will be able to cancel the long running operations by calling cancelDMLOperations() started by this Transaction during postChanges.

If a positive value of timeout is specified the operation is monitored by a global monitor thread. The monitor thread waits the specified amount of time (approximately) in milli-seconds, and cancels the operation by calling JDBC's Statement.cancel().

Specified by:
setDMLOperationTimeOut in interface Transaction
Parameters:
timeOutMills - if non-negative, number of milli-seconds before the DML operation is timed out.

addLongRunningDMLOperationHandle

public void addLongRunningDMLOperationHandle(LongRunningStatementHandle handle)

removeLongRunningDMLOperationHandle

public void removeLongRunningDMLOperationHandle(LongRunningStatementHandle handle)

cancelDMLOperations

public boolean cancelDMLOperations()
Description copied from interface: Transaction
Cancels the currently running Entity Object DML operations.

Specified by:
cancelDMLOperations in interface Transaction
Returns:
A false is returned if a DML cancel fails.

setForceDeferValidation

public void setForceDeferValidation(boolean bForceDefer)

isForceDeferValidation

public boolean isForceDeferValidation()

Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 2 (11.1.2.0.0)

E17483-01

Copyright © 1997, 2011, Oracle. All rights reserved.