# Business Logic — JBSbatKKAdChgSmtvlRnki.terminal() [19 LOC]

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

## 1. Role

### JBSbatKKAdChgSmtvlRnki.terminal()

This method serves as the **business service termination handler** (業務サービス終了処理) for the address change smart-barryu (home-to-mobile) linkage product. When a customer relocates between their home (home carrier) and mobile (mobile carrier) services and this migration is notified to KDDI, the batch system performs resource cleanup at the end of processing. The method implements the **Resource-Cleanup pattern** (also known as a destructor or finalizer callback) by closing all database access handles (SQL cursors and connection resources) that were opened during the address change processing lifecycle. It has no conditional branches — it unconditionally releases every database resource in a fixed, sequential order to guarantee no database cursor leaks, which is critical in a long-running batch job where resource exhaustion could impact subsequent processing. The method follows the framework's `JBSbatBusinessService` lifecycle contract, where `terminal()` is invoked after `execute()` completes (whether successfully or via exception), making it the system's last line of defense against database connection and cursor leaks. This is a **shared infrastructure method** — its cleanup logic was extended over multiple versions to include new tables as new features (OM-2014-0002047, ANK-2186-00-00, OM-2014-00003664, OM-2014-0003554) were added to the address change workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal() Entry"])
    CLOSE1["db_KK_T_TAJGSWKEI_TGKEI.close()"]
    CLOSE2["db_KK_T_PRG.close()"]
    CLOSE3["db_KK_T_SVC_KEI.close()"]
    CLOSE4["db_KK_T_IDO_RSV.close()"]
    CLOSE5["db_KK_T_TAJGS_WRIB_KEI.close()"]
    END_NODE(["Return void"])

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

**Processing Overview:**

The method performs a linear, sequential cleanup of 5 database access handles. Each `close()` call releases the underlying JDBC cursor and associated resources for the corresponding table. The close operations are ordered by dependency — the main processing table is closed first, followed by the progress-tracking table, then the feature-specific tables added in subsequent releases. If any `close()` throws an exception, subsequent closes are skipped and the exception propagates up to the framework's error handler.

| Step | Operation | Database Table | Purpose |
|------|-----------|---------------|---------|
| 1 | `db_KK_T_TAJGSWKEI_TGKEI.close()` | `KK_T_TAJGSWKEI_TGKEI` (Other Business Operator Contract Target Contract) | Release cursor for the primary address change contract processing table |
| 2 | `db_KK_T_PRG.close()` | `KK_T_PRG` (Progress) | Release cursor for the batch job progress-tracking table |
| 3 | `db_KK_T_SVC_KEI.close()` | `KK_T_SVC_KEI` (Service Contract) | Release cursor for the service contract table (added in OM-2014-0002047) |
| 4 | `db_KK_T_IDO_RSV.close()` | `KK_T_IDO_RSV` (Anomaly Reservation) | Release cursor for the anomaly reservation table — used for KDDI discrepancy notification when smart-barryu home-to-mobile migration occurs (added in ANK-2186-00-00) |
| 5 | `db_KK_T_TAJGS_WRIB_KEI.close()` | `KK_T_TAJGS_WRIB_KEI` (Other Business Operator Contract) | Release cursor for the other business operator contract write-permit table (added in OM-2014-00003664) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates entirely on instance fields (the database access handles). |

**Instance Fields Read/Used:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_TAJGSWKEI_TGKEI` | `JBSbatSQLAccess` | Database access cursor for the Other Business Operator Contract Target Contract table (`KK_T_TAJGSWKEI_TGKEI`) — used during address change contract processing |
| `db_KK_T_PRG` | `JBSbatSQLAccess` | Database access cursor for the Progress table (`KK_T_PRG`) — tracks batch job execution state |
| `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` | Database access cursor for the Service Contract table (`KK_T_SVC_KEI`) — used for service contract data (added OM-2014-0002047) |
| `db_KK_T_IDO_RSV` | `JBSbatSQLAccess` | Database access cursor for the Anomaly Reservation table (`KK_T_IDO_RSV`) — used for KDDI discrepancy notification during home-to-mobile migration (added ANK-2186-00-00) |
| `db_KK_T_TAJGS_WRIB_KEI` | `JBSbatSQLAccess` | Database access cursor for the Other Business Operator Contract write-permit table (`KK_T_TAJGS_WRIB_KEI`) — manages write-permission for other business operator contracts (added OM-2014-00003664) |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JACbatDataBnktUtil.close` | JACbatDataBnkt | - | Calls `close` in `JACbatDataBnktUtil` |
| - | `JACbatParamUtil.close` | JACbatParam | - | Calls `close` in `JACbatParamUtil` |
| - | `JACbatSchdlUtil.close` | JACbatSchdl | - | Calls `close` in `JACbatSchdlUtil` |
| - | `JBSbatCHChangeGroupKei.close` | JBSbatCHChangeGroupKei | - | Calls `close` in `JBSbatCHChangeGroupKei` |
| - | `JBSbatKKPrcIfCommon.close` | JBSbatKKPrcIfCommon | - | Calls `close` in `JBSbatKKPrcIfCommon` |

