package com.ffii.fpsms.modules.pickOrder.support

import jakarta.persistence.OptimisticLockException
import org.hibernate.StaleObjectStateException
import org.springframework.orm.ObjectOptimisticLockingFailureException

fun isOptimisticLockFailure(t: Throwable?): Boolean {
    var c: Throwable? = t
    while (c != null) {
        when (c) {
            is StaleObjectStateException -> return true
            is OptimisticLockException -> return true
            is ObjectOptimisticLockingFailureException -> return true
        }
        if (c.message?.contains("Row was updated or deleted by another transaction", ignoreCase = true) == true) {
            return true
        }
        c = c.cause
    }
    return false
}
