📄 customsessionfacadebean.java~2~
字号:
package loginejb;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import javax.ejb.*;
import java.lang.Object;
import javax.ejb.FinderException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collection;
public class CustomSessionFacadeBean
implements SessionBean {
SessionContext sessionContext;
private CustomHome customHome;
public void ejbCreate() throws CreateException {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
try {
findCustomHome();
}
catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
public void createCustom(CustomDTO customDTO) throws EJBException {
if (customDTO == null) {
return;
}
try {
Custom custom = customHome.create();
setCustomFromCustomDTO(custom, customDTO);
}
catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
public void removeCustom() throws EJBException {
Object object = new Object();
try {
customHome.remove(object);
}
catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
public void removeCustom(CustomDTO customDTO) throws EJBException {
if (customDTO != null) {
removeCustom();
}
}
public void updateCustom(CustomDTO customDTO) throws EJBException {
if (customDTO != null) {
Object object = new Object();
try {
Custom custom = customHome.findByPrimaryKey(object);
setCustomFromCustomDTO(custom, customDTO);
}
catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
}
public void updateCustoms(CustomDTO[] customDtos) throws EJBException {
if (customDtos != null) {
for (int i = 0; i < customDtos.length; i++) {
updateCustom(customDtos[i]);
}
}
}
public CustomDTO customFindByPrimaryKey() throws EJBException {
try {
Object object = new Object();
return assembleCustomDto(customHome.findByPrimaryKey(object));
}
catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
private void setCustomFromCustomDTO(Custom custom, CustomDTO customDTO) {
custom.setId(customDTO.getId());
}
private void findCustomHome() throws EJBException {
final String ENTITY_NAME = "java:comp/env/ejb/custom";
if (customHome == null) {
try {
ServiceLocator locator = ServiceLocator.getInstance();
customHome = (CustomHome) locator.getEjbLocalHome(ENTITY_NAME);
}
catch (ServiceLocatorException e) {
throw new EJBException(e.getMessage());
}
}
}
private CustomDTO assembleCustomDto(Custom custom) {
return CustomDtoAssembler.createDto(custom);
}
private CustomDTO[] assembleCustomDtos(Collection customs) {
List list = new ArrayList();
if (customs != null) {
Iterator iterator = customs.iterator();
while (iterator.hasNext()) {
Custom custom = (Custom) iterator.next();
list.add(assembleCustomDto(custom));
}
}
CustomDTO[] returnArray = new CustomDTO[list.size()];
return (CustomDTO[]) list.toArray(returnArray);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -