# Business Logic — JBSbatKKSkaWrkCnclProc.terminal() [23 LOC]

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

## 1. Role

### JBSbatKKSkaWrkCnclProc.terminal()

This method performs **business service termination processing** (業務サービス終了処理) for the Spica satellite construction cancellation batch. The batch's overall purpose is to handle cancellations of Spica (スカパー, a satellite broadcasting service in Japan) construction orders — specifically, reverting or cleaning up all database resources and state created during the cancellation workflow.

The `terminal()` method's sole responsibility is **resource cleanup**: it safely closes all four database access objects (`JBSbatSQLAccess` instances) that were opened during the batch's `initial()` phase. Each access object wraps a connection to a core operational table used throughout the cancellation processing pipeline. By ensuring each reference is non-null before calling `close()`, the method prevents `NullPointerException` errors during batch shutdown.

This method follows the **try-finally resource management pattern** (generated via a code generation tool, as indicated by the `ツールから生成した終了処理のソースです` comment — "Source code for termination processing generated from tool"). It is a standard lifecycle hook called at the end of the batch service execution, guaranteeing that database connections are properly released regardless of whether the batch succeeded or failed.

The method plays a **critical infrastructure role** in the batch framework: it is inherited from `JBSbatBusinessService` and overridden to include this class's specific cleanup needs. It is the final step in the batch service lifecycle, ensuring no database connection leaks occur after the Spica cancellation processing completes.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal() entry"])

    START --> CHECK1{"db_KK_T_IDO_RSV != null?"}
    CHECK1 -->|Yes| CLOSE1["db_KK_T_IDO_RSV.close()"]
    CHECK1 -->|No| SKIP1["skip"]
    SKIP1 --> CHECK2{"db_KK_T_CASCD_KNRI != null?"}
    CLOSE1 --> CHECK2
    CHECK2 -->|Yes| CLOSE2["db_KK_T_CASCD_KNRI.close()"]
    CHECK2 -->|No| SKIP2["skip"]
    SKIP2 --> CHECK3{"db_KK_T_OP_SVC_KEI != null?"}
    CLOSE2 --> CHECK3
    CHECK3 -->|Yes| CLOSE3["db_KK_T_OP_SVC_KEI.close()"]
    CHECK3 -->|No| SKIP3["skip"]
    SKIP3 --> CHECK4{"db_KK_T_OP_SVC_KEI_094 != null?"}
    CLOSE3 --> CHECK4
    CHECK4 -->|Yes| CLOSE4["db_KK_T_OP_SVC_KEI_094.close()"]
    CHECK4 -->|No| SKIP4["skip"]
    CLOSE4 --> END(["Return void"])

    END(["Return void"])
```

**Processing Summary:**

The method sequentially checks each of the four `JBSbatSQLAccess` instance fields. If the reference is non-null, it calls `close()` on the access object to release the underlying database connection. If the reference is null (e.g., the `initial()` phase was never called, or the connection failed to initialize), the method safely skips that resource. The four access objects correspond to three distinct database tables:

| Access Object | Null Check | Operation |
|---|---|---|
| `db_KK_T_IDO_RSV` | Yes (L853) | Closes access to `KK_T_IDO_RSV` (Idle/Reservation table) |
| `db_KK_T_CASCD_KNRI` | Yes (L858) | Closes access to `KK_T_CASCD_KNRI` (CAS Card Management table) |
| `db_KK_T_OP_SVC_KEI` | Yes (L863) | Closes access to `KK_T_OP_SVC_KEI` (Option Service Contract table) |
| `db_KK_T_OP_SVC_KEI_094` | Yes (L866) | Closes access to `KK_T_OP_SVC_KEI` (Option Service Contract table, 094 variant) |

Each `if` block follows the same pattern: guard with null check, then call `close()`. This is a defensive coding pattern generated by a code generator tool.

## 3. Parameter Analysis

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

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

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_IDO_RSV` | `JBSbatSQLAccess` | Database access handle for the KK_T_IDO_RSV table (Idle/Reservation) — used to read and manage idle reservation records during Spica cancellation processing |
| `db_KK_T_CASCD_KNRI` | `JBSbatSQLAccess` | Database access handle for the KK_T_CASCD_KNRI table (CAS Card Management) — used to read and manage CAS card information during cancellation |
| `db_KK_T_OP_SVC_KEI` | `JBSbatSQLAccess` | Database access handle for the KK_T_OP_SVC_KEI table (Option Service Contract) — used to read and manage option service contract data during cancellation |
| `db_KK_T_OP_SVC_KEI_094` | `JBSbatSQLAccess` | Database access handle for the KK_T_OP_SVC_KEI table (Option Service Contract, 094 variant) — a second handle to the same table for a distinct query path (KK_SELECT_094) |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `db_KK_T_IDO_RSV.close` | JBSbatSQLAccess | KK_T_IDO_RSV | Calls `close` on the SQL access object for the Idle Reservation table |
| - | `db_KK_T_CASCD_KNRI.close` | JBSbatSQLAccess | KK_T_CASCD_KNRI | Calls `close` on the SQL access object for the CAS Card Management table |
| - | `db_KK_T_OP_SVC_KEI.close` | JBSbatSQLAccess | KK_T_OP_SVC_KEI | Calls `close` on the SQL access object for the Option Service Contract table |
| - | `db_KK_T_OP_SVC_KEI_094.close` | JBSbatSQLAccess | KK_T_OP_SVC_KEI | Calls `close` on the SQL access object for the Option Service Contract table (094 variant) |

**Classification:** All four operations are **resource cleanup** (close) calls. They are not traditional CRUD operations (Create/Read/Update/Delete) on business data. Instead, they release database connection resources held by `JBSbatSQLAccess` wrapper objects, which were created during `initial()` to query these tables. The `close()` method internally handles any remaining transaction rollback or connection release logic.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `db_KK_T_IDO_RSV.close` | JBSbatSQLAccess | KK_T_IDO_RSV | Releases the database connection for the Idle/Reservation table |
| - | `db_KK_T_CASCD_KNRI.close` | JBSbatSQLAccess | KK_T_CASCD_KNRI | Releases the database connection for the CAS Card Management table |
| - | `db_KK_T_OP_SVC_KEI.close` | JBSbatSQLAccess | KK_T_OP_SVC_KEI | Releases the database connection for the Option Service Contract table |
| - | `db_KK_T_OP_SVC_KEI_094.close` | JBSbatSQLAccess | KK_T_OP_SVC_KEI | Releases the database connection for the Option Service Contract table (094 variant) |

## 5. Dependency Trace

This method has **no direct callers** found in the codebase. As a lifecycle callback method that extends `JBSbatBusinessService`, `terminal()` is invoked by the batch framework infrastructure automatically at the end of the batch processing lifecycle, after all business logic in the parent class execution completes.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKSkaWrkCnclProc | Batch framework lifecycle → JBSbatBusinessService.terminal → JBSbatKKSkaWrkCnclProc.terminal | `db_KK_T_IDO_RSV.close [-] KK_T_IDO_RSV` |
| 2 | Batch: JBSbatKKSkaWrkCnclProc | Batch framework lifecycle → JBSbatBusinessService.terminal → JBSbatKKSkaWrkCnclProc.terminal | `db_KK_T_CASCD_KNRI.close [-] KK_T_CASCD_KNRI` |
| 3 | Batch: JBSbatKKSkaWrkCnclProc | Batch framework lifecycle → JBSbatBusinessService.terminal → JBSbatKKSkaWrkCnclProc.terminal | `db_KK_T_OP_SVC_KEI.close [-] KK_T_OP_SVC_KEI` |
| 4 | Batch: JBSbatKKSkaWrkCnclProc | Batch framework lifecycle → JBSbatBusinessService.terminal → JBSbatKKSkaWrkCnclProc.terminal | `db_KK_T_OP_SVC_KEI_094.close [-] KK_T_OP_SVC_KEI` |

**Notes:**
- The method is part of the Spica Construction Cancellation Batch (`JBSbatKKSkaWrkCnclProc` — スカパー工事取消処理), which handles cancellation of Spica satellite construction orders.
- No screen-level (KKSV*) callers exist — this is a batch-only lifecycle method.

## 6. Per-Branch Detail Blocks

**Block 1** — IF `(db_KK_T_IDO_RSV != null)` (L853)

> Closes the database access object for the KK_T_IDO_RSV (Idle Reservation) table.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (db_KK_T_IDO_RSV != null)` // Null guard check for idle reservation DB access |
| 2 | CALL | `db_KK_T_IDO_RSV.close()` // Closes connection to KK_T_IDO_RSV table |

**Block 1.1** — ELSE (implicit, L853)

> Skipped if `db_KK_T_IDO_RSV` is null (e.g., `initial()` was not called).

---

**Block 2** — IF `(db_KK_T_CASCD_KNRI != null)` (L858)

> Closes the database access object for the KK_T_CASCD_KNRI (CAS Card Management) table.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (db_KK_T_CASCD_KNRI != null)` // Null guard check for CAS card management DB access |
| 2 | CALL | `db_KK_T_CASCD_KNRI.close()` // Closes connection to KK_T_CASCD_KNRI table |

**Block 2.1** — ELSE (implicit, L858)

> Skipped if `db_KK_T_CASCD_KNRI` is null.

---

**Block 3** — IF `(db_KK_T_OP_SVC_KEI != null)` (L863)

> Closes the database access object for the KK_T_OP_SVC_KEI (Option Service Contract) table — primary path.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (db_KK_T_OP_SVC_KEI != null)` // Null guard check for option service contract DB access |
| 2 | CALL | `db_KK_T_OP_SVC_KEI.close()` // Closes connection to KK_T_OP_SVC_KEI table |

**Block 3.1** — ELSE (implicit, L863)

> Skipped if `db_KK_T_OP_SVC_KEI` is null.

---

**Block 4** — IF `(db_KK_T_OP_SVC_KEI_094 != null)` (L866)

> Closes the database access object for the KK_T_OP_SVC_KEI (Option Service Contract) table — 094 variant path (used for distinct queries, e.g., `KK_SELECT_094`).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `if (db_KK_T_OP_SVC_KEI_094 != null)` // Null guard check for option service contract DB access (094 variant) |
| 2 | CALL | `db_KK_T_OP_SVC_KEI_094.close()` // Closes connection to KK_T_OP_SVC_KEI table (094 variant) |

**Block 4.1** — ELSE (implicit, L866)

> Skipped if `db_KK_T_OP_SVC_KEI_094` is null.

---

**Block 5** — RETURN (L870)

> Returns void. All four DB access objects have been safely closed (or verified null and skipped).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `void` // Method completes; batch framework proceeds to next lifecycle phase |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `terminal()` | Method | Business service termination processing — cleanup lifecycle hook called at the end of batch execution |
| JBSbatBusinessService | Class | Base batch business service class — provides common batch lifecycle methods (initial, terminal, etc.) |
| JBSbatSQLAccess | Class | Database SQL access wrapper — manages database connections and provides select/insert/update/delete operations on a single table |
| KK_T_IDO_RSV | Table | Idle/Reservation table — stores idle reservation records used during Spica cancellation processing |
| KK_T_CASCD_KNRI | Table | CAS Card Management table — stores CAS (Common Access System) card information for satellite service authentication |
| KK_T_OP_SVC_KEI | Table | Option Service Contract table — stores option service contract line item data for subscribed services |
| Spica (スカパー) | Business term | A Japanese satellite broadcasting service operated by K-Opticom; "Spica construction" refers to installation/setup of Spica satellite service at customer premises |
| スカパー工事取消 (Sukapaa kouji torikeshi) | Business term | Spica construction cancellation — the core business process of this batch, which cancels or reverts Spica satellite installation orders |
| 業務サービス終了処理 (Gyoubu saabisu shuuryo shori) | Business term | Business service termination processing — the lifecycle phase where all resources (DB connections, files, etc.) are released |
| ツールから生成 (Tool kara seisei) | Technical note | "Generated from tool" — indicates this method's source code was produced by an internal code generation tool, not hand-written |
| KK_SELECT_094 | SQL Define Key | SQL definition key for a specific SELECT query on KK_T_OP_SVC_KEI (variant 094) |
| KK_SELECT_114 | SQL Define Key | SQL definition key for a specific SELECT query on KK_T_IDO_RSV |
| KK_SELECT_115 | SQL Define Key | SQL definition key for a specific SELECT query on KK_T_IDO_RSV |
| KK_SELECT_005 | SQL Define Key | SQL definition key for a specific SELECT query on KK_T_CASCD_KNRI |
| FUNC_CD_UPD | Constant | Function code "1" — update mode |
| FUNC_CD_CHK | Constant | Function code "2" — check-only mode |
| SHORI_CD_CRS_CHG_CL | Constant | Process code "3" — course change cancellation |
| SPTVKEYINFOOPERATECC | Constant | SpTV Key Information Operation Common Component — constant referencing a common component for satellite key information operations |
