package org.jboss.test.banknew.ejb;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.test.util.ejb.SessionSupport;
import org.jboss.test.banknew.interfaces.AccountData;
import org.jboss.test.banknew.interfaces.AccountSession;
import org.jboss.test.banknew.interfaces.AccountSessionHome;
import org.jboss.test.banknew.interfaces.Bank;
import org.jboss.test.banknew.interfaces.BankException;
import org.jboss.test.banknew.interfaces.BankHome;
import org.jboss.test.banknew.interfaces.CustomerData;
import org.jboss.test.banknew.interfaces.CustomerSession;
import org.jboss.test.banknew.interfaces.CustomerSessionHome;
public class TellerSessionBean
extends SessionSupport
{
public void deposit( String pToAccountId, float pAmount )
throws BankException
{
try {
getAccountSession().deposit( pToAccountId, pAmount );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
throw new BankException( "Could not deposit " + pAmount +
" to " + pToAccountId, e );
}
}
public void transfer( String pFromAccountId, String pToAccountId, float pAmount )
throws BankException
{
try {
getAccountSession().transfer( pFromAccountId, pToAccountId, pAmount );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
throw new BankException( "Could not transfer " + pAmount +
" from " + pFromAccountId + " to " + pToAccountId, e );
}
}
public void withdraw( String pFromAccountId, float pAmount )
throws BankException
{
try {
getAccountSession().withdraw( pFromAccountId, pAmount );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
throw new BankException( "Could not withdraw " + pAmount +
" from " + pFromAccountId, e );
}
}
public AccountData createAccount( String pCustomerId, int pType, float pInitialDeposit )
throws BankException
{
try {
return getAccountSession().createAccount( pCustomerId, pType, pInitialDeposit );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not create account", e );
}
}
public void removeAccount( String pAccountId )
throws BankException
{
try {
getAccountSession().removeAccount( pAccountId );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public void removeAccount( String pCustomerId, int pType )
throws BankException
{
try {
getAccountSession().removeAccount( pCustomerId, pType );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public Collection getAccounts( String pCustomerId )
throws BankException
{
try {
return getAccountSession().getAccounts( pCustomerId );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public AccountData getAccount( String pCustomerId, int pType )
throws BankException
{
try {
return getAccountSession().getAccount( pCustomerId, pType );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public AccountData getAccount( String pAccountId )
throws BankException
{
try {
return getAccountSession().getAccount( pAccountId );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit )
throws BankException
{
try {
return getCustomerSession().createCustomer( pBankId, pName, pInitialDeposit );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not create account", e );
}
}
public void removeCustomer( String pCustomerId )
throws BankException
{
try {
getCustomerSession().removeCustomer( pCustomerId );
}
catch( Exception e ) {
sessionCtx.setRollbackOnly();
e.printStackTrace();
throw new BankException( "Could not remove account", e );
}
}
public CustomerData getCustomer( String pCustomerId )
throws BankException
{
try {
CustomerSession lSession = getCustomerSession();
return lSession.getCustomer( pCustomerId );
}
catch( Exception e ) {
e.printStackTrace();
throw new BankException( "Could not get customer for " + pCustomerId, e );
}
}
public Collection getCustomers( String pBankId )
throws BankException
{
try {
return getCustomerSession().getCustomers( pBankId );
}
catch( Exception e ) {
e.printStackTrace();
throw new BankException( "Could not get customers for bank " + pBankId, e );
}
}
private AccountSession getAccountSession()
throws RemoteException
{
try {
AccountSessionHome lHome = (AccountSessionHome) new InitialContext().lookup( AccountSessionHome.COMP_NAME );
return lHome.create();
}
catch( NamingException ne ) {
throw new EJBException( ne );
}
catch( CreateException ce ) {
throw new EJBException( ce );
}
}
private CustomerSession getCustomerSession()
throws RemoteException
{
try {
CustomerSessionHome lHome = (CustomerSessionHome) new InitialContext().lookup( CustomerSessionHome.COMP_NAME );
return lHome.create();
}
catch( NamingException ne ) {
throw new EJBException( ne );
}
catch( CreateException ce ) {
throw new EJBException( ce );
}
}
}