|
Business Components | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.jbo.server.DBTransactionImpl
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
.
Field Summary | |
static int |
MAX_CURSORS_UNINITIALIZED
|
protected ConnectionCredentials |
mConnectionCredentials
|
protected SQLBuilder |
mSQLBuilder
The SQLBuilder instance used to interact with JDBC in this transaction. |
Fields inherited from interface oracle.jbo.Transaction |
LOCK_NONE,
LOCK_OPTIMISTIC,
LOCK_PESSIMISTIC |
Constructor Summary | |
DBTransactionImpl(java.sql.Connection connection)
Creates an instance from an existing JDBC connection. |
|
DBTransactionImpl(java.lang.String url)
Attempts to establish a connection to a database through the given URL. |
|
DBTransactionImpl(java.lang.String url,
java.util.Properties info)
Attempts to establish a connection to a database through the given URL. |
|
DBTransactionImpl(java.lang.String url,
java.lang.String user,
java.lang.String password)
Attempts to establish a connection to a database through the given URL. |
|
DBTransactionImpl(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.util.Properties info)
Internal: Attempts to establish a connection to the given database URL. |
Method Summary | |
void |
addToValidationListeners(ValidationListener entity)
Adds a validation listener. |
void |
addTransactionListener(TransactionListener listener)
Adds a listener to the transaction's list. |
void |
addTransactionListenerNoCheck(TransactionListener listener)
Adds a listener to the transaction's list, without checking whether the listener was present. |
void |
addTransactionPostListener(TransactionPostListener listener)
Adds a subscriber to the transaction's post-events list. |
void |
addTransactionPostListenerNoCheck(TransactionPostListener listener)
Adds a subscriber to the transaction's post-events list, without checking if it is already present. |
void |
addWarning(JboWarning warn)
Adds a warning to the root Application Module's current list of warnings. |
void |
closeTransaction()
Closes this transaction's JDBC connection. |
void |
commit()
Commits all changes in this transaction to the database, making them visible to other users and transactions. |
void |
connect(java.sql.Connection sqlConnection)
Internal: Applications should not use this method. |
void |
connect(java.lang.String url)
Internal: Applications should not use this method. |
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. |
ApplicationModule |
createApplicationModule(java.lang.String defName)
Creates an Application Module. |
java.sql.CallableStatement |
createCallableStatement(java.lang.String str,
int noRowsPrefetch)
Creates a JDBC CallableStatement instance. |
EntityImpl |
createEntityInstance(EntityDefImpl entityDef,
AttributeList al)
Creates an EntityImpl instance based on the given defintion. |
EntityImpl |
createEntityInstance(java.lang.String entityDefName,
AttributeList al)
Creates an EntityImpl instance based on the named defintion. |
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 a View Link. |
ViewLink |
createViewLinkBetweenViewObjects(java.lang.String accessorName,
ViewObject master,
AttributeDef[] srcAttrs,
ViewObject detail,
AttributeDef[] destAttrs,
java.lang.String assocClause)
Creates a View Link. |
ViewLink |
createViewLinkFromEntityAssocName(java.lang.String entityAssocName,
ViewObject master,
ViewObject detail)
Creates a View Link. |
ViewObject |
createViewObject(java.lang.String voDefName)
Creates a ViewObject instance based on the named defintion. |
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 View Object. |
ViewObject |
createViewObjectFromQueryStmt(java.lang.String sqlStatement)
Creates a View Object from a SQL statement. |
void |
disconnect()
Internal: Applications should not use this method. |
protected void |
doCommit()
|
protected void |
doRollback()
|
void |
dumpEntityCaches(java.io.Writer out)
Internal: Applications should not use this method. |
java.lang.String |
dumpQueryResult(java.lang.String query,
java.lang.String dumpClassName,
java.lang.String[] data)
Internal : Applications should not use this method. |
int |
executeCommand(java.lang.String command)
Executes a SQL command using a JDBC Statement under the current transaction. |
EntityImpl |
findByPrimaryKey(EntityDefImpl entityDef,
Key key)
Finds an Entity Object in this transaction given a Primary Key. |
EntityImpl |
findByPrimaryKey(java.lang.String entityDefName,
Key key)
Finds an Entity Object in this transaction given a Primary Key. |
protected java.sql.Connection |
getJdbcConnection()
|
int |
getLockingMode()
Gets the preferred locking mode for this Transaction. |
int |
getPostThreshold()
Gets the threshold value for the commit-cycle's post phase. |
Session |
getSession()
Gets the session information. |
SQLBuilder |
getSQLBuilder()
|
TransactionHandler |
getTransactionHandler()
Internal: Applications should not use this method. |
int |
getValidationThreshold()
Gets the threshold value for the commit-cycle's validation phase. |
boolean |
isConnected()
Checks if the transaction is connected to the database. |
boolean |
isDirty()
Checks if any data within this Application Module has been modified but not yet committed. |
void |
postChanges()
Synchronizes the changes in the transaction-cache with the database. |
protected void |
postChanges(TransactionEvent te)
Synchronizes all the changes in this transaction-cache with the database. |
void |
reconnect(boolean force)
Reconnect the application module to the database, if necessary, using previously supplied database credentials. |
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 |
rollback()
Discards all modifications made in this transaction. |
void |
setLockingMode(int mode)
Sets the preferred locking mode for this Transaction. |
void |
setPostThreshold(int count)
Sets the threshold value for the commit-cycle's post phase. |
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()
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 |
protected SQLBuilder mSQLBuilder
public static final int MAX_CURSORS_UNINITIALIZED
protected ConnectionCredentials mConnectionCredentials
Constructor Detail |
public DBTransactionImpl(java.sql.Connection connection)
connection
- an existing connection.public DBTransactionImpl(java.lang.String url)
url
- a database URL of the form JDBC:subprotocol:subname.public DBTransactionImpl(java.lang.String url, java.util.Properties info)
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.public DBTransactionImpl(java.lang.String url, java.lang.String user, java.lang.String password)
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.public DBTransactionImpl(java.lang.String url, java.lang.String user, java.lang.String password, java.util.Properties info)
url
- a database url of the form jdbc:subprotocol:subnameuser
- the database user on whose behalf the Connection is being madepassword
- the user's passwordinfo
- a list of arbitrary string tag/value pairs as
connection arguments; normally at least a "user" and
"password" property should be includedMethod Detail |
public void closeTransaction()
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 ApplicationModule.disconnect()
to
terminate the JDBC connection. Applications should use this method
to properly release JDBC resources.
public SQLBuilder getSQLBuilder()
public void commit() throws JboException
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.
DBTransaction
public void rollback()
DBTransaction
public void addTransactionListener(TransactionListener listener)
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.
listener
- the subscriber to be added.public void addTransactionListenerNoCheck(TransactionListener listener)
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.
listener
- the subscriber to be added.public void removeTransactionListener(TransactionListener listener)
listener
- the subscriber to be removed.public void addTransactionPostListener(TransactionPostListener listener)
When postChanges()
is invoked
Each listed TransactionPostListener
is notified to post any changes to the database.
listener
- the subscriber to be added.public void addTransactionPostListenerNoCheck(TransactionPostListener listener)
When postChanges()
is invoked
Each listed TransactionPostListener
is notified to post any changes to the database.
listener
- the subscriber to be added.public void removeTransactionPostListener(TransactionPostListener listener)
listener
- the subscriber to be removed.public void postChanges()
This method bypasses the validation cycle and may allow invalid data to be posted to the database. 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.
protected void postChanges(TransactionEvent te)
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.
public java.sql.Statement createStatement(int noRowsPrefetch)
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.
noRowPrefetch
- the number of rows to prefetch when executing
this statement's query.public java.sql.CallableStatement createCallableStatement(java.lang.String str, int noRowsPrefetch)
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.
str
- the CallableStatement instance's SQL statement.noRowPrefetch
- the number of rows to prefetch when executing
this statement's query.public java.sql.PreparedStatement createPreparedStatement(java.lang.String str, int noRowsPrefetch)
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.
str
- the PreparedStatement instance's SQL statement.noRowPrefetch
- the number of rows to prefetch when executing
this statement's query.public int executeCommand(java.lang.String command)
command
- a SQL command.public java.lang.String dumpQueryResult(java.lang.String query, java.lang.String dumpClassName, java.lang.String[] data)
public int getLockingMode()
public void setLockingMode(int mode)
mode
- one of LOCK_PESSIMISTIC, LOCK_OPTIMISTIC or LOCK_NONE.public void addToValidationListeners(ValidationListener entity)
The listener will be notified to perform its own validation when this validation manager is validated.
w
- a validation listener.public void validate()
public void setValidationThreshold(int count)
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.
count
- the new threshold value.public int getValidationThreshold()
public void setPostThreshold(int count)
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.
count
- the new threshold value.public int getPostThreshold()
public boolean isDirty()
true
if the local data and the database differ.public void dumpEntityCaches(java.io.Writer out)
public void showCursorUsage(java.io.Writer out)
protected void doCommit()
protected void doRollback()
public void connect(java.sql.Connection sqlConnection)
public void connect(java.lang.String url)
url
- a database url of the form jdbc:subprotocol:subname.public void connect(java.lang.String url, java.util.Properties info)
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.public void connect(java.lang.String url, java.lang.String user, java.lang.String password)
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.public boolean isConnected()
public void reconnect(boolean force)
forced
- force a reconnect, should usually be falsepublic void disconnect()
public TransactionHandler getTransactionHandler()
public void setTransactionHandler(TransactionHandler txnHandler)
public EntityImpl createEntityInstance(EntityDefImpl entityDef, AttributeList al)
entityDef
- the defintion to to be used to create the instance.al
- an attribute list to be passed to the new instance's
create() method.public EntityImpl createEntityInstance(java.lang.String entityDefName, AttributeList al)
entityDefName
- the name of the defintion to to be used to create the instance.al
- an attribute list to be passed to the new instance's
create() method.public EntityImpl findByPrimaryKey(EntityDefImpl entityDef, Key key)
entityDef
- the defintion to to be used to find the instance.key
- the Primary Key.public EntityImpl findByPrimaryKey(java.lang.String entityDefName, Key key)
entityDefName
- the name of the defintion to to be used to find the instance.key
- the Primary Key.public ViewObject createViewObject(java.lang.String voDefName)
The caller should invoke remove() to dispose of the instance.
voDefName
- the name of the defintion to to be used to create the instance.public ViewObject createViewObjectFromQueryClauses(java.lang.String eoName, java.lang.String selectClause, java.lang.String fromClause, java.lang.String whereClause, java.lang.String orderByClause)
The View Object is constructed from an Entity Object and parts of a SQL statement.
The caller should invoke remove() to dispose of the instance.
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.public ViewObject createViewObjectFromQueryStmt(java.lang.String sqlStatement)
The caller should invoke remove() to dispose of the instance.
sqlStatement
- a SQL statement.public ApplicationModule createApplicationModule(java.lang.String defName)
defName
- the name of the Application Module definition to be used.
If null
a default definition is used.public ViewLink createViewLink(java.lang.String viewLinkDefName, ViewObject master, ViewObject detail)
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.master
or detail
are invalid.viewLinkName
is invalid.viewLinkName
already exists.public ViewLink createViewLinkFromEntityAssocName(java.lang.String entityAssocName, ViewObject master, ViewObject detail)
entityAssocName
- the entity association that the View Link will represent.master
- the link's source.detail
- the link's destination.master
,
detail
, or entityAssocName
are invalid.viewLinkName
is invalid.viewLinkName
already exists.public ViewLink createViewLinkBetweenViewObjects(java.lang.String accessorName, ViewObject master, AttributeDef[] srcAttrs, ViewObject detail, AttributeDef[] destAttrs, java.lang.String assocClause)
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
- master
or detail
are invalid.viewLinkName
or accessorName
are invalid.viewLinkName
or accessorName
already exist.public void addWarning(JboWarning warn)
These warnings may be used for diagnostic purposes and may contain application-specific messages.
a
- warning.public Session getSession()
protected java.sql.Connection getJdbcConnection()
public java.lang.Object createRef(java.lang.String structName, byte[] data)
|
Business Components | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |