  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Subject: Object Synchronization in DAO | Subject: Object Synchronization in DAO 2005-08-02 - By Chris Harrison
Back Hi All, If its local (if the DTO is not going to a remote client), why dont you use a CMP bean to do it for you? Chris.
-- --Original Message-- -- From: An interest list for Sun Java Center J2EE Pattern Catalog [mailto :J2EEPATTERNS-INTEREST@(protected)]On Behalf Of Jerry Osme?a Sent: Wednesday, 3 August 2005 9:12 AM To: J2EEPATTERNS-INTEREST@(protected) Subject: Re: Object Synchronization in DAO
I would assume that the User is a data transfer object(DTO), is that correct? The way I will do this is I will modify the DTO to be sensitive to the changes of any of its attributes. This can be done by adding a changes attribute of type hashmap of Name/value pair to your dto. Then when an attribute of this dto changes, add the name/value pair of this attribute in the hashmap. Then during the implementation of your DAO, you pull this list of changes and use the name and value to generate the sql accordingly. for e.g. Class User { String name; String userId; HashMap changes; Public User () { changes = new HasMap(); } setUserId(String userId) { this.userId = userId; fireChanges("userId", userId); <-- you can also make a condition such that if the value is Null or the same as the old value do not trigger the change. } fireChanges(String name, String value) { changes.put(name, value); } } In your DAO implementation get the changes map and loop thru it. Based on its name, generate the corresponding sql and bind the corresponding value. Hope this helps. Regards, Jerry Maciej Gawinecki <d299052@(protected)> wrote:
Imagine the situation from client side of DAO Design Pattern
class User { String name; int userID; ... }
... User user = UserDAO.findUser(UserID); user.setName("Johny"); UserDAO.updateUser(user); ...
In what a way UserDAO could guess which record in DB should be updated, if information contained in 'user' class are ambiguous, e.g. supposing there doesn't exist any unique primary key like userID?
Any help would be appreciated,
Maciej
==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
__ __
Start <http://us.rd.yahoo.com/evt=34442/*http://www.yahoo.com/r/hs> your day with Yahoo! - make it your home page ========================================== ========================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http: //archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD> <BODY> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=109551523-02082005>Hi All,</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=109551523-02082005></SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN class=109551523-02082005></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=109551523-02082005>If its local (if the DTO is not going to a remote client), w</SPAN></FONT><FONT face=Arial color=#0000ff size=2><SPAN class=109551523-02082005>hy dont you use a CMP bean to do it for you?</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=109551523-02082005><FONT face=Arial color=#0000ff size=2>Chris.</FONT></SPAN></DIV> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <BLOCKQUOTE> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-- --Original Message-- --<BR><B>From:</B> An interest list for Sun Java Center J2EE Pattern Catalog [mailto:J2EEPATTERNS-INTEREST@(protected)]<B>On Behalf Of </B>Jerry Osme?a<BR><B>Sent:</B> Wednesday, 3 August 2005 9:12 AM<BR><B>To:</B> J2EEPATTERNS-INTEREST@(protected)<BR><B>Subject:</B> Re: Object Synchronization in DAO<BR><BR></FONT></DIV> <DIV>I would assume that the User is a data transfer object(DTO), is that correct?</DIV> <DIV> </DIV> <DIV>The way I will do this is I will modify the DTO to be sensitive to the changes of any of its attributes. This can be done by adding a changes attribute of type hashmap of Name/value pair to your dto. Then when an attribute of this dto changes, add the name/value pair of this attribute in the hashmap. Then during the implementation of your DAO, you pull this list of changes and use the name and value to generate the sql accordingly.</DIV> <DIV> </DIV> <DIV>for e.g.</DIV> <DIV> </DIV> <DIV>Class User {</DIV> <DIV>String name;</DIV> <DIV>String userId;</DIV> <DIV>HashMap changes;</DIV> <DIV> </DIV> <DIV>Public User () {</DIV> <DIV> changes = new HasMap();</DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>setUserId(String userId)</DIV> <DIV>{</DIV> <DIV> this.userId = userId; </DIV> <DIV> fireChanges("userId", userId); <-- you can also make a condition such that if the value is Null or the same as the old value do not trigger the change.</DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>fireChanges(String name, String value)</DIV> <DIV>{</DIV> <DIV> changes.put(name, value); </DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>In your DAO implementation get the changes map and loop thru it. Based on its name, generate the corresponding sql and bind the corresponding value.</DIV> <DIV> </DIV> <DIV>Hope this helps.</DIV> <DIV> </DIV> <DIV>Regards,</DIV> <DIV> </DIV> <DIV>Jerry<BR><B><I>Maciej Gawinecki <d299052@(protected)></I></B> wrote:</DIV> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid" >Imagine the situation from client side of DAO Design Pattern<BR><BR>class User {<BR>String name;<BR>int userID;<BR>...<BR>}<BR><BR><BR>...<BR>User user = UserDAO.findUser(UserID);<BR>user.setName("Johny");<BR>UserDAO.updateUser (user);<BR>...<BR><BR>In what a way UserDAO could guess which record in DB should be updated, if<BR>information contained in 'user' class are ambiguous, e.g. supposing there<BR>doesn't exist any unique primary key like userID?<BR><BR>Any help would be appreciated,<BR><BR>Maciej<BR><BR>========================================= ===========================<BR>Companion Site: http://www.corej2eepatterns.com<BR>J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns<BR>List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html<BR >Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)<BR></BLOCKQUOTE> <P> <HR SIZE=1> <A href="http://us.rd.yahoo.com/evt=34442/*http://www.yahoo.com/r/hs">Start your day with Yahoo! - make it your home page </A>==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)</BLOCKQUOTE></BODY></HTML> ==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
|
|
 |