tech.ydb.yoj.repository.db.statement.Changeset Maven / Gradle / Ivy
Show all versions of yoj-repository Show documentation
package tech.ydb.yoj.repository.db.statement;
import lombok.NonNull;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @deprecated Blindly setting entity fields is not recommended. Use {@code Table.modifyIfPresent()} instead, unless you
* have specific requirements.
* Blind updates disrupt query merging mechanism, so you typically won't able to run multiple blind update statements
* in the same transaction, or interleave them with upserts ({@code Table.save()}) and inserts.
*
Blind updates also do not update projections because they do not load the entity before performing the update;
* this can cause projections to be inconsistent with the main entity.
*/
@Deprecated
public final class Changeset {
private final Map newValues = new LinkedHashMap<>();
public Changeset() {
}
public static Changeset setField(String fieldPath, V value) {
return new Changeset().set(fieldPath, value);
}
public Changeset set(@NonNull String fieldPath, T value) {
this.newValues.put(fieldPath, value);
return this;
}
public Changeset setAll(@NonNull Changeset other) {
return setAll(other.newValues);
}
public Changeset setAll(@NonNull Map fieldValues) {
this.newValues.putAll(fieldValues);
return this;
}
public Map toMap() {
return new LinkedHashMap<>(this.newValues);
}
}