📄 accountservicehbnimpl.java
字号:
package com.tarena.ebank.biz;
import org.hibernate.Session;
import com.tarena.ebank.persist.AccountDAO;
import com.tarena.ebank.persist.AccountDAOFactory;
import com.tarena.ebank.persist.DataException;
import com.tarena.ebank.persist.HbnUtil;
public class AccountServiceHbnImpl implements AccountService{
AccountDAO dao=AccountDAOFactory.getDAO();
public void createAccount(Account act) {
Session s=null;
try {
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
dao.insert(act, s);
s.getTransaction().commit();
} catch (DataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
s.getTransaction().rollback();
}
finally{
s.close();
}
}
public void deposite(String actNo, double amount) {
Session s=null;
try{
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
Account a=dao.findAccountByActNo(actNo, s);
a.deposite(amount);
s.getTransaction().commit();
}
catch(Exception e){
e.printStackTrace();
s.getTransaction().rollback();
}finally{
s.close();
}
}
public void getBal(String actNo) {
Session s=null;
try{
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
Account a=dao.findAccountByActNo(actNo, s);
a.getBal();
s.getTransaction().commit();
}
catch(Exception e){
e.printStackTrace();
s.getTransaction().rollback();
}finally{
s.close();
}
}
public void removeAccount(String actNo) {
Session s=null;
try{
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
dao.del(actNo, s);
s.getTransaction().commit();
}
catch(Exception e){
e.printStackTrace();
s.getTransaction().rollback();
}finally{
s.close();
}
}
public void transfer(String from, String to, double amount) {
Session s=null;
try{
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
Account a=dao.findAccountByActNo(from, s);
a.withdraw(amount);
Account b=dao.findAccountByActNo(to, s);
b.deposite(amount);
s.getTransaction().commit();
}
catch(Exception e){
e.printStackTrace();
s.getTransaction().rollback();
}finally{
s.close();
}
}
public void withdraw(String actNo, double amount) {
Session s=null;
try{
s=HbnUtil.getSessionFactory().openSession();
s.beginTransaction();
Account a=dao.findAccountByActNo(actNo, s);
a.withdraw(amount);
s.getTransaction().commit();
}
catch(Exception e){
e.printStackTrace();
s.getTransaction().rollback();
}finally{
s.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -