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

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

## 1. Role

### JBSbatKKKjFinClDataInTrn.updateSvkeiUwEohTv2()

This method performs the **cancellation update for service contract detail line items of "eo Hikari TV" (eo Light TV)**, a Japanese broadband television (IPTV/cable TV) service offered by K-Opticom (kopt). Specifically, it marks the affected record as "reservation application in progress" (予約適用中) by setting the reservation application code to `"1"` and simultaneously sets the invalid flag to `"1"` (無効 / invalid), indicating that this particular contract detail is being processed as part of a service cancellation workflow.

The method implements a **pessimistic locking pattern** — it acquires a row-level exclusive lock (`selectByPrimaryKeysForUpdateWait`) before updating, ensuring that no other batch transaction can modify the same record concurrently. This is essential in a batch processing context where multiple financial closure processes may touch the same service contracts.

The design follows a **routing/delegation pattern**: after preparing the update data, the method delegates the actual database UPDATE to the private helper method `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2`, which constructs the SET/WHERE maps and executes the SQL update via `db_KK_T_SVKEIUW_EOH_TV_2.updateByPrimaryKeys`. The method serves as a **shared utility** called by the parent batch `execute()` method during the financial data ingestion workflow for handling TV service cancellations.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateSvkeiUwEohTv2 svcKeiUcwkNoStr2, geneAddDtmStr2"])
    START --> INIT["Initialize where_map with SVC_KEI_UCWK_NO and GENE_ADD_DTM"]
    INIT --> QUERY["selectByPrimaryKeysForUpdateWait on db_KK_T_SVKEIUW_EOH_TV"]
    QUERY --> COND{Record Found}
    COND -->|null| THROW["JBSbatBusinessException EKB0210CE Record Not Found Error"]
    COND -->|exists| ARRAYS["Create value[2] and param[2] arrays"]
    ARRAYS --> SETVAL["value[0] = RSV_APLY_CD_TTDK = 1 value[1] = MK_FLG_MK = 1"]
    SETVAL --> SETPARAM["param[0] = svcKeiUcwkNoStr2 param[1] = geneAddDtmStr2"]
    SETPARAM --> CHKLOG{logPrint.chkLogLevel DEBUG}
    CHKLOG -->|true| LOG["printDebugLog for param and value arrays"]
    CHKLOG -->|false| SKIPLOG["Skip logging"]
    LOG --> CALL["executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2 value, param"]
    SKIPLOG --> CALL
    CALL --> END_NODE(["Return Next"])
    THROW --> END_NODE
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `JBSbatKKConst.RSV_APLY_CD_TTDK` | `"1"` | Reservation Application Code — In Progress (予約適用コード: 予約手続き中) |
| `JBSbatKKConst.MK_FLG_MK` | `"1"` | Invalid Flag — Invalid (無効フラグ: 無効) |

