Class MappedQuery.Default<T>

java.lang.Object
org.huiche.jdbc.MappedQuery.Default<T>
Type Parameters:
T - 类型
All Implemented Interfaces:
MappedQuery<T>
Enclosing interface:
MappedQuery<T>

public static final class MappedQuery.Default<T> extends Object implements MappedQuery<T>
MappedQuery默认实现
  • Method Details

    • collection

      public <C extends Collection<T>> C collection(C collection)
      Description copied from interface: MappedQuery
      查询为集合
      Specified by:
      collection in interface MappedQuery<T>
      Type Parameters:
      C - 集合类型
      Parameters:
      collection - 集合
      Returns:
      结果(实际为传入的结合对象,填充了结果)
    • first

      public T first(T defaultValue)
      Description copied from interface: MappedQuery
      查询第一条数据,自行确保sql查询结果为一条记录

      无结果行或第一行的值为 null 时返回 defaultValue; 若 defaultValue 也为 null,则按类型返回兜底值: 基本类型返回类型默认值,集合/Map/数组返回空对象.

      Specified by:
      first in interface MappedQuery<T>
      Parameters:
      defaultValue - 默认值
      Returns:
      结果
    • list

      public List<T> list()
      Description copied from interface: MappedQuery
      查询为list
      Specified by:
      list in interface MappedQuery<T>
      Returns:
      结果
    • optional

      public Optional<T> optional()
      Description copied from interface: MappedQuery
      查询为optional

      无结果行,或第一行的值为 null 时返回 Optional.empty().

      Specified by:
      optional in interface MappedQuery<T>
      Returns:
      结果
    • set

      public Set<T> set()
      Description copied from interface: MappedQuery
      查询为set,默认使用LikedHashSet实现,保留原顺序
      Specified by:
      set in interface MappedQuery<T>
      Returns:
      结果
    • stream

      public Stream<T> stream(Integer estimatedSize)
      Description copied from interface: MappedQuery
      查询为stream

      结果集读尽或遍历异常时会自动释放连接;短路操作(limit/findFirst/anyMatch 等) 不会读尽结果集,必须使用 try-with-resources 或显式 close 释放连接。

      Specified by:
      stream in interface MappedQuery<T>
      Parameters:
      estimatedSize - 预估条数, 仅作为 stream 的 estimateSize 提示值
      Returns:
      结果