⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountcontrollerbean.java

📁 j2ee API 开发重要工具 免费下载 欢迎使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003 Sun Microsystems, Inc.  All rights reserved.  U.S.  * Government Rights - Commercial software.  Government users are subject  * to the Sun Microsystems, Inc. standard license agreement and  * applicable provisions of the FAR and its supplements.  Use is subject  * to license terms.   *  * This distribution may include materials developed by third parties.  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and  * other countries.   *  * Copyright (c) 2003 Sun Microsystems, Inc. Tous droits reserves. *  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions  * en vigueur de la FAR (Federal Acquisition Regulations) et des  * supplements a celles-ci.  Distribue par des licences qui en  * restreignent l'utilisation. *  * Cette distribution peut comprendre des composants developpes par des  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE  * sont des marques de fabrique ou des marques deposees de Sun  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.ebank.ejb.account;import java.sql.*;import javax.sql.*;import java.util.*;import java.math.*;import javax.ejb.*;import javax.naming.*;import java.rmi.RemoteException;import com.sun.ebank.ejb.customer.CustomerHome;import com.sun.ebank.ejb.customer.Customer;import com.sun.ebank.ejb.exception.MissingPrimaryKeyException;import com.sun.ebank.ejb.exception.AccountNotFoundException;import com.sun.ebank.ejb.exception.CustomerInAccountException;import com.sun.ebank.ejb.exception.IllegalAccountTypeException;import com.sun.ebank.ejb.exception.CustomerRequiredException;import com.sun.ebank.ejb.exception.CustomerNotInAccountException;import com.sun.ebank.ejb.exception.CustomerNotFoundException;import com.sun.ebank.ejb.exception.InvalidParameterException;import com.sun.ebank.util.Debug;import com.sun.ebank.util.DomainUtil;import com.sun.ebank.util.DBHelper;import com.sun.ebank.util.AccountDetails;import com.sun.ebank.util.EJBGetter;import com.sun.ebank.util.CodedNames;public class AccountControllerBean implements SessionBean {    private String accountId;    private AccountHome accountHome;    private Account account;    private Connection con;        // account creation and removal methods    public String createAccount(String customerId, String type,        String description, BigDecimal balance, BigDecimal creditLine,         BigDecimal beginBalance, java.util.Date beginBalanceTimeStamp)           throws IllegalAccountTypeException, CustomerNotFoundException,        InvalidParameterException {        // makes a new account and enters it into db,        // customer for customerId must exist 1st,        // returns accountId        Debug.print("AccountControllerBean createAccount");        if (customerId == null)             throw new InvalidParameterException("null customerId" );        if (type == null)            throw new InvalidParameterException("null type");        if (description == null)            throw new InvalidParameterException("null description");        if (beginBalanceTimeStamp == null)            throw new InvalidParameterException("null beginBalanceTimeStamp");        DomainUtil.checkAccountType(type);        if (customerExists(customerId) == false)            throw new CustomerNotFoundException(customerId);        ArrayList customerIds = new ArrayList();        customerIds.add(customerId);        try {            makeConnection();            accountId = DBHelper.getNextAccountId(con);            account = accountHome.create(accountId, type,                description, balance, creditLine, beginBalance,                beginBalanceTimeStamp, customerIds);               insertXref(customerId, accountId);            releaseConnection();        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("createAccount: " + ex.getMessage());        }        return accountId;    } // createAccount    public void removeAccount(String accountId)         throws AccountNotFoundException, InvalidParameterException {       // removes account from db        Debug.print("AccountControllerBean removeAccount");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            makeConnection();            deleteAllAccountInXref(accountId);            releaseConnection();            account.remove();        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("removeAccount: " + ex.getMessage());        }    } // removeAccount    // customer-account relationship methods    public void addCustomerToAccount(String customerId,         String accountId) throws AccountNotFoundException,         CustomerNotFoundException, CustomerInAccountException,        InvalidParameterException {        // adds another customer to the account        Debug.print("AccountControllerBean addCustomerToAccount");        if (customerId == null)            throw new InvalidParameterException("null customerId" );        if (accountId == null)            throw new InvalidParameterException("null accountId" );        ArrayList customerIds;        CustomerHome customerHome;        if (customerExists(customerId) == false)            throw new CustomerNotFoundException(customerId);        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            makeConnection();            customerIds = getCustomerIds(accountId);        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("addCustomerToAccount: " + ex.getMessage());        }        if (customerIds.contains(customerId)) {            releaseConnection();            throw new CustomerInAccountException            ("customer " + customerId +              " already assigned to account " + accountId);        }         try {            insertXref(customerId, accountId);            releaseConnection();        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("addCustomerToAccount: " + ex.getMessage());        }    } // addCustomerToAccount    public void removeCustomerFromAccount(String customerId,         String accountId) throws AccountNotFoundException,        CustomerRequiredException, CustomerNotInAccountException,        InvalidParameterException {        // removes a customer from this account, but        // the customer is not removed from the db        Debug.print("AccountControllerBean removeCustomerFromAccount");        ArrayList customerIds;        if (customerId == null)            throw new InvalidParameterException("null customerId" );        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            makeConnection();            customerIds = getCustomerIds(accountId);        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("removeCustomerFromAccount: " + ex.getMessage());        }        if (customerIds.size() == 1) {            releaseConnection();            throw new CustomerRequiredException();        }         if (customerIds.contains(customerId) == false) {            releaseConnection();            throw new CustomerNotInAccountException            ("customer " + customerId +              " not assigned to account " + accountId);        }         try {            deleteOneCustomerInXref(customerId, accountId);            releaseConnection();        } catch (Exception ex) {             releaseConnection();             throw new EJBException             ("removeCustomerFromAccount: " + ex.getMessage());        }    } // removeCustomerFromAccount    // getters    public ArrayList getAccountsOfCustomer(String customerId)        throws AccountNotFoundException, InvalidParameterException {        // returns an ArrayList of AccountDetails         // that correspond to the accounts for the specified        // customer        Debug.print("AccountControllerBean getAccountsOfCustomer");        Collection accountIds;        if (customerId == null)             throw new InvalidParameterException("null customerId");        try {            accountIds = accountHome.findByCustomerId(customerId);            if (accountIds.isEmpty())                throw new AccountNotFoundException();        } catch (Exception ex) {             throw new AccountNotFoundException();        }        ArrayList accountList = new ArrayList();        Iterator i = accountIds.iterator();        while (i.hasNext()) {            Account account = (Account)i.next();            AccountDetails accountDetails = account.getDetails();            accountList.add(accountDetails);        }        return accountList;    } //  getAccountsOfCustomer    public AccountDetails getDetails(String accountId)         throws AccountNotFoundException, InvalidParameterException {        // returns the AccountDetails for the specified account        Debug.print("AccountControllerBean getDetails");        AccountDetails result;        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -