I have two classes, a server and some clients. The server class make a query to database and retrieve a certain number of rows. The clients request a part of these rows, each one a different part.
In the server class, is better I maintain the result of the query in the ResultSet and transforming in a array of objects when the client class make the request or transforming all in a array of objects and sending him partially when the request occur?
I think that maintain in the ResultSet is more easier to do and control.
Actually I’m not sure if I understood your approach. In typical client/server scenarios with persistance layers, a client (1) calls remote method, this (2) triggers a database operation and the service (3) responds with the requested objects.
In your scenario, it looks like the server reads data from a database, caches it and waits for clients to request chunks.
If I got it right, and the server is caching database objects, then it should transform the data from the result set in objects, I’d prefer a collection or a map to store the “rows”. A result set is a rather fragile data structure – like some result sets don’t support re-reading of set entries (= you can’t iterate twice). I’d always take the data from the set and close it as soon as possible.