当我使用带有 ServiceLocator 和 Locator 构造的 RequestFactory 请求实体列表时,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();
}