---

# Business Logic — JBSbatKKDelRun.updateDelTrnJssiDtmSvcKei() [83 LOC]

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

## 1. Role

### JBSbatKKDelRun.updateDelTrnJssiDtmSvcKei()

This method is responsible for **updating the deletion execution date and time** (`DEL_TRN_JSSI_DTM`) on the **service contract table** (`KK_T_SVC_KEI`) during the batch-based service contract deletion processing run. It is a core step within the service contract line (svc_kei) deletion workflow — the deletion job batch reads eligible records and invokes this method to mark them as "processing initiated" by writing the batch execution timestamp into the `SVCTK_BUT_DEL_TRN_JSSI_DTM` field.

The method implements an **optimistic concurrency control** (pessimistic locking) pattern introduced in version v33.00.00 (change OM-2017-0000735) to eliminate a **race condition** where concurrent batch executions could overwrite each other's timestamps. It performs a read-before-write check: it first selects the current record to obtain the authoritative `GENE_ADD_DTM` (service contract generation registration datetime), then uses that value as part of the update's WHERE clause to ensure only the expected version is overwritten.

The method acts as a **delegation handler** within the larger `JBSbatKKDelRun` batch service class. It is called by `updateDelTrnJssiDtm()` which coordinates the multi-line-item deletion of a service contract. The old version of this method (now commented out as a performance improvement deletion) performed full historical record insertion — writing archived copies of the service contract into subsidiary tables (`KK_T_SVC_KEI_EOH_NET`, `KK_T_SVC_KEI_EOADSL`, etc.) based on service type. The refactored version consolidates this into a single targeted update.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateDelTrnJssiDtmSvcKei(inMap)"])

    START --> SET_MAP["Create setMap with SVCTK_BUT_DEL_TRN_JSSI_DTM = sysDate"]
    SET_MAP --> SET_WHERE["Create whereMap: SVC_KEI_NO, GENE_ADD_DTM from inMap"]
    SET_WHERE --> PREPARE_PARAM["Prepare param[]: SVC_KEI_NO, opeDate"]
    PREPARE_PARAM --> EXEC_SELECT["executeKK_T_SVC_KEI_KK_SELECT_112(param)"]
    EXEC_SELECT --> SELECT_NEXT["db_KK_T_SVC_KEI_KK112.selectNext() -> getSvckeiMap"]
    SELECT_NEXT --> GET_SEDAI["GetString GENE_ADD_DTM from getSvckeiMap -> sedai"]
    GET_SEDAI --> COND{"sedai.equals(inMap GENE_ADD_DTM?)"

    COND -->|Yes| UPDATE_WITH_ORIG["DB access: updateByPrimaryKeys(whereMap, setMap)"]
    COND -->|No| UPDATE_WITH_MOD["Set whereMap GENE_ADD_DTM = sedai
DB access: updateByPrimaryKeys(whereMap, setMap)"]

    UPDATE_WITH_ORIG --> END_NODE(["Return / Next"])
    UPDATE_WITH_MOD --> END_NODE
```

**Processing flow description:**

1. **Prepare the update payload (`setMap`)**: Creates a `JBSbatCommonDBInterface` object and sets the field `SVCTK_BUT_DEL_TRN_JSSI_DTM` to the current system date (`this.sysDate`). This field records the batch deletion execution timestamp.

2. **Prepare the base WHERE clause (`whereMap`)**: Creates a second interface map containing the service contract number (`SVC_KEI_NO`) and the input's generation registration datetime (`GENE_ADD_DTM` from `inMap`) as the initial filtering criteria.

3. **Query for the authoritative record**: Prepares query parameters consisting of the service contract number and the batch operation date (`super.opeDate`), then calls `executeKK_T_SVC_KEI_KK_SELECT_112(param)` to fetch the current state of the service contract record from the database.

4. **Read-back the authoritative `GENE_ADD_DTM`**: Calls `db_KK_T_SVC_KEI_KK112.selectNext()` to retrieve the selected record, then extracts the current `GENE_ADD_DTM` value from the result set into the local variable `sedai`.

5. **Concurrency check (optimistic lock)**: Compares `sedai` (the DB's authoritative value) against `inMap.getString(JBSbatKKIFM161.SVKEI_GADTM)` (the value that was read earlier and sent for update). If they match, the optimistic lock succeeds — no concurrent modification occurred. If they differ, the WHERE clause is adjusted to use the DB's current `sedai` value instead of the input's stale value.

6. **Execute the update**: In **both branches**, calls `db_KK_T_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)` to update the service contract record. When `sedai` matches the input, the WHERE clause uses the original criteria. When it differs, the WHERE clause is updated to use `sedai`, effectively updating the record using the authoritative version as the lock token.

**Optimistic lock note**: The method always performs an update regardless of whether the optimistic lock matches. The key difference is in the WHERE clause — when the values differ, the WHERE clause is adjusted to use the DB's current `sedai` rather than the input's potentially stale value, ensuring the correct row is updated without raising an exception. This design choice reflects the batch deletion context where stale reads are acceptable because the deletion job re-processes records in subsequent runs.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | The input message carrying service contract deletion parameters. It contains the service contract number (`SVC_KEI_NO`) identifying which contract line item to mark for deletion, and the service contract generation registration datetime (`SVKEI_GADTM`) used as an optimistic concurrency token to prevent lost-update conflicts between concurrent batch runs. |
| 2 | `this.sysDate` | `String` (instance field) | The system date timestamp assigned at batch startup — used as the deletion execution datetime value to write into the `SVCTK_BUT_DEL_TRN_JSSI_DTM` field. |
| 3 | `super.opeDate` | `String` (instance field, inherited) | The batch operation date — used as a query parameter when selecting the current service contract record, ensuring the query targets the correct operational context. |
| 4 | `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` (instance field) | Database access handle for the `KK_T_SVC_KEI` (Service Contract) table. Used to execute the primary-key-based update. |
| 5 | `db_KK_T_SVC_KEI_KK112` | `JBSbatSQLAccess` (instance field) | Database access handle specifically configured for the `KK_T_SVC_KEI` table with the SELECT_112 SQL definition. Used to read back the current record state. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_SVC_KEI_KK_SELECT_112` | KK_T_SVC_KEI_KK | KK_T_SVC_KEI | Select the current service contract record for optimistic concurrency check |
| U | `db_KK_T_SVC_KEI.updateByPrimaryKeys` | KK_T_SVC_KEI | KK_T_SVC_KEI | Update the service contract deletion execution datetime via primary key |

**Detailed analysis:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_SVC_KEI_KK_SELECT_112` | KK_T_SVC_KEI_KK | KK_T_SVC_KEI | Selects the current service contract record using the service contract number and batch operation date. Retrieves the authoritative `GENE_ADD_DTM` (generation registration datetime) for optimistic locking. |
| U | `db_KK_T_SVC_KEI.updateByPrimaryKeys` | KK_T_SVC_KEI | KK_T_SVC_KEI | Updates the `SVCTK_BUT_DEL_TRN_JSSI_DTM` field (deletion execution date/time) on the service contract record. Uses primary keys and the optimistic lock token (`GENE_ADD_DTM`) in the WHERE clause. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKDelRun | `JBSbatKKDelRun.updateDelTrnJssiDtm` -> `JBSbatKKDelRun.updateDelTrnJssiDtmSvcKei` | `executeKK_T_SVC_KEI_KK_SELECT_112 [R] KK_T_SVC_KEI`, `updateByPrimaryKeys [U] KK_T_SVC_KEI` |

**Instructions followed:**
- Searched for all callers of `updateDelTrnJssiDtmSvcKei` in the codebase.
- The only direct caller is `updateDelTrnJssiDtm()` within the same class `JBSbatKKDelRun`.
- This is a batch processing method — part of the service contract deletion batch job.
- The method performs one Read (select) and one Update on the `KK_T_SVC_KEI` (Service Contract) table.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L1073)

> Creates the update payload (setMap) containing the deletion execution timestamp.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setMap = new JBSbatCommonDBInterface()` |
| 2 | SET | `setMap.setValue("SVCTK_BUT_DEL_TRN_JSSI_DTM", this.sysDate)` // Sets the deletion execution datetime to the current system date [-> SVCTK_BUT_DEL_TRN_JSSI_DTM = batch startup timestamp] |

---

**Block 2** — [SET] (L1076)

> Creates the WHERE clause map for the update operation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereMap = new JBSbatCommonDBInterface()` |
| 2 | SET | `whereMap.setValue("SVC_KEI_NO", inMap.getString(JBSbatKKIFM161.SVKEI_NO))` // Service contract number from input [-> SVC_KEI_NO identifies the contract line] |
| 3 | SET | `whereMap.setValue("GENE_ADD_DTM", inMap.getString(JBSbatKKIFM161.SVKEI_GADTM))` // Generation registration datetime from input [-> GENE_ADD_DTM used as optimistic lock token] |

---

**Block 3** — [SET] (L1080–L1086) — `//OM-2017-0000735 MOD START`

> Prepares query parameters for the optimistic concurrency check. Retrieves the service contract number and batch operation date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `param = null` |
| 2 | SET | `param = new String[2]` |
| 3 | SET | `param[0] = inMap.getString(JBSbatKKIFM161.SVKEI_NO)` // Deletion target data (post-check): Service contract number |
| 4 | SET | `param[1] = super.opeDate` // Batch operation date |

---

**Block 4** — [CALL] (L1088)

> Executes the SELECT_112 query to read back the current service contract record from the database.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVC_KEI_KK_SELECT_112(param)` // Query service contract for optimistic lock check |

---

**Block 5** — [SET] (L1091–L1092)

> Retrieves the selected record and extracts the authoritative generation registration datetime.

| # | Type | Code |
|---|------|------|
| 1 | SET | `getSvckeiMap = db_KK_T_SVC_KEI_KK112.selectNext()` // Gets the next row from the SELECT_112 result |
| 2 | SET | `sedai = (String) getSvckeiMap.getString("GENE_ADD_DTM")` // Service contract generation registration [-> sedai is the DB-authoritative GENE_ADD_DTM] |

---

**Block 6** — [IF/ELSE] (`sedai.equals(inMap.getString(JBSbatKKIFM161.SVKEI_GADTM))`) (L1093)

> Optimistic concurrency check: compares the DB's authoritative generation registration datetime against the input value. If they match, no concurrent modification occurred.

> **Business Description**: This check prevents lost-update anomalies in batch deletion. When multiple batch instances process the same service contract, the one with the most recent `GENE_ADD_DTM` wins. If the values match, the optimistic lock succeeds and the update proceeds with the original WHERE clause. If they differ, the WHERE clause is adjusted to use the DB's current value, ensuring the correct record is updated.

**Block 6.1** — [ELSE-IF] (condition: **true** — values match) (L1094–L1095)

> The DB's `GENE_ADD_DTM` matches the input value. No concurrent modification — proceed with original WHERE clause.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)` // DB access: update service contract deletion execution datetime |

**Block 6.2** — [ELSE] (condition: **true** — values differ) (L1096–L1098)

> The DB's `GENE_ADD_DTM` differs from the input value. A concurrent modification has occurred (or the record was modified since the input was prepared). Adjust the WHERE clause to use the authoritative DB value before updating.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereMap.setValue("GENE_ADD_DTM", sedai)` // Override WHERE clause with authoritative DB value |
| 2 | EXEC | `db_KK_T_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)` // DB access: update service contract deletion execution datetime with adjusted WHERE |

---

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `SVKEI_NO` | Field | Service contract number — unique identifier for a service contract line item within the telecom service provisioning system |
| `SVKEI_GADTM` | Field | Service contract generation registration date and time — timestamp indicating when this version of the service contract record was created/last regenerated; used as an optimistic concurrency control token |
| `GENE_ADD_DTM` | Field | Generation addition date and time — internal database column name matching `SVKEI_GADTM`; represents when the service contract record version was registered in the database |
| `SVCTK_BUT_DEL_TRN_JSSI_DTM` | Field | Service contract batch deletion transmission start datetime — records the exact date/time when the batch deletion job processed this record; marks the contract as "deletion initiated" |
| `SVC_KEI_NO` | Field | Service contract number — used in the WHERE clause to identify which specific service contract line to update |
| `sysDate` | Field | System date — the application server's current timestamp at batch startup, used as the value for deletion execution datetime fields throughout the batch processing |
| `opeDate` | Field | Operation date — the batch job's operational date, used as a query parameter to scope database searches to the correct operational context |
| `KK_T_SVC_KEI` | Table | Service contract table — the primary database table storing service contract line items for all service types (FTTH, ADSL, Mobile, VoIP, etc.) |
| `KK_T_SVC_KEI_KK112` | DB Handle | SQL access configured with the KK_SELECT_112 query definition — used to read the current service contract record state for optimistic locking |
| `db_KK_T_SVC_KEI` | DB Handle | SQL access handle for the KK_T_SVC_KEI table — used to execute the primary-key-based update operation |
| optimistic lock | Concept | Concurrency control pattern where the method reads a version token (`GENE_ADD_DTM`) before update and includes it in the WHERE clause; if the token has changed, the update uses the current DB value to avoid overwriting concurrent modifications |
| race condition | Concept | A defect where concurrent batch executions could overwrite each other's timestamps; eliminated in v33.00.00 by the read-before-write pattern implemented in this method |
| service contract (svc_kei) | Domain term | A line item in the telecom service provisioning system representing a customer's contracted service (e.g., FTTH internet, mobile phone, VoIP) |
| deletion execution (kesho jikko) | Domain term | The batch process that marks service contracts for deletion by writing timestamps and moving records to history/archive tables |
| batch operation (batch unyo) | Domain term | An automated scheduled job run that processes bulk data operations such as service contract deletions |
| performance improvement deletion (seihou kaizen deuri) | Comment | Japanese comment indicating that older code in this method was removed as part of a performance optimization effort |

---
