@SuppressWarnings("unchecked")
public static <BE, E extends AbstractElement<?, U>, U extends AbstractElement.Update> void update(
Class<E> entityClass,
Transaction<BE> tx, Query entityQuery, U update,
TransactionParticipant<BE, U> preUpdateCheck,
BiConsumer<BE, Transaction<BE>> postUpdateCheck) {
BE entity = tx.querySingle(entityQuery);
if (entity == null) {
if (update instanceof Relationship.Update) {
throw new RelationNotFoundException((String) null, Query.filters(entityQuery));
} else {
throw new EntityNotFoundException(entityClass, Query.filters(entityQuery));
}
}
if (preUpdateCheck != null) {
preUpdateCheck.execute(entity, update, tx);
}
E orig = tx.convert(entity, entityClass);
tx.update(entity, update);
if (postUpdateCheck != null) {
postUpdateCheck.accept(entity, tx);
}
E updated = tx.convert(entity, entityClass);
tx.getPreCommit().addNotifications(new EntityAndPendingNotifications<>(entity, updated,
new Action.Update<>(orig, update), Action.updated()));
}