# Business Logic — JBSbatKKAdHenkoHoyuDataChstu.terminal() [24 LOC]

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

## 1. Role

### JBSbatKKAdHenkoHoyuDataChstu.terminal()

The `terminal()` method implements the **business service termination processing** (業務サービス終了処理). It is the cleanup phase of the batch business service lifecycle, responsible for releasing all database resources that were acquired during the `initial()` phase. This method is part of the standard three-phase batch service pattern (`initial` -> main processing -> `terminal`) defined in the parent class `JBSbatBusinessService`, where `terminal()` is declared as an abstract method.

The method serves as a **resource disposal pattern**: it iterates through all `JBSbatSQLAccess` objects (which hold open DB connections, cursors, and transaction state) and invokes their `close()` methods to prevent resource leaks, dangling connections, and memory accumulation in the long-running batch job. This is a shared utility method — every batch execution of `JBSbatKKAdHenkoHoyuDataChstu` (and its subclasses `JBSbatKKAdHenkoHoyuDataChstuOtr` and `JBSbatKKAdHenkoHoyuDataChstuMan`) will invoke this `terminal()` method upon completion, whether the batch succeeds or encounters an exception.

The method is the termination point for a batch service that extracts changed-reserved address data from address code work tables. It cleans up access to 12 database entities including work tables (`KK_T_CHGTGAD_CD_WK`, `KK_T_CHG_AD_JGRTWK`), customer tables (`CK_T_CUST`, `CK_T_CUST_KOJIN`), service tables (`KK_T_SVKEIUW_EOH_TEL`, `KK_T_SVKEI_KAISEN_UW`, `KK_T_KKTK_SVC_KEI`, `KK_T_OPSVKEI_TV`, `KK_T_SEIKY_KEI`), and delivery/individual tables (`DK_T_HAISO`, `KU_T_KOJIAK`, `TU_T_DNWACHOMSK_NYO`).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal()"])
    CLOSE_1["close db_CHGTGAD_CD_WK<br/>(KK_T_CHGTGAD_CD_WK)"]
    CLOSE_2["close db_CHG_AD_JGRTWK<br/>(KK_T_CHG_AD_JGRTWK)"]
    CLOSE_3["close db_CK_T_CUST<br/>(CK_T_CUST)"]
    CLOSE_4["close db_CK_T_CUST_KOJIN<br/>(CK_T_CUST_KOJIN)"]
    CLOSE_5["close db_KK_T_SVKEIUW_EOH_TEL<br/>(KK_T_SVKEIUW_EOH_TEL)"]
    CLOSE_6["close db_KK_T_SVKEI_KAISEN_UW<br/>(KK_T_SVKEI_KAISEN_UW)"]
    CLOSE_7["close db_KK_T_KKTK_SVC_KEI<br/>(KK_T_KKTK_SVC_KEI)"]
    CLOSE_8["close db_KK_T_OPSVKEI_TV<br/>(KK_T_OPSVKEI_TV)"]
    CLOSE_9["close db_KK_T_SEIKY_KEI<br/>(KK_T_SEIKY_KEI)"]
    COMMENT_DELETED["Commented out:<br/>db_TU_T_BMP_KOJI and<br/>db_TU_T_DOBANITEN<br/>(ANK-4494-00-00)"]
    CLOSE_10["close db_TU_T_DNWACHOMSK_NYO<br/>(TU_T_DNWACHOMSK_NYO)"]
    CLOSE_11["close db_DK_T_HAISO<br/>(DK_T_HAISO)"]
    CLOSE_12["close db_KU_T_KOJIAK<br/>(KU_T_KOJIAK)"]
    END_NODE(["Return / Next"])

    START --> CLOSE_1
    CLOSE_1 --> CLOSE_2
    CLOSE_2 --> CLOSE_3
    CLOSE_3 --> CLOSE_4
    CLOSE_4 --> CLOSE_5
    CLOSE_5 --> CLOSE_6
    CLOSE_6 --> CLOSE_7
    CLOSE_7 --> CLOSE_8
    CLOSE_8 --> CLOSE_9
    CLOSE_9 --> COMMENT_DELETED
    COMMENT_DELETED --> CLOSE_10
    CLOSE_10 --> CLOSE_11
    CLOSE_11 --> CLOSE_12
    CLOSE_12 --> END_NODE
