/* updates the balance */ public AccountEntity updateBalance(String accountID, double tranAmount, char typeOfUpdate) throws Exception { Session session = SessionFactoryUtil.getSessionFactory().openSession(); try { session.beginTransaction(); this.accEntity = (AccountEntity) session.get(AccountEntity.class, accountID); if (accEntity == null) throw new Exception("Invalid Account passed [" + accountID + "]"); } catch (Exception e) { System.out.println("error satya in Account Service1 : " + e.getMessage()); e.printStackTrace(); throw e; } finally { session.close(); } double availableBalance = 0.0; if (typeOfUpdate == 'C') { availableBalance = accEntity.getAcctBalance() + tranAmount; } else if (typeOfUpdate == 'D') { availableBalance = accEntity.getAcctBalance() - tranAmount; if (availableBalance < 0.00) { throw new Exception("Balance is Insufficient"); } } accEntity.setAcctBalance(availableBalance); return accEntity; }
public AccountEntity getAccountDetails(String accountID) throws Exception { Session session = SessionFactoryUtil.getSessionFactory().openSession(); try { session.beginTransaction(); System.out.println("account = " + accountID); this.accEntity = (AccountEntity) session.get(AccountEntity.class, accountID); if (accEntity == null) throw new Exception("Invalid Account passed [" + accountID + "]"); } catch (Exception e) { System.out.println("error satya in Account Service : " + e.getMessage()); e.printStackTrace(); throw e; } finally { session.close(); } return this.accEntity; }