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

📄 accountcontrollerbean.java

📁 j2ee tutorial
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        InvalidParameterException {        Debug.print("AccountControllerBean setType");        if (type == null)            throw new InvalidParameterException("null type");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        DomainUtil.checkAccountType(type);        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            account.setType(type);        } catch (RemoteException ex) {             throw new EJBException("setType: " + ex.getMessage());        }     } // setType    public void setDescription(String description, String accountId)        throws AccountNotFoundException,InvalidParameterException {        Debug.print("AccountControllerBean setDescription");        if (description == null)            throw new InvalidParameterException("null description");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);    } // setDescription    public void setBalance(BigDecimal balance, String accountId)        throws AccountNotFoundException, InvalidParameterException {        Debug.print("AccountControllerBean setBalance");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            account.setBalance(balance);        } catch (RemoteException ex) {             throw new EJBException("setBalance: " + ex.getMessage());        }     } // setBalance    public void setCreditLine(BigDecimal creditLine, String accountId)        throws EJBException, AccountNotFoundException,        InvalidParameterException {        Debug.print("AccountControllerBean setCreditLine");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            account.setCreditLine(creditLine);        } catch (RemoteException ex) {             throw new EJBException("setCreditLine: " + ex.getMessage());        }     } // setCreditLine    public void setBeginBalance(BigDecimal beginBalance, String accountId)        throws AccountNotFoundException, InvalidParameterException {        Debug.print("AccountControllerBean setBeginBalance");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            account.setBeginBalance(beginBalance);        } catch (RemoteException ex) {             throw new EJBException("setBeginBalance: " + ex.getMessage());        }     } // setBeginBalance    public void setBeginBalanceTimeStamp(java.util.Date beginBalanceTimeStamp,         String accountId)        throws AccountNotFoundException, InvalidParameterException {        Debug.print("AccountControllerBean setBeginBalanceTimeStamp");        if (beginBalanceTimeStamp == null)            throw new InvalidParameterException("null beginBalanceTimeStamp");        if (accountId == null)            throw new InvalidParameterException("null accountId" );        if (accountExists(accountId) == false)            throw new AccountNotFoundException(accountId);        try {            account.setBeginBalanceTimeStamp(beginBalanceTimeStamp);        } catch (RemoteException ex) {             throw new EJBException("setBeginBalanceTimeStamp: "                  + ex.getMessage());        }     } // setBeginBalanceTimeStamp    // ejb methods    public void ejbCreate() {        Debug.print("AccountControllerBean ejbCreate");        try {            accountHome = EJBGetter.getAccountHome();        } catch (Exception ex) {             throw new EJBException("ejbCreate: " +                 ex.getMessage());        }        account = null;        accountId = null;    } // ejbCreate    public AccountControllerBean() {}    public void ejbRemove() {}    public void ejbActivate() {}    public void ejbPassivate() {}    public void setSessionContext(SessionContext sc) {}    // private methods    private boolean accountExists(String accountId) {        // If a business method has been invoked with        // a different accountId, then find the new        // accountId and update the accountId and account         // variables.  Return false if the account        // cannot be found.        Debug.print("AccountControllerBean accountExists");        if (accountId.equals(this.accountId) == false) {            try {                account = accountHome.findByPrimaryKey(accountId);                this.accountId = accountId;            } catch (Exception ex) {                return false;            }        } // if        return true;    } // accountExists    private boolean customerExists(String customerId) {        Debug.print("AccountControllerBean customerExists");        CustomerHome customerHome;        try {            customerHome = EJBGetter.getCustomerHome();        } catch (Exception ex) {             throw new EJBException("customerExists: " +                 ex.getMessage());        }        try {            customerHome.findByPrimaryKey(customerId);            return true;        } catch (Exception ex) {            return false;        }    } // customerExists/*********************** Database Routines *************************/    private void makeConnection() {           Debug.print("AccountControllerBean makeConnection");        try {            InitialContext ic = new InitialContext();            DataSource ds = (DataSource) ic.lookup(CodedNames.BANK_DATABASE);            con =  ds.getConnection();        } catch (Exception ex) {             throw new EJBException("Unable to connect to database. " +                 ex.getMessage());        }    } // makeConnection       private void releaseConnection() {           Debug.print("AccountControllerBean releaseConnection");        try {            con.close();        } catch (SQLException ex) {             throw new EJBException("releaseConnection: " + ex.getMessage());        }    } // releaseConnection    private void insertXref (String customerId, String accountId)         throws SQLException {           Debug.print("AccountControllerBean insertXref");                 String insertStatement =            "insert into customer_account_xref " +            "values ( ? , ? )";        PreparedStatement prepStmt =             con.prepareStatement(insertStatement);           prepStmt.setString(1, customerId);        prepStmt.setString(2, accountId);        prepStmt.executeUpdate();        prepStmt.close();    }    private void deleteAllAccountInXref (String accountId)        throws SQLException {           Debug.print("AccountControllerBean deleteAllAccountInXref");                 String deleteStatement =            "delete from customer_account_xref " +            "where account_id  = ? ";        PreparedStatement prepStmt =             con.prepareStatement(deleteStatement);           prepStmt.setString(1, accountId);        prepStmt.executeUpdate();        prepStmt.close();    }    private ArrayList getCustomerIds(String accountId)         throws SQLException {           Debug.print("AccountControllerBean getCustomerIds");        String selectStatement =                "select customer_id " +                "from customer_account_xref " +                "where account_id = ? ";        PreparedStatement prepStmt =                 con.prepareStatement(selectStatement);           prepStmt.setString(1, accountId);        ResultSet rs = prepStmt.executeQuery();        ArrayList a = new ArrayList();           while (rs.next()) {            a.add(rs.getString(1));        }           prepStmt.close();        return a;    } // getCustomerIds    private void deleteOneCustomerInXref (String customerId, String accountId)        throws SQLException {           Debug.print("AccountControllerBean deleteOneCustomerInXref");                 String deleteStatement =            "delete from customer_account_xref " +            "where account_id  = ? and customer_id = ? ";        PreparedStatement prepStmt =             con.prepareStatement(deleteStatement);           prepStmt.setString(1, accountId);        prepStmt.setString(2, customerId);        prepStmt.executeUpdate();        prepStmt.close();    }} // AccountControllerBean

⌨️ 快捷键说明

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