mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[fleet] make EntityType.upsert set the attribute that is used for lookup
GitOrigin-RevId: 124a7b5b1203edfa28b6ef095dc02bb04d42ae10
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6d0c9c150c
commit
87e95b992a
@@ -119,7 +119,7 @@ interface ChangeScope {
|
|||||||
* */
|
* */
|
||||||
operator fun <E : Entity, V : Any> E.set(
|
operator fun <E : Entity, V : Any> E.set(
|
||||||
attribute: Attributes<E>.Required<V>,
|
attribute: Attributes<E>.Required<V>,
|
||||||
value: V
|
value: V,
|
||||||
): Unit = context.run {
|
): Unit = context.run {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
add(eid, attribute.attr as Attribute<Any>, attribute.toIndexValue(value))
|
add(eid, attribute.attr as Attribute<Any>, attribute.toIndexValue(value))
|
||||||
@@ -133,7 +133,7 @@ interface ChangeScope {
|
|||||||
* */
|
* */
|
||||||
operator fun <E : Entity, V : Any> E.set(
|
operator fun <E : Entity, V : Any> E.set(
|
||||||
attribute: Attributes<E>.Optional<V>,
|
attribute: Attributes<E>.Optional<V>,
|
||||||
value: V?
|
value: V?,
|
||||||
): Unit = context.run {
|
): Unit = context.run {
|
||||||
when {
|
when {
|
||||||
value == null ->
|
value == null ->
|
||||||
@@ -241,15 +241,24 @@ interface ChangeScope {
|
|||||||
|
|
||||||
fun <E : Entity, V : Any> EntityType<E>.upsert(attribute: EntityAttribute<E, V>, value: V, builder: EntityBuilder<E>): E =
|
fun <E : Entity, V : Any> EntityType<E>.upsert(attribute: EntityAttribute<E, V>, value: V, builder: EntityBuilder<E>): E =
|
||||||
let { entityType ->
|
let { entityType ->
|
||||||
entity(attribute, value)?.apply { update(builder) } ?: entityType.new(builder)
|
entity(attribute, value)?.apply { update(builder) } ?: entityType.new {
|
||||||
|
when (attribute) {
|
||||||
|
is Attributes<E>.Many<V> -> it[attribute] = setOf(value)
|
||||||
|
is Attributes<E>.Optional<V> -> it[attribute] = value
|
||||||
|
is Attributes<E>.Required<V> -> it[attribute] = value
|
||||||
|
}
|
||||||
|
builder.build(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for legacy entity definitions
|
* Support for legacy entity definitions
|
||||||
* */
|
* */
|
||||||
fun <T : LegacyEntity> new(c: KClass<T>,
|
fun <T : LegacyEntity> new(
|
||||||
part: Part = defaultPart,
|
c: KClass<T>,
|
||||||
constructor: T.() -> Unit = {}): T =
|
part: Part = defaultPart,
|
||||||
|
constructor: T.() -> Unit = {},
|
||||||
|
): T =
|
||||||
withDefaultPart(part) {
|
withDefaultPart(part) {
|
||||||
context.new(c, constructor)
|
context.new(c, constructor)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user