# Business Logic — JBSbatKKKjFinClDataInTrn.updateSvkeiUwEohTv() [49 LOC]

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

## 1. Role

### JBSbatKKKjFinClDataInTrn.updateSvkeiUwEohTv()

This method performs the update processing for the Service Detail Breakdown &lt;eo Light TV&gt; (New) entity (`KK_T_SVKEIUW_EOH_TV` table), which represents the line-item breakdown of a service contract for K-Opticom's "eo Hikari TV" (fiber-optic television) subscription. It operates as an exclusive-lock-and-update pattern: first acquiring a pessimistic row lock via `selectByPrimaryKeysForUpdateWait`, then updating two specific fields — the Reservation Application Code (`RSV_APLY_CD`) and the Invalid Flag (`MK_FLG`) — to mark the contract line item as "under processing" (`"1"` for both values, meaning "reservation application in progress" and "invalid flag set"). If no matching record is found, it throws a `JBSbatBusinessException` with error code `EKKB0210CE` indicating a record-not-found condition. The method serves as a coordination point within the batch processing pipeline, called by the parent `execute()` method of the same class, and is responsible for transitioning a newly added service contract detail into a reserved/processing state. The design follows a find-then-update pattern with optimistic concurrency control via primary-key-based pessimistic locking.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateSvkeiUwEohTv svcKeiUcwkNoStr, geneAddDtmStr"])
    START --> INIT["Initialize map, where_map (JBSbatCommonDBInterface)"]
    INIT --> WHERE["where_map.setValue SVC_KEI_UCWK_NO svcKeiUcwkNoStr"]
    WHERE --> WHERE2["where_map.setValue GENE_ADD_DTM geneAddDtmStr"]
    WHERE2 --> SELECT["selectByPrimaryKeysForUpdateWait where_map"]
    SELECT --> CHECK{map != null}
    CHECK -- true --> ALLOCS["Allocate value[] param[] (size 2)"]
    ALLOCS --> VSET["value[0] = RSV_APLY_CD_TTDK = \"1\" (Reservation Application: Under Processing)"]
    VSET --> VSET2["value[1] = MK_FLG_MK = \"1\" (Invalid Flag: Invalid)"]
    VSET2 --> PSET["param[0] = svcKeiUcwkNoStr param[1] = geneAddDtmStr"]
    PSET --> LOGCHK{logPrint.chkLogLevel DEBUG}
    LOGCHK -- true --> LOG["printDebugLog param and value details"]
    LOGCHK -- false --> EXEC["executeKK_T_SVKEIUW_EOH_TV_PKUPDATE value, param"]
    LOG --> EXEC
    EXEC --> END_RETURN(["Return void"])
    CHECK -- false --> THROW["throw JBSbatBusinessException EKKB0210CE record not found"]
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `JBSbatKKConst.RSV_APLY_CD_TTDK` | `"1"` | Reservation Application Code — "Under Processing" (Yoyaku Shuchuu) |
| `JBSbatKKConst.MK_FLG_MK` | `"1"` | Invalid Flag — "Invalid" (Mukou), marks the record as logically invalidated |

The method implements a **Find-Then-Update with Pessimistic Lock** pattern. It first queries the target record with a `FOR UPDATE` lock (exclusive row-level lock with wait), and only proceeds with the update if the record exists. This prevents concurrent modification of the same service contract line item.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiUcwkNoStr` | `String` | Service Contract Detail Work Number — the unique internal identifier for a service contract line item (line of a service contract). Used as the primary key to locate the exact record to update in the `KK_T_SVKEIUW_EOH_TV` table. Corresponds to the `SVC_KEI_UCWK_NO` database column. |
| 2 | `geneAddDtmStr` | `String` | Generation Registration Date/Time — the timestamp of when this version (generation) of the record was originally registered. Used as the second part of the composite primary key for optimistic concurrency control. Corresponds to the `GENE_ADD_DTM` database column. Ensures the update applies only to the correct generation of the record. |

| No | Field Name | Source | Business Description |
|----|-----------|--------|---------------------|
| 1 | `db_KK_T_SVKEIUW_EOH_TV` | Instance field | Database access object for the `KK_T_SVKEIUW_EOH_TV` table — provides `selectByPrimaryKeysForUpdateWait` and `updateByPrimaryKeys` operations. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatCommonDBInterface.selectByPrimaryKeysForUpdateWait` | - | `KK_T_SVKEIUW_EOH_TV` | Exclusive-lock read (SELECT FOR UPDATE WAIT) — acquires a pessimistic row lock on the service contract detail record matching the primary key (`SVC_KEI_UCWK_NO`, `GENE_ADD_DTM`). This prevents concurrent modifications. |
| U | `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE` | JBSbatKKKjFinClDataInTrn | `KK_T_SVKEIUW_EOH_TV` | Updates the target record's `RSV_APLY_CD` (Reservation Application Code → "1") and `MK_FLG` (Invalid Flag → "1") fields via primary-key-based update. Sets the record to "under processing" and "invalid" status. |
| - | `JBSbatLogUtil.printDebugLog` (via super.logPrint) | JBSbatLogUtil | - | Debug logging — conditionally logs parameter values and update values when debug log level is active. Logged values include service contract detail number, generation timestamp, reservation application code, and invalid flag. |

**Classification rationale:**
- **R (Read)**: `selectByPrimaryKeysForUpdateWait` performs a SELECT with an exclusive row lock — this is a read operation with concurrency control.
- **U (Update)**: `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE` performs an UPDATE on two fields of the target record via the DB access object's `updateByPrimaryKeys` method.

## 5. Dependency Trace

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

Direct callers found: 1 methods.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKjFinClDataInTrn | `JBSbatKKKjFinClDataInTrn.execute()` → `JBSbatKKKjFinClDataInTrn.updateSvkeiUwEohTv(svcKeiUcwkNoStr, geneAddDtmStr)` | `selectByPrimaryKeysForUpdateWait [R] KK_T_SVKEIUW_EOH_TV` ; `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE [U] KK_T_SVKEIUW_EOH_TV` |

**Terminal operations reached from this method:**

| Terminal Method | Operation | Entity / DB |
|----------------|-----------|-------------|
| `selectByPrimaryKeysForUpdateWait` | R (Read) | `KK_T_SVKEIUW_EOH_TV` |
| `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE` | U (Update) | `KK_T_SVKEIUW_EOH_TV` |

## 6. Per-Branch Detail Blocks

**Block 1** — [VARIABLE DECLARATION] (L2170)

> Initialize working data structures for the query and value maps.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface map = new JBSbatCommonDBInterface()` |
| 2 | SET | `JBSbatCommonDBInterface where_map = new JBSbatCommonDBInterface()` |
| 3 | SET | `String[] value = null` |
| 4 | SET | `String[] param = null` |

**Block 2** — [SET] Where clause preparation (L2175)

> Populate the WHERE map with the composite primary key values used to locate the target record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `where_map.setValue(JBSbatKK_T_SVKEIUW_EOH_NET.SVC_KEI_UCWK_NO, svcKeiUcwkNoStr)` — Set primary key: Service Contract Detail Work Number |
| 2 | SET | `where_map.setValue(JBSbatKK_T_SVKEIUW_EOH_NET.GENE_ADD_DTM, geneAddDtmStr)` — Set primary key: Generation Registration Date/Time |

**Block 3** — [CALL] Exclusive-lock read (L2178)

> Perform a pessimistic lock query (SELECT FOR UPDATE WAIT) to acquire the row before updating. The Japanese comment reads "排他検索を行います" (Perform exclusive search).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `map = db_KK_T_SVKEIUW_EOH_TV.selectByPrimaryKeysForUpdateWait(where_map)` — Returns the locked record or null |

**Block 4** — [IF] Record existence check (L2180)

> The Japanese comment reads "排他検索結果がある場合" (When exclusive search result exists). This is the success branch where a matching record was found.

| # | Type | Code |
|---|------|------|
| 1 | SET | `value = new String[2]` |
| 2 | SET | `param = new String[2]` |
| 3 | SET | `value[0] = JBSbatKKConst.RSV_APLY_CD_TTDK = "1"` [-> `RSV_APLY_CD_TTDK = "1"` (Reservation Application: Under Processing)] |
| 4 | SET | `value[1] = JBSbatKKConst.MK_FLG_MK = "1"` [-> `MK_FLG_MK = "1"` (Invalid Flag: Invalid)] |
| 5 | SET | `param[0] = svcKeiUcwkNoStr` — Service Contract Detail Number (used as WHERE clause value) |
| 6 | SET | `param[1] = geneAddDtmStr` — Generation Registration Date/Time (used as WHERE clause value) |
| 7 | IF | [See Block 4.1 below — debug logging conditional] |
| 8 | CALL | `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE(value, param)` — Execute the database update |

**Block 4.1** — [IF] Debug log level check (L2194)

> The Japanese comment reads "ログレベルがデバッグモードの場合" (When log level is debug mode). Conditionally logs the parameter values and update values for debugging purposes.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` — Check if debug logging is enabled |
| 2 | IF | Condition is true → execute Block 4.1.1 (log statements) |

**Block 4.1.1** — [EXEC] Debug log output (L2196-2199)

> The Japanese comments read: "param(サービス契約内訳番号)" (param: Service Contract Detail Number), "param(世代登録年月日時分秒)" (param: Generation Registration Date/Time), "value(予約適用コード（1:予約手続中）)" (value: Reservation Application Code (1: Under Processing)), "value(無効フラグ（1:無効）)" (value: Invalid Flag (1: Invalid)).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("param(サービス契約内訳番号): " + param[0])` — Log service contract detail number |
| 2 | EXEC | `super.logPrint.printDebugLog("param(世代登録年月日時分秒): " + param[1])` — Log generation timestamp |
| 3 | EXEC | `super.logPrint.printDebugLog("value(予約適用コード（1:予約手続中）): " + value[0])` — Log reservation application code |
| 4 | EXEC | `super.logPrint.printDebugLog("value(無効フラグ（1:無効）): " + value[0])` — Log invalid flag |

**Block 4.2** — [CALL] Execute DB update (L2208)

> The Japanese comment reads "排他エラーの場合" (Exclusive error case) — this label actually appears on the ELSE branch. Block 4.2 is the update execution within the if-success branch.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE(value, param)` — Update `RSV_APLY_CD` and `MK_FLG` on `KK_T_SVKEIUW_EOH_TV` |
| 2 | RETURN | `return` (void) |

**Block 5** — [ELSE] Record not found (L2211)

> The Japanese comments read "排他エラーの場合" (Exclusive error case) and "該当レコード無しのエラー" (Error for no matching record). When no record matches the primary key, this branch throws a business exception.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0210CE, new String[]{"サービス契約内訳＜eo光TV＞", "サービス契約内訳番号" + svcKeiUcwkNoStr})` — Throw exception with error code `EKKB0210CE`, message key "サービス契約内訳＜eo光TV＞" (Service Detail Breakdown &lt;eo Hikari TV&gt;) and the specific service contract detail number |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_ucwk_no` | Field | Service Contract Detail Work Number — unique identifier for a line item within a service contract. Used as the primary key to locate records in the service contract detail breakdown tables. |
| `gene_add_dtm` | Field | Generation Registration Date/Time — timestamp of when this version (generation) of a record was created. Part of the composite primary key, used for optimistic concurrency control in generation-managed tables. |
| `KK_T_SVKEIUW_EOH_TV` | Table | Service Detail Breakdown &lt;eo Light TV&gt; — database table storing line-item breakdowns for K-Opticom's "eo Hikari TV" (fiber-optic television) service contracts. "TV" suffix distinguishes it from "NET" (internet), "TEL" (telephone), and other service types. |
| `RSV_APLY_CD` | Field | Reservation Application Code — indicates the reservation/application status of a service contract line item. Value `"1"` means "Under Processing" (Yoyaku Shuchuu), meaning the service is being provisioned and the contract is not yet active. |
| `MK_FLG` | Field | Invalid Flag — logical deletion flag. Value `"1"` (MK_FLG_MK) means "Invalid" (Mukou), indicating the record is logically invalidated while the physical record is retained for audit/history purposes. |
| `RSV_APLY_CD_TTDK` | Constant | Reservation Application Code constant = `"1"` — "Under Processing" (Yoyaku Shuchuu). Indicates the service application is in progress. |
| `MK_FLG_MK` | Constant | Invalid Flag constant = `"1"` — "Invalid" (Mukou). Marks the record as logically deleted/invalid. |
| `EKKB0210CE` | Error Code | Business exception code — "Record Not Found" error. Thrown when the target record matching the primary key does not exist in the database. |
| `selectByPrimaryKeysForUpdateWait` | Method | Pessimistic lock read — performs a SELECT query with a row-level exclusive lock (SELECT FOR UPDATE WAIT). The "Wait" variant blocks (rather than immediately failing) if another transaction holds a lock on the row. |
| `JBSbatCommonDBInterface` | Class | Common database interface — a key-value map abstraction used to pass WHERE conditions and SET values to database access methods. |
| `eo Hikari TV` | Business term | K-Opticom's fiber-optic television service. "Hikari" (光) means "light" (fiber), and "TV" refers to the television broadcasting component bundled with the internet connection. |
| `Service Contract Detail Breakdown` | Business term | The line-item level data structure for a service contract, where each line (detail) represents a specific service type (e.g., TV, Internet, Telephone) with its own attributes and status. |
| `Generation Management` | Business concept | A data management pattern where each change to a record creates a new "generation" with a new timestamp (`GENE_ADD_DTM`), preserving historical records rather than updating them in place. |
