Learning
Documentation
Community
Open Exchange
Global Masters
Home / Class Reference / %SYS namespace / %Library.Transaction
Private  Storage   

%Library.Transaction


%Library.Transaction is a system class that allows an application to include local database activity with remote activity into a single transaction. Creating an instance of this performs a TSTART. If the transaction object is destroyed before committing, it is automatically rolled back. A transaction object can be used multiple times. A new transaction can be initiated simply by calling Start(). Start() will not start a new transaction if one is already active. The Transaction maintains a list of top-level objects that are part of the transaction set. It is the developer's job to add objects to this set. Calling Commit() on the transaction does the following: - We call %Save() on each object in the transaction set - If all Saves succeed, then we will call an additional Commit method for each connection object. TODO: We should try to make use of XA (2 phase) logic either automatically or via a setting in the transaction object. The tricky part here is that it should be possible to control an XA transaction among N data sources even if ONE of the sources does not support XA!

Inventory


Parameters Properties Methods Queries Indices ForeignKeys Triggers
3 8


Summary


Properties
debug

Methods
%%OIDGet %AddToSaveSet %BindExport %BuildObjectGraph
%ClassIsLatestVersion %ClassName %Close %ConstructClone
%DispatchClassMethod %DispatchGetModified %DispatchGetProperty %DispatchMethod
%DispatchSetModified %DispatchSetMultidimProperty %DispatchSetProperty %Extends
%GetParameter %IncrementCount %IsA %IsModified
%New %NormalizeObject %ObjectModified %OriginalNamespace
%PackageName %RemoveFromSaveSet %SerializeObject %SetModified
%ValidateObject Commit IncludeObject RemoveAllObjects
RemoveObject Rollback Start


Properties


• property debug as %Boolean [ InitialExpression = 0 ];
• property object as %RegisteredObject [ Private,MultiDimensional ];
• property state as %String(DISPLAYLIST=",No Tran,In Tran,Committed,Rolled back",VALUELIST=",0,1,2,3") [ Private,InitialExpression = "0" ];

Methods


• private method %OnClose() as %Status
This callback method is invoked by the %Close method to provide notification that the current object is being closed.

The return value of this method is ignored.

Closing a transaction object that has an active transaction will automatically roll back the transaction.

• private method %OnNew(initvalue As %RawString) as %Status
This callback method is invoked by the %New method to provide notification that a new instance of an object is being created.

If this method returns an error then the object will not be created.

It is passed the arguments provided in the %New call. When customizing this method, override the arguments with whatever variables and types you expect to receive from %New(). For example, if you're going to call %New, passing 2 arguments, %OnNew's signature could be:

Method %OnNew(dob as %Date = "", name as %Name = "") as %Status

A new instance of %Transaction will automatically start a transaction.

• method Commit() as %Status
Commit the current transaction. If the transaction is not active then an error is returned and no work is done. If the transaction encounters an error during commit then it is rolled back and the error returned.
• method IncludeObject(pObject As %RegisteredObject) as %Status
Include the pObject in the current transaction set.
• method RemoveAllObjects() as %Status
Remove the pObject from the current transaction set.
• method RemoveObject(pObject As %RegisteredObject) as %Status
Remove the pObject from the current transaction set.
• method Rollback() as %Status
Roll back the current transaction if the transaction is active. If the transaction is not active or if an error occurs during rollback then an error is returned.
• method Start() as %Integer
Start a new transaction if one is not already active.