**Requirements:**
- The method has a primary conditional branch: whether the record exists after the pessimistic lock query.
- A secondary conditional branch checks if debug logging is enabled.
- Both branches converge into a single database update call.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiUcwkNoStr2` | `String` | Service Contract Detail Number — the unique identifier for a service contract line item (e.g., a specific eo Hikari TV subscription line under a broader broadband contract). Used as the primary key WHERE clause to identify the target record for locking and update. |
| 2 | `geneAddDtmStr2` | `String` | Generation Registration Timestamp — the timestamp (year/month/day/hour/minute/second) associated with the current version/generation of this record. Used in conjunction with `svcKeiUcwkNoStr2` as a compound primary key for optimistic/pessimistic concurrency control. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_SVKEIUW_EOH_TV` | `DBInterface` | Database access object for the `KK_T_SVKEIUW_EOH_TV` table (Service Contract Detail <eo Hikari TV> table). Used to perform the pessimistic lock SELECT. |
| `super.logPrint` | `JBSbatLogUtil` | Inherited log utility for debug-level output during batch processing. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatCommonDBInterface.selectByPrimaryKeysForUpdateWait` | JBSbatCommonDB | `KK_T_SVKEIUW_EOH_TV` | Selects a single row with exclusive lock (pessimistic locking) for the given primary key (`SVC_KEI_UCWK_NO`, `GENE_ADD_DTM`). This ensures no other transaction can modify the record during the update process. |
| U | `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2` | JBSbatKKKjFinClDataInTrn | `KK_T_SVKEIUW_EOH_TV` | Updates the `KK_T_SVKEIUW_EOH_TV` table row by primary key. Sets `RSV_APLY_CD` to `"1"` (in progress) and `MK_FLG` to `"1"` (invalid). The WHERE clause matches on `SVC_KEI_UCWK_NO` and `GENE_ADD_DTM`. |
| - | `super.logPrint.printDebugLog` | JBSbatLogUtil | - | Debug logging utility call. Outputs parameter and value details when debug mode is active. Not a CRUD operation. |
| - | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDB | - | Sets key-value pairs in the `JBSbatCommonDBInterface` map objects used to construct WHERE and SET clauses. |

### How to classify:

- **R** (Read): `selectByPrimaryKeysForUpdateWait` — queries a single row with an exclusive lock for update.
- **U** (Update): `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2` — updates the `KK_T_SVKEIUW_EOH_TV` table by primary key, setting the reservation application code and invalid flag.

### How to find SC Code:

- The `selectByPrimaryKeysForUpdateWait` call uses the `db_KK_T_SVKEIUW_EOH_TV` access object, and the `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2` method directly calls `db_KK_T_SVKEIUW_EOH_TV_2.updateByPrimaryKeys`. Both reference the same table: `KK_T_SVKEIUW_EOH_TV` (Service Contract Detail <eo Hikari TV> table).
- No explicit SC code pattern (e.g., `EKK0361A010SC`) is present in this method's call chain — the method operates at the batch service layer with direct table access.

### How to find Entity/DB tables:

- The table name is derived from the database accessor: `db_KK_T_SVKEIUW_EOH_TV` and `db_KK_T_SVKEIUW_EOH_TV_2` → table `KK_T_SVKEIUW_EOH_TV`.
- The entity/join-table constant class `JBSbatKK_T_SVKEIUW_EOH_NET` defines fields including `SVC_KEI_UCWK_NO` and `GENE_ADD_DTM` which are used as the WHERE clause keys.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2` [U], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-], `printDebugLog` [-]

### Caller trace:

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

**Call chain detail (from `execute()` at line 668):**

```
JBSbatKKKjFinClDataInTrn.execute()
  └── updateSvkeiUwEohTv2(svcKeiUcwkNoStr, geneAddDtmStr)
        ├── db_KK_T_SVKEIUW_EOH_TV.selectByPrimaryKeysForUpdateWait(where_map)  [R]
        └── executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2(value, param)
              └── db_KK_T_SVKEIUW_EOH_TV_2.updateByPrimaryKeys(whereMap, setMap)  [U]
```

The `execute()` method calls `updateSvkeiUwEohTv2` within a loop iteration where the caller has already fetched the `svcKeiUcwkNo` and `geneAddDtm` from a prior SQL SELECT result (`KK_T_SVC_KEI_UCWK_KK_SELECT_061`). This means the record is expected to exist, and the method serves as the actual update step in the financial closure cancellation processing pipeline.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET/INIT] `Initialize data structures` (L2234)

> Initializes the WHERE clause map with the primary key fields for the pessimistic lock query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `map = new JBSbatCommonDBInterface()` // Initialize result map |
| 2 | SET | `where_map = new JBSbatCommonDBInterface()` // Initialize WHERE clause map |
| 3 | SET | `value = null` // Initialize update value array |
| 4 | SET | `param = null` // Initialize WHERE parameter array |
| 5 | SET | `where_map.setValue(JBSbatKK_T_SVKEIUW_EOH_NET.SVC_KEI_UCWK_NO, svcKeiUcwkNoStr2)` // Set primary key: Service Contract Detail Number [-> Field from JBSbatKK_T_SVKEIUW_EOH_NET] |
| 6 | SET | `where_map.setValue(JBSbatKK_T_SVKEIUW_EOH_NET.GENE_ADD_DTM, geneAddDtmStr2)` // Set primary key: Generation Registration Timestamp [-> Field from JBSbatKK_T_SVKEIUW_EOH_NET] |

**Block 2** — [CALL/EXEC] `Pessimistic lock SELECT` (L2247)

> Performs a row-level exclusive lock query on the target table. This is the "exclusive control" (排他制御) step described in the Javadoc. The `selectByPrimaryKeysForUpdateWait` method acquires a database-level lock (e.g., `SELECT ... FOR UPDATE`) with wait, preventing concurrent modifications.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `map = db_KK_T_SVKEIUW_EOH_TV.selectByPrimaryKeysForUpdateWait(where_map)` // Pessimistic lock SELECT on KK_T_SVKEIUW_EOH_TV |

**Block 3** — [IF/ELSE] `Record existence check: map != null` (L2250)

> Javadoc comment: 排他検索結果がある場合 (When there is a result from the exclusive search). If the pessimistic lock query returns a non-null record, proceed with the update. Otherwise (else branch), throw an exception.

**Block 3.1** — [ELSE] `Record not found — throw exception` (L2277)

> Javadoc comment: 排他エラーの場合 / 該当レコード無しのエラー (Exclusive error / Record-not-found error). This is the error path when the target record does not exist for the given primary key. Throws a business exception `EKB0210CE` with a descriptive message including the table name "サービス契約内訳＜ｅｏ光Tv＞２" and the service contract detail number.

| # | Type | Code |
|---|------|------|
| 1 | THROW | `throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0210CE, new String[]{"サービス契約内訳＜ｅｏ光Tv＞２", "サービス契約内訳番号２：" + svcKeiUcwkNoStr2})` // Record not found error with table name and contract number |

**Block 3.2** — [IF body] `Record found — prepare update data` (L2252)

> Javadoc comment: 排他検索結果がある場合 (When there is a result from the exclusive search). The record exists, so prepare the SET values and WHERE parameters for the update.

| # | Type | Code |
|---|------|------|
| 1 | SET | `value = new String[2]` // Allocate update value array |
| 2 | SET | `param = new String[2]` // Allocate WHERE parameter array |
| 3 | SET | `value[0] = JBSbatKKConst.RSV_APLY_CD_TTDK` // [-> `RSV_APLY_CD_TTDK = "1"`] Reservation Application Code: In Progress (予約適用コード: 予約手続き中) |
| 4 | SET | `value[1] = JBSbatKKConst.MK_FLG_MK` // [-> `MK_FLG_MK = "1"`] Invalid Flag: Invalid (無効フラグ: 無効) |

**Block 3.3** — [SET] `Assign WHERE parameters` (L2260)

| # | Type | Code |
|---|------|------|
| 1 | SET | `param[0] = svcKeiUcwkNoStr2` // Service Contract Detail Number for WHERE clause |
| 2 | SET | `param[1] = geneAddDtmStr2` // Generation Registration Timestamp for WHERE clause |

**Block 4** — [IF/ELSE] `Debug logging check` (L2265)

> Javadoc comment: ログレベルがデバッグモードの場合 (When the log level is debug mode). Condition: `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)`. Only executes when debug-level logging is enabled.

**Block 4.1** — [IF body] `Debug log output` (L2267)

> Outputs parameter and value details to the debug log for traceability during batch execution.

| # | 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 registration timestamp |
| 3 | EXEC | `super.logPrint.printDebugLog("value(予約適用コード（1：予約手続き中）)：" + value[0])` // Log reservation application code |
| 4 | EXEC | `super.logPrint.printDebugLog("value(無効フラグ（1：無効）)：" + value[1])` // Log invalid flag |

**Block 5** — [CALL] `Execute the database UPDATE` (L2274)

