?? subscibehibernatedao.java
字號:
package com.laoer.bbscs.dao.hibernate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.ISubscibeDAO;
import com.laoer.bbscs.bean.Subscibe;
import java.util.*;
import org.springframework.dao.*;
import com.laoer.bbscs.sys.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.hibernate.*;
import net.sf.hibernate.type.*;
import org.springframework.orm.hibernate.HibernateCallback;
import java.sql.SQLException;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class SubscibeHibernateDAO
extends HibernateDaoSupport implements ISubscibeDAO {
private static final Log logger = LogFactory.getLog(SubscibeHibernateDAO.class);
public SubscibeHibernateDAO() {
super();
}
/**
* saveSubscibe
*
* @param subs Subscibe
* @return Subscibe
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public Subscibe saveSubscibe(Subscibe subs) {
try {
this.getHibernateTemplate().saveOrUpdate(subs);
return subs;
}
catch (DataAccessException ex) {
logger.error(ex);
return null;
}
}
/**
* getSubscibe
*
* @param id long
* @param userID long
* @param bid long
* @return Subscibe
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public Subscibe getSubscibe(long id, long userID, long bid) {
String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.id = ? and subs.userID = ?";
Object[] o = {
new Long(id), new Long(userID)};
List l = this.getHibernateTemplate().find(q, o);
if (l.size() == 0) {
return null;
}
else {
return (Subscibe) l.get(0);
}
}
/**
* getPostSubscibe
*
* @param postID long
* @param userID long
* @param bid long
* @return Subscibe
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public Subscibe getPostSubscibe(long postID, long userID, long bid) {
String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.postID = ? and subs.userID = ?";
Object[] o = {
new Long(postID), new Long(userID)};
List l = this.getHibernateTemplate().find(q, o);
if (l.size() == 0) {
return null;
}
else {
return (Subscibe) l.get(0);
}
}
/**
* getSubscibeNum
*
* @param userID long
* @param bid long
* @return int
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public int getSubscibeNum(long userID, long bid) {
String q = "select count(subs.id) from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.userID = ?";
try {
List l = this.getHibernateTemplate().find(q, new Long(userID));
return ( (Integer) l.get(0)).intValue();
}
catch (DataAccessException ex) {
logger.error("getSubscibeNum(long userID, long bid):" + ex);
return 0;
}
}
/**
* getSubscibeSendList
*
* @param postID long
* @return List
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public List getSubscibeSendList(long postID, long bid) {
String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.postID = ?";
try {
List l = this.getHibernateTemplate().find(q, new Long(postID));
return l;
}
catch (DataAccessException ex) {
logger.error(ex);
return new ArrayList();
}
}
/**
* getMySubscibeList
*
* @param userID long
* @param bid long
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public List getMySubscibeList(final long userID, final long bid, final int firstResult,
final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.userID = ?";
Query query = s.createQuery(q);
query.setLong(0, userID);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
/**
* removeSubscibe
*
* @param id long
* @param userID long
* @param bid long
* @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
*/
public void removeSubscibe(final long id, final long userID, final long bid) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
" subs where subs.id = ? and subs.userID = ?";
Object[] o = {
new Long(id), new Long(userID)};
Type[] t = {
Hibernate.LONG, Hibernate.LONG};
s.delete(q, o, t);
return null;
}
});
}
public void removeSubscibe(Subscibe subs) {
try {
this.getHibernateTemplate().delete(subs);
}
catch (DataAccessException ex) {
logger.error(ex);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -