📄 messagedaoimpl.java
字号:
package org.bestteam.dao.impl;
import java.util.List;
import org.bestteam.dao.MessageDao;
import org.bestteam.domain.Message;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class MessageDaoImpl extends HibernateDaoSupport implements MessageDao {
/**
*
* @param ApplicationContext 一个ApplicationContext的对象
* @return Message的对象
* 在类加载时通过AplicationContext对象得到Message的对象
*/
public static Message getFromApplicationContext(ApplicationContext ctx) {
return (Message) ctx.getBean("messageDao");
}
public boolean attachClean(Message instance) {
try{
getHibernateTemplate().lock(instance, LockMode.NONE);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
/**
* @param Message 一个Message的对象
* @return boolean
* 对传进来的Message对象保存或更新
* 当该对象为一个托管对象时,该方法会执行更新动作
* 当对象为一个瞬时对象时,该方法会执行保存动作
*/
public boolean attachDirty(Message instance) {
try{
getHibernateTemplate().saveOrUpdate(instance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
public boolean delete(Message persistentInstance) {
try{
getHibernateTemplate().delete(persistentInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
public List findMessageByExample(Message instance) {
List messageList = null;
try{
messageList = getHibernateTemplate().findByExample(instance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return messageList;
}
/**
* @param Integer 信息的ID
* @return Message的对象
* 根据该信息的ID(主键),查找该条信息的内容
* 如果信息ID不存在,则返回空值
*/
public Message findMessageById(Integer id) {
Message message = null;
try{
message = (Message) getHibernateTemplate().get(Message.class, id);
}catch(RuntimeException re) {
re.printStackTrace();
}
return message;
}
/**
* @param String 该类对象的一个属性的名称
* Object 该属性名所对应的对象的值
* @return List列表
* 根据类对象的一个属性的名称和其对应的值,查找该类对象的实例,
* 因为输入的属性不保证能唯一标识该对象,所以返回的对象将是一个由该类对象组成的List列表
*/
public List findMessageByProperty(String propertyName, Object value) {
List messageList = null;
try{
String queryString = "from Message as message where message."
+ propertyName + "=?";
messageList = getHibernateTemplate().find(queryString, value);
}catch(RuntimeException re) {
re.printStackTrace();
}
return messageList;
}
public Message merge(Message detachedInstance) {
Message message = null;
try{
message = (Message) getHibernateTemplate().merge(detachedInstance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return message;
}
/**
* @param Message Message的对象
* @return boolean
* 将传入的Message对象持久化
* 应注意传入的对象的id(在对象中应该保持该属性为Null)不能重复
*/
public boolean save(Message transientInstance) {
try{
getHibernateTemplate().save(transientInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -