# Business Logic — JBSbatKKAdChgTekkyoKjFinUpd.isTimeStampCheck() [31 LOC]

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

## 1. Role

### JBSbatKKAdChgTekkyoKjFinUpd.isTimeStampCheck()

This method performs **optimistic concurrency control** via timestamp comparison for the Service Contract Disposition Control table (`KK_T_SVKEI_EXC_CTRL`). It is a core concurrency-safety mechanism in a batch processing system that handles service contract changes related to delivery/completion finalization (`TekkyoKjFin`). The method compares two timestamp strings — an expected (initial search) timestamp (`lastUpdDtmStrBf`) and the current (most recent) timestamp (`lastUpdDtmStrAf`) — to detect whether the underlying database row has been modified by another process between the initial data retrieval and the current operation. If the timestamps match, it proceeds to acquire an **update lock** on the disposition control row by executing `selectByPrimaryKeysForUpdateWait`, then returns the locked row data for the caller to proceed with its update. If the timestamps differ, it indicates a concurrent modification has occurred, and the method returns `null` to signal a concurrency conflict, allowing the caller to log an error and abort. This method is the low-level predicate called inside `timeStampCheckSvcExecHaita()`, which iterates over a list of service contract line items to validate each one's timestamp in sequence. The design pattern implemented is **guard-gate**: the timestamp equality check acts as a guard that gates access to the database row lock, ensuring no stale-data writes occur during batch-driven service contract disposition updates.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isTimeStampCheck()"])
    DEBUG_1["chkLogLevel
debug"]
    LOG_INIT["Print debug:
lastUpdDtmStrBf"]
    LOG_NOW["Print debug:
lastUpdDtmStrAf"]
    COND["Timestamp Equal?
lastUpdDtmStrAf.equals(lastUpdDtmStrBf)"]
    MAP_CREATE["Create JBSbatCommonDBInterface
svkeiExcCtrlMap"]
    PK_SET["setValue(SVC_KEI_NO,
svcKeiNo)"]
    DB_SELECT["selectByPrimaryKeysForUpdateWait
(db_KK_T_SVKEI_EXC_CTRL)"]
    DEBUG_2["chkLogLevel
debug"]
    LOG_OK["Print debug:
Timestamp check OK"]
    RETURN_DB["Return dbmap
Timestamp valid"]
    DEBUG_3["chkLogLevel
debug"]
    LOG_NG["Print debug:
Timestamp check NG"]
    RETURN_NULL["Return null
Timestamp mismatch"]
    END(["End"])

    START --> DEBUG_1
    DEBUG_1 --> LOG_INIT
    LOG_INIT --> LOG_NOW
    LOG_NOW --> COND
    COND -- Yes --> MAP_CREATE
    MAP_CREATE --> PK_SET
    PK_SET --> DB_SELECT
    DB_SELECT --> DEBUG_2
    DEBUG_2 --> LOG_OK
    LOG_OK --> RETURN_DB
    RETURN_DB --> END
    COND -- No --> DEBUG_3
    DEBUG_3 --> LOG_NG
    LOG_NG --> RETURN_NULL
    RETURN_NULL --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | **Service Contract Number** — the primary key of the Service Contract Disposition Control table. Identifies the specific service contract line item whose timestamp is being validated. This number is used as the search condition when acquiring an update lock on the disposition row. |
| 2 | `lastUpdDtmStrBf` | `String` | **Last Update Timestamp (Before / Initial Search)** — the expected value of the `LAST_UPD_DTM` column as it was when the data was initially fetched by the caller (via `searchSvkeiExcCtrl()`). Represents the "golden copy" timestamp against which concurrency is checked. If this value has changed, it means another process has updated this row. |
| 3 | `lastUpdDtmStrAf` | `String` | **Last Update Timestamp (After / Current Value)** — the actual current value of the `LAST_UPD_DTM` column re-read from the database right before this check. This is the live value retrieved from `KK_T_SVKEI_EXC_CTRL` via the caller's `searchSvkeiExcCtrl()` call. If this matches `lastUpdDtmStrBf`, no concurrent modification occurred. |

**External state read:**
| Source | Field | Description |
|--------|-------|-------------|
| `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` | Log level flag | Controls whether debug logging statements are emitted. Only evaluated when debug mode is active. |
| `this.db_KK_T_SVKEI_EXC_CTRL` | Database accessor | A `JBSbatSQLAccess` instance initialized at construction time to the `KK_T_SVKEI_EXC_CTRL` table. Used to execute the `selectByPrimaryKeysForUpdateWait` query. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_SVKEI_EXC_CTRL.selectByPrimaryKeysForUpdateWait()` | - | `KK_T_SVKEI_EXC_CTRL` (Service Contract Disposition Control) | **Read with update lock** — Acquires a database-level row lock on the service contract disposition control record using `selectByPrimaryKeysForUpdateWait`. This is an optimistic concurrency pattern: it re-reads the row under lock only if the timestamp matches, ensuring no stale update. |
| - | `super.logPrint.chkLogLevel()` | - | - | Debug log level check utility |
| - | `super.logPrint.printDebugLog()` | - | - | Debug log output (3 calls total) |

## 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: `printDebugLog` [-], `printDebugLog` [-], `selectByPrimaryKeysForUpdateWait` `KK_T_SVKEI_EXC_CTRL` [R], `printDebugLog` [-], `printDebugLog` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKAdChgTekkyoKjFinUpd.timeStampCheckSvcExecHaita()` | `timeStampCheckSvcExecHaita()` -> `isTimeStampCheck(svcKeiNo, lastUpdateBf, dbTimestamp)` | `selectByPrimaryKeysForUpdateWait [R] KK_T_SVKEI_EXC_CTRL` |

The caller `timeStampCheckSvcExecHaita()` is a sibling private method in the same class. It iterates over a list of service contract numbers and their pre-fetched timestamps, calling `searchSvkeiExcCtrl()` to re-read each row's current timestamp, then passing that value to `isTimeStampCheck()` for comparison. If any timestamp check fails, the caller logs a business error (`EKKB0360KE`) and returns `false`, aborting the batch processing for that service contract.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` (L697)

> Debug mode check: if the logging level is set to DEBUG, log the initial and current timestamp values for auditability.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `super.logPrint.printDebugLog("----lastUpdDtmStr(Initial Search): " + lastUpdDtmStrBf)` | Logs the expected timestamp (initial search value) with label "----Last Update Timestamp (Initial Search)" [Japanese: `----更新年月日時分秒(初期検索)：`] |
| 2 | EXEC | `super.logPrint.printDebugLog("----lastUpdDtmStr(Current Value): " + lastUpdDtmStrAf)` | Logs the current timestamp (live DB value) with label "----Last Update Timestamp (Current Value)" [Japanese: `----更新年月日時分秒(直前値)：`] |

---

**Block 2** — [IF] `lastUpdDtmStrAf.equals(lastUpdDtmStrBf)` (L703)

> **Timestamp Match Branch** — If the re-read timestamp matches the initial timestamp, no concurrent modification occurred. The method acquires an update lock on the disposition control row and returns the locked data for the caller to proceed.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `JBSbatCommonDBInterface svkeiExcCtrlMap = new JBSbatCommonDBInterface()` | Create a new map object to hold the primary key search condition. [Japanese: implied — "Generate execution result acquisition map"] |
| 2 | SET | `svkeiExcCtrlMap.setValue(JBSbatKK_T_SVKEI_EXC_CTRL.SVC_KEI_NO, svcKeiNo)` | Set the service contract number as the primary key search condition. [Japanese: `--Set condition item--`] |
| 3 | SET | `JBSbatCommonDBInterface dbmap = db_KK_T_SVKEI_EXC_CTRL.selectByPrimaryKeysForUpdateWait(svkeiExcCtrlMap)` | Execute the database query with an update lock (SELECT FOR UPDATE equivalent) on `KK_T_SVKEI_EXC_CTRL`. [Japanese: `--Execute disposition control processing on the Service Contract Disposition Control table--`] |
| 4 | IF | `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` (L711) | Debug mode check for the success path. |
| 4.1 | EXEC | `super.logPrint.printDebugLog("Timestamp check result_OK")` | Log success message. [Japanese: `タイムスタンプチェック結果_OK`] |
| 5 | RETURN | `return dbmap;` | Return the locked row data. Timestamp is valid — caller can proceed with update. |

---

**Block 3** — [implicit ELSE / fall-through] `lastUpdDtmStrAf` does not equal `lastUpdDtmStrBf` (L716)

> **Timestamp Mismatch Branch** — The timestamps differ, indicating that another process has modified this row since it was initially fetched. This is a concurrency conflict. The method logs the failure and returns `null` to signal the error to the caller.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | IF | `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` (L716) | Debug mode check for the failure path. |
| 1.1 | EXEC | `super.logPrint.printDebugLog("Timestamp check result_NG")` | Log failure message. [Japanese: `タイムスタンプチェック結果_NG`] |
| 2 | RETURN | `return null;` | Return null to indicate timestamp mismatch — caller should log a business error and abort the disposition update. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` / `SVC_KEI_NO` | Field | Service Contract Number — primary key of the `KK_T_SVKEI_EXC_CTRL` table. Identifies a specific service contract line item in the K-Opticom customer backbone system. |
| `lastUpdDtmStrBf` | Field | Last Update Timestamp (Before) — the expected value of the `LAST_UPD_DTM` column as initially fetched. Used as the reference for optimistic concurrency comparison. |
| `lastUpdDtmStrAf` | Field | Last Update Timestamp (After) — the current value of the `LAST_UPD_DTM` column re-read from the database. Used to detect concurrent modifications. |
| `KK_T_SVKEI_EXC_CTRL` | Table | Service Contract Disposition Control table — a database table that tracks the disposition state of service contracts. Contains columns: `SVC_KEI_NO` (primary key), `LAST_UPD_DTM` (last update timestamp), `ADD_DTM` (registration timestamp), `ADD_OPEACNT` (registration operator account), `UPD_DTM` (update timestamp), `UPD_OPEACNT` (update operator account), `DEL_DTM` (deletion timestamp). |
| `timeStampCheckSvcExecHaita` | Method | Sibling method in the same class. Iterates over a list of service contract numbers, calls `searchSvkeiExcCtrl()` to re-read each row, then calls `isTimeStampCheck()` to validate each timestamp. If any check fails, logs error `EKKB0360KE` and aborts. [Japanese: `サービス契約排制御のタイムスタンプチェックをします（同時にロックしておく）`] |
| `searchSvkeiExcCtrl` | Method | Sibling method that performs a primary key search on `KK_T_SVKEI_EXC_CTRL` and returns the result as a `JBSbatCommonDBInterface`. |
| `selectByPrimaryKeysForUpdateWait` | Method | Database access method that executes a primary-key-based SELECT with an **update lock** (row-level lock). Ensures no other transaction can modify the row until the lock is released. |
| Optimistic Concurrency Control | Pattern | A concurrency control strategy where rows are read without locking first, and a timestamp/version check is performed before write. If the timestamp has changed, the update is rejected to prevent lost updates. |
| Batch (バッチ) | Concept | A non-interactive, scheduled background processing mode. This class is a batch service that processes bulk service contract change completions. |
| `logPrint` | Field | Inherited logging utility from the parent class. Provides `chkLogLevel()` and `printDebugLog()` methods. |
| `JBSbatCommonDBInterface` | Class | A map-like interface used to hold database query parameters and results in the batch framework. Provides `setValue()` and `getValue()` for key-value operations. |
| `JBSbatSQLAccess` | Class | Database access abstraction layer used by batch services to execute queries. The `db_KK_T_SVKEI_EXC_CTRL` instance is initialized to target the `KK_T_SVKEI_EXC_CTRL` table. |
| `D_TBL_NAME_KK_T_SVKEI_EXC_CTRL` | Constant | Table name constant used during initialization of the `db_KK_T_SVKEI_EXC_CTRL` SQL accessor. |
| `EKKB0360KE` | Error Code | Business error code logged when a timestamp mismatch (concurrency conflict) occurs during service contract disposition control processing. |
