GWT / RequestFactory:检索给定的实体列表时,执行 n +1 SQL 调用
当我使用 RequestFactory 请求实体列表时ServiceLocator和Locator构造,GWT执行n+1个SQL调用。
//HcpcsDAOBean
@Singleton
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class HcpcsDAOBean {
@Inject
@DatasourceAnnotation
EntityManager em;
....
public Hcpcs find(Long id) {
return em.find(Hcpcs.class, id);
}
}
//BeanLocator
public class BeanLocator implements ServiceLocator {
@Override
public Object getInstance(Class<?> clazz) {
return lookupBean(clazz);
}
@SuppressWarnings({"unchecked", "CallToThreadDumpStack"})
public static <T> T lookupBean(Class<T> clazz) {
try {
return (T) InitialContext.doLookup("java:module/" + clazz.getSimpleName());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
//RequestFactory and RequestContext
public interface AppRequestFactory extends RequestFactory{
@Service(value=HcpcsDAOBean.class, locator=BeanLocator.class)
interface HcpcsServiceRequest extends RequestContext{
Request<Void> persist(HcpcsProxy hcpcsProxy);
Request<Void> remove(HcpcsProxy hcpcsProxy);
Request<List<HcpcsProxy>> findEntries(int firstResult, int maxResult );
Request<List<HcpcsProxy>> findAll();
}
HcpcsServiceRequest hcpcsServiceRequest();
}
Possible Duplicate:
requestfactory and findEntity method in GWT
When I request a list of entities using RequestFactory with ServiceLocator and Locator constructs, GWT executes n+1 SQL calls.
//HcpcsDAOBean
@Singleton
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class HcpcsDAOBean {
@Inject
@DatasourceAnnotation
EntityManager em;
....
public Hcpcs find(Long id) {
return em.find(Hcpcs.class, id);
}
}
//BeanLocator
public class BeanLocator implements ServiceLocator {
@Override
public Object getInstance(Class<?> clazz) {
return lookupBean(clazz);
}
@SuppressWarnings({"unchecked", "CallToThreadDumpStack"})
public static <T> T lookupBean(Class<T> clazz) {
try {
return (T) InitialContext.doLookup("java:module/" + clazz.getSimpleName());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
//RequestFactory and RequestContext
public interface AppRequestFactory extends RequestFactory{
@Service(value=HcpcsDAOBean.class, locator=BeanLocator.class)
interface HcpcsServiceRequest extends RequestContext{
Request<Void> persist(HcpcsProxy hcpcsProxy);
Request<Void> remove(HcpcsProxy hcpcsProxy);
Request<List<HcpcsProxy>> findEntries(int firstResult, int maxResult );
Request<List<HcpcsProxy>> findAll();
}
HcpcsServiceRequest hcpcsServiceRequest();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与这里是同一问题:GWT 中的 requestfactory 和 findEntity 方法 。
尽管如此,这也适用于不使用定位器或服务定位器的构造。
我有同样的问题并理解,RequestFactory 需要检查实体是否存在,但这对于像 findAll() 这样的调用来说确实是不必要的,或者我错过了什么?
有没有办法禁用某些服务方法的 isLive 检查?例如,我知道我可以覆盖定位器中的 isLive 方法并返回 true,但这将禁用对每个服务调用的检查,并且我不想错过此功能以进行持久或删除操作。
I think this is the same question as here: requestfactory and findEntity method in GWT.
Altough, this also applies to constructs where no Locator or ServiceLocators are used.
I am having the same question and understand, that RequestFactory needs to check if an entity is live or not, but this is really unessesary for a call like findAll(), or am i missing something?
Is there a way to disable the isLive check for some service methods? I know i can override the isLive method in the Locator and return true for example, but this would disable the check for every service call, and i do not want to miss this feature for Persist or delete operations.