```

**Processing Summary:**

This method performs **sequential resource cleanup** with no conditional branches. The entire processing flow is a linear chain of 12 `close()` invocations on `JBSbatSQLAccess` objects:

1. Closes work table `KK_T_CHGTGAD_CD_WK` (Change Target Address Code Work)
2. Closes work table `KK_T_CHG_AD_JGRTWK` (Change Address Registration Work)
3. Closes customer table `CK_T_CUST`
4. Closes individual customer table `CK_T_CUST_KOJIN`
5. Closes service table `KK_T_SVKEIUW_EOH_TEL`
6. Closes service table `KK_T_SVKEI_KAISEN_UW`
7. Closes service table `KK_T_KKTK_SVC_KEI`
8. Closes service table `KK_T_OPSVKEI_TV`
9. Closes service table `KK_T_SEIKY_KEI`
10. **Skipped** (commented out since ANK-4494-00-00): `db_TU_T_BMP_KOJI` and `db_TU_T_DOBANITEN`
11. Closes table `TU_T_DNWACHOMSK_NYO` (Delivery Wait Confirmation Input)
12. Closes table `DK_T_HAISO`
13. Closes table `KU_T_KOJIAK`

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates entirely on instance fields (DB access objects) initialized during the `initial()` phase. |

**Instance fields read by this method:**

| Field Name | Type | Business Description |
|-----------|------|---------------------|
| `db_CHGTGAD_CD_WK` | `JBSbatSQLAccess` | Database access object for the Change Target Address Code Work table (`KK_T_CHGTGAD_CD_WK`) |
| `db_CHG_AD_JGRTWK` | `JBSbatSQLAccess` | Database access object for the Change Address Registration Work table (`KK_T_CHG_AD_JGRTWK`) |
| `db_CK_T_CUST` | `JBSbatSQLAccess` | Database access object for the Customer table (`CK_T_CUST`) — NTT contract holder address code |
| `db_CK_T_CUST_KOJIN` | `JBSbatSQLAccess` | Database access object for the Individual Customer table (`CK_T_CUST_KOJIN`) |
| `db_KK_T_SVKEIUW_EOH_TEL` | `JBSbatSQLAccess` | Database access object for the Service Detail EOH Telephone table (`KK_T_SVKEIUW_EOH_TEL`) |
| `db_KK_T_SVKEI_KAISEN_UW` | `JBSbatSQLAccess` | Database access object for the Service Detail Improvement Unsettled table (`KK_T_SVKEI_KAISEN_UW`) |
| `db_KK_T_KKTK_SVC_KEI` | `JBSbatSQLAccess` | Database access object for the KKTK Service Detail table (`KK_T_KKTK_SVC_KEI`) |
| `db_KK_T_OPSVKEI_TV` | `JBSbatSQLAccess` | Database access object for the Operation Service Detail TV table (`KK_T_OPSVKEI_TV`) |
| `db_KK_T_SEIKY_KEI` | `JBSbatSQLAccess` | Database access object for the Settlement Detail table (`KK_T_SEIKY_KEI`) |
| `db_TU_T_BMP_KOJI` | `JBSbatSQLAccess` | (Commented out — ANK-4494-00-00) Previously accessed the BMP Official Work table (`TU_T_BMP_KOJI`) |
| `db_TU_T_DOBANITEN` | `JBSbatSQLAccess` | (Commented out — ANK-4494-00-00) Previously accessed the Branch Store table (`TU_T_DOBANITEN`) |
| `db_TU_T_DNWACHOMSK_NYO` | `JBSbatSQLAccess` | Database access object for the Delivery Wait Confirmation Input table (`TU_T_DNWACHOMSK_NYO`) |
| `db_DK_T_HAISO` | `JBSbatSQLAccess` | Database access object for the Delivery table (`DK_T_HAISO`) |
| `db_KU_T_KOJIAK` | `JBSbatSQLAccess` | Database access object for the Individual Account table (`KU_T_KOJIAK`) |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatSQLAccess.close` | - | `KK_T_CHGTGAD_CD_WK` | Closes DB access for Change Target Address Code Work table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_CHG_AD_JGRTWK` | Closes DB access for Change Address Registration Work table |
| - | `JBSbatSQLAccess.close` | - | `CK_T_CUST` | Closes DB access for Customer (NTT contract holder address) table |
| - | `JBSbatSQLAccess.close` | - | `CK_T_CUST_KOJIN` | Closes DB access for Individual Customer table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_SVKEIUW_EOH_TEL` | Closes DB access for Service Detail EOH Telephone table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_SVKEI_KAISEN_UW` | Closes DB access for Service Detail Improvement Unsettled table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_KKTK_SVC_KEI` | Closes DB access for KKTK Service Detail table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_OPSVKEI_TV` | Closes DB access for Operation Service Detail TV table |
| - | `JBSbatSQLAccess.close` | - | `KK_T_SEIKY_KEI` | Closes DB access for Settlement Detail table |
| - | `JBSbatSQLAccess.close` | - | `TU_T_DNWACHOMSK_NYO` | Closes DB access for Delivery Wait Confirmation Input table |
| - | `JBSbatSQLAccess.close` | - | `DK_T_HAISO` | Closes DB access for Delivery table |
| - | `JBSbatSQLAccess.close` | - | `KU_T_KOJIAK` | Closes DB access for Individual Account table |

**Classification notes:**
- All 12 operations are **resource deallocation** (neither C/R/U/D in the traditional CRUD sense). The `JBSbatSQLAccess.close()` method closes database cursors, releases result sets, and returns connections to the pool — it is a cleanup/teardown operation.
- The two entries `db_TU_T_BMP_KOJI` and `db_TU_T_DOBANITEN` are **commented out** as of ANK-4494-00-00 (2024/03/06) as part of "Two-way Banner" correspondence work. They no longer participate in this method's execution.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdHenkoHoyuDataChstuOtr | `BatchRunner.invoke()` -> `JBSbatKKAdHenkoHoyuDataChstuOtr.execute()` -> `super.terminal()` -> `JBSbatKKAdHenkoHoyuDataChstu.terminal()` | `JBSbatSQLAccess.close [CLEANUP] KK_T_CHGTGAD_CD_WK, KK_T_CHG_AD_JGRTWK, CK_T_PROSCST, DK_T_YBKIKI_HAISO, KU_T_SENKO_DSGN` |
| 2 | Batch: JBSbatKKAdHenkoHoyuDataChstuMan | `BatchRunner.invoke()` -> `JBSbatKKAdHenkoHoyuDataChstuMan.execute()` -> `super.terminal()` -> `JBSbatKKAdHenkoHoyuDataChstu.terminal()` | `JBSbatSQLAccess.close [CLEANUP] KK_T_CHGTGAD_CD_WK, KK_T_CHG_AD_JGRTWK, CK_T_CUST, CK_T_CUST_KOJIN, KK_T_KKTK_SVC_KEI, KK_T_OPSVKEI_TV, KK_T_SEIKY_KEI, KU_T_KOJIAK, TU_T_DNWACHOMSK_NYO` |
| 3 | Batch: JBSbatKKAdHenkoHoyuDataChstu | `BatchRunner.invoke()` -> `JBSbatKKAdHenkoHoyuDataChstu.execute()` -> `super.terminal()` -> `JBSbatKKAdHenkoHoyuDataChstu.terminal()` | `JBSbatSQLAccess.close [CLEANUP] KK_T_CHGTGAD_CD_WK, KK_T_CHG_AD_JGRTWK, CK_T_CUST, CK_T_CUST_KOJIN, KK_T_SVKEIUW_EOH_TEL, KK_T_SVKEI_KAISEN_UW, KK_T_KKTK_SVC_KEI, KK_T_OPSVKEI_TV, KK_T_SEIKY_KEI, TU_T_DNWACHOMSK_NYO, DK_T_HAISO, KU_T_KOJIAK` |

**Notes:**
- `terminal()` is declared as `abstract` in `JBSbatBusinessService` (line 92) and overridden by `JBSbatKKAdHenkoHoyuDataChstu`.
- The child classes `JBSbatKKAdHenkoHoyuDataChstuOtr` and `JBSbatKKAdHenkoHoyuDataChstuMan` do NOT override `terminal()` — they inherit the parent's implementation. However, each child class has a **different set of DB access fields**, so the `close()` operations executed differ across the three concrete classes.
- The method is called as the final step of the batch lifecycle, invoked by the batch framework after main processing completes (or during exception handling cleanup).

## 6. Per-Branch Detail Blocks

This method has **no conditional branches** — it is a pure sequential cleanup flow.

**Block 1** — [PROCESSING] Sequential DB resource close operations (L1130)

> Opens the resource cleanup section generated by the tool (ツールから生成した終了処理のソースです).

| # | Type | Code | Comment |
|---|------|------|---------|
| 1 | EXEC | `db_CHGTGAD_CD_WK.close()` | Close DB access for Change Target Address Code Work table |
| 2 | EXEC | `db_CHG_AD_JGRTWK.close()` | Close DB access for Change Address Registration Work table |
| 3 | EXEC | `db_CK_T_CUST.close()` | Close DB access for Customer table |
| 4 | EXEC | `db_CK_T_CUST_KOJIN.close()` | Close DB access for Individual Customer table |
| 5 | EXEC | `db_KK_T_SVKEIUW_EOH_TEL.close()` | Close DB access for Service Detail EOH Telephone table |
| 6 | EXEC | `db_KK_T_SVKEI_KAISEN_UW.close()` | Close DB access for Service Detail Improvement Unsettled table |
| 7 | EXEC | `db_KK_T_KKTK_SVC_KEI.close()` | Close DB access for KKTK Service Detail table |
| 8 | EXEC | `db_KK_T_OPSVKEI_TV.close()` | Close DB access for Operation Service Detail TV table |
| 9 | EXEC | `db_KK_T_SEIKY_KEI.close()` | Close DB access for Settlement Detail table |

**Block 1.1** — [COMMENTED OUT / SKIPPED] ANK-4494-00-00 DEL (L1139-1141)

> The following two close operations were removed as part of the "Two-way Banner" (双方向番ポ) correspondence. They are retained as comments for historical traceability.

| # | Type | Code | Comment |
|---|------|------|---------|
| 1 | COMMENT | `//db_TU_T_BMP_KOJI.close()` | (ANK-4494-00-00) BMP Official Work — SKIPPED |
| 2 | COMMENT | `//db_TU_T_DOBANITEN.close()` | (ANK-4494-00-00) Branch Store — SKIPPED |

