123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- /*
- * Copyright 2009 by primedata Corporation.
- * ,
- *
- * All rights reserved.
- *
- * This software is the confidential and proprietary information of
- * primedata Corporation ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with primedata.
- */
- package com.primeton.dams.utils.template;
- import org.hibernate.transform.ResultTransformer;
- import org.springframework.dao.DataAccessException;
- import org.springframework.jdbc.core.JdbcTemplate;
- import javax.persistence.LockModeType;
- import java.io.Serializable;
- import java.util.Collection;
- import java.util.List;
- import java.util.Map;
- /**
- * Data Access Implement Interface.
- * find开头的方法是HQL方法,query开头的是SQL方法。
- * @author user
- * @version 1.0 2007-1-27
- */
- // FIXME 迁移至core工程
- public interface IDAOService {
- /** Get HQL from xxxSql.xml file*/
- String getSQL(String name);
-
- /** Get dynamic HQL from xxxSql.xml file, voOrMap is a VO or a map.*/
- String getSQL(String name, Object voOrMap);
-
- /** Get dynamic Params from xxxSql.xml file, voOrMap is a VO or a map.*/
- Object[] getParam(String name, Object voOrMap);
-
- /** Get dynamic Params from xxxSql.xml file, voOrMap is a VO or a map.*/
- Map getMapParam(String name, Object voOrMap);
-
- /**Persist the given transient instance*/
- void add(Object vo) throws DataAccessException;
- /**Update the given persistent instance*/
- void update(Object vo) throws DataAccessException;
- /**
- * hibernate merge
- * @param entity
- * @throws DataAccessException
- */
- void merge(Object entity) throws DataAccessException;
-
- /**Save or update the given persistent instance, according to its id */
- void addOrUpdate(Object vo) throws DataAccessException;
-
- /**Save or update the given persistent instances*/
- void addAll(Collection vos) throws DataAccessException;
- /**Return the persistent instance of the given entity class with the given identifier,
- *or null if not found*/
- Object get(Class entityClass, Serializable id);
-
- /**Return the persistent instance of the given entity class with the given identifier,
- *or null if not found*/
- Object get(Class entityClass, Serializable id, LockModeType lockMode);
-
- /**Delete the given persistent instance, according to its id*/
- void delete(Object entity) throws DataAccessException;
- /**Delete the given persistent instance*/
- void delete(Class entityClass, Serializable id) throws DataAccessException;
- /**Delete all given persistent instances*/
- void deleteAll(Collection entities) throws DataAccessException;
- /**Update/delete all objects according to the given query*/
- int execute(String updateSql);
-
- /**Update/delete all objects according to the given query*/
- int execute(String updateSql, Object[] params);
-
- /**flush*/
- void flush();
-
- /**clear*/
- void clear();
-
- /** count(*). */
- int count(String queryString, Object[] parameters);
-
- /**
- * 执行SQL查询。提供结果集的转换接口ResultTransformer。
- * @param query Query
- * @param params 参数
- * @param rt ResultTransformer
- * @return
- */
- List query(javax.persistence.Query query, Object[] params, ResultTransformer rt);
- /**
- * 执行SQL查询。提供结果集的转换接口ResultTransformer。
- * @param query
- * @param params
- * @param rt
- * @param firstResult
- * @param maxResult
- * @return
- */
- public List query(javax.persistence.Query query, Object[] params, ResultTransformer rt, final int firstResult, final int maxResult);
- /**
- * 执行SQL查询。提供结果集的转换接口ResultTransformer。
- * @param sql 脚本
- * @param params 参数
- * @param rt ResultTransformer
- * @return
- */
- List query(String sql, Object[] params, ResultTransformer rt);
- /**
- * 执行SQL查询
- * @param id statement id
- * @return Object[]/Object
- */
- default List queryById(String id) {
- return queryById(id, null, null);
- }
- /**
- * 执行SQL查询
- * @param id 脚本
- * @param params 参数
- * @return Object[]/Object
- */
- default List queryById(String id, Map<String, Object> params){
- return queryById(id, params, null);
- }
- /**
- * 执行 statement id 的查询,返回 ResultTransformer 的转换结果
- * @param id statement id
- * @param params 参数
- * @param entityClass 结果转换
- * @return 返回 ResultTransformer 的转换结果
- */
- public List queryById(String id, Map<String, Object> params, Class entityClass);
- /**
- * 执行 statement id 的查询,返回 ResultTransformer 的转换结果, 并应用分页
- * @param id
- * @param params
- * @param entityClass
- * @param firstResult
- * @param maxResult
- * @return
- */
- public List queryById(String id, Map<String, Object> params, Class entityClass, final int firstResult, final int maxResult);
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @return Object[]/Object
- */
- default List querySQL(String sql) {
- return querySQL(sql, null);
- }
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @param params 参数
- * @return Object[]/Object
- */
- default List querySQL(String sql, Object[] params) {
- return query(sql, params, null);
- }
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @param params 参数
- * @return Object[]/Object
- */
- default List querySQL(String sql, Object[] params, Class entityClass) {
- return query(sql, params, null);
- }
- /**
- * 执行SQL查询Query
- * @param query Query,脚本
- * @param params 参数
- * @return Object[]/Object
- */
- List querySQL(javax.persistence.Query query, Object[] params);
-
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @return Map
- */
- default List queryForMap(String sql) {
- return queryForMap(sql, null);
- }
-
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @param params 参数
- * @return Map
- */
- List queryForMap(String sql, Object[] params);
-
- /**
- * 执行SQL查询
- * @param query Query
- * @param params 参数
- * @return
- */
- List queryForMap(javax.persistence.Query query, Object[] params);
-
- /**
- * 执行SQL查询
- * @param sql 脚本
- * @param params 参数
- * @param firstResult 开始位置
- * @param maxResult 最大记录数
- * @return
- */
- List queryForMap(String sql, Object[] params, int firstResult, int maxResult);
- /**
- * 查询SQL返回实体。用法介绍:<br>
- * <pre>
- * sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
- * .addEntity("cat", Cat.class)
- * .addEntity("mother", Cat.class)
- * </pre>
- * @param sql 脚本
- * @param entityClass 实体类
- * @return entity List
- */
- public List queryForEntity(String sql, Class entityClass);
- /**
- * 查询SQL返回实体。用法介绍:<br>
- * <pre>
- * sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
- * .addEntity("cat", Cat.class)
- * .addEntity("mother", Cat.class)
- * </pre>
- * @param sql 脚本
- * @param params 参数
- * @param entityClass 实体类
- * @return entity List
- */
- List queryForEntity(String sql, Object[] params, Class entityClass);
-
- /**
- * 查询SQL返回实体。用法介绍:<br>
- * <pre>
- * sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
- * .addEntity("cat", Cat.class)
- * .addEntity("mother", Cat.class)
- * </pre>
- * @param sql 脚本
- * @param params 参数
- * @param entityClass 实体类
- * @param firstResult 开始位置
- * @param maxResult 最大记录数
- * @return entity List
- */
- List queryForEntity(String sql, Object[] params, Class entityClass, int firstResult, int maxResult);
- /**
- * 查询返回一条数据,无数据则返回 null
- * @param sql
- * @param entityClass DO 实体类,或者 Map
- * @param <T>
- * @return
- */
- default public <T> T queryForObject(String sql, Class<T> entityClass) {
- return queryForObject(sql, null, entityClass);
- }
- /**
- * 查询返回一条数据,无数据则返回 null
- * @param sql
- * @param params
- * @param entityClass DO 实体类,或者 Map
- * @param <T>
- * @return
- */
- public <T> T queryForObject(String sql, Object[] params, Class<T> entityClass);
- /**
- * 查询整数值
- * @param sql 脚本
- * @return Long
- */
- default Long queryForLong(String sql) {
- return this.queryForLong(sql, null);
- }
-
- /**
- * 查询整数值
- * @param sql 脚本
- * @param params 参数
- * @return Long
- */
- long queryForLong(String sql, Object[] params);
- /**
- * 执行SQL更新、删除
- * @param id 脚本
- * @return
- */
- default int updateById(String id){
- return updateById(id, null);
- }
- /**
- * 执行SQL更新、删除
- * @param id statement id
- * @param params 参数
- * @return
- */
- int updateById(String id, Map<String, Object> params);
-
- /**
- * 执行SQL更新、删除
- * @param sql 脚本
- * @param params 参数
- * @return
- */
- int updateSQL(String sql, Object[] params);
-
- /**
- * 批量执行SQL
- * @param sql SQL
- * @return int[]
- */
- int[] batchUpdateSQL(String[] sql);
-
- /**
- * 分页查询SQL
- * @param sql 脚本
- * @param params 参数
- * @param page 分页
- * @return Object[] List
- */
- List queryPageList(String sql, Object[] params, Page page);
-
- /**
- * 分页查询SQL
- * @param sql 脚本
- * @param params 参数
- * @param page 分页
- * @return map List
- */
- List queryPageMap(String sql, Object[] params, Page page);
-
- /**
- * 分页查询SQL,返回实体。用法介绍:<br>
- * <pre>
- * sess.createSQLQuery("SELECT {cat.*}, {mother.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = c.ID")
- * .addEntity("cat", Cat.class)
- * .addEntity("mother", Cat.class)
- * </pre>
- * @param sql 脚本
- * @param params 参数
- * @param page 分页参数
- * @param entityClass 实体集合
- * @return entity List
- */
- List queryPageEntity(String sql, Object[] params, Page page, Class entityClass);
-
- /**
- * 解析SQL转换成count(*)的 统计脚本
- * @param sql 原始SQL
- * @return 统计SQL
- */
- String getCountSQL(String sql);
-
- /**
- * 统计查询SQL
- * @param sql 脚本
- * @param params 参数
- * @return count(*)的结果
- */
- int countSQL(String sql, Object[] params);
-
- /**
- * (Oracle)获取序列号的下一个值
- * @param sequence
- * @return
- */
- Long getSQNextValue(String sequence);
-
- /**
- * (Oracle)获取序列号的当前值
- * @param sequence
- * @return
- */
- Long getSQCurrValue(String sequence);
-
- /**
- * 获取SimpleJdbcTemplate
- * @return SimpleJdbcTemplate
- */
- JdbcTemplate getJdbcTemplate();
- }
|