📄 itemdao.java
字号:
/*
* Created on 2005-9-4
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.bid.hibernate;
import java.math.BigDecimal;
import java.util.List;
import net.sf.hibernate.*;
import com.bid.domain.Item;
import com.bid.exceptions.InfrastructureException;
/**
* @author Ma Dou
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class ItemDAO {
/**
*
*/
public ItemDAO() {
super();
// TODO Auto-generated constructor stub
HibernateUtil.beginTransaction();
}
public void insert(Item item)throws InfrastructureException{
Session session = HibernateUtil.currentSession();
try {
item = (Item) session.save(item);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}
public void update(Item item)throws InfrastructureException{
Session session = HibernateUtil.currentSession();
try {
session.update(item);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}
public Item getItemById(Long itemId) throws InfrastructureException {
Session session = HibernateUtil.currentSession();
Item item = null;
try {
item = (Item) session.load(Item.class, itemId);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return item;
}
public BigDecimal getMaxBidAmount(Long itemId)
throws InfrastructureException {
Session session = HibernateUtil.currentSession();
BigDecimal maxBidAmount = null;
try {
String query = "select max(b.bidAmount)"
+ " from Bid b where b.item = :item";
Query q = session.createQuery(query);
q.setLong("item", itemId.longValue());
List results = q.list();
if(results!=null && results.size()>0){
maxBidAmount = (BigDecimal) q.uniqueResult();
}else{
maxBidAmount = new BigDecimal(0);
}
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return maxBidAmount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -