From 96286178ee1c257c130cb2ad964a781f36c4eee5 Mon Sep 17 00:00:00 2001
From: yn147 <2270338776@qq.com>
Date: 星期三, 10 五月 2023 16:23:27 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
src/main/java/com/qxueyou/scc/base/dao/BaseDAO.java | 558 ++++++++++++++++++++++++++++---------------------------
1 files changed, 281 insertions(+), 277 deletions(-)
diff --git a/src/main/java/com/qxueyou/scc/base/dao/BaseDAO.java b/src/main/java/com/qxueyou/scc/base/dao/BaseDAO.java
index 5dec6f7..843a3db 100644
--- a/src/main/java/com/qxueyou/scc/base/dao/BaseDAO.java
+++ b/src/main/java/com/qxueyou/scc/base/dao/BaseDAO.java
@@ -7,6 +7,7 @@
package com.qxueyou.scc.base.dao;
+import java.beans.Transient;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -29,6 +30,7 @@
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
+import org.springframework.transaction.annotation.Transactional;
/**
* 鍩虹DAO绫�,鑷姩娉ㄥ叆sessionFactory
@@ -37,11 +39,12 @@
* @since JDK1.6
* @history 2010-07-28 澶忓痉铏� 鏂板缓
*/
+@Transactional(readOnly=false)
public class BaseDAO extends HibernateDaoSupport {
-
- /** 娉ㄩ噴 rawtypes */
- private static final String RAW_TYPES = "rawtypes";
-
+
+ /** 娉ㄩ噴 rawtypes */
+ private static final String RAW_TYPES = "rawtypes";
+
/**
* 娉ㄥ叆sessionFactory
*
@@ -61,9 +64,9 @@
* @return 鏌ユ壘鍒扮殑缁撴灉,濡傛灉娌℃壘鍒�,杩斿洖null
*/
public <T> T read(Class<T> clz, Serializable key) {
- if(key==null){
- return null;
- }
+ if(key==null){
+ return null;
+ }
return clz.cast(this.getHibernateTemplate().get(clz, key));
}
@@ -73,7 +76,7 @@
public void update(Object obj) {
this.getHibernateTemplate().update(obj);
}
-
+
/**
* 淇濆瓨瀵硅薄
*/
@@ -84,6 +87,7 @@
/**
* 淇濆瓨鎴栨洿鏂板璞�
*/
+ @Transactional(readOnly = false)
public void saveOrUpdate(Object obj) {
this.getHibernateTemplate().saveOrUpdate(obj);
}
@@ -93,7 +97,7 @@
*/
public void saveOrUpdateAll(@SuppressWarnings(RAW_TYPES) Collection collection) {
for(Object obj:collection){
- this.getHibernateTemplate().saveOrUpdate(obj);
+ this.getHibernateTemplate().saveOrUpdate(obj);
}
}
@@ -103,7 +107,7 @@
public void deleteAll(@SuppressWarnings(RAW_TYPES) Collection col) {
this.getHibernateTemplate().deleteAll(col);
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -112,10 +116,10 @@
* @return
*/
@SuppressWarnings("unchecked")
- public <T> List<T> find(String hql, Class<T> cls) {
+ public <T> List<T> find(String hql, Class<T> cls) {
return find(hql,Collections.EMPTY_LIST,cls);
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -124,11 +128,11 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- public <T> List<T> find(final String hql,final List<Object> args,final Class<T> cls) {
- return this.getHibernateTemplate().execute(new HibernateCallback<List<T>>() {
+ public <T> List<T> find(final String hql,final List<Object> args,final Class<T> cls) {
+ return this.getHibernateTemplate().execute(new HibernateCallback<List<T>>() {
@SuppressWarnings("unchecked")
- public List<T> doInHibernate(Session session) {
+ public List<T> doInHibernate(Session session) {
Query query = session.createQuery(hql);
int i = 0;
for (Object arg : args) {
@@ -140,7 +144,7 @@
}
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃
*
@@ -149,11 +153,11 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- @SuppressWarnings("unchecked")
- public List<Object[]> findwithRawResult(String hql, List<Object> args) {
+ @SuppressWarnings("unchecked")
+ public List<Object[]> findwithRawResult(String hql, List<Object> args) {
return (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
}
-
+
/**
* 鏍规嵁hql鏌ヨ,杩斿洖鍒楄〃鏁版嵁鎬绘暟
*
@@ -162,28 +166,28 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- public int findCount(final String hql, final List<Object> args) {
- return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
-
+ public int findCount(final String hql, final List<Object> args) {
+ return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
+
@Override
public Integer doInHibernate(Session session){
-
- Query query = session.createQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
- int i = 0;
- for (Object arg : args) {
+
+ Query query = session.createQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
+ int i = 0;
+ for (Object arg : args) {
query.setParameter(i++, arg);
}
-
- if(null != query.uniqueResult()){
- return ((Long)query.uniqueResult()).intValue();
- }else{
- return 0 ;
- }
+
+ if(null != query.uniqueResult()){
+ return ((Long)query.uniqueResult()).intValue();
+ }else{
+ return 0 ;
+ }
}
});
}
-
- /**
+
+ /**
* 鏍规嵁hql鏌ヨ,杩斿洖鍒楄〃鏁版嵁鎬绘暟
*
* @param hql 鏌ヨ璇彞
@@ -191,27 +195,27 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- public int findCountBySql(final String sql, final List<Object> args) {
- return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
-
+ public int findCountBySql(final String sql, final List<Object> args) {
+ return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
+
@Override
public Integer doInHibernate(Session session){
-
- Query query = session.createSQLQuery(sql.trim().startsWith("from")?"select count(1) ".concat(sql):sql);
- int i = 0;
- for (Object arg : args) {
+
+ Query query = session.createSQLQuery(sql.trim().startsWith("from")?"select count(1) ".concat(sql):sql);
+ int i = 0;
+ for (Object arg : args) {
query.setParameter(i++, arg);
}
-
- if(null != query.uniqueResult()){
- return ((BigInteger)query.uniqueResult()).intValue();
- }else{
- return 0 ;
- }
+
+ if(null != query.uniqueResult()){
+ return ((BigInteger)query.uniqueResult()).intValue();
+ }else{
+ return 0 ;
+ }
}
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,杩斿洖鍒楄〃鍒嗛〉鏁版嵁
*
@@ -221,7 +225,7 @@
* @return
*/
@SuppressWarnings({ "unchecked" })
- public <T> List<T> findList(final String hql, final Pager page, final List<Object> args,Class<T> cls) {
+ public <T> List<T> findList(final String hql, final Pager page, final List<Object> args,Class<T> cls) {
return this.getHibernateTemplate().execute(new HibernateCallback<List<T>>() {
public List<T> doInHibernate(Session session) {
@@ -236,7 +240,7 @@
}
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,杩斿洖鍞竴鐨勬暟鎹�
*
@@ -246,7 +250,7 @@
* @return
*/
@SuppressWarnings({ RAW_TYPES, "unchecked" })
- public <T> T findUnique(final String hql, final List<Object> args,Class<T> cls) {
+ public <T> T findUnique(final String hql, final List<Object> args,Class<T> cls) {
return (T)this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
@@ -287,7 +291,7 @@
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -307,14 +311,14 @@
query.setParameter(i++, arg);
}
query.setFirstResult(pager.getPageSize()*(pager.getPageNum()-1));
- query.setMaxResults(pager.getPageSize());
+ query.setMaxResults(pager.getPageSize());
return query.list();
}
});
}
-
-
+
+
/**
* hql鍙惈鍗曚竴鍙傛暟
*
@@ -324,17 +328,17 @@
* @return
*/
public Result bulkUpdateInLoop(String hql, Object args[]) {
- int iCount = 0;
+ int iCount = 0;
for(Object arg:args){
- iCount += getHibernateTemplate().bulkUpdate(hql, arg);
+ iCount += getHibernateTemplate().bulkUpdate(hql, arg);
}
Map<String,Object> attrs = new HashMap<String,Object>(1);
attrs.put("doCount", iCount);
Result result = new Result(true);
result.setData(attrs);
- return result;
+ return result;
}
-
+
/**
* hql鍙惈鍗曚竴鍙傛暟
*
@@ -344,14 +348,14 @@
* @return
*/
public Result bulkUpdate(String hql, Object args[]) {
- int count = getHibernateTemplate().bulkUpdate(hql, args);
+ int count = getHibernateTemplate().bulkUpdate(hql, args);
Map<String,Object> attrs = new HashMap<String,Object>(1);
attrs.put("doCount", count);
Result result = new Result(true);
result.setData(attrs);
- return result;
+ return result;
}
-
+
/**
* 瀛樺偍杩囩▼璇彞
*
@@ -359,25 +363,25 @@
* @param args 鍙傛暟鏁扮粍
* @return
*/
- public Result executeProduce(final String sql, final Object args[]) {
-
- Integer result = getHibernateTemplate().execute(new HibernateCallback<Integer>(){
+ public Result executeProduce(final String sql, final Object args[]) {
- @Override
- public Integer doInHibernate(Session session)
- throws HibernateException {
-
- Query query = session.createSQLQuery("{ "+sql+" }");
- for(int i=0;i<args.length;i++){
- query.setParameter(i, args[i]);
- }
+ Integer result = getHibernateTemplate().execute(new HibernateCallback<Integer>(){
+
+ @Override
+ public Integer doInHibernate(Session session)
+ throws HibernateException {
+
+ Query query = session.createSQLQuery("{ "+sql+" }");
+ for(int i=0;i<args.length;i++){
+ query.setParameter(i, args[i]);
+ }
return query.executeUpdate();
- }
-
+ }
+
});
return new Result(true,String.valueOf(result));
}
-
+
/**
* 鎵цsql鍒犻櫎
*
@@ -385,24 +389,24 @@
* @param args 鍙傛暟鏁扮粍
* @return
*/
- public int executeSqlDelete(final String sql, final Object args[]) {
-
- return getHibernateTemplate().execute(new HibernateCallback<Integer>(){
+ public int executeSqlDelete(final String sql, final Object args[]) {
- @Override
- public Integer doInHibernate(Session session)
- throws HibernateException {
-
- Query query = session.createSQLQuery(sql);
- for(int i=0;i<args.length;i++){
- query.setParameter(i, args[i]);
- }
+ return getHibernateTemplate().execute(new HibernateCallback<Integer>(){
+
+ @Override
+ public Integer doInHibernate(Session session)
+ throws HibernateException {
+
+ Query query = session.createSQLQuery(sql);
+ for(int i=0;i<args.length;i++){
+ query.setParameter(i, args[i]);
+ }
return query.executeUpdate();
- }
-
+ }
+
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -413,30 +417,30 @@
*/
@SuppressWarnings({RAW_TYPES, "unchecked" })
public List<Object[]> findRawByComplexHql(final String hql, final Map<String, Object> map) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
return (List<Object[]>)this.getHibernateTemplate().execute(new HibernateCallback<List>() {
public List doInHibernate(Session session) {
Query query = session.createQuery(hql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- query.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- query.setParameterList(string, (Object[])obj);
- }else{
- query.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ query.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ query.setParameterList(string, (Object[])obj);
+ }else{
+ query.setParameter(string, obj);
+ }
+ }
+ }
return query.list();
}
});
- }
-
+ }
+
/**
* 鏍规嵁hql鏌ヨ,杩斿洖鍒楄〃鏁版嵁鎬绘暟
*
@@ -445,39 +449,39 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- public int findCountByComplexHql(final String hql, final Map<String, Object> map) {
- return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
-
+ public int findCountByComplexHql(final String hql, final Map<String, Object> map) {
+ return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
+
@Override
public Integer doInHibernate(Session session){
-
- Query queryHql = session.createQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
-
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+
+ Query queryHql = session.createQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
+
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- queryHql.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- queryHql.setParameterList(string, (Object[])obj);
- }else{
- queryHql.setParameter(string, obj);
- }
- }
- }
-
- if(null != queryHql.uniqueResult()){
- return ((Long)queryHql.uniqueResult()).intValue();
- }else{
- return 0 ;
- }
+ if(obj instanceof Collection<?>){
+ queryHql.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ queryHql.setParameterList(string, (Object[])obj);
+ }else{
+ queryHql.setParameter(string, obj);
+ }
+ }
+ }
+
+ if(null != queryHql.uniqueResult()){
+ return ((Long)queryHql.uniqueResult()).intValue();
+ }else{
+ return 0 ;
+ }
}
});
}
-
- /**
+
+ /**
* 鏍规嵁sql鏌ヨ,杩斿洖鍒楄〃鏁版嵁鎬绘暟
*
* @param hql 鏌ヨ璇彞
@@ -485,38 +489,38 @@
* @param cls 杩斿洖绫诲瀷
* @return
*/
- public int findCountByComplexSql(final String hql, final Map<String, Object> map) {
- return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
-
+ public int findCountByComplexSql(final String hql, final Map<String, Object> map) {
+ return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
+
@Override
public Integer doInHibernate(Session session){
-
- Query querySql = session.createSQLQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
-
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+
+ Query querySql = session.createSQLQuery(hql.trim().startsWith("from")?"select count(1) ".concat(hql):hql);
+
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- querySql.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- querySql.setParameterList(string, (Object[])obj);
- }else{
- querySql.setParameter(string, obj);
- }
- }
- }
-
- if(null != querySql.uniqueResult()){
- return ((BigInteger)querySql.uniqueResult()).intValue();
- }else{
- return 0 ;
- }
+ if(obj instanceof Collection<?>){
+ querySql.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ querySql.setParameterList(string, (Object[])obj);
+ }else{
+ querySql.setParameter(string, obj);
+ }
+ }
+ }
+
+ if(null != querySql.uniqueResult()){
+ return ((BigInteger)querySql.uniqueResult()).intValue();
+ }else{
+ return 0 ;
+ }
}
});
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -526,12 +530,12 @@
* @return
*/
public <T> List<T> findByComplexHql(final String hql, final Map<String, Object> map, Class<T> cls) {
- Pager page = new Pager();
- page.setPageSize(Integer.MAX_VALUE);
- page.setPageNum(1);
+ Pager page = new Pager();
+ page.setPageSize(Integer.MAX_VALUE);
+ page.setPageNum(1);
return findByComplexHql(hql, page, map, cls);
}
-
+
/**
* 澶嶆潅hql
* @param sql
@@ -540,43 +544,43 @@
* @return
*/
public <T> T findUniqueByHql(final String hql, final Map<String, Object> map){
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
List<T> lst = this.getHibernateTemplate().execute(new HibernateCallback<List<T>>() {
-
+
@SuppressWarnings("unchecked")
- public List<T> doInHibernate(Session session) {
+ public List<T> doInHibernate(Session session) {
Query queryHql = session.createQuery(hql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- queryHql.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- queryHql.setParameterList(string, (Object[])obj);
- }else{
- queryHql.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ queryHql.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ queryHql.setParameterList(string, (Object[])obj);
+ }else{
+ queryHql.setParameter(string, obj);
+ }
+ }
+ }
queryHql.setFirstResult(0);
queryHql.setMaxResults(1);
-
+
List<?> r = queryHql.list();
-
+
List<T> lst = new ArrayList<T>(r.size());
for(Object o:r) {
- lst.add((T)o);
+ lst.add((T)o);
}
return lst;
}
});
-
+
return lst.isEmpty()?null:lst.get(0);
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉锛屽垪琛ㄦ暟鎹负Map
*
@@ -585,13 +589,13 @@
* @return
*/
public List<Map<String,Object>> findListWithMapByHql(final String hql, final Map<String, Object> map) {
- Pager page = new Pager();
- page.setPageNum(1);
- page.setPageSize(Integer.MAX_VALUE);
-
+ Pager page = new Pager();
+ page.setPageNum(1);
+ page.setPageSize(Integer.MAX_VALUE);
+
return findListWithMapByHql(hql,map,page);
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉锛屽垪琛ㄦ暟鎹负Map
*
@@ -601,34 +605,34 @@
*/
@SuppressWarnings("unchecked")
public List<Map<String,Object>> findListWithMapByHql(final String hql, final Map<String, Object> map,final Pager page) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
List<Map<String,Object>> lst = getHibernateTemplate().execute(new HibernateCallback<List<Map<String,Object>>>() {
- public List<Map<String,Object>> doInHibernate(Session session) {
+ public List<Map<String,Object>> doInHibernate(Session session) {
Query query = session.createQuery(hql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- query.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- query.setParameterList(string, (Object[])obj);
- }else{
- query.setParameter(string, obj);
- }
+ if(obj instanceof Collection<?>){
+ query.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ query.setParameterList(string, (Object[])obj);
+ }else{
+ query.setParameter(string, obj);
+ }
}
- }
+ }
query.setFirstResult(page.getPageSize()*(page.getPageNum()-1));
query.setMaxResults(page.getPageSize());
return query.list();
}
});
-
+
return lst;
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炲敮涓�涓�鏉$粨鏋�
*
@@ -639,35 +643,35 @@
*/
@SuppressWarnings({RAW_TYPES })
public <T> T findUniqueByComplexHql(final String hql, final Map<String, Object> map, Class<T> cls) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
List<T> lst = this.getHibernateTemplate().execute(new HibernateCallback<List<T>>() {
public List doInHibernate(Session session) {
Query query = session.createQuery(hql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- query.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- query.setParameterList(string, (Object[])obj);
- }else{
- query.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ query.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ query.setParameterList(string, (Object[])obj);
+ }else{
+ query.setParameter(string, obj);
+ }
+ }
+ }
query.setFirstResult(0);
query.setMaxResults(1);
return query.list();
}
});
-
+
return lst.isEmpty()?null:cls.cast(lst.get(0));
}
-
+
/**
* 鏍规嵁Sql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -677,13 +681,13 @@
* @return
*/
public <T> List<T> findByComplexSql(final String sql, final Map<String, Object> map, Class<T> cls) {
- Pager page = new Pager();
- page.setPageSize(Integer.MAX_VALUE);
- page.setPageNum(1);
+ Pager page = new Pager();
+ page.setPageSize(Integer.MAX_VALUE);
+ page.setPageNum(1);
return findByComplexSql(sql, page, map, cls);
}
-
-
+
+
/**
* 鏍规嵁Sql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -694,32 +698,32 @@
*/
@SuppressWarnings({RAW_TYPES, "unchecked" })
public List<Object[]> findRawByComplexSql(final String sql, final Map<String, Object> map) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
return (List<Object[]>)this.getHibernateTemplate().execute(new HibernateCallback<List>() {
public List doInHibernate(Session session) {
SQLQuery query = session.createSQLQuery(sql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- query.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- query.setParameterList(string, (Object[])obj);
- }else{
- query.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ query.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ query.setParameterList(string, (Object[])obj);
+ }else{
+ query.setParameter(string, obj);
+ }
+ }
+ }
return query.list();
}
});
-
-
+
+
}
-
+
/**
* 鏍规嵁hql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -730,31 +734,31 @@
*/
@SuppressWarnings({RAW_TYPES })
public <T> List<T> findByComplexHql(final String hql,final Pager page, final Map<String, Object> map, Class<T> cls) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
List lst = this.getHibernateTemplate().execute(new HibernateCallback<List>() {
public List doInHibernate(Session session) {
Query queryHql = session.createQuery(hql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- queryHql.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- queryHql.setParameterList(string, (Object[])obj);
- }else{
- queryHql.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ queryHql.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ queryHql.setParameterList(string, (Object[])obj);
+ }else{
+ queryHql.setParameter(string, obj);
+ }
+ }
+ }
queryHql.setFirstResult(page.getPageSize()*(page.getPageNum()-1));
queryHql.setMaxResults(page.getPageSize());
return queryHql.list();
}
});
-
+
// 缁勮缁撴灉
List<T> result = new ArrayList<T>();
for (Object obj : lst) {
@@ -762,7 +766,7 @@
}
return result;
}
-
+
/**
* 鏍规嵁Sql鏌ヨ,骞惰繑鍥炴墽琛岀被鍨嬬殑鍒楄〃缁撴灉
*
@@ -773,31 +777,31 @@
*/
@SuppressWarnings({RAW_TYPES })
public <T> List<T> findByComplexSql(final String sql,final Pager page, final Map<String, Object> map, Class<T> cls) {
- // 鏌ヨ缁撴灉
+ // 鏌ヨ缁撴灉
List lst = this.getHibernateTemplate().execute(new HibernateCallback<List>() {
public List doInHibernate(Session session) {
- SQLQuery querySql = session.createSQLQuery(sql);
- if (map != null) {
- Set<String> keySet = map.keySet();
- for (String string : keySet) {
- Object obj = map.get(string);
+ SQLQuery querySql = session.createSQLQuery(sql);
+ if (map != null) {
+ Set<String> keySet = map.keySet();
+ for (String string : keySet) {
+ Object obj = map.get(string);
//杩欓噷鑰冭檻浼犲叆鐨勫弬鏁版槸浠�涔堢被鍨嬶紝涓嶅悓绫诲瀷浣跨敤鐨勬柟娉曚笉鍚�
- if(obj instanceof Collection<?>){
- querySql.setParameterList(string, (Collection<?>)obj);
- }else if(obj instanceof Object[]){
- querySql.setParameterList(string, (Object[])obj);
- }else{
- querySql.setParameter(string, obj);
- }
- }
- }
+ if(obj instanceof Collection<?>){
+ querySql.setParameterList(string, (Collection<?>)obj);
+ }else if(obj instanceof Object[]){
+ querySql.setParameterList(string, (Object[])obj);
+ }else{
+ querySql.setParameter(string, obj);
+ }
+ }
+ }
querySql.setFirstResult(page.getPageSize()*(page.getPageNum()-1));
querySql.setMaxResults(page.getPageSize());
return querySql.list();
}
});
-
+
// 缁勮缁撴灉
List<T> result = new ArrayList<T>();
for (Object obj : lst) {
@@ -805,6 +809,6 @@
}
return result;
}
-
-
+
+
}
--
Gitblit v1.8.0