GWT RequestFactory,如何实现查询结果DTO

发布于 2024-11-30 21:58:45 字数 1256 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕头说它不想醒 2024-12-07 21:58:45

只需使用 ValueProxy 而不是 EntityProxy,您就可以将 RequestFactory 变成“简单 RPC”机制,类似于 GWT-RPC。

代理:

@ProxyFor(ClientRankingDTO.class)
interface ClientRankingProxy extends ValueProxy {
  // getters for the properties, no need for setters if it's only server-to-client
}

然后,在RequestContext(客户端)中:

Request<ClientRankingProxy> getClientRanking(String clientCode, Date fromDate, Date untilDate);

以及在服务器端的服务中:

public ClientRankingDTO getClientRanking(String clientCode, Date fromDate, Date untilDate) {
  // your request to the database, mapping the result to ClientRankingDTO
}

Simply use ValueProxy instead of EntityProxy, and you turn RequestFactory into a "simple RPC" mechanism, similar to GWT-RPC.

Proxy:

@ProxyFor(ClientRankingDTO.class)
interface ClientRankingProxy extends ValueProxy {
  // getters for the properties, no need for setters if it's only server-to-client
}

Then, in the RequestContext (client-side):

Request<ClientRankingProxy> getClientRanking(String clientCode, Date fromDate, Date untilDate);

And in the service on the server-side:

public ClientRankingDTO getClientRanking(String clientCode, Date fromDate, Date untilDate) {
  // your request to the database, mapping the result to ClientRankingDTO
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文