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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKSkaLckDteEdit` |
| Layer | Batch Service (package `eo.business.service`, under `koptBatch`) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKSkaLckDteEdit.terminal()

This method implements the **business service termination (cleanup) lifecycle hook** as defined by the `JBSbatBusinessService` abstract base class. Its sole responsibility is to release the database access resource (`db_KK_T_IDO_RSV`) that was allocated during the batch's `main` (initialization) phase. The Javadoc states "業務サービス終了処理" (business service termination processing), and the source includes a tool-generated placeholder "ツールから生成した終了処理のソースです" (source of termination processing generated from the tool). The method implements the **resource cleanup/disposal pattern** — a defensive null-check followed by a single `close()` call on the SQL access handle. As a terminal hook, this method is invoked by the batch framework after all primary batch processing (the "skarga kunci penyesuaian tanggal" / date adjustment lock adjustment) has completed, ensuring no database connection leaks occur. It serves as a safety net for the `KK_T_IDO_RSV` (displaced reservation) table access, a table shared across many batch services in the system for reservation-style work coordination.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal()"])
    CHECK["db_KK_T_IDO_RSV != null?"]
    CLOSE["db_KK_T_IDO_RSV.close()"]
    END_NODE(["Return / Next"])

    START --> CHECK
    CHECK -->|true| CLOSE
    CHECK -->|false| END_NODE
    CLOSE --> END_NODE
```

The method performs a single defensive cleanup step:

1. **Null-check** on the `db_KK_T_IDO_RSV` SQL access handle (an instance field of type `JBSbatSQLAccess` initialized to `null` in the class declaration).
2. If the handle is **not null** (meaning the batch's initialization phase successfully created it), call `close()` to release the underlying database connection and result set resources.
3. If the handle **is null** (initialization was skipped or failed before allocation), skip directly to return — no exception is thrown.
4. Return immediately (void method).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

The method takes no parameters. It operates entirely on the instance-level database access resource.

| # | Instance Field | Type | Business Description |
|---|---------------|------|---------------------|
| 1 | `db_KK_T_IDO_RSV` | `JBSbatSQLAccess` | Database access handle for the `KK_T_IDO_RSV` (displaced reservation) table — holds the active SQL connection opened during batch initialization and closed here at termination |

## 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 analysis:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| D | `db_KK_T_IDO_RSV.close` | - | `KK_T_IDO_RSV` | Closes the SQL access handle for the displaced reservation table, releasing the database connection and any pending cursors |

## 5. Dependency Trace

No direct callers of `JBSbatKKSkaLckDteEdit.terminal()` were found in the codebase beyond the abstract base class declaration. This method is invoked **indirectly** by the batch framework's lifecycle management, following the template pattern defined in `JBSbatBusinessService`.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch Framework | `JBSbatBusinessService.main()` (framework lifecycle) -> `JBSbatKKSkaLckDteEdit.terminal` | `db_KK_T_IDO_RSV.close [D] KK_T_IDO_RSV` |
| 2 | `JBSbatBusinessService` (abstract) | Defines abstract `terminal()` method — all batch services in `eo.business.service` override this to define their own cleanup | - |

The method is part of the standard batch service lifecycle: batch entry -> `main()` processing -> `terminal()` cleanup. The framework calls it after the batch's primary processing completes (or if an error occurs during processing).

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(db_KK_T_IDO_RSV != null)` (L279)

> Null-check guard on the database access handle. Only executes cleanup if the handle was successfully initialized.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (db_KK_T_IDO_RSV != null)` // Guard: verify SQL access handle was allocated before closing [Field: `db_KK_T_IDO_RSV`] |
| 2 | EXEC | `db_KK_T_IDO_RSV.close();` // Release database connection and resources for the displaced reservation table |

**Block 1.1** — [implicit else] `(db_KK_T_IDO_RSV == null)` (L279)

> If the handle was never allocated (e.g., batch initialization was skipped or failed early), skip cleanup entirely. No action taken.

| # | Type | Code |
|---|------|------|
| 1 | NOOP | (no-op — null handle means nothing to close) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `terminal` | Method | Business service termination processing — lifecycle hook for cleanup resources at end of batch execution |
| `db_KK_T_IDO_RSV` | Field | Database access handle for the `KK_T_IDO_RSV` table — a `JBSbatSQLAccess` instance wrapping the connection |
| `KK_T_IDO_RSV` | Table | Displaced Reservation Table (異動予約) — a work table used across batch services to reserve and track data displacement operations; shared by many batch services including `JBSbatKKWatchCtrlReq`, `JBSbatKKTgKktkSvcKeiUpd`, `JBSbatKKEoTVChgeFix`, and others |
| `D_TBL_NAME_KK_T_IDO_RSV` | Constant | Table name constant = `"KK_T_IDO_RSV"` — static field defining the displaced reservation table name for SQL access instantiation |
| `JBSbatSQLAccess` | Class | Database SQL access utility class — provides `selectNext()`, `insertByPrimaryKeys()`, `updateByPrimaryKeys()`, `close()` methods for batch DB operations |
| `JBSbatBusinessService` | Class | Abstract base class for all batch business services — defines the `terminal()` lifecycle hook as an abstract method |
| `KKSkaLckDteEdit` | Domain | Skarga Kunci Penyesuaian Tanggal (Date Adjustment Lock Adjustment) — the batch domain this service class handles; likely adjusts date-based lock/skarga conditions |
| `close()` | Method | Database resource cleanup — releases the SQL connection, closes result sets, and frees native resources held by `JBSbatSQLAccess` |