> Javadoc comment: 更新処理を実行します (Execute the update process). Delegates to the private helper method which constructs SET/WHERE maps and calls `db_KK_T_SVKEIUW_EOH_TV_2.updateByPrimaryKeys`. The actual database operation updates the `RSV_APLY_CD` and `MK_FLG` columns for the identified record.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2(value, param)` // Execute PK-based UPDATE on KK_T_SVKEIUW_EOH_TV table |

**Block 5.1** — [Private helper] `executeKK_T_SVKEIUW_EOH_TV_PKUPDATE2` (L1702, separate method)

| # | Type | Code |
|---|------|------|
| 1 | SET | `setMap = new JBSbatCommonDBInterface()` // Initialize SET map |
| 2 | SET | `setMap.setValue("RSV_APLY_CD", setParam[0])` // Set reservation application code to "1" |
| 3 | SET | `setMap.setValue("MK_FLG", setParam[1])` // Set invalid flag to "1" |
| 4 | SET | `whereMap = new JBSbatCommonDBInterface()` // Initialize WHERE map |
| 5 | SET | `whereMap.setValue("SVC_KEI_UCWK_NO", whereParam[0])` // Set primary key for WHERE |
| 6 | SET | `whereMap.setValue("GENE_ADD_DTM", whereParam[1])` // Set primary key for WHERE |
| 7 | CALL | `db_KK_T_SVKEIUW_EOH_TV_2.updateByPrimaryKeys(whereMap, setMap)` // Execute the SQL UPDATE statement |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiUcwkNoStr2` | Field | Service Contract Detail Number — internal tracking identifier for a service contract line item (e.g., a specific broadband/TV subscription under a customer contract) |
| `geneAddDtmStr2` | Field | Generation Registration Timestamp — the date/time when this record version was created, used for optimistic/pessimistic concurrency control |
| `RSV_APLY_CD_TTDK` | Constant | Reservation Application Code — In Progress (予約適用コード: 予約手続き中) — indicates the service contract detail is currently being processed as part of a reservation workflow |
| `MK_FLG_MK` | Constant | Invalid Flag — Invalid (無効フラグ: 無効) — marks the record as logically deleted/invalidated (value "1") |
| `KK_T_SVKEIUW_EOH_TV` | Table | Service Contract Detail <eo Hikari TV> Table — the database table storing line-level details for eo Hikari TV service contracts, including reservation and cancellation status |
| `JBSbatKK_T_SVKEIUW_EOH_NET` | Join Entity | Join-table constant class defining field names for the `KK_T_SVKEIUW_EOH_TV` table (e.g., `SVC_KEI_UCWK_NO`, `GENE_ADD_DTM`) |
| `selectByPrimaryKeysForUpdateWait` | Method | Pessimistic lock SELECT — acquires a row-level exclusive lock (`SELECT ... FOR UPDATE`) on the target record, waiting if another transaction holds the lock |
| `updateByPrimaryKeys` | Method | Primary-key-based SQL UPDATE — executes an UPDATE statement using the WHERE clause values from the first parameter and column values from the second parameter |
| `JBSbatBusinessException` | Class | Business exception class used to signal application-level errors (e.g., record not found) during batch processing |
| `EKKB0210CE` | Error Code | Error code for "record not found" — thrown when a pessimistic lock query returns null, indicating the target record does not exist |
| eo Hikari TV (ｅｏ光Tv) | Business term | A Japanese broadband television (IPTV/cable TV) service offered by K-Opticom — "Hikari" (光) means "light" (fiber-optic), "TV" refers to the television service component |
| 予約適用中 (yoyaku tekiyou-chuu) | Business term | Reservation application in progress — a status indicating that a service contract detail is queued for reservation application but has not yet been finalized |
| 無効 (mukou) | Business term | Invalid — a flag value indicating that a record should be treated as logically inactive/deleted |
| K-Opticom (kopt) | Company | The telecommunications company (K-Opticom Corporation) whose batch processing system this code belongs to |
| 排他制御 (gata sei-gyo) | Japanese term | Exclusive control — database-level concurrency management, specifically pessimistic locking via `SELECT ... FOR UPDATE` |
