Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON AbstractParser Transaction Management

From Leeroopedia
Knowledge Sources
Domains ORM, Transaction_Management, Database
Last Updated 2026-10-11 00:00 GMT

Overview

Concrete transaction lifecycle methods that begin, commit, and rollback database transactions for write operations (POST/PUT/DELETE), ensuring atomicity of multi-table operations within a single APIJSON request, provided by the APIJSON ORM framework.

Description

The onBegin', onCommit, and onRollback methods on AbstractParser manage the database transaction lifecycle:

  • onBegin(): Called before recursive object parsing. Skipped for query methods (GET/HEAD/GETS/HEADS). Calls begin(getTransactionIsolation()) on the SQL executor to start a transaction.
  • onCommit(): Called after successful parsing. Skipped for query methods when TRANSACTION_NONE. Calls commit() on the SQL executor. Logs but does not rethrow on SQLException.
  • onRollback(): Called on exception during parsing. Skipped for query methods. Calls rollback(), and if that fails, attempts rollback(null). Logs all errors.

All write operations (POST/PUT/DELETE) within a single parseResponse call share one transaction. If any table operation fails, the entire transaction is rolled back, ensuring atomicity.

Usage

Called internally by parseResponse() in sequence: onBegin() → onObjectParse() → onCommit() (or onRollback() on exception). Override to customize transaction behavior (e.g., setting savepoints between operations).

Code Reference

Source Location

  • Repository: APIJSON
  • File: src/main/java/apijson/orm/AbstractParser.java

Signature

protected void onBegin()

protected void onCommit()

protected void onRollback()

Import

import apijson.orm.AbstractParser;

I/O Contract

Inputs

Name Type Required Description
requestMethod RequestMethod Yes HTTP method (query methods skip transaction)
transactionIsolation int No JDBC isolation level

Outputs

Name Type Description
return (all) void No return; transaction state changes

Usage Examples

Transaction Flow in parseResponse

// In parseResponse():
sqlExecutor = getSQLExecutor();
onBegin();                    // BEGIN TRANSACTION
try {
    requestObject = onObjectParse(request, null, null, null, false, null);
    onCommit();               // COMMIT
} catch (Exception e) {
    error = e;
    onRollback();             // ROLLBACK
}
// All table operations in the request are atomic

Custom Transaction Isolation

public class MyParser extends AbstractParser<Long, JSONObject, JSONArray> {
    @Override
    protected void onBegin() {
        // Set custom isolation level
        setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        super.onBegin();
    }
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment