# Business Logic — JBSbatKKAdHenkoHoyuDataChstuOtr.terminal() [13 LOC]

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

## 1. Role

### JBSbatKKAdHenkoHoyuDataChstuOtr.terminal()

This method is the **business service termination handler** (業務サービス終了処理) for the `JBSbatKKAdHenkoHoyuDataChstuOtr` batch service. The class (`Henko Hoyu Data Chstu Otr` — 変更保留住所データ抽出 — "Address-Held Data Extraction") is responsible for extracting address master records and inserting them into a registration work table, specifically for changing target address codes (変更対象住所コードワーク). The `terminal()` method's sole responsibility is **resource cleanup**: it closes all five `JBSbatSQLAccess` database connection handles that were opened during the `initial()` initialization phase. This ensures that database cursor and connection resources allocated to the batch job are properly released back to the pool when the service lifecycle completes, preventing resource leaks. It follows the standard `JBSbatBusinessService` lifecycle pattern where `initial()` opens DB connections, `execute()` performs business processing, and `terminal()` tears them down.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal()"])
    CLOSE1["db_CHGTGAD_CD_WK.close()"]
    CLOSE2["db_CHG_AD_JGRTWK.close()"]
    CLOSE3["db_CK_T_PROSCST.close()"]
    CLOSE4["db_DK_T_YBKIKI_HAISO.close()"]
    CLOSE5["db_KU_T_SENKO_DSGN.close()"]
    END_NODE(["Return void"])

    START --> CLOSE1
    CLOSE1 --> CLOSE2
    CLOSE2 --> CLOSE3
    CLOSE3 --> CLOSE4
    CLOSE4 --> CLOSE5
    CLOSE5 --> END_NODE
```

**Processing Summary:** The method performs a linear, unconditional sequence of five DB access close calls. There are no conditional branches, loops, or decision nodes. Each `close()` call releases the underlying database cursor/connection held by the corresponding `JBSbatSQLAccess` instance.

```mermaid
sequenceDiagram
    participant SYS as System
    participant SVC as JBSbatKKAdHenkoHoyuDataChstuOtr
    SYS->>SVC: terminal()
    SVC->>SVC: db_CHGTGAD_CD_WK.close()
    SVC->>SVC: db_CHG_AD_JGRTWK.close()
    SVC->>SVC: db_CK_T_PROSCST.close()
    SVC->>SVC: db_DK_T_YBKIKI_HAISO.close()
    SVC->>SVC: db_KU_T_SENKO_DSGN.close()
    SVC-->>SYS: return
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates purely on instance-level state (the five `JBSbatSQLAccess` DB connection handles established during `initial()`). |

**Instance fields / external state read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_CHGTGAD_CD_WK` | `JBSbatSQLAccess` | DB access handle for `KK_T_CHGTGAD_CD_WK` (Changed-Target Address Code Work table) |
| `db_CHG_AD_JGRTWK` | `JBSbatSQLAccess` | DB access handle for `KK_T_CHG_AD_JGRTWK` (Changed-Post Address Registration Work table) |
| `db_CK_T_PROSCST` | `JBSbatSQLAccess` | DB access handle for `CK_T_PROSCST` (Customer-prospect address master table; used for inquiry customer address extraction via `KK_SELECT_003`) |
| `db_DK_T_YBKIKI_HAISO` | `JBSbatSQLAccess` | DB access handle for `DK_T_YBKIKI_HAISO` (Reserve Equipment Delivery table; used for spare equipment delivery address data) |
| `db_KU_T_SENKO_DSGN` | `JBSbatSQLAccess` | DB access handle for `KU_T_SENKO_DSGN` (Pioneer Design table) |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `db_CHGTGAD_CD_WK.close` | JBSbatSQLAccess | - | Closes DB access cursor/connection for `KK_T_CHGTGAD_CD_WK` |
| - | `db_CHG_AD_JGRTWK.close` | JBSbatSQLAccess | - | Closes DB access cursor/connection for `KK_T_CHG_AD_JGRTWK` |
| - | `db_CK_T_PROSCST.close` | JBSbatSQLAccess | - | Closes DB access cursor/connection for `CK_T_PROSCST` |
| - | `db_DK_T_YBKIKI_HAISO.close` | JBSbatSQLAccess | - | Closes DB access cursor/connection for `DK_T_YBKIKI_HAISO` |
| - | `db_KU_T_SENKO_DSGN.close` | JBSbatSQLAccess | - | Closes DB access cursor/connection for `KU_T_SENKO_DSGN` |

This method performs no Create, Read, Update, or Delete operations on business data. It only closes previously opened `JBSbatSQLAccess` resource handles. The CRUD operations on the underlying tables (`selectBySqlDefine` and `insertByPrimaryKeys`) occur in the sibling `execute()` method.

## 5. Dependency Trace

The `terminal()` method is not directly called by any other class in the codebase. It is invoked by the **batch framework runtime** as part of the standard `JBSbatBusinessService` lifecycle. When the batch framework executes a service class, it calls `initial()` → `execute()` → `terminal()` in sequence. The batch scheduler entry point (`JACbatSchdlUtil`) coordinates the overall batch execution flow, but the framework itself internally dispatches `terminal()` as a lifecycle callback.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Framework: JBSbatBusinessService lifecycle | `batchScheduler.execute(service)` → `JBSbatBusinessService.terminal()` | `close [R/U] KK_T_CHGTGAD_CD_WK`<br>`close [R/U] KK_T_CHG_AD_JGRTWK`<br>`close [R/U] CK_T_PROSCST`<br>`close [R/U] DK_T_YBKIKI_HAISO`<br>`close [R/U] KU_T_SENKO_DSGN` |

**Note:** No direct caller class references `JBSbatKKAdHenkoHoyuDataChstuOtr.terminal()` in the source code. The method is a framework lifecycle hook that the batch execution engine invokes automatically after the `execute()` method completes.

## 6. Per-Branch Detail Blocks

### Block 1 — CLOSE `(resource cleanup)` (L242)

> Closes all five DB access objects allocated during `initial()`. This is a linear sequence — no conditional branches exist. Each `close()` call releases database cursors and connection resources held by the corresponding `JBSbatSQLAccess` instance.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_CHGTGAD_CD_WK.close()` // Closes DB access for Changed-Target Address Code Work table (変更対象住所コードワーク) |
| 2 | EXEC | `db_CHG_AD_JGRTWK.close()` // Closes DB access for Changed-Post Address Registration Work table (変更後住所登録ワーク) |
| 3 | EXEC | `db_CK_T_PROSCST.close()` // Closes DB access for Customer-Prospect Address table (顧客 prospects 住所マスタ) |
| 4 | EXEC | `db_DK_T_YBKIKI_HAISO.close()` // Closes DB access for Reserve Equipment Delivery table (予備機器配送) |
| 5 | EXEC | `db_KU_T_SENKO_DSGN.close()` // Closes DB access for Pioneer Design table (先導設計) |

### Block 2 — RETURN `(void)` (L252)

> The method returns `void` to the batch framework lifecycle runner. No value is returned; the only side effect is the released DB resources.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Returns to batch framework lifecycle |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_CHGTGAD_CD_WK` | Table | Changed-Target Address Code Work — Temporary work table holding address codes that are designated as change targets for batch processing (変更対象住所コードワーク) |
| `KK_T_CHG_AD_JGRTWK` | Table | Changed-Post Address Registration Work — Work table where validated address data is registered after extraction (変更後住所登録ワーク) |
| `CK_T_PROSCST` | Table | Customer Prospect Address — Customer address master table queried during batch processing for inquiry customer records (顧客 prospects 住所) |
| `DK_T_YBKIKI_HAISO` | Table | Reserve Equipment Delivery — Table holding data on spare/reserve equipment delivery addresses (予備機器配送) |
| `KU_T_SENKO_DSGN` | Table | Pioneer Design — Table holding pioneer (preliminary) design data for service provisioning (先導設計) |
| `JBSbatBusinessService` | Class | Base batch business service class providing the standard `initial()` → `execute()` → `terminal()` lifecycle |
| `JBSbatSQLAccess` | Class | Database SQL access abstraction layer providing `selectBySqlDefine`, `insertByPrimaryKeys`, `selectNext`, and `close` methods |
| `JBSbatCommonDBInterface` | Class | Common database interface for holding parameter values and result rows in batch processing |
| `initial()` | Method | Batch service initialization — opens DB connection handles and sets common parameters |
| `execute()` | Method | Batch service main processing — extracts address data and inserts it into the registration work table |
| `terminal()` | Method | Batch service termination — closes all DB resource handles (業務サービス終了処理) |
| HENKO | Business term | Change / Modification (変更) — prefix used in table and field names relating to address changes |
| HOYU | Business term | Hold / Pending (保留) — indicates data held for processing or awaiting action |
| CHSTU | Business term | Registration / Insertion (登録/挿入) — refers to data insertion operations |
| OTR | Business term | Extract / Output (抽出) — refers to data extraction operations |
| AD_CD | Field | Address Code (住所コード) — unique identifier for an address |
| PROSCST_NO | Field | Prospect Number — customer prospect identification number |
| PCD | Field | Postal Code (郵便番号) — Japanese postal addressing code |
| STATE_NM | Field | State Name — prefecture/regional name in the address |
| CITY_NM | Field | City Name — municipal name in the address |
| OAZTSU_NM | Field | Oaza Town Name — large-area town designation in Japanese addressing (大字町名) |
| AZCHO_NM | Field | Azacho Name — smaller-area street designation (字丁目名) |
| AD_SHUSEI_CD | Field | Address Correction Code — code indicating how the address was corrected or validated |
| NEW_AD_CD | Field | New Address Code — the updated address code after change processing |
| OLD_AD_CD | Field | Old Address Code — the previous address code before the change |
| AD_TOHAIGO_TRN_STAT_CD | Field | Address Change Destination Transfer Status Code — tracks the transfer status of the address change (変更先送信送信ステータスコード) |
| HENKO_ADD_CD_MI | Constant | "Not Added" status code — indicates a record has not yet been added/registered |
| CHG_AD_JGRTWK_NO | Field | Changed-Post Address Registration Work Number — unique sequence-generated work record ID (変更後住所登録ワーク番号) |
| CHG_TG_SCHEMA_ID | Field | Change Target Schema ID — identifies the target schema/source type (e.g., `CK0051`, `DK0061`) for the change target (変更対象スキーマID) |
| CHG_TG_KMK_NM_EINM | Field | Change Target Customer Name EINM — human-readable name of the change target entity (変更対象顧客名エイリアス名) |
| SEQ_NAME | Constant | Sequence name `SEQ_CHG_AD_JGRTWK_NO` — Oracle database sequence for generating unique work record numbers (シーケンス名) |
| SEQ_KETA | Constant | Sequence digit count — the fixed number of digits in the formatted sequence number (シーケンス桁数) |
| JCCOracleSeqUtil | Class | Oracle database sequence utility — provides formatted next sequence number retrieval |
| JZMBatCommon | Class | Common batch utility — provides methods like `getInMapData` for extracting data from input maps |
| INMAP | Data structure | Input Map — a `JBSbatServiceInterfaceMap` carrying batch input parameters by key (e.g., `AD_CD`) |
| Batch Service | Concept | A scheduled batch job that processes large volumes of data offline, typically run on a nightly basis |
