?? userdaoimpl.java
字號:
package org.itfuture.www.dao.impl;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.itfuture.www.dao.UserDao;
import org.itfuture.www.po.Account;
import org.itfuture.www.po.Item;
import org.itfuture.www.po.Lineitem;
import org.itfuture.www.po.LineitemId;
import org.itfuture.www.po.Orders;
import org.itfuture.www.po.Orderstatus;
import org.itfuture.www.po.Profile;
import org.itfuture.www.po.Signon;
import org.itfuture.www.service.impl.CarImpl;
import org.itfuture.www.vo.Car;
import www.hibernate.util.method.DaoSupport;
//該類是一個實現類
public class UserDaoImpl extends DaoSupport implements UserDao {
// 用于校驗用戶名,密碼
public Signon checkOut(String name, String password) {
String hql = "from Signon A where A.username=? and A.password=?";
List<Signon> list = this.getHibernateTemplate().query(hql,
new String[] { name, password });
return list.get(0);
}
// 注冊新用戶
public boolean regist(Signon signon, Account account, Profile profile) {
account.setSignon(signon);
profile.setSignon(signon);
signon.setAccount(account);
signon.setProfile(profile);
boolean is = false;
this.getHibernateTemplate().save(signon);
is = true;
return is;
}
// 生成訂單信息數據,存入數據庫
public boolean addOrder(Orders order, Signon signon) {
order.setOrderdate(new Date());
CarImpl ci = new CarImpl();
order.setOrderid(Long.parseLong(this.getValue()));
order.setTotalprice(ci.totalPrice());
String hql = "from Account A where A.userid=?";
List<Account> list = this.getHibernateTemplate().query(hql,
new String[] { signon.getUserid() });
order.setAccount(list.get(0));
Iterator<Car> iter = CarImpl.map.values().iterator();
boolean is = false;
Orderstatus os = new Orderstatus(order, new Date(), "1");
order.setOrderstatus(os);
Set set = new TreeSet();
while (iter.hasNext()) {
Car car = iter.next();
Item item = car.getItem();
LineitemId id = new LineitemId(order, Long.parseLong(this
.getValue()));
Lineitem li = new Lineitem();
li.setId(id);
li.setItem(item);
li.setListprice(item.getListprice());
li.setQuantity((long) car.getQuantity());
order.getLineitems().add(li);
}
this.getHibernateTemplate().save(order);
is = true;
return is;
}
// 得到一個序列號,當作商品編號
public String getValue() {
String hql = "select HIBERNATE_SEQUENCE.Nextval from dual";
return this.getHibernateTemplate().openSession().createSQLQuery(hql)
.list().get(0).toString();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -