Commit Callback (FWD Extension)¶
- Commit Callback (FWD Extension)
This is part of FWD extension. It was developed in Redmine task #11383
Overview¶
The COMMIT callback is an FWD-only extension of the 4GL callback mechanism. It notifies application code after the records created, modified or deleted by a transaction have been physically committed to the database, so that an external consumer (a message broker, a search index, a replication feed) can read the committed state instead of an in-flight, possibly-to-be-undone image.
This addresses the problem that a REPLICATION-WRITE trigger will publish a record to an external consumer while the FWD transaction is still open. From the point of view of the consumer, a SQL query at that specific time against the same row returns the pre-transaction data (or an empty result set, if the record was created during the transaction).
The impact on conversion was kept to a minimum: all changes are runtime-only. The existing SET-CALLBACK-PROCEDURE and SET-CALLBACK 4GL methods were extended to accept an additional value for their first parameter (the event name) and an additional parameter that selects batch mode.
The callback differs from the existing buffer and DATASET callbacks (BEFORE-FILL, ROW-CREATE, AFTER-ROW-FILL, ...) in three ways:
- it is registered on a buffer of a permanent table, as opposed to a temp-table or dataset buffer;
- it is registered per user context, not per buffer instance — any buffer of the table may be used to register it, and the registration outlives that buffer;
- by design, it cannot be raised by the application; it is raised only by the persistence layer, at commit time.
Registration¶
The callback is configured with the existing SET-CALLBACK-PROCEDURE and SET-CALLBACK buffer-handle methods, using the new event name "COMMIT". No conversion changes are required: these handle methods are mapped to the CallbackProcedure interface in rules/convert/methods_attributes.rules, and the event name is an ordinary string argument. New overloaded methods were added to the interface to accommodate the additional parameter for batch mode; the batch size is declared as NumberType, so any numeric 4GL expression (INTEGER, INT64, DECIMAL) is accepted and converted to an integer.
Two delivery modes exist. The mode is selected by the presence and the value of the batch-size argument.
Batch size k |
Delivery |
|---|---|
| absent, unknown, or negative | per-record: one invocation per record, buffer handle and row state signature |
| 0 | batch: one single invocation per table, carrying every affected record |
| 1 or more | batch: ceil(N / k) invocations, each carrying at most k records |
Note that k equal to 1 is still batch mode: the callback is invoked with the JSON signature and a one-element extent, not with a buffer handle. Per-record delivery is requested by omitting the argument, or by passing a negative or unknown value.
Per-record mode (buffer handle)¶
Registering without a batch size — or with a negative or unknown one — selects per-record delivery. The callback is invoked once per committed record and receives a handle to a read-only buffer with that record loaded, together with the row state of the record (created, modified or deleted).
DEFINE VARIABLE hBook AS HANDLE NO-UNDO.
CREATE BUFFER hBook FOR TABLE "book".
/* context defaults to THIS-PROCEDURE */
hBook:SET-CALLBACK-PROCEDURE("COMMIT", "book-committed").
/* explicit context: the internal procedure is looked up in hCtx */
hBook:SET-CALLBACK-PROCEDURE("COMMIT", "book-committed", hCtx).
Batch mode (longchar in JSON format)¶
Registering with a batch size of 0 or more selects batch delivery. The affected records of the table are JSON-serialized individually and passed as a LONGCHAR EXTENT parameter. A positive value causes the callback to receive at most that many records per invocation, so the callback is invoked ceil(N / k) times per table, where N is the number of affected records of that table and k the batch size. A batch size of 0 requests a single invocation carrying all tracked records of the table.
DEFINE VARIABLE hCust AS HANDLE NO-UNDO.
CREATE BUFFER hCust FOR TABLE "customer".
/* at most 500 customer records per invocation */
hCust:SET-CALLBACK-PROCEDURE("COMMIT", "customer-committed", 500).
/* all affected customer records in one single invocation */
hCust:SET-CALLBACK-PROCEDURE("COMMIT", "customer-committed", 0).
Batching bounds the number of records materialized in memory at once, and bounds the size of the LONGCHAR array handed to the 4GL. A batch size of 0 gives up both bounds in exchange for a single notification per table.
Class methods as targets¶
SET-CALLBACK accepts an object reference, so a method of a class instance can serve as the callback target. Both delivery modes are available.
/* per-record mode, method of the current class instance */
hBook:SET-CALLBACK("COMMIT", "BookCommitted", THIS-OBJECT).
/* batch mode, method of the current class instance */
hBook:SET-CALLBACK("COMMIT", "BookCommitted", THIS-OBJECT, 500).
/* batch mode, internal procedure in an explicit procedure context */
hBook:SET-CALLBACK("COMMIT", "book-committed", hCtx, 500).
When the context argument is unknown, the target defaults to THIS-OBJECT if the registration happens inside a class, and to THIS-PROCEDURE otherwise.
Argument summary¶
| Form | Optional arguments | Mode |
|---|---|---|
hBuf:SET-CALLBACK-PROCEDURE("COMMIT", routine) |
absent | per-record |
hBuf:SET-CALLBACK-PROCEDURE("COMMIT", routine, hCtx) |
HANDLE |
per-record |
hBuf:SET-CALLBACK-PROCEDURE("COMMIT", routine, k) |
numeric | per k, see above |
hBuf:SET-CALLBACK("COMMIT", method, THIS-OBJECT) |
Progress.Lang.Object |
per-record |
hBuf:SET-CALLBACK("COMMIT", method, THIS-OBJECT, k) |
Progress.Lang.Object + numeric |
per k, see above |
hBuf:SET-CALLBACK("COMMIT", routine, hCtx, k) |
HANDLE + numeric |
per k, see above |
The third argument is overloaded on type: a HANDLE is the execution context, an object reference is the owning class instance, and a numeric value is the batch size.
Conversion notes¶
The two methods are emitted as instance calls on the CallbackProcedure interface, so the number and the types of the arguments are resolved when the generated Java is compiled; no rule had to be taught about the new event name or the new argument. One detail is worth knowing when writing the 4GL: com/goldencode/p2j/convert/SignatureHelper.java describes SET-CALLBACK-PROCEDURE as two mandatory parameters out of three, the third typed as HANDLE, and SET-CALLBACK likewise with the third typed as BaseDataType. Those descriptors are consulted only when an argument's type must be inferred from its context, so a literal or a typed numeric variable in the batch-size position converts correctly, as does the fourth argument of the SET-CALLBACK forms. Prefer a literal or a typed numeric variable there, rather than an expression whose type conversion has to infer. Every combination the conversion emits for the COMMIT forms has a matching overload: a literal or a CHARACTER expression for the event and for the routine, an object or a HANDLE context, and a literal or a numeric expression for the batch size.
Removing a callback¶
Passing the empty string as the routine name removes the registration for that table.
hBook:SET-CALLBACK-PROCEDURE("COMMIT", "").
Passing the unknown value (?) as the routine name is a no-op and returns TRUE. Registering a second callback for the same table replaces the first: there is exactly one COMMIT callback per table per user context.
Callback signatures¶
The signature of the target routine is determined by the delivery mode. A mismatch is not detected at registration time, only when the event is raised. Even then it does not disturb the committing code: the failure is logged once as a warning and the remaining records of that table are skipped. See Failures inside the callback below.
Per-record mode¶
PROCEDURE book-committed:
DEFINE INPUT PARAMETER hBuf AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER row-state AS INTEGER NO-UNDO.
/* hBuf is a read-only buffer of 'book' with one committed record loaded */
CASE row-state:
WHEN ROW-CREATED THEN MESSAGE "created:" hBuf:BUFFER-FIELD("title"):BUFFER-VALUE.
WHEN ROW-MODIFIED THEN MESSAGE "modified:" hBuf:BUFFER-FIELD("title"):BUFFER-VALUE.
WHEN ROW-DELETED THEN MESSAGE "deleted:" hBuf:BUFFER-FIELD("title"):BUFFER-VALUE.
END CASE.
END PROCEDURE.
The second parameter is the row state of the record, using the same numeric values as the ROW-STATE attribute: ROW-CREATED (3), ROW-MODIFIED (2) or ROW-DELETED (1). ROW-UNMODIFIED is never passed.
For a created or modified record, the buffer holds the record as it is read from the database after the commit, that is, its committed state. A deleted record no longer exists in the database: the buffer holds a detached copy rebuilt from the data captured when the record was deleted, with the original ROWID and the last values of its fields. See Deleted records below.
The buffer passed in is created by the runtime, is marked read-only, and is released after the last record of the table has been reported. The temporary record is dropped from the buffer between invocations. While the callback runs, SELF is the context procedure; when the target is a class method, SELF is the buffer.
Note: the row-state parameter was added together with the support for deleted records. A routine written for the earlier signature, with the buffer handle as its only parameter, no longer matches: the mismatch is logged as a warning when the event is raised, and no record of that table is delivered.
Batch mode¶
PROCEDURE customer-committed:
DEFINE INPUT PARAMETER table-name AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER jsons AS LONGCHAR EXTENT NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO EXTENT(jsons):
RUN publish-to-broker (INPUT table-name, INPUT jsons[i]).
END.
END PROCEDURE.
The payload parameter must be declared as an indeterminate EXTENT; the runtime sizes it to the number of records in the current batch, which is at most the configured batch size, or the full set when the batch size is 0. LONGCHAR is required — a serialized record can exceed the 32K limit of CHARACTER (see #11383-34).
The batch signature carries no separate row-state parameter: the row state of each record is written into its JSON document, as the _rowstate property (see JSON encoding below). Within one invocation, the created and modified records come first, followed by the deleted ones.
The table name is passed as the first parameter so that one generic callback can serve several tables. The same routine may be registered for book and for customer and dispatch on table-name.
JSON encoding¶
Each record is serialized to a single-line JSON object. The _rowid pseudo-field is emitted first, followed by the _rowstate pseudo-field, then by every field of the table in DMO property order, keyed by its legacy (4GL) name.
{"_rowid":"0x0000000000000406", "_rowstate":"CREATED", "book-id":1001, "title":"Dune", "author":"Frank Herbert", "price":24.5, "published":"1965-06-01", "in-stock":true, "tags":["scifi","classic",null]}
This format was chosen for its flexibility:
- one record is one self-contained JSON document, shorter and cheaper to parse than a single document wrapping the whole set, and the PK — which uniquely identifies a record in any table — is intentionally the first node encountered, followed by the kind of change;
- if the set of records has to be forwarded to a public API and one call per record is expensive, the individual documents can simply be concatenated into a JSON array and sent as a single request, where the consumer supports such a syntax.
Value mapping:
| 4GL type | JSON |
|---|---|
INTEGER, INT64 |
number |
DECIMAL |
number, always with a fractional part (24.0, not 24) |
CHARACTER, LONGCHAR |
string |
LOGICAL |
true / false |
DATE, DATETIME, DATETIME-TZ |
ISO-8601 string |
RAW, BLOB |
base64 string |
| unknown value | null |
EXTENT field |
JSON array, one element per extent slot |
Notes on the encoding:
_rowidis emitted as a string in0x%016xform (16 hex digits,0xprefix). This deviates from the 4GL JSON encoding of theROWIDdata type and is deliberate — it keeps the value usable as an opaque key on the consumer side;_rowstateis one of the strings"CREATED","MODIFIED"or"DELETED": the names of the 4GL row-state constants, without theirROW-prefix;- a deleted record is serialized from the data captured when it was deleted, so its fields carry the last values it had. If that data is not available, only the two pseudo-fields are written, for example
{"_rowid":"0x0000000000000407", "_rowstate":"DELETED"}. The fields are omitted, rather than written with their initial values, so that they cannot be mistaken for real data; Stringvalues are escaped per RFC 8259. The common control characters use their compact escapes (\t,\n,\r,\b); every other control character is emitted in\u00XXform.
Scalar values are produced by the same code path as the native 4GL JSON support, so the output is consistent with WRITE-JSON for the field types listed above.
When the event is raised¶
The event is raised by the persistence layer immediately after the JDBC COMMIT of the session's connection succeeds, and before the transaction bookkeeping is torn down. The callback therefore runs after the database commit, while the 4GL transaction is still being completed. The records it reports are durable, and a query issued from the callback (or by an external consumer it notifies) sees them; equally, a record reported as deleted is no longer found by such a query. Because the commit is still in progress, no COMMIT callback can be registered from inside a callback (see Writing a callback below).
Only changes that are still in effect at the moment of the commit are reported:
- records created, modified or deleted inside the transaction are collected as they are flushed to the database or deleted from it;
- records collected inside a sub-transaction that is rolled back are discarded, so an
UNDO-ed block reports nothing; - records collected inside a sub-transaction that ends normally are rolled up into the enclosing block;
- a full transaction rollback discards everything collected and the event is not raised.
Whether the transaction commits or rolls back, the collected data is released at the end of it, leaving the structure ready for the next transaction.
A record changed several times inside one transaction is reported once, with the row state that sums up its changes:
| Changes to one record inside one transaction | Reported |
|---|---|
| created, then modified any number of times | once, as created |
| modified any number of times | once, as modified |
| modified, then deleted | once, as deleted, with the last values of its fields |
| created, then deleted | not reported: the record never existed outside the transaction |
| deleted, then a record with the same key created again | twice: the old record as deleted and the new one as created (they have different @ROWID@s) |
| changed inside a block that is undone | as if the change had never happened |
The order in which the records are reported is not part of the contract and should not be relied upon. Currently, in per-record mode, the records are reported in ascending ROWID order. In batch mode, the batches are formed in ascending ROWID order, but inside an invocation the created and modified records come first, in no particular order, followed by the deleted ones.
Collection is armed at the start of the transaction from the set of tables that have a callback registered at that moment. A callback cannot be registered while a transaction is active, even if no records were touched yet.
Deleted records¶
When the event is raised, a deleted record is already gone from the database, so it cannot be read back like the created and modified ones. Its data is captured instead at the moment it is deleted, inside the transaction:
- the data is captured only for tables that have a
COMMITcallback registered; deleting records of other tables costs nothing extra; - for a complete record, the captured data is a copy of the record as it is in memory at the moment of the delete, including the changes made to it earlier in the same transaction;
- an incomplete record (one read with a
FIELDSorEXCEPToption) is first re-read in full from the database, where the row is still present and locked by the current session; the record in the application's buffer is not changed; - a record that was created but not yet flushed to the database leaves no trace: as far as the database is concerned, it never existed.
When the event is raised, the captured data is turned into a detached record which carries the original primary key. That record is never attached to a session and cannot be saved; it is only loaded into the read-only callback buffer, or serialized to JSON.
If the data could not be captured (an incomplete record that could not be re-read), the record is still reported as deleted. In per-record mode the fields of the buffer hold their initial values; in batch mode only _rowid and _rowstate are written.
The captured data is held in memory until the end of the transaction. A transaction that deletes a large number of records of a monitored table keeps the data of all of them until it commits or rolls back. Batching bounds the size of each invocation, not this memory.
Performance cost. Reporting deleted records is the price the 4GL program pays for monitoring a table. Each deleted record of a monitored table has to be captured on its own, so a mass delete such as FOR EACH ... EXCLUSIVE-LOCK: DELETE ... cannot use FWD's fast bulk-delete path for that table. In a measurement on PostgreSQL, deleting 100,000 rows in one transaction took 8.5 s without a callback and about 150 s with one; creating or modifying rows showed no measurable cost. Tables that are not monitored are not affected. This may be optimized later.
Introspection¶
| Method | Behaviour for "COMMIT" |
|---|---|
hBuf:GET-CALLBACK-PROC-NAME("COMMIT") |
the registered routine name, or the unknown value if none |
hBuf:GET-CALLBACK-PROC-CONTEXT("COMMIT") |
the context procedure handle; an invalid handle if none, or if the target is a method of an object |
hBuf:APPLY-CALLBACK("COMMIT") |
always FALSE — see below |
APPLY-CALLBACK is deliberately a no-op for this event. The event's contract is "these records are committed"; raising it by hand, either mid-transaction (where the records' fate is undecided) or outside a transaction (where there is nothing to commit), would violate that contract.
Writing a callback¶
The COMMIT callback was designed primarily to communicate with external applications: writing to a log file, a quick write to another database, sending an HTTP request or a message to a broker. It runs inside the commit of the application's transaction, so it must be as fast and as silent as possible, and interfere as little as possible with the rest of the program. The 4GL programmer using this extension should keep in mind that:
- the callback should do the minimum: hand the records over (to a file, a queue, another system) and return. Slow work inside the callback delays the completion of every commit of the monitored tables;
- a callback cannot set callbacks: while it runs, the commit is still in progress, so
SET-CALLBACKandSET-CALLBACK-PROCEDUREforCOMMIT, for its own table or any other, returnFALSEwith error-100and change nothing; - changes the callback makes to the database run in their own transaction and are committed. A change to the table being reported is not reported again: there is no re-entry. Whether a change to another monitored table is reported is not defined. Avoid writing to monitored tables from a callback;
- the callback cannot affect the program that committed. Its failures are logged and swallowed (see the next section), so it should not be used to validate or veto anything: the data is already committed when it runs.
Failures inside the callback¶
The callback cannot affect the 4GL program that committed. When the callback runs, the records are already durable in the database. A condition raised at that point is too late to change anything, and the committing code is not in a position to handle it. So every failure is logged as a warning in the server log, naming the table, the routine and the error, and is then swallowed. The committing code never sees a condition, and its ERROR-STATUS is left as it was.
When a routine raises a condition for many records of one commit, only the first occurrence is logged in full; the following ones are counted and reported in one summary line at the end of the delivery.
| Failure | Handling |
|---|---|
the routine raises ERROR (for example RETURN ERROR or UNDO, THROW) |
logged, swallowed; delivery continues with the next record or batch of the table, then with the other tables, as if nothing happened |
the routine raises STOP |
same as ERROR |
the routine cannot be invoked: not found, wrong signature, a FUNCTION instead of a procedure, a non-public method, an invalid or deleted context |
logged once; the remaining records of that table are skipped, because every invocation would fail the same way; the other tables are still delivered |
| a created or modified record cannot be re-read, or a deleted one cannot be rebuilt | logged; that record is skipped, delivery continues |
In practice:
- Records already handed to the routine before it failed stay delivered. The routine must be prepared for a partial delivery, typically by making its own work idempotent.
- Handling a failure is the routine's job. Use
CATCHblocks orNO-ERRORinside the routine where a failure matters, for example to queue the record for a later retry. - A
STOPthat comes from outside the routine while it runs, such as a user interrupt or aSTOP-AFTERtimeout, is swallowed as well. Keep the routines short: hand the records to a queue rather than doing slow work inside the callback.
Restrictions and error conditions¶
- Permanent tables only. Registering on a temp-table buffer (whether it is a dataset member or not) or on a meta-schema buffer returns
FALSEand does nothing, with everySET-CALLBACKandSET-CALLBACK-PROCEDUREform. No error is raised or recorded inERROR-STATUS; a warning is written to the server log. Temp-tables are not transactional in the sense this event describes; - Permanent, non-temporary databases only. Collection is armed only for a session whose database is a primary permanent database;
- No registration inside a transaction. Attempting to register while a transaction is active returns
FALSEand reports error-100("Cannot set a COMMIT callback while a transaction is in progress."), because the set of monitored tables is fixed when the transaction starts. This holds whichever buffer of the table is used, including one not yet used in the transaction. The error follows the usual 4GL rules: withNO-ERRORit is only recorded inERROR-STATUS; inside a block with aCATCH, or underBLOCK-LEVEL(or, in the routine's top-level block,ROUTINE-LEVEL)ON ERROR UNDO, THROW, it is raised as anERRORthat can be caught; otherwise the message is displayed and execution continues. Register during application start-up, or at least outside any transaction block; - Not on dataset or query handles.
COMMITis a buffer event.DATASETandQUERYhandles report it like any unknown event name, as OpenEdge does:FALSEwith error 11950 ("Argument COMMIT to CALLBACK method must be a valid buffer or dataset event name") or 12352 ("... must be a valid query event name such as OFF-END"); - Per user context. The registry is context-local. A registration made by one session is not visible to another, and it is discarded when the context ends;
- One callback per table. Re-registering replaces the previous entry. A single callback can serve several tables if it is written generically enough (see the example below), but a callback can equally be written for one specific table. The latter is usually cleaner than testing the table name at the moment the callback is fired;
- Failures inside the callback are logged and swallowed.
ERRORandSTOPraised by the routine never reach the committing code, and the commit itself is already durable. See Failures inside the callback above; - Deleted records are kept in memory. The data of every deleted record of a monitored table is held until the end of the transaction. See Deleted records above.
Performance¶
The figures below come from the performance driver of the test suite, run against PostgreSQL on a development machine. The table had its triggers disabled, and the callback only counted the rows it received. Times are in seconds, for the whole workload. They show orders of magnitude, not guarantees: single runs of the large modify and delete workloads varied noticeably.
| Workload | No callback | Per-record mode | Batch mode (size 0) |
|---|---|---|---|
| 10,000 transactions, one created record each | 3.0 | 4.7 | 7.7 |
| 1 transaction, 100,000 created records | 28.1 | 27.7 | 28.8 |
| 1 transaction, 100,000 modified records | 217.1 | 221.3 | 219.1 |
| 1 transaction, 100,000 deleted records | 8.5 | 155.1 | 156.9 |
| 1 transaction with 10,000 nested sub-transactions | 3.4 | 3.6 | 3.4 |
- Created and modified records cost practically nothing extra in a large transaction. The time of a large modify is spent by the update itself, with or without a callback.
- Deleted records are where the callback costs. Each deleted record of a monitored table is captured individually, so a mass delete cannot take the fast bulk-delete path (see Deleted records above).
- Many small transactions pay a fixed cost per transaction that reports something: about 0.2 ms in per-record mode and 0.5 ms in batch mode, for the delivery set-up.
- Bookkeeping is negligible. A transaction that changes no monitored record costs next to nothing (10,000 such transactions took about 0.5 s with a callback configured), and nested sub-transactions cost the same with or without a callback.
The batch size only matters when it is very small. For 100,000 created records in one transaction:
| Batch size | 1 | 100 | 1000 | 0 (all in one call) |
|---|---|---|---|---|
| Seconds | 63 to 78 | 28 to 30 | 28 to 29 | 27 to 28 |
The work done inside the callback adds to the commit time of every monitored transaction. In the measurements, an empty routine and one that counts the records cost the same, while a routine that stored each record in a temp-table and parsed its JSON added 1 to 2 s per 10,000 records. For high volumes, prefer batch mode with a batch size of 100 or more, and keep the routine light (see Writing a callback above).
Examples¶
Publishing two tables through one generic callback¶
DEFINE VARIABLE hBook AS HANDLE NO-UNDO.
DEFINE VARIABLE hCust AS HANDLE NO-UNDO.
CREATE BUFFER hBook FOR TABLE "book".
CREATE BUFFER hCust FOR TABLE "customer".
hBook:SET-CALLBACK-PROCEDURE("COMMIT", "record-committed", 200).
hCust:SET-CALLBACK-PROCEDURE("COMMIT", "record-committed", 200).
/* the buffers are only needed for registration; the callbacks survive them */
DELETE OBJECT hBook.
DELETE OBJECT hCust.
PROCEDURE record-committed:
DEFINE INPUT PARAMETER table-name AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER jsons AS LONGCHAR EXTENT NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO EXTENT(jsons):
RUN publish-to-broker (INPUT table-name, INPUT jsons[i]).
END.
END PROCEDURE.
A transaction that inserts 3 books and updates 1 customer results in one call with table-name = "book" and EXTENT(jsons) = 3, and one call with table-name = "customer" and EXTENT(jsons) = 1. Registering with a batch size of 0 instead of 200 gives exactly the same two calls, whatever the number of affected records. If the same transaction also deletes 2 existing books, the "book" call carries 5 elements: the 3 created records, followed by the 2 deleted ones, each one tagged by its _rowstate property.
Per-record mode with a static buffer¶
The registration needs any buffer of the table, including a static one. The callback appends one line per record to a log file, and returns: it neither waits for the user nor does slow work (see Writing a callback above).
DEFINE BUFFER b-book FOR book.
DEFINE STREAM s-log.
BUFFER b-book:SET-CALLBACK-PROCEDURE("COMMIT", "book-committed").
PROCEDURE book-committed:
DEFINE INPUT PARAMETER hBuf AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER row-state AS INTEGER NO-UNDO.
OUTPUT STREAM s-log TO VALUE("book-commits.log") APPEND.
PUT STREAM s-log UNFORMATTED
"book " (IF row-state = ROW-DELETED THEN "deleted" ELSE "committed")
" rowid: " STRING(hBuf:ROWID)
" title: " hBuf:BUFFER-FIELD("title"):BUFFER-VALUE SKIP.
OUTPUT STREAM s-log CLOSE.
END PROCEDURE.
Sub-transaction rollback¶
DO TRANSACTION:
CREATE book.
ASSIGN book.title = "Kept".
DO TRANSACTION ON ERROR UNDO, LEAVE:
CREATE book.
ASSIGN book.title = "Discarded".
UNDO, LEAVE.
END.
END.
The callback is invoked for the "Kept" record only. The record created in the inner block never reaches the commit, so it is not reported.
Deleting records¶
DO TRANSACTION:
FIND FIRST book WHERE book.book-id = 1001 EXCLUSIVE-LOCK.
ASSIGN book.price = 19.99.
DELETE book.
CREATE book.
ASSIGN book.book-id = 1002
book.title = "Temporary".
DELETE book.
END.
The callback is invoked once, for book 1001, as deleted. In per-record mode the buffer shows a price of 19.99, the value the record had when it was deleted; in batch mode the JSON document carries "_rowstate":"DELETED" and the same value. Book 1002 is created and deleted inside the transaction, so it is not reported.
Turning the notification off¶
DEFINE BUFFER b-cust FOR customer.
/* stop monitoring 'customer'; 'book' registration, if any, is unaffected */
BUFFER b-cust:SET-CALLBACK-PROCEDURE("COMMIT", "").
© 2026 Golden Code Development Corporation. ALL RIGHTS RESERVED.