Implementation:APIJSON APIJSON AbstractSQLConfig Where Clause Construction
| Knowledge Sources | |
|---|---|
| Domains | ORM, SQL_Generation, Query_DSL |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Concrete SQL WHERE clause builder that parses key-suffix operators, logical prefixes, and @combine expressions to generate dialect-specific WHERE strings with prepared-statement support, provided by the APIJSON ORM framework.
Description
The WHERE clause construction methods on 'AbstractSQLConfig transform the request's key-value conditions into a SQL WHERE clause. The main methods are:
- getWhere() - Returns the raw Map<String, Object> of WHERE conditions
- getWhereString(boolean hasPrefix, RequestMethod method, Map where, String combine, List<Join> joinList, boolean verifyName) - Generates the WHERE clause string
- parseCombineExpression(...) - Parses @combine expressions for complex AND/OR/NOT grouping with parentheses
The method handles:
- Operator suffix parsing: Extracts the SQL operator from key suffixes (>, <, >=, <=, !=, {}, }{, ~, $, <> etc.)
- Logical prefix parsing: Uses Logic to determine AND/OR/NOT for each condition
- Combine expressions: Parses @combine string like "(name~ | age>) & status" into a structured AND/OR/NOT tree
- Dialect-specific quoting: Uses getQuote() to wrap column names with the correct quote character
- Prepared-statement values: When isPrepared == true, replaces values with ? and adds to preparedValueList
- Join WHERE merging: Calls concatJoinWhereString() to merge join table conditions
Usage
Called internally by gainSelectSQL(), gainUpdateSQL(), gainDeleteSQL() during SQL generation. Not typically called directly.
Code Reference
Source Location
- Repository: APIJSON
- File: src/main/java/apijson/orm/AbstractSQLConfig.java
Signature
public Map<String, Object> getWhere()
public String getWhereString(boolean hasPrefix, RequestMethod method,
Map<String, Object> where, String combine,
List<Join<T, M, L>> joinList, boolean verifyName) throws Exception
// Also: gainWhereString(boolean hasPrefix) - convenience wrapper
Parameters:
- hasPrefix - Whether to prepend " WHERE" to the result
- method - HTTP method (determines if conditions are required)
- where - Map of key-value conditions
- combine - @combine expression string for grouping
- joinList - Join list for merge with join conditions
- verifyName - Whether to validate column names
Returns: String - WHERE clause string (e.g., " WHERE \"id\" > 10 AND \"name\" LIKE 'Tom'")
Import
import apijson.orm.AbstractSQLConfig;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| where | Map<String,Object> | Yes | Key-value conditions |
| combine | String | No | @combine expression for AND/OR/NOT grouping |
| joinList | List<Join> | No | Joins for WHERE merging |
| isPrepared | boolean | Yes | Whether using prepared statements |
| quote | String | Yes | Dialect-specific quote character |
Outputs
| Name | Type | Description |
|---|---|---|
| return | String | WHERE clause string |
| preparedValueList | List<Object> | Updated with condition values |
Usage Examples
Simple Conditions
// Request: { "id": 1, "name": "Tom", "age>": 18 }
// getWhere() returns: { "id": 1, "name": "Tom", "age>": 18 }
// getWhereString(true, GET, where, null, null, true)
// Returns: WHERE `id` = 1 AND `name` = 'Tom' AND `age` > 18
IN and LIKE
// Request: { "id{}": [1, 2, 3], "name~": "Tom" }
// WHERE `id` IN (1, 2, 3) AND `name` LIKE 'Tom'
@combine Expression
// Request: {
// "name~": "Tom",
// "age>": 18,
// "status": 1,
// "@combine": "(name~ | age>) & status"
// }
// WHERE (name LIKE 'Tom' OR age > 18) AND status = 1
Prepared Statement
// isPrepared = true:
// WHERE `id` > ? AND `name` LIKE ?
// preparedValueList: [1, "Tom"]