📄 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 + -