IQueryService
<---- QueryServiceImpl:利用GenericDAO实现查询
IQueryObject:查询对象接口
<---- QueryObject:主要用于分页查询,默认查询条件为1=1
<---- BaseQueryObject extends QueryObject
IQuery <---- DbQuery :通用的数据库查询器,根据数据库操作对象IDAO执行数据库分页查询操作
<---- GenericFieldQuery:利用GenericDAO实现查询
<---- GenericQuery:代码与上同
<---- ListQuery :List对象查询,简单
<---- ArrayQuery:Arrays对象查询(未写)
IFieldQueryObject <--- FieldQueryObject:与QueryObject同,只添加了queryFields,但与查询功能无关
QueryUtil:唯一方法IPageList query(IQueryObject queryObject, Class entityType, GenericDAO dao),利用GenericPageList.doList做分页用
IDAO<T>:数据库操作接口
<---EasyDBODAO:引用com.easyjf.dbo.EasyJDB实现查询
<---EntityMangerDaoSurport:利用JPA实现持久化(EntityManagerFactory是如何注入的?)
<---HibernateDaoSurport:利用hibernate实现持久化(SessionFactory如何注入?)
GenericDAO<T>:泛型DAO接口
<---GenericDAOImpl extends JpaDaoSupport
-->get(id)、remove(T)、save(T)、update(T)==>通过this.getJpaTemplate()实现
-->List<T> find(condition, params, begin, max)==>condition为where后的条件,em.createQuery(sql),query.setParameter,query.getResultList
-->List query(jpql, params, begin, max)==>jpql为整个查询语句,同上
-->T getBy(String property, Object value)==>select o from className o where o.property = :value
-->List executeNamedQuery(name, params, begin, max)==>em.createNamedQuery
-->List executeNativeNamedQuery(name)==>em.createNamedQuery
-->List executeNativeQuery(sql, params, begin, max)==>em.createNativeQuery
-->List executeNativeSQL(sql)==>em.createNativeQuery
Query nativeQuery = manager.createNativeQuery("select * from child where id = ?1", Child.class); nativeQuery.setParameter(1, 1); Object o = nativeQuery.getSingleResult(); Assert.assertEquals(Child.class,o.getClass()); Query query = manager.createQuery("select o from Child o where o.id = ?1 and o.name = :name"); query.setParameter(1, 1); query.setParameter("name", "merge"); Child c = (Child)query.getSingleResult(); Assert.assertNotNull(c); // 该方法需要在Child类上添加注解@NamedQuery(name = "findAllChild", query = "select o from Child o") Query nameQuery = manager.createNamedQuery("findAllChild"); List list = nameQuery.getResultList()
EasyJDB