# Business Logic — JBSbatKKAdChgTekkyoKjFinChsht.terminal() [11 LOC]

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

## 1. Role

### JBSbatKKAdChgTekkyoKjFinChsht.terminal()

This method performs the business service shutdown (resource cleanup) routine at the end of a batch processing lifecycle. The class name `JBSbatKKAdChgTekkyoKjFinChsht` translates to "Address Change Delivery Completion Extraction" — it is a batch service product that handles the extraction of completed work items for address change (move) operations where the cancellation start date is linked to the actual delivery completion date (per fix OM-2014-0003696, version 11.00.00).

The `terminal()` method implements the standard `JBSbatBusinessService` template method pattern: after `initial()` opens database access objects and `execute()` processes the address change delivery completion extraction data, `terminal()` is the lifecycle callback responsible for releasing all allocated resources. It closes the three `JBSbatSQLAccess` database connection handles that were initialized during `initial()`, ensuring no database connection leaks occur.

Its role in the larger system is as a **shared utility cleanup hook** — the `terminal()` method is an abstract lifecycle hook defined in the parent class `JBSbatBusinessService` that is invoked automatically by the batch execution framework after the main processing completes (whether successfully or with an exception). This ensures consistent resource management across all batch services.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["terminal()"])
    STEP1["db_KK_T_KJ_FIN_WK.close()
Close Work Order Completion Work table access"]
    STEP2["db_KK_T_ADCHG_DTL.close()
Close Address Change Detail table access"]
    STEP3["db_KK_T_ADCHG.close()
Close Address Change table access"]
    END_NODE(["Return / Next"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> END_NODE
```

**Processing Flow:**
1. **Close Work Order Completion Work table access** — Invokes `close()` on the `JBSbatSQLAccess` instance `db_KK_T_KJ_FIN_WK`, releasing the database connection/resources for the temporary work table `KK_T_KJ_FIN_WK` (Work Order Completion Work).
2. **Close Address Change Detail table access** — Invokes `close()` on `db_KK_T_ADCHG_DTL`, releasing resources for the Address Change Detail table `KK_T_ADCHG_DTL`.
3. **Close Address Change table access** — Invokes `close()` on `db_KK_T_ADCHG`, releasing resources for the Address Change table `KK_T_ADCHG`.
4. **Return** — Method returns `void`; the batch framework proceeds to the next phase (or completes the batch job).

**Constant Resolution:**
| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `D_TBL_NAME_KK_T_KJ_FIN_WK` | `"KK_T_KJ_FIN_WK"` | Work Order Completion Work temporary table |
| `D_TBL_NAME_KK_T_ADCHG_DTL` | `"KK_T_ADCHG_DTL"` | Address Change Detail temporary table |
| `D_TBL_NAME_KK_T_ADCHG` | `"KK_T_ADCHG"` | Address Change temporary table |

## 3. Parameter Analysis

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

**Instance Fields / External State read:**

| No | Field Name | Type | Business Description |
|----|------------|------|---------------------|
| 1 | `db_KK_T_KJ_FIN_WK` | `JBSbatSQLAccess` | Database access handle for the Work Order Completion Work table (`KK_T_KJ_FIN_WK`). Opened during `initial()`, closed in `terminal()`. |
| 2 | `db_KK_T_ADCHG_DTL` | `JBSbatSQLAccess` | Database access handle for the Address Change Detail table (`KK_T_ADCHG_DTL`). Opened during `initial()`, closed in `terminal()`. |
| 3 | `db_KK_T_ADCHG` | `JBSbatSQLAccess` | Database access handle for the Address Change table (`KK_T_ADCHG`). Opened during `initial()`, closed in `terminal()`. |

## 4. CRUD Operations / Called Services

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

The `terminal()` method closes all three database access objects. This is a standard cleanup pattern where each `JBSbatSQLAccess.close()` call releases the underlying JDBC resources (result sets, prepared statements, connection handles).

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `db_KK_T_KJ_FIN_WK.close` | JBSbatSQLAccess | `KK_T_KJ_FIN_WK` | Closes the SQL access connection for the Work Order Completion Work table |
| - | `db_KK_T_ADCHG_DTL.close` | JBSbatSQLAccess | `KK_T_ADCHG_DTL` | Closes the SQL access connection for the Address Change Detail table |
| - | `db_KK_T_ADCHG.close` | JBSbatSQLAccess | `KK_T_ADCHG` | Closes the SQL access connection for the Address Change table |

**Classification rationale:**
- These are **not** CRUD (Create/Read/Update/Delete) operations against business data.
- They are **resource deallocation** calls that release database access objects and their underlying JDBC connections.
- Each `close()` call ensures proper cleanup to prevent connection pool exhaustion and resource leaks.

## 5. Dependency Trace

This method is defined as an `abstract` lifecycle hook in the parent class `JBSbatBusinessService`. It is invoked by the batch execution framework after `initial()` and `execute()` complete. The `terminal()` implementation in this class is the final cleanup step of the batch lifecycle.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch Framework (JBSbatBusinessService lifecycle) | `JBSbatBusinessService.executeBatch()` -> `terminal()` | `db_KK_T_KJ_FIN_WK.close [R] KK_T_KJ_FIN_WK`<br>`db_KK_T_ADCHG_DTL.close [R] KK_T_ADCHG_DTL`<br>`db_KK_T_ADCHG.close [R] KK_T_ADCHG` |

**Notes:**
- No direct caller class was found in the codebase searching for `JBSbatKKAdChgTekkyoKjFinChsht` references — the method is invoked through the batch framework's template method dispatch mechanism.
- The parent class `JBSbatBusinessService` declares `terminal()` as `public abstract void terminal() throws Exception` (line 92), which the batch framework calls as part of its standard lifecycle management.

## 6. Per-Branch Detail Blocks

**Block 1** — [PROCEDURE] `(db_KK_T_KJ_FIN_WK.close)` (L191)

> Close database access for the Work Order Completion Work temporary table. This is the first cleanup step in the resource deallocation sequence.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_KJ_FIN_WK.close()` // Closes DB access to Work Order Completion Work (KK_T_KJ_FIN_WK) table |

**Block 2** — [PROCEDURE] `(db_KK_T_ADCHG_DTL.close)` (L192)

> Close database access for the Address Change Detail temporary table. The second cleanup step, executed unconditionally after Block 1.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_ADCHG_DTL.close()` // Closes DB access to Address Change Detail (KK_T_ADCHG_DTL) table |

**Block 3** — [PROCEDURE] `(db_KK_T_ADCHG.close)` (L193)

> Close database access for the Address Change temporary table. The final cleanup step, executed unconditionally after Block 2.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_ADCHG.close()` // Closes DB access to Address Change (KK_T_ADCHG) table |

**Block 4** — [RETURN] `(void)` (L194)

> Return from method. The batch framework continues to the next lifecycle phase (or terminates the batch job if this was the final method).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Implicit void return |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kjfinwk` | Field | Work Order Completion — prefix for work order completion work table fields |
| `kojiakNo` | Field | Work Order Number — unique identifier for a work order (案件番号 = case number) |
| `svc_kei_no` | Field | Service Contract Number — internal tracking ID for a service contract line item |
| `jssi_ymd` | Field | Work Implementation Year-Month-Day — the date when the work was actually performed |
| `adchg_no` | Field | Address Change Number — unique identifier for an address change record |
| `adchgdtl` | Field | Address Change Detail — table alias for address change detail records |
| `mskm_no` | Field | Application Number — the submission/registration number for an address change request |
| `KK_T_KJ_FIN_WK` | Table | Work Order Completion Work temporary table — holds intermediate work order completion data during batch processing |
| `KK_T_ADCHG_DTL` | Table | Address Change Detail temporary table — holds detail-level address change records (e.g., old/new addresses) |
| `KK_T_ADCHG` | Table | Address Change temporary table — holds header-level address change records |
| `KK_SELECT_042` | SQL Key | SQL definition key used for querying the Address Change Detail table |
| `KK_SELECT_021` | SQL Key | SQL definition key used for querying the Address Change table |
| `JBSbatSQLAccess` | Class | Database access abstraction layer — manages JDBC connections, prepared statements, and result sets for batch operations |
| `JBSbatBusinessService` | Class | Abstract base class for all batch business services — defines the lifecycle: `initial()` -> `execute()` -> `terminal()` |
| `AdChg` | Acronym | Address Change — a customer move/migration operation that updates a customer's registered address |
| `Tekkyo` | Business term | Delivery — refers to the physical installation/delivery work at the customer's premises |
| `KjFin` | Acronym | Work Order Completion — status indicating that field work has been completed |
| `Chsht` | Acronym | Extraction — refers to data extraction/querying for reporting or downstream processing |
| `OM-2014-0003696` | Change | Fix that linked cancellation start date to delivery completion date for address change operations (version 11.00.00) |
