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 Fake Delete

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

Overview

Concrete soft-delete implementation that converts DELETE operations into UPDATE statements with configurable deleted-flag columns, and automatically filters out soft-deleted rows in GET queries, provided by the APIJSON ORM framework.

Description

The fake-delete feature on 'AbstractSQLConfig consists of three methods:

  • isFakeDelete(): Returns false by default in the base class. Subclasses override to check ACCESS_FAKE_DELETE_MAP.containsKey(getTable()) && getMethod() == DELETE. Returns true if the table is configured for fake-delete and the operation is DELETE.
  • onFakeDelete(Map<String,Object> map): Returns the map unchanged by default. Subclasses override to set the deleted flag: map.put(deletedKey, deletedValue). The method changes the SQLConfig method from DELETE to PUT internally.
  • Automatic WHERE filtering: In getWhereString(), when the table is in ACCESS_FAKE_DELETE_MAP and the method is GET, a condition deletedKey = notDeletedValue is appended to the WHERE clause, filtering out soft-deleted rows automatically.

The ACCESS_FAKE_DELETE_MAP on AbstractVerifier maps table names to fake-delete configuration: deletedKey (column name), notDeletedValue (value for active rows), deletedValue (value for deleted rows).

Usage

Configure fake-delete by inserting records into the Access table with fake-delete columns. Override isFakeDelete() and onFakeDelete() in a subclass of AbstractSQLConfig to enable.

Code Reference

Source Location

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

Signature

public boolean isFakeDelete()

public Map<String, Object> onFakeDelete(Map<String, Object> map)

Base class defaults:

  • isFakeDelete() returns false
  • onFakeDelete() returns the input map unchanged

Import

import apijson.orm.AbstractSQLConfig;
import apijson.orm.AbstractVerifier;  // for ACCESS_FAKE_DELETE_MAP

I/O Contract

Inputs

Name Type Required Description
table String Yes Table name to check
method RequestMethod Yes HTTP method (DELETE triggers fake-delete)
ACCESS_FAKE_DELETE_MAP Map<String,Map<String,Object>> Yes Fake-delete config

Outputs

Name Type Description
isFakeDelete return boolean Whether to fake-delete this table
onFakeDelete return Map<String,Object> Map with deleted flag set

Usage Examples

Subclass Implementation

public class MySQLConfig extends AbstractSQLConfig<Long, JSONObject, JSONArray> {
    @Override
    public boolean isFakeDelete() {
        Map<String, Object> map = AbstractVerifier.ACCESS_FAKE_DELETE_MAP.get(getTable());
        return map != null && getMethod() == RequestMethod.DELETE;
    }
    
    @Override
    public Map<String, Object> onFakeDelete(Map<String, Object> map) {
        Map<String, Object> config = AbstractVerifier.ACCESS_FAKE_DELETE_MAP.get(getTable());
        if (config != null) {
            map.put((String) config.get("deletedKey"), config.get("deletedValue"));
        }
        return map;
    }
}

Fake-Delete SQL Generation

// DELETE request on fake-delete-enabled table:
// config.setMethod(RequestMethod.DELETE);
// config.setTable("Moment");
// config.putWhere("id", 123, true);

// In gainSQL -> gainDeleteSQL:
// 1. isFakeDelete() returns true
// 2. onFakeDelete() sets deletedKey=deletedValue
// 3. Method changed to PUT
// 4. gainUpdateSQL() generates:
//    UPDATE `Moment` SET `isDeleted` = 1 WHERE `id` = 123
//    (instead of: DELETE FROM `Moment` WHERE `id` = 123)

Automatic GET Filtering

// GET request on fake-delete-enabled table:
// config.setMethod(RequestMethod.GET);
// config.setTable("Moment");

// In getWhereString():
// Appends: WHERE `isDeleted` = 0 AND ... (user conditions)
// Soft-deleted rows are automatically excluded from query results

Related Pages

Implements Principle

Requires Environment

Page Connections

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