private AccountDataBean getAccountDataFromResultSet(ResultSet rs) throws Exception { AccountDataBean accountData = null; if (!rs.next()) Log.error("TradeDirect:getAccountDataFromResultSet -- cannot find account data"); else accountData = new AccountDataBean(new Integer(rs.getInt("accountID")), rs.getInt("loginCount"), rs .getInt("logoutCount"), rs.getTimestamp("lastLogin"), rs.getTimestamp("creationDate"), rs .getBigDecimal("balance"), rs.getBigDecimal("openBalance"), rs.getString("profile_userID")); return accountData; }
public String toHTML() { return "<BR>Account Data for account: <B>" + getAccountID() + "</B>" + "<LI> loginCount:" + getLoginCount() + "</LI>" + "<LI> logoutCount:" + getLogoutCount() + "</LI>" + "<LI> lastLogin:" + getLastLogin() + "</LI>" + "<LI> creationDate:" + getCreationDate() + "</LI>" + "<LI> balance:" + getBalance() + "</LI>" + "<LI> openBalance:" + getOpenBalance() + "</LI>" + "<LI> profileID:" + getProfileID() + "</LI>" ; }
public void login(String password) { AccountProfileDataBean profile = getProfile(); if ((profile == null) || (profile.getPassword().equals(password) == false)) { String error = "AccountBean:Login failure for account: " + getAccountID() + ((profile == null) ? "null AccountProfile" : "\n\tIncorrect password-->" + profile.getUserID() + ":" + profile.getPassword()); throw new RuntimeException(error); } setLastLogin(new Timestamp(System.currentTimeMillis())); setLoginCount(getLoginCount() + 1); }
public void logout() { setLogoutCount(getLogoutCount() + 1); }
public AccountDataBean(int loginCount, int logoutCount, Date lastLogin, Date creationDate, BigDecimal balance, BigDecimal openBalance, String profileID) { setLoginCount(loginCount); setLogoutCount(logoutCount); setLastLogin(lastLogin); setCreationDate(creationDate); setBalance(balance); setOpenBalance(openBalance); setProfileID(profileID); }
BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); account.setBalance(balance.subtract(total));
private void creditAccountBalance(Connection conn, AccountDataBean accountData, BigDecimal credit) throws Exception { PreparedStatement stmt = getStatement(conn, creditAccountBalanceSQL); stmt.setBigDecimal(1, credit); stmt.setInt(2, accountData.getAccountID().intValue()); int count = stmt.executeUpdate(); stmt.close(); }
public AccountDataBean getAccountData(String userID) { if (Log.doTrace()) Log.trace("TradeJPADirect:getAccountData", userID); EntityManager entityManager = emf.createEntityManager(); AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); /* * Inflate the lazy data memebers */ AccountDataBean account = profile.getAccount(); account.getProfile(); // Added to populate transient field for account account.setProfileID(profile.getUserID()); entityManager.close(); entityManager = null; return account; }
public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditcard, BigDecimal openBalance) { AccountDataBean account = null; AccountProfileDataBean profile = null; if (Log.doTrace()) Log.trace("TradeSLSBBean:register", userID, password, fullname, address, email, creditcard, openBalance); // Check to see if a profile with the desired userID already exists profile = entityManager.find(AccountProfileDataBean.class, userID); if (profile != null) { Log.error("Failed to register new Account - AccountProfile with userID(" + userID + ") already exists"); return null; } else { profile = new AccountProfileDataBean(userID, password, fullname, address, email, creditcard); account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID); profile.setAccount(account); account.setProfile(profile); entityManager.persist(profile); entityManager.persist(account); } return account; }
double quantity = order.getQuantity(); String userID = account.getProfile().getUserID();
BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); account.setBalance(balance.subtract(total));
public AccountDataBean(int loginCount, int logoutCount, Date lastLogin, Date creationDate, BigDecimal balance, BigDecimal openBalance, String profileID) { setLoginCount(loginCount); setLogoutCount(logoutCount); setLastLogin(lastLogin); setCreationDate(creationDate); setBalance(balance); setOpenBalance(openBalance); setProfileID(profileID); }
private void creditAccountBalance(Connection conn, AccountDataBean accountData, BigDecimal credit) throws Exception { PreparedStatement stmt = getStatement(conn, creditAccountBalanceSQL); stmt.setBigDecimal(1, credit); stmt.setInt(2, accountData.getAccountID().intValue()); int count = stmt.executeUpdate(); stmt.close(); }
public AccountDataBean getAccountData(String userID) { if (Log.doTrace()) Log.trace("TradeSLSBBean:getAccountData", userID); AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); /* * Inflate the lazy data memebers */ AccountDataBean account = profile.getAccount(); account.getProfile(); // Added to populate transient field for account account.setProfileID(profile.getUserID()); return account; }
public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditcard, BigDecimal openBalance) { AccountDataBean account = null; AccountProfileDataBean profile = null; if (Log.doTrace()) Log.trace("TradeSLSBBean:register", userID, password, fullname, address, email, creditcard, openBalance); // Check to see if a profile with the desired userID already exists profile = entityManager.find(AccountProfileDataBean.class, userID); if (profile != null) { Log.error("Failed to register new Account - AccountProfile with userID(" + userID + ") already exists"); return null; } else { profile = new AccountProfileDataBean(userID, password, fullname, address, email, creditcard); account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID); profile.setAccount(account); account.setProfile(profile); entityManager.persist(profile); entityManager.persist(account); } return account; }
double quantity = order.getQuantity(); String userID = account.getProfile().getUserID();
public void logout() { setLogoutCount(getLogoutCount() + 1); }
public String toString() { return "\n\tAccount Data for account: " + getAccountID() + "\n\t\t loginCount:" + getLoginCount() + "\n\t\t logoutCount:" + getLogoutCount() + "\n\t\t lastLogin:" + getLastLogin() + "\n\t\t creationDate:" + getCreationDate() + "\n\t\t balance:" + getBalance() + "\n\t\t openBalance:" + getOpenBalance() + "\n\t\t profileID:" + getProfileID() ; }
public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode) { OrderDataBean order; BigDecimal total; try { if (Log.doTrace()) Log.trace("TradeSLSBBean:buy", userID, symbol, quantity, orderProcessingMode); AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); AccountDataBean account = profile.getAccount(); QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol); HoldingDataBean holding = null; // The holding will be created by this buy order order = createOrder(account, quote, holding, "buy", quantity); // UPDATE - account should be credited during completeOrder BigDecimal price = quote.getPrice(); BigDecimal orderFee = order.getOrderFee(); BigDecimal balance = account.getBalance(); total = (new BigDecimal(quantity).multiply(price)).add(orderFee); account.setBalance(balance.subtract(total)); if (orderProcessingMode == TradeConfig.SYNCH) completeOrder(order.getOrderID(), false); else if (orderProcessingMode == TradeConfig.ASYNCH_2PHASE) queueOrder(order.getOrderID(), true); } catch (Exception e) { Log.error("TradeSLSBBean:buy(" + userID + "," + symbol + "," + quantity + ") --> failed", e); /* On exception - cancel the order */ // TODO figure out how to do this with JPA // if (order != null) order.cancel(); throw new EJBException(e); } return order; }
public AccountDataBean(Integer accountID, int loginCount, int logoutCount, Date lastLogin, Date creationDate, BigDecimal balance, BigDecimal openBalance, String profileID) { setAccountID(accountID); setLoginCount(loginCount); setLogoutCount(logoutCount); setLastLogin(lastLogin); setCreationDate(creationDate); setBalance(balance); setOpenBalance(openBalance); setProfileID(profileID); }