이것이 최선의 방법인지 또는 피해야하는지에 대해 더 궁금합니다. 각각 다른 유형의 객체, 위젯 및 foo로 작동하는 두 개의 EJBS가 있다고 가정 해보십시오. 위젯을 관리하는 EJB는 일부 처리를 수행하는 데 필요한 모음을 가져와야합니다. 이 기능은 이미 FooManager bean에서 작성됩니다.EJB가 다른 EJB 메소드를 호출하는 중
FidManager 메서드가 이미 생성되어있는 반면 WidgetManager의 메서드가 만들어지고 있습니다.
다음은 내가 말하는 의미의 예입니다. 이것은 간단한 예입니다.
@Stateless
public class FooManager implements FooManagerLocal, FooManagerRemote
{
public List<Foo> getAllFoosForAWidget(widgetId)
{
//runs queries and builds foo list
}
public Boolean isWidgetCloseable(widgetId)
{
//a widget is closeable if all foos for that widget are set to "done"
List<Foo> foos = getallFoosForAWidget(widgetId);
boolean isCloseable = false;
//process foos and update isCloseable respectively
return new Boolean(boolean);
}
}
@Stateless
public class WidgetManager implements WidgetManagerLocal, WidgetManagerRemote
{
public void closeWidgetIfFoosAreDone(widgetId) //needs to do stuff with foos
{
//generate the widget based on widgetId
Widget widget = find(Widget.class, widgetId)
//is this appropriate?
//beans are gathered through our own beanclient
FooManager fooManager = BeanClient.getBean(FooManager.class);
if(fooManager.isWidgetCloseable(widgetId)
{
widget.setStatus(Close);
save(widget); //save widget back to database
}
}
}
제 질문은 WidgetManager bean이 FooManager bean의 이미 생성 된 메소드를 호출해야합니까? 클라이언트는 닫을 수있는 위젯을 확인하고 그 ID 목록을 WidgetManager에 보내야합니까?
EJB가 서로 다른 메소드를 호출하는 것에 대해 걱정할 필요가 없도록 후자의 상황에 기대고 있습니다. 클라이언트는 이들을 활용할 수 있으며 ID 목록을 보내면됩니다.
http://www.adam-bien.com/roller/abien/entry/why_service_isn_t_a 솔직히 설명은 완전하고 추상적의 종류가 아닙니다. –
나는 동의한다. 어딘가에가는 것처럼 시작하고, 그 다음에 시작하지 않습니다. – b3bop