All Downloads are FREE. Search and download functionalities are using the official Maven repository.

springdao.RepositoryManager Maven / Gradle / Ivy

package springdao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Do everything that {@link DaoRepository } do, it's main purpose is
 * transaction management.
* Standard JPA does not support custom isolation levels, So we must declare * {@link Transactional @Transactional} here.
* 封裝{@link DaoRepository}的功能,只是為了交易控制. * * @author Kent Yeh * @param */ @Transactional(readOnly = true) public class RepositoryManager { private DaoRepository dao; protected static Logger logger = LogManager.getLogger(RepositoryManager.class); public DaoRepository getDao() { return dao; } public void setDao(DaoRepository dao) { this.dao = dao; } public E instanate() throws InstantiationException, IllegalAccessException { return dao.instanate(); } public E findByPrimaryKey(Serializable primaryKey) { return dao == null ? null : dao.findByPrimaryKey(primaryKey); } public E findByPrimaryKey(Serializable primaryKey, String lockMode) { return dao == null ? null : dao.findByPrimaryKey(primaryKey, lockMode); } public E findByPrimaryKey(Serializable primaryKey, Map properties) { return dao == null ? null : dao.findByPrimaryKey(primaryKey, properties); } /** * @param properties Not used.不使用 */ public E findByPrimaryKey(Serializable primaryKey, String lockMode, Map properties) { return dao == null ? null : dao.findByPrimaryKey(primaryKey, lockMode, properties); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E save(E entity) { return dao == null ? null : dao.save(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Collection save(Collection entities) { return dao == null ? null : dao.save(entities); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E persist(E entity) { return dao == null ? null : dao.persist(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E update(E entity) { return dao == null ? null : dao.update(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Collection update(Collection entities) { return dao == null ? null : dao.update(entities); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E merge(E entity) { return dao == null ? null : dao.merge(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Collection merge(Collection entity) { return dao == null ? null : dao.merge(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E saveOrUpdate(E entity) { return dao == null ? null : dao.saveOrUpdate(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Collection saveOrUpdate(Collection entities) { return dao == null ? null : dao.saveOrUpdate(entities); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void delete(Serializable primaryKey) { dao.delete(primaryKey); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void delete(Serializable primaryKey, String lockMode) { dao.delete(primaryKey, lockMode); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void delete(Collection primaryKeys) { dao.delete(primaryKeys); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E remove(E entity) { return dao.remove(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E remove(E entity, String lockMode) { return dao.remove(entity, lockMode); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Collection remove(Collection entities) { return dao.remove(entities); } public E refresh(E entity) { return dao == null ? null : dao.refresh(entity); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public E refresh(E entity, String lockMode) { return dao == null ? null : dao.refresh(entity, lockMode); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int sqlUpdate(String sql) { return dao == null ? null : dao.sqlUpdate(sql); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int sqlUpdate(String sql, Object... parameters) { return dao == null ? null : dao.sqlUpdate(sql, parameters); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int sqlUpdate(String sql, Mapparameters) { return dao == null ? null : dao.sqlUpdate(sql, parameters); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public List sqlUpdate(List sqls) { return dao == null ? null : dao.sqlUpdate(sqls); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int bulkUpdate(String QL) { return dao == null ? null : dao.bulkUpdate(QL); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public List bulkUpdate(List QLs) { return dao == null ? null : dao.bulkUpdate(QLs); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int bulkUpdate(String QL, Object... parameters) { return dao == null ? null : dao.bulkUpdate(QL, parameters); } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public int bulkUpdate(String QL, Map parameters) { return dao == null ? null : dao.bulkUpdate(QL, parameters); } public String getEntityName() { return dao == null ? "" : dao.getEntityName(); } public String $e() { return getEntityName(); } public String getAliasName() { return dao == null ? "" : dao.getAliasName(); } public String $a() { return getAliasName(); } public String $a(String field) { return getAliasName() + "." + field; } public String $ea() { return getEntityName() + " AS " + getAliasName(); } public List findByCriteria(String qlCriteria) { return dao == null ? null : dao.findByCriteria(qlCriteria); } public List findByCriteria(String qlCriteria, Object... parameters) { return dao == null ? null : dao.findByCriteria(qlCriteria, parameters); } public List findByCriteria(String qlCriteria, Map parameters) { return dao == null ? null : dao.findByCriteria(qlCriteria, parameters); } public List findByCriteria(String qlCriteria, int startPageNo, int pageSize, Object... parameters) { return dao == null ? null : dao.findByCriteria(qlCriteria, startPageNo, pageSize, parameters); } public List findByCriteria(String qlCriteria, int startPageNo, int pageSize, Map parameters) { return dao == null ? null : dao.findByCriteria(qlCriteria, startPageNo, pageSize, parameters); } public List findByCriteria(String qlCriteria, int startPageNo, int pageSize) { return dao == null ? null : dao.findByCriteria(qlCriteria, startPageNo, pageSize); } public E findFirstByCriteria(String qlCriteria) { List result = findByCriteria(qlCriteria, 1, 1); return result.isEmpty() ? null : result.get(0); } public E findFirstByCriteria(String qlCriteria, Object... parameters) { List result = findByCriteria(qlCriteria, 1, 1, parameters); return result.isEmpty() ? null : result.get(0); } public List findByNamedQuery(String name) { return dao == null ? null : dao.findByNamedQuery(name); } public List findByNamedQuery(String name, Object... parameters) { return dao == null ? null : dao.findByNamedQuery(name, parameters); } public List findByNamedQuery(String name, Map parameters) { return dao == null ? null : dao.findByNamedQuery(name, parameters); } public List findBySQLQuery(String sql) { return dao == null ? null : dao.findBySQLQuery(sql); } public List findBySQLQuery(String sql, Object... parameters) { return dao == null ? null : dao.findBySQLQuery(sql, parameters); } public List findBySQLQuery(String sql, Map parameters) { return dao == null ? null : dao.findBySQLQuery(sql, parameters); } public List findBySQLQuery(String sql, String entityAlias) { return dao == null ? null : dao.findBySQLQuery(sql, entityAlias); } public List findBySQLQuery(String sql, String entityAlias, Object... parameters) { return dao == null ? null : dao.findBySQLQuery(sql, entityAlias, parameters); } public T findUniqueByQL(String QL) { if (dao == null) { return null; } else { return dao.findUniqueByQL(QL); } } public T findUniqueByQL(Class clazz, String QL) { return findUniqueByQL(QL); } public T findUniqueByQL(String QL, Object... parameters) { if (dao == null) { return null; } else { return dao.findUniqueByQL(QL, parameters); } } public T findUniqueByQL(Class clazz, String QL, Object... parameters) { return findUniqueByQL(QL, parameters); } public T findUniqueByQL(String QL, Map parameters) { if (dao == null) { return null; } else { return dao.findUniqueByQL(QL, parameters); } } public T findUniqueByQL(Class clazz, String QL, Map parameters) { return findUniqueByQL(QL, parameters); } public List findListByQL(String QL) { if (dao == null) { return null; } else { return dao.findListByQL(QL); } } public List findListByQL(Class clazz, String QL) { return findListByQL(QL); } public List findListByQL(String QL, Object... parameters) { if (dao == null) { return null; } else { return dao.findListByQL(QL, parameters); } } public List findListByQL(Class clazz, String QL, Object... parameters) { return findListByQL(QL, parameters); } public List findListByQL(String QL, Map parameters) { if (dao == null) { return null; } else { return dao.findListByQL(QL, parameters); } } public List findListByQL(Class clazz, String QL, Map parameters) { return findListByQL(QL, parameters); } public List findListByNamedQuery(String name) { if (dao == null) { return null; } else { return dao.findListByNamedQuery(name); } } public List findListByNamedQuery(Class clazz, String name) { return findListByNamedQuery(name); } public List findListByNamedQuery(String name, Object... parameters) { if (dao == null) { return null; } else { return dao.findListByNamedQuery(name, parameters); } } public List findListByNamedQuery(Class clazz, String name, Object... parameters) { return findListByNamedQuery(name, parameters); } public List findListByNamedQuery(String name, Map parameters) { if (dao == null) { return null; } else { return dao.findListByNamedQuery(name, parameters); } } public List findListByNamedQuery(Class clazz, String name, Map parameters) { return findListByNamedQuery(name, parameters); } public E initLazyCollection(E entity, String collectionFieldName) { return dao == null ? null : dao.initLazyCollection(entity, collectionFieldName); } public void clear() { if (dao != null) { dao.clear(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy