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 executeAppJoin

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

Overview

Concrete application-level join executor that fetches child table rows via IN-based batch queries after the main table query, merging results without SQL JOIN clauses, provided by the APIJSON ORM framework.

Description

The executeAppJoin' method on AbstractSQLExecutor implements the APP JOIN strategy. After the main table query completes, for each join with isAppJoin() == true (joinType "@"):

  1. Collects the target key values from all main table result rows (e.g., all userId values)
  2. Replaces the join's origin key with an IN clause: WHERE id IN (collected_values)
  3. Executes a separate query for the joined table
  4. For one-to-many joins, adds row_number() OVER (PARTITION BY ...) to limit child rows per parent
  5. Merges child results into the main table response maps

This avoids the row multiplication problem of SQL JOINs for one-to-many relationships. Instead of N × M rows from a SQL JOIN, the main query returns N rows and the child query returns M rows, merged in code.

Usage

Called internally by AbstractSQLExecutor.execute() after the main query results are available. Triggered when the request contains "@join": "@/Table/key@'' directives.

Code Reference

Source Location

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

Signature

protected void executeAppJoin(
    SQLConfig<T, M, L> config,
    List<M> resultList,
    Map<String, List<M>> childMap,
    Map<String, String> keyMap
) throws Exception

Parameters:

  • config - Main table SQLConfig with joinList
  • resultList - Main table query results (list of row maps)
  • childMap - Child results map to populate
  • keyMap - Key mapping for result merging

Import

import apijson.orm.AbstractSQLExecutor;

I/O Contract

Inputs

Name Type Required Description
config SQLConfig<T,M,L> Yes Main table config with joinList
resultList List<M> Yes Main table query results
childMap Map<String,List<M>> Yes Child results map (populated by this method)
keyMap Map<String,String> Yes Key mapping for merging

Outputs

Name Type Description
childMap Map<String,List<M>> Populated with child table rows

Usage Examples

APP JOIN Execution Flow

// Request: {
//   "[]": {
//     "count": 3,
//     "Moment": { "userId@": "/User/id" },
//     "User": { "id@": "@/Moment/userId" }
//   }
// }

// 1. Main query: SELECT * FROM Moment LIMIT 3
//    resultList: [{ id:1, userId:82001 }, { id:2, userId:82002 }, { id:3, userId:82001 }]

// 2. executeAppJoin collects userId values: [82001, 82002]
//    (deduplicated)

// 3. Child query: SELECT * FROM User WHERE id IN (82001, 82002)
//    childResults: [{ id:82001, name:"Tom" }, { id:82002, name:"Jerry" }]

// 4. Merge: each Moment gets its User nested:
//    [
//      { Moment: { id:1, userId:82001 }, User: { id:82001, name:"Tom" } },
//      { Moment: { id:2, userId:82002 }, User: { id:82002, name:"Jerry" } },
//      { Moment: { id:3, userId:82001 }, User: { id:82001, name:"Tom" } }
//    ]

Related Pages

Implements Principle

Requires Environment

Page Connections

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