📄 financialaccountsessionfacadebean.java
字号:
package com.fund.client;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import com.fund.ServiceLocator;
import com.fund.ServiceLocatorException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collection;
import javax.ejb.EJBException;
/**
*
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FinancialAccountSessionFacadeBean implements SessionBean {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* sessionContext
*/
SessionContext sessionContext;
/**
* financialAccountHome
*/
private FinancialAccountHome financialAccountHome;
/**
* ejbCreate
* @throws CreateException e
*/
public void ejbCreate() throws CreateException {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
*
* @param sessionContext SessionContext
*/
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
try {
findFinancialAccountHome();
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
/**
*
* @param financialAccountDto FinancialAccountDto
* @throws EJBException e
*/
public void createFinancialAccount(FinancialAccountDto financialAccountDto)
throws
EJBException {
if (financialAccountDto == null) {
return;
}
try {
FinancialAccount financialAccount = financialAccountHome.create(
financialAccountDto.getAccountNo());
setFinancialAccountFromFinancialAccountDto(financialAccount,
financialAccountDto);
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
/**
*
* @param accountNo Integer
* @throws EJBException e
*/
public void removeFinancialAccount(Integer accountNo) throws EJBException {
try {
financialAccountHome.remove(accountNo);
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
/**
*
* @param financialAccountDto FinancialAccountDto
* @throws EJBException e
*/
public void removeFinancialAccount(FinancialAccountDto financialAccountDto)
throws
EJBException {
if (financialAccountDto != null) {
Integer accountNo = financialAccountDto.getAccountNo();
removeFinancialAccount(accountNo);
}
}
/**
*
* @param financialAccountDto FinancialAccountDto
* @throws EJBException e
*/
public void updateFinancialAccount(FinancialAccountDto financialAccountDto)
throws
EJBException {
if (financialAccountDto != null) {
Integer accountNo = financialAccountDto.getAccountNo();
try {
FinancialAccount financialAccount = financialAccountHome.
findByPrimaryKey(accountNo);
setFinancialAccountFromFinancialAccountDto(financialAccount,
financialAccountDto);
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
}
/**
*
* @param financialAccountDtos FinancialAccountDto[]
* @throws EJBException e
*/
public void updateFinancialAccounts(FinancialAccountDto[]
financialAccountDtos) throws
EJBException {
if (financialAccountDtos != null) {
for (int i = 0; i < financialAccountDtos.length; i++) {
updateFinancialAccount(financialAccountDtos[i]);
}
}
}
/**
*
* @param accountNo Integer
* @return FinancialAccountDto
* @throws EJBException e
*/
public FinancialAccountDto financialAccountFindByPrimaryKey(Integer
accountNo) throws EJBException {
try {
return assembleFinancialAccountDto(financialAccountHome.
findByPrimaryKey(accountNo));
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
/**
*
* @param clientNo Integer
* @return FinancialAccountDto
* @throws EJBException e
*/
public FinancialAccountDto financialAccountFindByClientNo(Integer clientNo)
throws
EJBException {
try {
return assembleFinancialAccountDto(financialAccountHome.
findByClientNo(clientNo));
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
/**
*
* @param financialAccount FinancialAccount
* @param financialAccountDto FinancialAccountDto
*/
private void setFinancialAccountFromFinancialAccountDto(FinancialAccount
financialAccount, FinancialAccountDto financialAccountDto) {
financialAccount.setClientNo(financialAccountDto.getClientNo());
financialAccount.setFinancingAmount(financialAccountDto.
getFinancingAmount());
financialAccount.setCreatedDate(financialAccountDto.getCreatedDate());
financialAccount.setStatus(financialAccountDto.getStatus());
financialAccount.setPassword(financialAccountDto.getPassword());
}
/**
*
* @throws EJBException e
*/
private void findFinancialAccountHome() throws EJBException {
String entityName = "java:comp/env/ejb/financialAccount";
if (financialAccountHome == null) {
try {
ServiceLocator locator = ServiceLocator.getInstance();
financialAccountHome = (FinancialAccountHome) locator.
getEjbLocalHome(entityName);
} catch (ServiceLocatorException e) {
throw new EJBException(e.getMessage());
}
}
}
/**
*
* @param financialAccount FinancialAccount
* @return FinancialAccountDto
*/
private FinancialAccountDto assembleFinancialAccountDto(FinancialAccount
financialAccount) {
return FinancialAccountDtoAssembler.createDto(financialAccount);
}
/**
*
* @param financialAccounts Collection
* @return FinancialAccountDto[]
*/
private FinancialAccountDto[] assembleFinancialAccountDtos(Collection
financialAccounts) {
List list = new ArrayList();
if (financialAccounts != null) {
Iterator iterator = financialAccounts.iterator();
while (iterator.hasNext()) {
FinancialAccount financialAccount = (FinancialAccount) iterator.
next();
list.add(assembleFinancialAccountDto(financialAccount));
}
}
FinancialAccountDto[] returnArray
= new FinancialAccountDto[list.size()];
return (FinancialAccountDto[]) list.toArray(returnArray);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -