Search code examples
javajsongwtrpcrequestfactory

Pushing mysql query results to clients GWT


I am looking for an efficient way to convert a ResultSet into a form I can send via GWT-RPC that can be part of a GWT server-client communication in general. What are the advantages and disadvantages of using JSON vs the RequestFactory? Would someone care to explain them in case I want to use them as described above?

It might be important to say that I want to process at the client large portions of the database and not just single entries. I'm talking about hundreds of entries at a time, so I basically think I need a way to efficiently transfer the data.

Wouldn't requesting one entry at a time create a large overhead?

A tutorial in something similar would be appreciated.


Solution

  • Moving large chunks of data around is usually a really bad idea and un-typical for a client-server architecture. So I would recommend a redesign.

    GWT-RPC is service oriented. Which all RPC frameworks are. The main purpose is to serialize/deserialize the method call. In other words, what server and client are communicating are messages which must be well defined. In GWT the underlying transport mechanism is JSON and in SOAP (for example) it is XML but the mechanisms are the same.

    RequestFactory is much more data-centric. Imagine a servlet that is triggered by a simple HTTP request with the URL /getCustomers. The servlet simply accesses the database and returns the result. RequestFactory is very much like that but offers additional facilities. For example, RequestFactory relies on creating an entity object Customer on the server and a proxy object CustomerProxy on the client. The framework handles transport of data between these objects. More specifically, RequestFactory can update individual properties (i.e. 'fields') and can thus increase efficiency by sending the differences in state only.

    An important architectural difference is that GWT-RPC operates at a more functional level. RequestFactory operates at the data level. A typical implementation could be to have a CRUD interface setup using RequestFactory. Such a design would be very wrong using GWT-RPC.

    I recommend reading up on these two frameworks more before you make a decision. However, RequestFactory seems to be the best solution to your problem.

    If you have only one use case for this then implementing your own servlet would probably do just fine. Use a RequestBuilder in your GWT code to request the data from the servlet. Access the db, convert the ResultSet to JSON, at the client you convert the response back into a JavaScriptObject and you are done. This would save you the work for setting up RequestFactory and all the entities, proxies and locators.