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 AbstractSQLConfig Where Clause Construction

From Leeroopedia
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:

  1. Operator suffix parsing: Extracts the SQL operator from key suffixes (>, <, >=, <=, !=, {}, }{, ~, $, <> etc.)
  2. Logical prefix parsing: Uses Logic to determine AND/OR/NOT for each condition
  3. Combine expressions: Parses @combine string like "(name~ | age>) & status" into a structured AND/OR/NOT tree
  4. Dialect-specific quoting: Uses getQuote() to wrap column names with the correct quote character
  5. Prepared-statement values: When isPrepared == true, replaces values with ? and adds to preparedValueList
  6. 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"]

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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