Implementation:APIJSON APIJSON Join Class
| Knowledge Sources | |
|---|---|
| Domains | ORM, SQL_Join, Multi_Table_Query |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Concrete configuration class that represents a multi-table join directive parsed from request JSON, holding the join type, target table, alias, ON conditions, and per-join SQL configurations, provided by the APIJSON ORM framework.
Description
The Join class encapsulates all information needed to generate a SQL JOIN clause or execute an application-level (APP) join. It supports 11 join types, each identified by a single character:
- "@" - APP JOIN (application-level batch, no SQL JOIN)
- "<" - LEFT JOIN
- ">" - RIGHT JOIN
- "&" - INNER JOIN
- "*" - CROSS JOIN
- "|" - FULL JOIN
- "!" - OUTER JOIN
- "^" - SIDE JOIN
- "("' - ANTI JOIN
- ")" - FOREIGN JOIN
- "~" - ASOF JOIN
The inner class Join.On represents a single ON condition, with fields for the logical operator (logic), relationship type (relateType: "" = 1:1, "{}" = 1:many, "<>" = many:1), origin column (key), and target table/column (targetTable, targetKey).
The class also holds multiple SQLConfig instances:
- joinConfig - config for the joined table's query
- cacheConfig - config for APP JOIN result caching
- onConfig - config for ON condition resolution
- outerConfig - config for outer join conditions
Usage
Created internally by AbstractParser.onJoinParse() when parsing @join directives or key@ reference keys. Accessed by AbstractSQLConfig during SQL generation and by AbstractSQLExecutor during APP JOIN execution.
Code Reference
Source Location
- Repository: APIJSON
- File: src/main/java/apijson/orm/Join.java
Signature
public class Join<T, M extends Map<String, Object>, L extends List<Object>> {
private String path;
private String joinType; // "@", "<", ">", "&", "*", "|", "!", "^", "(", ")", "~"
private String table; // joined table name
private String alias; // table alias
private int count = 1; // child row count for APP JOIN
private List<On> onList; // ON conditions
private M request;
private M on;
private M outer;
private SQLConfig<T, M, L> joinConfig;
private SQLConfig<T, M, L> cacheConfig;
private SQLConfig<T, M, L> onConfig;
private SQLConfig<T, M, L> outerConfig;
// Type checks
public boolean isAppJoin(); // joinType == "@"
public boolean isLeftJoin(); // joinType == "<"
public boolean isRightJoin(); // joinType == ">"
public boolean isInnerJoin(); // joinType == "&"
public boolean isCrossJoin(); // joinType == "*"
public boolean isSQLJoin(); // not APP JOIN
public boolean isLeftOrRightJoin();
public static class On {
private Logic logic; // & | !
private String relateType; // "", "{}", "<>"
private String key; // origin column
private String targetTable; // target table name
private String targetKey; // target column
private String originKey; // original request key
private String originValue; // original reference path
public void setKeyAndType(String joinType, String table, String originKey) throws Exception
}
}
Import
import apijson.orm.Join;
import apijson.orm.Join.On;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| joinType | String | Yes | Join type character |
| table | String | Yes | Joined table name |
| alias | String | No | Table alias |
| count | int | No | Child row count for APP JOIN (default 1) |
| onList | List<On> | Yes | ON conditions |
Outputs
| Name | Type | Description |
|---|---|---|
| joinConfig | SQLConfig | Config for joined table query |
| cacheConfig | SQLConfig | Config for APP JOIN caching |
| onConfig | SQLConfig | Config for ON condition |
Usage Examples
Join Directive in Request
// Request JSON:
// {
// "[]": {
// "Moment": {
// "@join": "</User:id@",
// "userId@": "/User/id"
// },
// "User": { "id@": "/Moment/userId" }
// }
// }
// Parses to:
// Join {
// joinType: "<", // LEFT JOIN
// table: "User",
// onList: [ On { key: "id", targetTable: "Moment", targetKey: "userId" } ]
// }
// Generated SQL: SELECT ... FROM `Moment` LEFT JOIN `User` ON `User`.`id` = `Moment`.`userId`
APP JOIN (Application-Level)
// Request JSON:
// {
// "[]": {
// "count": 5,
// "Moment": {
// "@join": "@/User/id@",
// "userId@": "/User/id"
// }
// }
// }
// APP JOIN does NOT use SQL JOIN.
// Instead, it:
// 1. Queries Moment: SELECT * FROM Moment LIMIT 5
// 2. Collects userId values: [82001, 82002, 82003]
// 3. Batch queries User: SELECT * FROM User WHERE id IN (82001, 82002, 82003)
// 4. Merges results in application code