### Method-specific CRUD analysis:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `db_KK_T_TAJGSWKEI_TGKEI.close()` | JBSbatSQLAccess | `KK_T_TAJGSWKEI_TGKEI` | Closes the database cursor for the Other Business Operator Contract Target Contract table, releasing all associated JDBC resources |
| - | `db_KK_T_PRG.close()` | JBSbatSQLAccess | `KK_T_PRG` | Closes the database cursor for the Progress table, releasing batch progress-tracking resources |
| - | `db_KK_T_SVC_KEI.close()` | JBSbatSQLAccess | `KK_T_SVC_KEI` | Closes the database cursor for the Service Contract table, releasing service-contract-related resources |
| - | `db_KK_T_IDO_RSV.close()` | JBSbatSQLAccess | `KK_T_IDO_RSV` | Closes the database cursor for the Anomaly Reservation table, releasing KDDI discrepancy notification resources |
| - | `db_KK_T_TAJGS_WRIB_KEI.close()` | JBSbatSQLAccess | `KK_T_TAJGS_WRIB_KEI` | Closes the database cursor for the Other Business Operator Contract write-permit table, releasing write-permission management resources |

**Classification note:** All operations are **resource-cleanup** (not traditional CRUD). The `close()` method on `JBSbatSQLAccess` closes an open database cursor (JDBC result set or statement). No select/insert/update/delete operations occur in this method. The tables listed were previously accessed (likely via **R** select operations) in the main processing logic within the `execute()` method or its delegated child services, and this `terminal()` method ensures those cursors are released.

## 5. Dependency Trace

The `terminal()` method is a framework-defined lifecycle callback on the `JBSbatBusinessService` base class. It is not called directly from business code in `JBSbatKKAdChgCstScreenKidou.java` — instead, the framework invokes it automatically after the batch service's `execute()` method completes. The caller trace below shows the full chain from the batch coordinator through the address change execution to this terminal method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgCstScreenKidou | `JBSbatKKAdChgCstScreenKidou.execute()` -> `this.execRunObjSmtvl.execute(...)` -> `JBSbatBusinessService.execute()` -> `JBSbatBusinessService.terminal()` (framework callback) | `db_KK_T_TAJGSWKEI_TGKEI.close` [R release] `KK_T_TAJGSWKEI_TGKEI` \| `db_KK_T_PRG.close` [R release] `KK_T_PRG` \| `db_KK_T_SVC_KEI.close` [R release] `KK_T_SVC_KEI` \| `db_KK_T_IDO_RSV.close` [R release] `KK_T_IDO_RSV` \| `db_KK_T_TAJGS_WRIB_KEI.close` [R release] `KK_T_TAJGS_WRIB_KEI` |

**Caller context — JBSbatKKAdChgCstScreenKidou:** This is the main address change smart-barryu (home-to-mobile) linkage batch processor. It instantiates `JBSbatKKAdChgSmtvlRnki` as `execRunObjSmtvl` (line 208), initializes it with `commonItem` (line 209), and calls `execute()` on it for each smart-barryu linkage record. The `terminal()` method is invoked by the `JBSbatBusinessService` framework after each `execute()` call finishes, ensuring database resources are cleaned up before the next record is processed or the batch job exits.

## 6. Per-Branch Detail Blocks

This method has **no conditional branches** — it is a linear sequence of 5 `close()` calls. Below is the block-by-block analysis.

**Block 1** — [CALL] `(sequential close operations)` (L509)

> Close the database access cursor for the Other Business Operator Contract Target Contract table (`KK_T_TAJGSWKEI_TGKEI`). This table stores address change contract target data that was processed during the main batch operation.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_TAJGSWKEI_TGKEI.close()` // Releases JDBC cursor and resources for KK_T_TAJGSWKEI_TGKEI table [-> D_TBL_NAME_KK_T_TAJGSWKEI_TGKEI = "KK_T_TAJGSWKEI_TGKEI"] |

**Block 2** — [CALL] `(sequential close operations)` (L510)

> Close the database access cursor for the Progress table (`KK_T_PRG`). This table tracks batch job execution progress.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_PRG.close()` // Releases JDBC cursor and resources for KK_T_PRG table [-> D_TBL_NAME_KK_T_PRG = "KK_T_PRG"] |

**Block 3** — [CALL] `(sequential close operations)` (L512)

> Close the database access cursor for the Service Contract table (`KK_T_SVC_KEI`). This table was added in version v8.00.00 (OM-2014-0002047) to support service contract data handling during address change processing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI.close()` // Releases JDBC cursor and resources for KK_T_SVC_KEI table [-> D_TBL_NAME_KK_T_SVC_KEI = "KK_T_SVC_KEI"] [OM-2014-0002047] |

**Block 4** — [CALL] `(sequential close operations)` (L515)

> Close the database access cursor for the Anomaly Reservation table (`KK_T_IDO_RSV`). This table was added in version v9.00.00 (ANK-2186-00-00) to support KDDI discrepancy notification when a smart-barryu home-to-mobile migration occurs during a customer address change.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_IDO_RSV.close()` // Releases JDBC cursor and resources for KK_T_IDO_RSV table [-> D_TBL_NAME_KK_T_IDO_RSV = "KK_T_IDO_RSV"] [ANK-2186-00-00] |

**Block 5** — [CALL] `(sequential close operations)` (L518)

> Close the database access cursor for the Other Business Operator Contract write-permit table (`KK_T_TAJGS_WRIB_KEI`). This table was added in version v11.00.00 (OM-2014-00003664) to manage write-permissions for other business operator contracts during address change processing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_TAJGS_WRIB_KEI.close()` // Releases JDBC cursor and resources for KK_T_TAJGS_WRIB_KEI table [-> D_TBL_NAME_KK_T_TAJGS_WRIB_KEI = "KK_T_TAJGS_WRIB_KEI"] [OM-2014-00003664] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_TAJGSWKEI_TGKEI` | Table | Other Business Operator Contract Target Contract — stores contract target data for address changes involving other business operators (他事業者割当契約対象契約) |
| `KK_T_PRG` | Table | Progress — tracks batch job execution progress state (進捗) |
| `KK_T_SVC_KEI` | Table | Service Contract — stores service contract line item data (サービス契約) |
| `KK_T_IDO_RSV` | Table | Anomaly Reservation — reserves anomaly/discrepancy records for KDDI notification (異動予約). Used when a customer moves between home and mobile carriers during address change, triggering a discrepancy notification to KDDI |
| `KK_T_TAJGS_WRIB_KEI` | Table | Other Business Operator Contract Write-Permit — manages write-permission for other business operator contracts (他事業者割当契約) |
| `terminal()` | Method | Business service termination handler — framework lifecycle callback invoked after `execute()` completes to release all resources |
| `JBSbatSQLAccess` | Class | Database access cursor class — wraps JDBC cursor lifecycle (select, insert, update, delete, close) |
| `JBSbatBusinessService` | Class | Framework base class for all batch business services — defines the lifecycle: `initial()` -> `execute()` -> `terminal()` |
| JBSbatKKAdChgCstScreenKidou | Class | Address change smart-barryu linkage batch — main batch processor for home-to-mobile migration address change processing (住所変更スマートバリュー連携) |
| JBSbatKKAdChgSmtvlRnki | Class | Address change smart-barryu run (execution) object — the specific service module for address change smart-barryu processing (住所変更スマートバリュー実行) |
| スマートバリュー (Smart Barryu) | Business term | K-Opticom's bundled home + mobile carrier migration service — allows customers to seamlessly migrate their home (fixed-line) and mobile phone services between carriers |
| 住所変更 (Juusho Henkou) | Business term | Address change — the core business operation being processed; when a customer changes their registered address |
| KDDI 異動通知 (KDDI Idou Tsuuchi) | Business term | KDDI discrepancy/migration notification — notification sent to KDDI when customer information changes during a smart-barryu home-to-mobile migration |
| OM | Acronym | Operation Modification — internal change request / feature ticket prefix |
| ANK | Acronym | Anket (Survey/Research) — internal development ticket prefix |
| ST | Acronym | System Test — internal testing-related ticket prefix |
| IT | Acronym | Issue Tracking — internal issue ticket prefix |
| `D_TBL_NAME_*` | Constant | Database table name constant prefix — `D` = Definition, all values resolve to `"KK_T_..."` table name strings |
