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 AbstractSQLExecutor execute

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

Overview

Concrete JDBC executor that takes a populated SQLConfig, generates SQL, executes it against the database, and transforms the ResultSet into JSON maps, provided by the APIJSON ORM framework.

Description

The execute method on AbstractSQLExecutor is the bridge between SQL generation and database execution. It:

  1. Generates the SQL string via config.gainSQL(false)
  2. Determines if the operation is a query (SELECT) or update (POST/PUT/DELETE)
  3. For SELECT: executes a query, iterates the ResultSet, converts each row to a Map<String, Object>, and handles @raw and @json column modifiers
  4. For UPDATE: executes an update, returns the affected row count
  5. Executes APP JOINs (executeAppJoin) for application-level batch joins after the main query
  6. Handles vice-table (JOIN) result merging
  7. Caches generated/executed SQL counts for diagnostics

The method supports both unknownType execution (generic Statement for unknown database types) and typed execution (PreparedStatement for known types with prepared-statement parameter binding).

Usage

Called internally by ObjectParser.executeSQL() after setSQLConfig() has populated the SQLConfig. Override in a subclass to customize JDBC behavior, such as using a connection pool or adding query timeouts.

Code Reference

Source Location

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

Signature

public M execute(@NotNull SQLConfig<T, M, L> config, boolean unknownType) throws Exception

Parameters:

  • config - Fully populated SQLConfig with generated SQL, table, method, database connection info
  • unknownType - Whether the database type is unknown (uses generic Statement instead of PreparedStatement)

Returns: M (Map<String, Object>) - For SELECT: query rows with column data; for INSERT/UPDATE/DELETE: affected count and id

Import

import apijson.orm.AbstractSQLExecutor;

I/O Contract

Inputs

Name Type Required Description
config SQLConfig<T,M,L> Yes Config with SQL string, method, database info
unknownType boolean Yes Whether database type is unknown

Outputs

Name Type Description
return (SELECT) M (Map<String,Object>) Query result with @RAW@LIST and column data
return (UPDATE) M (Map<String,Object>) Result with count (affected rows) and id
generatedSQLCount int Incremented for each SQL generated
executedSQLCount int Incremented for each SQL executed

Usage Examples

Standard Query Execution

// After ObjectParser sets up SQLConfig:
// config.setMethod(RequestMethod.GET);
// config.setTable("Moment");
// config.putWhere("userId", 82001, true);

M result = executor.execute(config, false);
// result: { "id": 1, "userId": 82001, "content": "Hello", ... }

Update Execution

config.setMethod(RequestMethod.PUT);
config.setTable("Comment");
config.putWhere("id", 123, true);
config.putWhereSet("content", "Updated");

M result = executor.execute(config, false);
// result: { "code": 200, "count": 1 }  // 1 row affected

APP JOIN Execution

// After main query, executeAppJoin is called for @-type joins:
// executeAppJoin(config, resultList, childMap, keyMap)
// Executes: SELECT * FROM User WHERE id IN (1, 2, 3)
// Merges child results into main table response maps

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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