DTO doubt....
Hi all,
I am having some doubt in Transfer Object pattern.. How should we implement that pattern exactly? Lets take an example of displaying data from customer table. In my customerDAO iam creating an arraylist (containing records retrieved) and sending back to the presentation tier through stateless session bean. means iam returning the arraylist containing all the retrieved records from database. Inorder to implement the DTO in my application, how should i proceed?
Thanks in advance...
[511 byte] By [
jvmana] at [2007-11-27 11:01:10]

# 2
A DTO is just a javabean class which represents one database record.
public class Customer {
private Long id;
private String name;
private Integer age;
private Address address;
...
// Implement public getters and setters here.
}
The CustomerDAO should have methods to create/read/update/delete a single Customer DTO or collection of Customer DTO's.
public class CustomerDAO {
public List<Customer> getAllCustomers() {}
public Customer getCustomerById(Long id) {}
public void deleteCustomer(Customer customer) {}
...
}
# 3
Thanks very much for ur help.
My appln is like this..
jsf->managedbean->servicelocator->stateless session bean->class(pojo)->CustomerDAO->db
In display() meth of DAO, i got the db values of customer table. It returns arraylist to display() in class(pojo). the arraylist is passed to jsp in reverse direction.
Now where should i populate my CustomerTO? in CustomerDAO or backing class. What will be the return type of display() method? is it arraylist containing CustomerTO's?
Did the CustomerTO implement Serializable intf or not?
Thanks..
jvmana at 2007-7-29 12:34:50 >

# 5
Yes. I already understood that Customer class is the DTO.
I replied keeping in mind that Customer as a CustomerTO.
If i want to display a customer table, i will get more rows. means more CustomerTO objects. how to send them all? should i keep all of them in the arraylist?
till now(without CustomerTO) iam copying each record in to each arraylist and keeping all that arraylists in to one arraylist and passing them.
So, please solve my problems given in my previous post.
Thanks.
jvmana at 2007-7-29 12:34:50 >

# 6
Look to the example methods I mentioned in the CustomerDAO. There is one method with this signature:public List<Customer> getAllCustomers() {}
This should light something up, I guess?
# 7
Thanks BalusC for ur timely help. It seems i must populate my CustomerTO with in my CustomerDAO's getAllCustomers() method which returns List.
I will do that.
thanks again for ur help.
jvmana at 2007-7-29 12:34:50 >
