Skip to content

Embedded DB2 -> Spring JDBC repositories that run the programs' own SQL (#3618) - #3680

Merged
squid-protocol merged 1 commit into
mainfrom
feat/db2-repos-3618
Sep 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feat/db2-repos-3618

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #3618 (epic #3625).

The idea: carry the program's SQL, don't reinvent it

Until now the engine kept each embedded statement's verb, tables, cursor and host variables, but not the statement. A repository method could only guess what the query does. So:

layer change
engine sql_statement_data.statement_text: every statement's text (comments stripped, whitespace collapsed, literals kept). The column is healed into existing DBs; the rehydrator and galaxy_ir read it; a pre-#3618 DB loads None
IR GalaxyIR.db2_tables(): each table (unqualified name, all spellings kept) with its DECLARE … TABLE columns and every statement against it; a cursor carries its OPEN / FETCH / CLOSE lines. In estate.json
Java per table, a <Table>Row data class (DECLAREd columns, SQL→Java types) and a <Table>Repository over NamedParameterJdbcTemplate, one method per embedded statement, running the program's own SQL

SQL handling:

  • host variables become named parameters (:WS-ACCT-ID → :wsAcctId), with indicators dropped;
  • a singleton SELECT … INTO :x, :y loses its INTO list and returns the row (queryForMap; SQLCODE +100 surfaces as EmptyResultDataAccessException);
  • a cursor runs its SELECT (queryForList), and the javadoc lists its OPEN/FETCH/CLOSE lines;
  • INSERT / UPDATE / DELETE / MERGE use update;
  • a positioned WHERE CURRENT OF keeps its text, with a TODO.

Real output (CardDemo COTRTLIC, a forward-browse cursor):

    /** EXEC SQL DECLARE CURSOR at app/app-transaction-type-db2/cbl/COTRTLIC.cbl:338 (COTRTLIC, read access).
     *  The cursor's FETCH at line 1626, FETCH at line 1661, OPEN at line 1943, CLOSE at line 1971.
     *  Parameters: wsEditDescFlag = :WS-EDIT-DESC-FLAG, ..., wsStartKey = :WS-START-KEY, ... */
    public List<Map<String, Object>> cursorCTrTypeForwardL338Cotrtlic(Map<String, ?> params) {
        return jdbc.queryForList("""
            SELECT TR_TYPE ,TR_DESCRIPTION FROM CARDDEMO.TRANSACTION_TYPE WHERE TR_TYPE >= :wsStartKey AND ((:wsEditTypeFlag = '1' AND TR_TYPE = :wsTypeCdFilter) OR (:wsEditTypeFlag <> '1')) AND ... ORDER BY TR_TYPE
            """, params);
    }

Not JPA, on purpose. DECLARE TABLE states no primary key, and an @Entity needs one; inventing a key would be a guess. With a database.engine other than db2, the repository states that the SQL is DB2's and needs review. Each program's service gets its tables' repositories injected.

Results

corpus repositories row classes statements as written positioned (TODO)
CardDemo 2 2 14 0
CBSA 3 3 31 0
GENAPP 7 0 (no DECLAREs in the repo) 33 1

Attributes consumed (consumer audit)

attribute keyed?
table × access per program keyed (DB2 table access)
DECLARE columns / types / nullability keyed (DB2 table columns)
statement text (new) unverified: the key does not read SQL text. Spot-checked on CardDemo's statements (cursor filters, INTO removal, literals intact). A follow-up can add it to the key as #3649 did for refmods

Verified

  • Blast radius (ir_join_diff.py): only programs changes, on the three DB2 corpora (statements gained their text). db2_tables is new.
  • Compile: 6 corpora × 13 configs compile via --scan. preflight.py: all PASS. Full suite: 11,682 passed.
  • Tests: to_jdbc (INTO, indicators, cursor, positioned), SQL→Java types, the join with its cursor use, a pre-Java conversion: embedded DB2 (table access + DCLGEN) -> repositories, dialect per config #3618 DB, and end to end (row class, repository methods and SQL, injection, audit).

🤖 Generated with Claude Code

https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g

…QL (#3618)

Engine: every embedded SQL statement now keeps its text (comments
stripped, whitespace collapsed, literals kept) in a new
sql_statement_data.statement_text column, healed into existing DBs. The
rehydrator and galaxy_ir read it, and an older DB loads None.

IR: GalaxyIR.db2_tables() treats each table (the unqualified name; every
spelling kept) as one unit, joining:
- its EXEC SQL DECLARE ... TABLE (declared_in, line, columns);
- every embedded statement against it (file, line, verb, access,
  cursor, host variables, text);
- for a DECLARE CURSOR, the cursor's OPEN / FETCH / CLOSE lines.
The skeleton's estate.json carries it.

Forge (cobol_to_java_db2_forge.py, registered in SkeletonForges). Each
table a converted program uses becomes:
- <Table>Row (dto.db2): the DECLAREd columns with Java types for their
  SQL types (DECIMAL -> BigDecimal, DATE -> LocalDate, ...), each citing
  type, length, nullability and column number;
- <Table>Repository (repository.db2): a @repository over
  NamedParameterJdbcTemplate with one method per statement, running the
  program's own SQL:
  - host variables become named parameters (:WS-ACCT-ID -> :wsAcctId,
    indicators dropped);
  - a singleton SELECT's INTO list is dropped (queryForMap);
  - a cursor's SELECT is run as queryForList, citing its OPEN / FETCH /
    CLOSE lines; INSERT / UPDATE / DELETE / MERGE -> update;
  - a positioned WHERE CURRENT OF keeps its text with a TODO.
Each program's service gets its tables' repositories injected. Not JPA:
DECLARE TABLE states no primary key, and an invented one would be a
guess. With a database.engine other than db2, the repository says the
SQL is DB2's.

Results:
- CardDemo: 2 tables, 14 statements;
- CBSA: 3 tables, 31 statements, all with row classes;
- GENAPP: 7 tables, 33 statements (no DECLAREs in the repo, so maps
  only), 1 positioned.
- 6 corpora x 13 configs compile via --scan.
- ir_join_diff: only `programs` changes, on the DB2 corpora (the
  statement text).
- preflight all PASS; full suite 11,682 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 77f2776 into main Sep 25, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the feat/db2-repos-3618 branch September 25, 2026 20:46
squid-protocol added a commit that referenced this pull request Sep 25, 2026
Conflict in skeleton_forges: kept both TraceLog wiring and Db2Forge. Db2Forge now
records each statement method (source file:line, "DB2 table access", a TODO when the
engine isn't db2) and each DECLAREd row class. Also untangles the #3617/#3618
comments glued onto one ESTATE_JOINS line by the #3680 conflict resolution.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java conversion: embedded DB2 (table access + DCLGEN) -> repositories, dialect per config

1 participant