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