【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-TxControllerBean.java,希望本篇文章对您学习有所帮助。
/*
* Copyright (c) 2006 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) 2006 Sun Microsystems, Inc. Tous droits reserves.
*
* Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
* commercial. Les utilisateurs gouvernementaux sont sou
mis 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.tx;
import java.util.*;
import java.math.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.RemoteException;
import com.sun.ebank.ejb.account.LocalAccountHome;
import com.sun.ebank.ejb.account.LocalAccount;
import com.sun.ebank.ejb.util.LocalNextId;
import com.sun.ebank.ejb.util.LocalNextIdHome;
import com.sun.ebank.ejb.exception.*;
import com.sun.ebank.util.Debug;
import com.sun.ebank.util.TxDetails;
import com.sun.ebank.util.EJBGetter;
import com.sun.ebank.util.CodedNames;
import com.sun.ebank.util.DomainUtil;
public class TxControllerBean implements SessionBean {
private LocalTxHome txHome;
private LocalAccountHome accountHome;
private LocalNextIdHome nextIdHome;
private SessionContext context;
private BigDecimal bigZero = new BigDecimal("0.00");
public TxControllerBean() {
}
public ArrayList getTxsOfAccount(java.util.Date startDate,
java.util.Date endDate, String accountId)
throws InvalidParameterException {
Debug.print("TxControllerBean getTxsOfAccount");
Collection txIds;
ArrayList txList = new ArrayList();
if (startDate == null) {
throw new InvalidParameterException("null startDate");
}
if (endDate == null) {
throw new InvalidParameterException("null endDate");
}
if (accountId == null) {
throw new InvalidParameterException("null accountId");
}
try {
txIds = txHome.findByAccountId(startDate, endDate, accountId);
} catch (Exception ex) {
return txList;
}
return copyTxsToDetails(txIds);
} // getTxsOfAccount
public TxDetails getDetails(String txId)
throws TxNotFoundException, InvalidParameterException {
Debug.print("TxControllerBean getDetails");
TxDetails details;
if (txId == null) {
throw new InvalidParameterException("null txId");
}
try {
LocalTx tx = txHome.findByPrimaryKey(txId);
details = new TxDetails(tx.getTxId(), tx.getTimeStamp(),
tx.getAmount(), tx.getBalance(), tx.getDescription());
} catch (Exception ex) {
throw new TxNotFoundException(txId);
}
return details;
} // getDetails
public void withdraw(BigDecimal amount, String description, String accountId)
throws InvalidParameterException, AccountNotFoundException,
IllegalAccountTypeException, InsufficientFundsException {
Debug.print("TxControllerBean withdraw");
LocalAccount account = checkAccountArgs(amount, description, accountId);
String type = account.getType();
if (DomainUtil.isCreditAccount(type)) {
context.setRollbackOnly();
throw new IllegalAccountTypeException(type);
}
BigDecimal newBalance = account.getBalance()
.subtract(amount);
if (newBalance.compareTo(bigZero) == -1) {
context.setRollbackOnly();
throw new InsufficientFundsException();
}
executeTx(amount.negate(), description, newBalance, account);
}
public void deposit(BigDecimal amount, String description, String accountId)
throws InvalidParameterException, AccountNotFoundException,
IllegalAccountTypeException {
Debug.print("TxControllerBean deposit");
LocalAccount account = checkAccountArgs(amount, description, accountId);
String type = account.getType();
if (DomainUtil.i