https://kotlinlang.org logo
#exposed
Title
# exposed
a

Allan Wang

05/22/2018, 4:16 PM
Is there a DAO equivalent to the DSL insert ignore? Right now I have a helper function:
Copy code
fun <ID : Comparable<ID>, T : Entity<ID>> EntityClass<ID, T>.newOrUpdate(id: ID, update: T.() -> Unit): T {
    val existing = findById(id)
    return if (existing != null) existing.apply(update)
    else new(id, update)
}
But there is an unnecessary query if the entity isn't cached. This method aims to just end up with a new entity with the supplied id, regardless of whether it exists already
1
t

tapac

05/22/2018, 4:33 PM
No, there is no such functionality.
11 Views