Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getters & setters

 
yoga raj
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a newbie and trying to learn, I have a type & service table
type
t_id
t_name
blah
blah

service
s_id
t_id (fk)
blah
blah

For a Add Screen, I have Type in a text field & JTable for the service (can be multiple for one type).

Now normally when it is recommended to have getters & setters for everything, how do i have setters for the JTable (ie corresponding to the service table).

I don't want to basically go back and forth the database 50 times , ie do the setter, insert to db, and repeat.

Both are in the same screen as per the UI design ? How does everyone normally does this ?

Thanks much
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java! Normally people use data transfer objects (DTO) in this case, although this gets a bit beyond a beginner question. Basically, a DTO allows you to load a bunch of related data from the database all at once. After it's loaded, the DTO can be accessed directly by the JTable code or whatever else through its getters (and possibly setters) without hitting the database again. Of course, you have to worry about things like stale data, how to handle updates, etc. In many situations, simple DTO objects are sufficient. In others, you might need to use entity EJBs hosted on a J2EE application server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic