Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting database data using RMI  RSS feed

 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i'm writing a program for a uni project where several clients may interact with a database which resides on a server. To do this i am using RMI. I have been updating tables and submitting queries on the database ok. To do this i have simply been passing string sql statements to the server and then returing an array/vector populated with the database results etc. However is this the best way to pass database data from a server to client?

Although this has been working ok, i'm wondering ahead if there may be performance issues with putting database rows in an array. For instance, what if the database returned 1000's of rows. Would the array be albe to take this and would the performance be acceptable?! Also, where a two dimensional array is not enough, on a single screen several arrays may be needed to populate the various views and data.

Any comments would be greatly appreciated, cheers
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a requirement to return a serializable object, so an array is fine in this respect. I question whether you need Vectors, but that is not the major issue.

If the object that you are returning becomes so huge that it poses a performance problem, then you need to question why it needs to be so big. For instance, why can't the client do some filtering and request only the data which is required. Or why can't the client request a limited amount of data and leave it to the user to request more information.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roger you post some interesting points.

I don't particulary like using Vectors....but find them useful for populating a JList or JTable the client end. When i've tried doing this with arrays it goes crazy.....i imagine this has something to do with the default size of the array but thats another issue!

I take on board fully what you said about limiting the amount of data that is sent back to the client. This seems a sensible thing to do! However, i assume from your response that using arrays is a perfactly acceptable way to do what i'm doing....and there isn't perhaps some more superior way of doing it that a novice like me does not know about?!

Cheers
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I can see what you are doing, you are passing Vectors in the constructors of JList and JTable. It's been a while since I did any Swing programming, what I used to do was to pass in Object arrays as I didn't want to use those old fashioned Vectors. However, it probably isn't a good idea for you to refactor your code right now, especially if it's working.

An array is fine as every array IS-A Serializable. So long as the array contains only what is needed by the client, then it can't be made any smaller. My personal preference is to create a custom Serializable class (known as a transfer object) for shipping the data. If possible, I also make it immutable. But don't go around changing your server-side code yet, it's the client-side code that may need attention.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roger,

Thanks for the reply. I'm particulary interested in:

My personal preference is to create a custom Serializable class (known as a transfer object) for shipping the data. If possible, I also make it immutable.


Could you expand on this slightly and explain what you mean and perhaps why this is a preference. I'm quite new to java and especially RMI. It seems i'm shipping everything to and from the server and client in some form of string, or string array and i'm guessing that although this is doing the job it may be not the most sophisticated way of operating!
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a design pattern known as the Transfer Object. Here is some information on it.
http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html

As for immutable objects, there is every reason to use them if you can and no drawbacks as far as I know. Think of security (neither the class nor its subclasses can change the data), thread-safety (no need to synchronize a read-only object). As Transfer Objects are usually not changed after they have been populated, then they are good candidates for being made immutable.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roger you've been a great help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!