日期:2014-05-17 浏览次数:21298 次
public boolean cancelOrder(Orders orders) throws DataAccessException {
Session session =null;
Transaction tx = null;
Balance bal = null;
try{
session = hibernateTemplate.getSessionFactory().openSession();
tx = session.beginTransaction();
ClientLoginInfo clientLoginInfo = orders.getClientLoginInfo();
String manualName=orders.getClientLoginInfo().getClientUserName();
double money=orders.getSumMoney();
Company c = orders.getClientLoginInfo().getCompany();
Integer companyId = c.getCompanyId();
List list = this.hibernateTemplate.find(
"from Balance as g where g.company.companyId=?", companyId);
if (list.isEmpty()) {
bal = new Balance();
bal.setCompany(c);
bal.setBalanceMoney(money);
session.save(bal);
} else {
bal= (Balance) list.get(0);
bal.setBalanceMoney(bal.getBalanceMoney()
+ money);
session.merge(bal);
}
session.merge(orders);
tx.commit();
return true;
}catch (DataAccessException e) {
tx.rollback();
e.printStackTrace();
throw e;
}finally{
if(session!=null)
session.close();
}
}
public static void main(String[] args) {
synchronized (Test.class) {
//you code here
}
}