| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package com.zhcs.dt.dao;
- import java.util.List;
- import javax.annotation.Resource;
- import org.apache.ibatis.session.ExecutorType;
- import org.apache.ibatis.session.SqlSession;
- import org.apache.ibatis.session.SqlSessionFactory;
- import org.mybatis.spring.SqlSessionTemplate;
- import org.springframework.stereotype.Repository;
- /**
- * 第2数据源
- * @author FH Q 31 359 6790
- * 修改时间:2016、04、29
- */
- @Repository("daoSupport2")
- public class DaoSupport2 implements DAO {
- //@Resource(name = "sqlSessionTemplate2") //去掉注释,打开第2数据源
- private SqlSessionTemplate sqlSessionTemplate2;
-
- /**
- * 保存对象
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object save(String str, Object obj) throws Exception {
- return sqlSessionTemplate2.insert(str, obj);
- }
-
- /**
- * 批量更新
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object batchSave(String str, List objs )throws Exception{
- return sqlSessionTemplate2.insert(str, objs);
- }
-
- /**
- * 修改对象
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object update(String str, Object obj) throws Exception {
- return sqlSessionTemplate2.update(str, obj);
- }
- /**
- * 批量更新
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public void batchUpdate(String str, List objs )throws Exception{
- SqlSessionFactory sqlSessionFactory = sqlSessionTemplate2.getSqlSessionFactory();
- //批量执行器
- SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
- try{
- if(objs!=null){
- for(int i=0,size=objs.size();i<size;i++){
- sqlSession.update(str, objs.get(i));
- }
- sqlSession.flushStatements();
- sqlSession.commit();
- sqlSession.clearCache();
- }
- }finally{
- sqlSession.close();
- }
- }
-
- /**
- * 批量更新
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object batchDelete(String str, List objs )throws Exception{
- return sqlSessionTemplate2.delete(str, objs);
- }
-
- /**
- * 删除对象
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object delete(String str, Object obj) throws Exception {
- return sqlSessionTemplate2.delete(str, obj);
- }
-
- /**
- * 查找对象
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object findForObject(String str, Object obj) throws Exception {
- return sqlSessionTemplate2.selectOne(str, obj);
- }
- /**
- * 查找对象
- * @param str
- * @param obj
- * @return
- * @throws Exception
- */
- public Object findForList(String str, Object obj) throws Exception {
- return sqlSessionTemplate2.selectList(str, obj);
- }
-
- public Object findForMap(String str, Object obj, String key, String value) throws Exception {
- return sqlSessionTemplate2.selectMap(str, obj, key);
- }
-
- }
|