Class JDBCDao<Entity>

java.lang.Object
cool.scx.data.jdbc.JDBCDao<Entity>
All Implemented Interfaces:
Dao<Entity,Long>

public class JDBCDao<Entity> extends Object implements Dao<Entity,Long>
使用 JDBC 接口, 通过 SQL 操作关系型数据库的 DAO
Version:
0.0.1
Author:
scx567888
  • Field Details

  • Constructor Details

  • Method Details

    • add

      public final Long add(Entity entity, FieldFilter updateFilter)
      Specified by:
      add in interface Dao<Entity,Long>
    • add

      public final List<Long> add(Collection<Entity> entityList, FieldFilter updateFilter)
      Specified by:
      add in interface Dao<Entity,Long>
    • find

      public final List<Entity> find(Query query, FieldFilter selectFilter)
      Specified by:
      find in interface Dao<Entity,Long>
    • find

      public void find(Query query, FieldFilter fieldFilter, Consumer<Entity> consumer)
      Specified by:
      find in interface Dao<Entity,Long>
    • get

      public Entity get(Query query, FieldFilter columnFilter)
      Specified by:
      get in interface Dao<Entity,Long>
    • update

      public final long update(Entity entity, Query query, FieldFilter updateFilter)
      Specified by:
      update in interface Dao<Entity,Long>
    • delete

      public final long delete(Query query)
      Specified by:
      delete in interface Dao<Entity,Long>
    • count

      public final long count(Query query)
      Specified by:
      count in interface Dao<Entity,Long>
    • clear

      public final void clear()
      Specified by:
      clear in interface Dao<Entity,Long>
    • entityClass

      public final Class<Entity> entityClass()
      Specified by:
      entityClass in interface Dao<Entity,Long>
    • tableInfo

      public final AnnotationConfigTable tableInfo()
    • sqlRunner

      public final SQLRunner sqlRunner()
    • beanBuilder

      public BeanBuilder<Entity> beanBuilder()
    • entityBeanListHandler

      public ResultHandler<List<Entity>> entityBeanListHandler()
    • entityBeanHandler

      public ResultHandler<Entity> entityBeanHandler()
    • buildSelectSQL

      public final SQL buildSelectSQL(Query query, FieldFilter selectFilter)
      构建 (根据聚合查询条件 Query 获取数据列表) 的SQL
      可用于另一条查询语句的 where 条件 用法
      
            // 假设有以下结构的两个实体类
            public class Person {
      
                // ID
                public Long id;
      
                // 关联的 汽车 ID
                public Long carID;
      
                // 年龄
                public Integer age;
      
            }
            public class Car {
      
                // ID
                public Long id;
      
                // 汽车 名称
                public String name;
      
            }
            // 现在想做如下查询 根据所有 person 表中年龄小于 100 的 carID 查询 car 表中的数据
            // 可以按照如下写法
            var cars = carService._select(new Query().in("id",
                       personService._buildSelectSQL(new Query().lessThan("age", 100), ColumnFilter.ofIncluded("carID")),
                       ColumnFilter.ofExcluded()
            ));
            // 同时也支持 whereSQL 方法
            // 这个写法和上方完全相同
            var cars1 = carService._select(new Query().whereSQL("id IN ",
                       personService._buildSelectSQL(new Query().lessThan("age", 100), ColumnFilter.ofIncluded("carID")),
                       ColumnFilter.ofExcluded()
            ));
        

      注意 !!! 若同时使用 limit 和 in/not in 请使用 buildSelectSQLWithAlias(Query, FieldFilter)
      Parameters:
      query - 聚合查询参数对象
      selectFilter - 查询字段过滤器
      Returns:
      selectSQL
    • buildSelectSQLWithAlias

      public final SQL buildSelectSQLWithAlias(Query query, FieldFilter selectFilter)
      在 mysql 中 不支持 in 子句中包含 limit 但是我们可以使用 一个嵌套的别名表来跳过检查 此方法便是用于生成嵌套的 sql 的
      Parameters:
      query - q
      selectFilter - s
      Returns:
      a
    • buildGetSQL

      public final SQL buildGetSQL(Query query, FieldFilter selectFilter)
    • buildGetSQLWithAlias

      public final SQL buildGetSQLWithAlias(Query query, FieldFilter selectFilter)
      在 mysql 中 不支持 in 子句中包含 limit 但是我们可以使用 一个嵌套的别名表来跳过检查 此方法便是用于生成嵌套的 sql 的
      Parameters:
      query - q
      selectFilter - s
      Returns:
      a