GWT RequestFactory,如何实现查询结果DTO
我有一个 GWT-RPC 的大型实现,实际上我正在评估迁移到 RequestFactory 的替代方案。 我这样做的基本原因是因为我对 GWT-RPC 生成的 TypeSerializers 解决方案不太满意,并且为序列化/反序列化生成的代码量很大,在我的情况下,它实际上占整体的 60% 以上JS 结果代码。
因此,一周来我一直在阅读有关 requestFactory 的所有内容,我的第一印象是该 API 仅限于持久实体的管理,但它并没有清楚地显示该 API 将如何支持查询结果代理。
我读到它可以通过使用 ValueProxy 来完成,但我找不到任何好的例子。 我的意思是假设我需要提供上个月前 10 名客户的销售排名。 类似的信息很容易通过 RPC 提供,但对于 RequestFactory 我不确定。 我没有任何要代理的域对象。
通过 GWT-RPC,我将有一个如下的服务方法:
List<ClientRankingDTO> getClientRanking(String clientCode, Date fromDate, Date untilDate);
我的 ClientRankingDTO 将如下所示:
public class ClientRankingDTO implements Serializable {
private String clientCode;
private String clientDescription;
private Integer rankingPosition;
private BigDecimal amount;
// Getters and setters are hidden for simplicity
}
因此,在我的 DAO 层,我将在 SalesStatistics 域模型实体上有一些方法,该方法将计算相应的排名,并生成具有相应排名的 ClientRankingDTO 列表结果。
这可以通过一个简单的查询来完成,例如:
Select top 10 client_code, sum(amount) from sales_stats A
where A.sales_date>=fromDate
and A.sales_date<=untilDate
group by client_code
order by amount desc
使用您选择的 ORM 实现。
我的问题是如何使用RequestFactory实现这种服务?
I have a large implementation of GWT-RPC and actually I'm evaluating the alternative to move to RequestFactory.
The basic reason why I'm doing that is because I'm not very happy with TypeSerializers solution that GWT-RPC produce, and the huge size of code generated for serialize/deserialize that actually represent in my case more than 60% of the whole JS resulting code.
So for a week I have been reading all about requestFactory and my first impression was that the API is confined to the management of persistent Entities, but it doesn't shows clearly how the API will support Query Results Proxys.
I read that it could be done by using ValueProxy but I couldn't found any good example of doing that.
What I mean is asume that I need to provide a Sales Ranking of Top 10 clients for last month.
Information like that is easy to provide via RPC, but with RequestFactory I'm not sure.
I don't have any Domain Object to proxy.
via GWT-RPC I will have a service method like:
List<ClientRankingDTO> getClientRanking(String clientCode, Date fromDate, Date untilDate);
My ClientRankingDTO will looks like:
public class ClientRankingDTO implements Serializable {
private String clientCode;
private String clientDescription;
private Integer rankingPosition;
private BigDecimal amount;
// Getters and setters are hidden for simplicity
}
So at my DAO layer I will have some method over the SalesStatistics Domain Model Entity that will calculate the corresponding ranking and will generates the List of ClientRankingDTO with the corresponding results.
That could be done by a simple query like:
Select top 10 client_code, sum(amount) from sales_stats A
where A.sales_date>=fromDate
and A.sales_date<=untilDate
group by client_code
order by amount desc
implemented with the ORM of your choice.
My question is how can I implement this kind of service with RequestFactory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
ValueProxy
而不是EntityProxy
,您就可以将 RequestFactory 变成“简单 RPC”机制,类似于 GWT-RPC。代理:
然后,在
RequestContext
(客户端)中:以及在服务器端的服务中:
Simply use
ValueProxy
instead ofEntityProxy
, and you turn RequestFactory into a "simple RPC" mechanism, similar to GWT-RPC.Proxy:
Then, in the
RequestContext
(client-side):And in the service on the server-side: