package cn.cerc.mis.ado;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

import cn.cerc.db.core.DataRow;

public interface EntityQueryOne<T> {

    boolean isEmpty();

    // loadOne.isEmptyThrow: 载入一条数据，若为空就抛出异常
    <X extends Throwable> EntityQueryOne<T> isEmptyThrow(Supplier<? extends X> exceptionSupplier) throws X;

    boolean isPresent();

    // loadOne.isPresentThrow: 载入一条数据，若不为空就抛出异常
    <X extends Throwable> EntityQueryOne<T> isPresentThrow(Supplier<? extends X> exceptionSupplier) throws X;

    T get();

    // 取得entity，若取不到就抛出异常
    <X extends Throwable> T getElseThrow(Supplier<? extends X> exceptionSupplier) throws X;

    void save(T entity);

    // update.orElseInsert: 更新entity，若为空无法更新就执行插入
    // update.isPresentThrow: 更新entity，若为空无法更新就抛出异常
    EntityQueryOne<T> update(Consumer<T> action);

    // loadOne.orElseInsert: 载入一条数据，若为空就执行插入
    EntityQueryOne<T> orElseInsert(Consumer<T> action);

    // delete.orElseThrow: 删除entity，若为空无法删除就抛出异常
    Optional<T> delete();

    DataRow current();

}

@@ -434,32 +434,84 @@
 %E5%85%A5%E4%B8%80%E6%9D%A1%E6%95%B0%E6%8D%AE%EF%BC%8C%E8%8B%A5%E4%B8%8D%E4%B8%BA%E7%A9%BA%E5%B0%B1%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%0A
+    // isPresentThrow.update: %E6%9B%B4%E6%96%B0entity%EF%BC%8C%E8%8B%A5%E4%B8%BA%E7%A9%BA%E6%97%A0%E6%B3%95%E6%9B%B4%E6%96%B0%E5%B0%B1%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%0A
     %3CX extends T
@@ -818,60 +818,8 @@
 %E8%A1%8C%E6%8F%92%E5%85%A5%0A
-    // update.isPresentThrow: %E6%9B%B4%E6%96%B0entity%EF%BC%8C%E8%8B%A5%E4%B8%BA%E7%A9%BA%E6%97%A0%E6%B3%95%E6%9B%B4%E6%96%B0%E5%B0%B1%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%0A
     

Update EntityQueryOne.java