File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes getters & setters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getters & setters" Watch "getters & setters" New topic
Author

getters & setters

yoga raj
Greenhorn

Joined: Jul 08, 2004
Posts: 1
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

Joined: Oct 01, 2001
Posts: 2853
    
  11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getters & setters