You can register callback methods that are invoked just before a transaction is committed. To register a callback method, call the
The following code fragment specifies that when a transaction for the current process commits, a method Customer::commitCallback is to be called for the receiver cust, which is of type Customer.
process.enableTransTraceCallback(Customer::commitCallback, cust, true);
The callback method must have no parameters and no return type.
You can call the enableTransTraceCallback method multiple times, to register additional method callbacks when a transaction commits. Calling the enableTransTraceCallback with a method and receiver combination that has been previously registered is ignored.
Methods are invoked in reverse order of when they were registered; that is, the most recently registered methods are invoked first.
The invoked method should not attempt to commit the transaction. Doing so causes repeated invocations of the method, leading eventually to a kernel stack overflow.
Similarly, the invoked method should not abort the current transaction. Doing so raises a
If an exception occurs within an invoked method and is not dealt with by an exception handler, the transaction is not committed.
The following example of a callback method uses functionality in the
commitCallback(); vars trace : JadeTransactionTrace; index : Integer; totalEntries : Integer; object : Object; operation : Integer; property : Property; value : Any; begin trace := process.getTransactionTraceObject; totalEntries := trace.getEntryCount(); write "============================="; write "Transaction ID: " & trace.tranId.String; write "Started at: " & trace.startTime.String; write "Total traced updates: " & totalEntries.String; foreach index in 1 to totalEntries do write ""; //retrieve the specific entry and write out the details trace.getEntry(index, object, operation, property, value); write "Traced Update: " & index.String; write "Object: " & object.String; write "Operation: " & operation.String & " - " & self.translateTraceOperation(operation); // if the entry is a property update, output that information as well if property <> null then write "Property: " & property.schemaType.name & "::" & property.name; write "Property Value: " & value.String; endif; endforeach; write "============================="; end;
The following output from the commitCallback example callback method is representative.
============================= Transaction ID: 5928 Started at: 18 February 2009, 14:15:40 Total traced updates: 2 Traced Update: 1 Object: Customer/2085.5 Operation: 3 - Object Update Traced Update: 2 Object: Customer/2085.5 Operation: 7 - Manual Set Property Property: Customer::status Property Value: Bankrupt =============================