@@ -42,7 +42,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
4242 newSuspendedTransaction(db = databaseManager.getDatabase()) {
4343 val row = WorkItemsTable .selectAll().where { WorkItemsTable .id eq id }.singleOrNull()
4444 if (row != null ) {
45- Result .Success (mapRowToWorkItem (row))
45+ Result .Success (toWorkItem (row))
4646 } else {
4747 Result .Error (RepositoryError .NotFound (id, " WorkItem not found with id: $id " ))
4848 }
@@ -133,7 +133,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
133133 val items = WorkItemsTable .selectAll()
134134 .where { WorkItemsTable .parentId eq parentId }
135135 .limit(limit)
136- .mapNotNull { mapRowToWorkItemSafe (it) }
136+ .mapNotNull { toWorkItemOrNull (it) }
137137 Result .Success (items)
138138 }
139139 } catch (e: Exception ) {
@@ -145,7 +145,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
145145 val items = WorkItemsTable .selectAll()
146146 .where { WorkItemsTable .role eq role.name.lowercase() }
147147 .limit(limit)
148- .mapNotNull { mapRowToWorkItemSafe (it) }
148+ .mapNotNull { toWorkItemOrNull (it) }
149149 Result .Success (items)
150150 }
151151 } catch (e: Exception ) {
@@ -157,7 +157,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
157157 val items = WorkItemsTable .selectAll()
158158 .where { WorkItemsTable .depth eq depth }
159159 .limit(limit)
160- .mapNotNull { mapRowToWorkItemSafe (it) }
160+ .mapNotNull { toWorkItemOrNull (it) }
161161 Result .Success (items)
162162 }
163163 } catch (e: Exception ) {
@@ -169,7 +169,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
169169 val row = WorkItemsTable .selectAll()
170170 .where { WorkItemsTable .parentId.isNull() and (WorkItemsTable .depth eq 0 ) }
171171 .singleOrNull()
172- Result .Success (row?.let { mapRowToWorkItemSafe (it) })
172+ Result .Success (row?.let { toWorkItemOrNull (it) })
173173 }
174174 } catch (e: Exception ) {
175175 Result .Error (RepositoryError .DatabaseError (" Failed to find root WorkItem: ${e.message} " , e))
@@ -183,7 +183,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
183183 (WorkItemsTable .title like pattern) or (WorkItemsTable .summary like pattern)
184184 }
185185 .limit(limit)
186- .mapNotNull { mapRowToWorkItemSafe (it) }
186+ .mapNotNull { toWorkItemOrNull (it) }
187187 Result .Success (items)
188188 }
189189 } catch (e: Exception ) {
@@ -203,7 +203,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
203203 newSuspendedTransaction(db = databaseManager.getDatabase()) {
204204 val items = WorkItemsTable .selectAll()
205205 .where { WorkItemsTable .parentId eq parentId }
206- .mapNotNull { mapRowToWorkItemSafe (it) }
206+ .mapNotNull { toWorkItemOrNull (it) }
207207 Result .Success (items)
208208 }
209209 } catch (e: Exception ) {
@@ -273,7 +273,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
273273 .orderBy(sortColumn, order)
274274 .limit(limit)
275275 .offset(offset.toLong())
276- .mapNotNull { mapRowToWorkItemSafe (it) }
276+ .mapNotNull { toWorkItemOrNull (it) }
277277
278278 Result .Success (items)
279279 }
@@ -333,7 +333,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
333333 newSuspendedTransaction(db = databaseManager.getDatabase()) {
334334 val counts = WorkItemsTable .selectAll()
335335 .where { WorkItemsTable .parentId eq parentId }
336- .mapNotNull { mapRowToWorkItemSafe (it) }
336+ .mapNotNull { toWorkItemOrNull (it) }
337337 .groupBy { it.role }
338338 .mapValues { (_, items) -> items.size }
339339 Result .Success (counts)
@@ -347,7 +347,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
347347 val items = WorkItemsTable .selectAll()
348348 .where { WorkItemsTable .parentId.isNull() }
349349 .limit(limit)
350- .mapNotNull { mapRowToWorkItemSafe (it) }
350+ .mapNotNull { toWorkItemOrNull (it) }
351351 Result .Success (items)
352352 }
353353 } catch (e: Exception ) {
@@ -364,7 +364,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
364364 val current = queue.removeFirst()
365365 val children = WorkItemsTable .selectAll()
366366 .where { WorkItemsTable .parentId eq current }
367- .mapNotNull { mapRowToWorkItemSafe (it) }
367+ .mapNotNull { toWorkItemOrNull (it) }
368368 results.addAll(children)
369369 queue.addAll(children.map { it.id })
370370 }
@@ -383,7 +383,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
383383 Result .Success (
384384 WorkItemsTable .selectAll()
385385 .where { WorkItemsTable .id inList entityIds }
386- .mapNotNull { mapRowToWorkItemSafe (it) }
386+ .mapNotNull { toWorkItemOrNull (it) }
387387 )
388388 }
389389 } catch (e: Exception ) {
@@ -416,7 +416,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
416416 WorkItemsTable .id.castTo<String >(VarCharColumnType (36 )).like(" $formattedPrefix %" )
417417 }
418418 .limit(limit)
419- .mapNotNull { mapRowToWorkItemSafe (it) }
419+ .mapNotNull { toWorkItemOrNull (it) }
420420 Result .Success (items)
421421 }
422422 } catch (e: Exception ) {
@@ -452,7 +452,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
452452 val inputEntityIds = itemIds.map { EntityID (it, WorkItemsTable ) }
453453 val inputItems = WorkItemsTable .selectAll()
454454 .where { WorkItemsTable .id inList inputEntityIds }
455- .mapNotNull { mapRowToWorkItemSafe (it) }
455+ .mapNotNull { toWorkItemOrNull (it) }
456456 inputItems.forEach { cache[it.id.toString()] = it }
457457
458458 // BFS upward: collect all parentIds that need fetching
@@ -461,7 +461,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
461461 val fetchEntityIds = toFetch.map { EntityID (UUID .fromString(it), WorkItemsTable ) }
462462 val fetched = WorkItemsTable .selectAll()
463463 .where { WorkItemsTable .id inList fetchEntityIds }
464- .mapNotNull { mapRowToWorkItemSafe (it) }
464+ .mapNotNull { toWorkItemOrNull (it) }
465465 fetched.forEach { cache[it.id.toString()] = it }
466466 toFetch = fetched.mapNotNull { it.parentId }.map { it.toString() }.toSet() - cache.keys
467467 }
@@ -506,7 +506,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
506506 }.reduce { acc, op -> acc or op }
507507 }
508508
509- private fun mapRowToWorkItem (row : ResultRow ): WorkItem {
509+ private fun toWorkItem (row : ResultRow ): WorkItem {
510510 return WorkItem (
511511 id = row[WorkItemsTable .id].value,
512512 parentId = row[WorkItemsTable .parentId],
@@ -530,15 +530,15 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
530530 }
531531
532532 /* *
533- * Safe variant of [mapRowToWorkItem] for bulk-read operations.
533+ * Safe variant of [toWorkItem] that returns null on failure, for bulk-read operations.
534534 *
535535 * Returns null and logs a warning if a row contains data that fails domain validation
536536 * (e.g. an oversized title written by an older version of the server). This prevents
537537 * a single corrupt row from crashing an entire list query.
538538 */
539- private fun mapRowToWorkItemSafe (row : ResultRow ): WorkItem ? {
539+ private fun toWorkItemOrNull (row : ResultRow ): WorkItem ? {
540540 return try {
541- mapRowToWorkItem (row)
541+ toWorkItem (row)
542542 } catch (e: Exception ) {
543543 logger.warn(
544544 " Skipping corrupt WorkItem row (id={}): {}" ,
0 commit comments