# Business Logic — JBSbatKKAdHenkoErrOutput.terminal() [10 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdHenkoErrOutput` |
| Layer | Service (Batch) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKAdHenkoErrOutput.terminal()

This method serves as the **batch termination handler** for the `JBSbatKKAdHenkoErrOutput` service, which is responsible for outputting unprocessable data from the address modification worklist (変更住所一覧ワーク) — specifically records that failed during municipal merger or address name change processing (市区町村合併・住所変更). When invoked, `terminal()` performs resource cleanup by closing all open database connections and data access objects acquired during the batch's execution lifecycle. It acts as a **delegated cleanup routine** in the batch service lifecycle pattern, ensuring no database connection leaks occur when the batch processing ends — whether normally or abnormally. The method is a standard lifecycle callback provided by the `JBSbatBusinessService` base class contract, and its role in the larger system is to guarantee **transaction-safe resource deallocation** so that the `KK_T_CHG_AD_JGRTWK` (change-address joint work table) and general DB access connections are properly released back to the pool.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal() Entry"])
    STEP1["Close dbAccess (DB connection cleanup)"]
    STEP2["Close db_CHG_AD_JGRTWK (Address joint work table DB cleanup)"]
    END_NODE(["Return void — Batch termination complete"])

    START --> STEP1 --> STEP2 --> END_NODE
```

**CRITICAL — Constant Resolution:**
This method contains no conditional branches or constant comparisons. It executes a linear sequence of two close operations unconditionally.

**Processing Flow:**
1. **Close primary DB access** — `dbAccess.close()` releases the main database connection used by this batch service.
2. **Close secondary DB access** — `db_CHG_AD_JGRTWK.close()` releases the database connection dedicated to the `KK_T_CHG_AD_JGRTWK` table (changed-address joint work table / 変更住所合算ワーク).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It is a lifecycle callback that operates on instance-level database access resources initialized during batch construction. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `dbAccess` | `JBSbatSQLAccess` | Primary database access object for general batch SQL operations |
| `db_CHG_AD_JGRTWK` | `JBSbatSQLAccess` | Database access object for the `KK_T_CHG_AD_JGRTWK` (changed-address joint work table) used to store intermediate results during address modification error output processing |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatSQLAccess.close` (via `dbAccess`) | JBSbatSQL | - | Closes the primary database SQL access connection |
| - | `JBSbatSQLAccess.close` (via `db_CHG_AD_JGRTWK`) | JBSbatSQL | `KK_T_CHG_AD_JGRTWK` | Closes the database SQL access connection for the changed-address joint work table |

**Analysis:**
This method performs **no CRUD operations** (Create/Read/Update/Delete). It exclusively invokes `close()` on `JBSbatSQLAccess` instances, which are resource cleanup calls that return database connections to the connection pool. The `KK_T_CHG_AD_JGRTWK` table is referenced because `db_CHG_AD_JGRTWK` was instantiated as a `JBSbatSQLAccess` object backed by that table (as seen in similar classes like `JBSbatKKAdEmgSODSendOutput` and `JBSbatKKAdHenkoHoyuDataChstuOtr` which declare `db_CHG_AD_JGRTWK = new JBSbatSQLAccess(commonItem, "KK_T_CHG_AD_JGRTWK")`).

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `dbAccess.close` | JBSbatSQL | - | Releases the primary database connection acquired by the batch service |
| - | `db_CHG_AD_JGRTWK.close` | JBSbatSQL | `KK_T_CHG_AD_JGRTWK` | Releases the database connection dedicated to the changed-address joint work table |

## 5. Dependency Trace

No external callers were found for this method. It is a **lifecycle callback method** on the `JBSbatBusinessService` base class, invoked internally by the batch framework when the batch processing phase completes. The framework's batch execution engine calls `terminal()` automatically as part of the standard batch service lifecycle (init → execute → terminal).

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Framework: BatchExecutor | `BatchExecutor.executeService` -> `JBSbatBusinessService.terminal` | `dbAccess.close` [cleanup], `db_CHG_AD_JGRTWK.close` [cleanup KK_T_CHG_AD_JGRTWK] |

**What this method calls:**

| # | Called Method | Return Type | Business Description |
|---|--------------|-------------|---------------------|
| 1 | `dbAccess.close()` | `void` | Closes the primary SQL access database connection |
| 2 | `db_CHG_AD_JGRTWK.close()` | `void` | Closes the SQL access connection for the changed-address joint work table (`KK_T_CHG_AD_JGRTWK`) |

## 6. Per-Branch Detail Blocks

**Block 1** — [TRY-CLEANUP] (L134)

> Closes all database access resources acquired during the batch lifecycle.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbAccess.close()` // Close primary DB access connection — releases database resources back to pool |
| 2 | CALL | `db_CHG_AD_JGRTWK.close()` // Close secondary DB access for changed-address joint work table (`KK_T_CHG_AD_JGRTWK`) — releases table-specific DB resources |

**No conditional branches.** The method executes a deterministic, linear sequence of two close operations. No exceptions are caught internally — the `throws Exception` declaration in the method signature means any cleanup failure propagates to the batch framework caller.

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `dbAccess` | Field | Primary database SQL access object — used for general-purpose batch database operations |
| `db_CHG_AD_JGRTWK` | Field | Database SQL access object for the changed-address joint work table — dedicated connection for the `KK_T_CHG_AD_JGRTWK` table used during address modification processing |
| `KK_T_CHG_AD_JGRTWK` | Table | Changed-Address Joint Work Table (変更住所合算ワーク) — temporary/work table storing intermediate results related to address modification and municipal merger processing |
| JBSbatKKAdHenkoErrOutput | Class | Batch service class for outputting unprocessable records from the address modification worklist — specifically handles data that failed during municipal merger or address name change operations |
| `terminal()` | Method | Batch service lifecycle termination method — performs cleanup of all resources before the batch process completes |
| JBSbatBusinessService | Class | Abstract base class for all batch business services — defines the standard batch lifecycle (init, execute, terminal) and common resource management patterns |
| JBSbatSQLAccess | Class | SQL access framework class — provides database connection management, SQL execution, and CRUD operations for batch services |
| 市区町村合併 | Japanese term | Municipal merger — the administrative consolidation of municipalities (cities, towns, villages) in Japan, which triggers address record updates |
| 住所変更 | Japanese term | Address change — modification of registered residential addresses in the system |
| 変更住所合算ワーク | Japanese term | Changed-address joint work table — the work table (`KK_T_CHG_AD_JGRTWK`) used to accumulate and process address change records |
| 変更対象住所一覧 | Japanese term | Address modification target worklist — the batch worklist containing addresses scheduled for modification processing |
| Batch | Business term | A non-interactive, scheduled program execution that processes large volumes of data without user interaction |
