我更好奇这是否是最佳实践或应该避免。假设我有两个 EJBS,每个都使用不同类型的对象,一个小部件和一个 foo。管理小部件的 EJB 需要获取 foo 的集合来进行一些处理。此功能已在 FooManager bean 中创建。
WidgetManager 中的方法正在创建,而 FooManager 方法已经创建。
这是我的意思的一个例子。这是一个简短的例子。
@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 列表。