?? bulletinhibernatedao.java
字號:
package com.laoer.bbscs.dao.hibernate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.IBulletinDAO;
import com.laoer.bbscs.bean.Bulletin;
import org.springframework.dao.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import net.sf.hibernate.*;
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 BulletinHibernateDAO
extends HibernateDaoSupport implements IBulletinDAO {
private static final Log logger = LogFactory.getLog(BulletinHibernateDAO.class);
private static final String LOAD_ALL =
"from Bulletin bull order by bull.id desc";
private static final String LOAD_COUNT =
"select count(bull.id) from Bulletin bull";
private static final String LOAD_BY_ID =
"from Bulletin bull where bull.id = ?";
public BulletinHibernateDAO() {
super();
}
/**
*
* @param bulletin Bulletin
* @return Bulletin
* @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
*/
public Bulletin saveBulletin(Bulletin bulletin) {
try {
getHibernateTemplate().saveOrUpdate(bulletin);
return bulletin;
}
catch (DataAccessException ex) {
logger.error(ex);
return null;
}
}
/**
*
* @param id long
* @return Bulletin
* @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
*/
public Bulletin getBulletin(long id) {
return (Bulletin) getHibernateTemplate().get(Bulletin.class, new Long(id));
}
/**
*
* @return int
* @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
*/
public int getBulletinNum() {
try {
List l = this.getHibernateTemplate().find(LOAD_COUNT);
return ( (Integer) l.get(0)).intValue();
}
catch (DataAccessException ex) {
logger.error(ex);
return 0;
}
}
/**
*
* @param pages Pages
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
*/
public List getBulletinList(final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(LOAD_ALL);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
/**
*
* @param id long
* @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
*/
public void removeBulletin(final long id) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
s.delete(LOAD_BY_ID, new Long(id), Hibernate.LONG);
return null;
}
});
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -