📄 notehibernatedao.java
字号:
package com.opensource.blog.dao.hibernate;
import org.springframework.orm.hibernate3.support.*;
import org.springframework.orm.hibernate3.*;
import org.hibernate.*;
import com.opensource.blog.dao.NoteDAO;
import com.opensource.blog.model.Note;
import java.util.List;
import java.sql.SQLException;
public class NoteHibernateDAO
extends HibernateDaoSupport implements NoteDAO {
private static final String LOAD_BY_ID_BLOGID = "from Note where id = ? and blogid = ?";
private static final String GET_COUNT_BY_ARTID = "select count(*) from Note where artid = ?";
private static final String LOADS_BY_ARTID = "from Note where artid = ? order by id desc";
private static final String GET_COUNT_BY_BLOGID = "select count(*) from Note where blogid = ?";
private static final String LOADS_BY_BLOGID = "from Note where blogid = ? order by id desc";
public NoteHibernateDAO() {
super();
}
/**
*
* @param note Note
* @return Note
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public Note saveNote(Note note) {
this.getHibernateTemplate().saveOrUpdate(note);
return note;
}
/**
*
* @param id long
* @param blogID long
* @return Note
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public Note findNoteByID_BlogID(long id, long blogID) {
Object[] o = {
new Long(id), new Long(blogID)};
List l = this.getHibernateTemplate().find(LOAD_BY_ID_BLOGID, o);
if (l == null || l.isEmpty()) {
return null;
}
else {
return (Note) l.get(0);
}
}
/**
*
* @param artID long
* @return int
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public int getNoteCountByArtID(long artID) {
List l = this.getHibernateTemplate().find(GET_COUNT_BY_ARTID, new Long(artID));
if (l == null || l.isEmpty()) {
return 0;
}
else {
return ( (Integer) l.get(0)).intValue();
}
}
/**
*
* @param artID long
* @return List
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public List findNotesByArtID(long artID) {
return this.getHibernateTemplate().find(LOADS_BY_ARTID, new Long(artID));
}
/**
*
* @param blogID long
* @return int
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public int getNoteCountByBlogID(long blogID) {
List l = this.getHibernateTemplate().find(GET_COUNT_BY_BLOGID, new Long(blogID));
if (l == null || l.isEmpty()) {
return 0;
}
else {
return ( (Integer) l.get(0)).intValue();
}
}
/**
*
* @param blogID long
* @param firstResult int
* @param maxResults int
* @return List
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public List getNotesByBlogID(final long blogID, final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(LOADS_BY_BLOGID);
query.setLong(0, blogID);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.list();
}
});
}
/**
*
* @param note Note
* @todo Implement this com.opensource.blog.dao.NoteDAO method
*/
public void removeNote(Note note) {
this.getHibernateTemplate().delete(note);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -