📄 notedaohibernate.java
字号:
package com.relationinfo.dao.hibernate;import java.util.List;import com.relationinfo.model.Note;import com.relationinfo.dao.NoteDAO;import org.hibernate.HibernateException;import org.hibernate.Session;import org.hibernate.criterion.Example;import org.hibernate.criterion.MatchMode;import org.springframework.orm.ObjectRetrievalFailureException;import org.springframework.orm.hibernate3.HibernateCallback;public class NoteDAOHibernate extends BaseDAOHibernate implements NoteDAO { /** * @see com.relationinfo.dao.NoteDAO#getNotes(com.relationinfo.model.Note) */ public List getNotes(final Note note) { if (note == null) { return getHibernateTemplate().find("from Note"); } else { // filter on properties set in the note HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Example ex = Example.create(note).ignoreCase().enableLike(MatchMode.ANYWHERE); return session.createCriteria(Note.class).add(ex).list(); } }; return (List) getHibernateTemplate().execute(callback); } } /** * @see com.relationinfo.dao.NoteDAO#getNote(String notecode) */ public Note getNote(final String notecode) { Note note = (Note) getHibernateTemplate().get(Note.class, notecode); if (note == null) { log.warn("uh oh, note with notecode '" + notecode + "' not found..."); throw new ObjectRetrievalFailureException(Note.class, notecode); } return note; } /** * @see com.relationinfo.dao.NoteDAO#saveNote(Note note) */ public void saveNote(final Note note) { getHibernateTemplate().saveOrUpdate(note); } /** * @see com.relationinfo.dao.NoteDAO#removeNote(String notecode) */ public void removeNote(final String notecode) { getHibernateTemplate().delete(getNote(notecode)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -