Implementation:APIJSON APIJSON Logic Class
| Knowledge Sources | |
|---|---|
| Domains | ORM, SQL_Generation, Query_DSL |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Concrete parser class that extracts logical operators (&, |, !) from request key suffixes and encodes them as OR, AND, or NOT types for SQL WHERE/HAVING clause construction, provided by the APIJSON ORM framework.
Description
The Logic class parses the logical prefix of a request key to determine how the resulting SQL condition should be combined with other conditions. When a key like "&id>"': 10 is encountered, the Logic constructor extracts the & prefix, sets the type to TYPE_AND, and stores the remaining key "id>".
The three logical types:
- TYPE_OR (0) - represented by | prefix, condition combined with OR
- TYPE_AND (1) - represented by & prefix, condition combined with AND
- TYPE_NOT (2) - represented by ! prefix, condition combined with NOT
If no logical prefix is present, the default type is TYPE_OR (0), which means the condition is combined with AND in the WHERE clause (the default connector).
The class provides type-checking methods (isOr(), isAnd(), isNot()) and conversion methods (getChar(), getName()).
= Usage
Created internally by AbstractSQLConfig when parsing WHERE conditions and by Join.On.setKeyAndType() when parsing join ON conditions. Not typically instantiated directly by application code.
Code Reference
Source Location
- Repository: APIJSON
- File: src/main/java/apijson/orm/Logic.java
Signature
public class Logic {
public static final int TYPE_OR = 0;
public static final int TYPE_AND = 1;
public static final int TYPE_NOT = 2;
public Logic(String key); // Parses key prefix for logical operator
public Logic(int type); // Direct type construction
public int getType();
public String getKey(); // Key without the logical prefix
public String getOriginKey(); // Original key with prefix
public String getChar(); // "|", "&", "!"
public String getName(); // "OR", "AND", "NOT"
public boolean isOr();
public boolean isAnd();
public boolean isNot();
public static int getType(String logicChar);
public static int getType(char logicChar);
}
Import
import apijson.orm.Logic;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | String | Yes | , !) |
Outputs
| Name | Type | Description |
|---|---|---|
| type | int | 0=OR, 1=AND, 2=NOT |
| key | String | Key without logical prefix |
Usage Examples
Parsing Logical Prefixes
Logic l1 = new Logic("id"); // type=OR(0), key="id"
Logic l2 = new Logic("&id>"); // type=AND(1), key="id>"
Logic l3 = new Logic("|name~"); // type=OR(0), key="name~"
Logic l4 = new Logic("!id{}"); // type=NOT(2), key="id{}"
l2.isAnd(); // true
l2.getChar(); // "&"
l2.getName(); // "AND"
In WHERE Clause Construction
// Request: { "id": 1, "&name~": "Tom", "!age<": 18 }
// Logic parses each key:
// "id" -> OR (default, combined with AND in WHERE)
// "&name~" -> AND (explicit AND)
// "!age<" -> NOT (NOT condition)
// Generated WHERE: WHERE id = 1 AND name LIKE 'Tom' AND NOT age < 18