**Block 2** — [PROCESSING] Remaining DB resource close operations (L1142-1144)

| # | Type | Code | Comment |
|---|------|------|---------|
| 1 | EXEC | `db_TU_T_DNWACHOMSK_NYO.close()` | Close DB access for Delivery Wait Confirmation Input table |
| 2 | EXEC | `db_DK_T_HAISO.close()` | Close DB access for Delivery table |
| 3 | EXEC | `db_KU_T_KOJIAK.close()` | Close DB access for Individual Account table |

**Block 3** — [CLOSE SECTION] End of cleanup (L1145)

> Closing the resource cleanup section generated by the tool (ツールから生成した終了処理のソースです 終了).

| # | Type | Code | Comment |
|---|------|------|---------|
| 1 | SECTION | `/**終了▲▲▲▲▲▲ツールから生成した終了処理のソースです▲▲▲▲▲▲*/` | End marker comment |

**Block 4** — [RETURN] Implicit void return (L1146)

| # | Type | Code | Comment |
|---|------|------|---------|
| 1 | RETURN | `return;` | Implicit — void method |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_CHGTGAD_CD_WK` | Table | Change Target Address Code Work — temporary work table holding address codes that are targets for address modification operations |
| `KK_T_CHG_AD_JGRTWK` | Table | Change Address Registration Work — temporary work table holding pending address registration records for batch processing |
| `CK_T_CUST` | Table | Customer (Keiyakusha) — NTT contract holder master table storing customer and address code information |
| `CK_T_CUST_KOJIN` | Table | Individual Customer (Kojin) — individual-level customer detail table linked to `CK_T_CUST` |
| `KK_T_SVKEIUW_EOH_TEL` | Table | Service Detail EOH Telephone — telephone number information associated with service contract line items (EOH = End of House) |
| `KK_T_SVKEI_KAISEN_UW` | Table | Service Detail Improvement Unsettled — unsettled service improvement records |
| `KK_T_KKTK_SVC_KEI` | Table | KKTK Service Detail — K-Opticom telecom service contract detail table |
| `KK_T_OPSVKEI_TV` | Table | Operation Service Detail TV — operational records for TV/cable services |
| `KK_T_SEIKY_KEI` | Table | Settlement Detail — billing and settlement records for services |
| `TU_T_DNWACHOMSK_NYO` | Table | Delivery Wait Confirmation Input — temporary table for delivery wait confirmation input records |
| `DK_T_HAISO` | Table | Delivery — delivery management records for service installation/delivery |
| `KU_T_KOJIAK` | Table | Individual Account — individual account information table |
| `TU_T_BMP_KOJI` | Table | (Commented out) BMP Official Work — official work records related to BMP operations |
| `TU_T_DOBANITEN` | Table | (Commented out) Branch Store — branch store information table |
| `JBSbatSQLAccess` | Class | Database access utility class — provides DB connection management, SQL execution, and result set handling for batch processing |
| `JBSbatBusinessService` | Class | Abstract parent class for batch business services — defines the lifecycle (`initial`, main processing, `terminal`) |
| `initial()` | Method | Batch service initialization phase — opens and configures all `JBSbatSQLAccess` objects |
| `terminal()` | Method | Batch service termination phase — closes all `JBSbatSQLAccess` objects to release DB resources |
| `ANK-4494-00-00` | Ticket | Jira ticket for "Two-way Banner Correspondence" (双方向番ポ対応) — caused removal of `db_TU_T_BMP_KOJI` and `db_TU_T_DOBANITEN` DB access objects as of v72.00.00 (2024/03/06) |
| SOD | Acronym | Service Order Data — telecom order fulfillment entity |
| FTTH | Business term | Fiber To The Home — fiber-optic internet service (K-Opticom's primary broadband offering) |
| EOH | Acronym | End of House — refers to the customer's premises in fiber optic network topology |
| AD_CD | Field | Address Code — internal code identifying a customer's registered address |
| CHG_AD_JGRTWK_NO | Field | Change Address Registration Work Number — unique sequence number for address registration work records |
| CK | Acronym | Customer (Keiyakusha) master data — customer-facing configuration tables |
| KK | Acronym | K-Opticom internal work tables — temporary work tables for batch processing |
| DK | Acronym | Delivery-related tables — delivery management and tracking |
| KU | Acronym | Individual/Kojiake tables — individual customer account data |
| TU | Acronym | Utility/Work tables — temporary work tables for specific operational tasks |
