Return-Path: Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 61683 invoked by uid 99); 24 Jan 2005 20:44:31 -0000 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from web53104.mail.yahoo.com (HELO web53104.mail.yahoo.com) (206.190.39.207) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 24 Jan 2005 12:44:30 -0800 Received: (qmail 71368 invoked by uid 60001); 24 Jan 2005 20:44:27 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=Qodi4X2f7iRPh0oL9J1B7nGzmRZWbSijlNrkWW6ThSKWIZOfaHB0LJGEhQufmE/+PJPXzSEt/bsIbhkhdo5cW0OoQioNCC76NWIjVU+Tc/oE+1w+/B20v20ftZHfN/+eHRMoerLXPuxHQwLSkfT2R2wRBXHrb/e1unDzM+wRUCo= ; Message-ID: <20050124204427.71364.qmail@web53104.mail.yahoo.com> Received: from [20.137.2.51] by web53104.mail.yahoo.com via HTTP; Mon, 24 Jan 2005 12:44:27 PST Date: Mon, 24 Jan 2005 12:44:27 -0800 (PST) From: Prashanth Sukumaran Subject: Re: java.util.HashMap as resultClass To: ibatis-user-java@incubator.apache.org In-Reply-To: <1106592527.22780.88.camel@standing-cow.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Checked: Checked Hi Pascal, I think i understand what Brandon is trying to say. He is talking about using the right pattern for the kind of job you are trying to achieve. If my guess is right. Looks like you trying to do this for your dropdowns. I do it this way and i feel it is much cleaner this way. public interface ValueObject{ /** * Gets the iD attribute of the KeyValueObject object * * @return The iD value */ String getID(); /** * Gets the value attribute of the KeyValueObject object * * @return The value value */ String getValue(); /** * This method returns sort field * * * @return value of sort field */ public Object getSortFieldValue(); } All Objects that you are using for Dropdowns will extend the ValueObject, and they will implement the three methods. In your case getID() will return SKU, getValue will return Description. and for the getSortFieldValue() have an empty implementation. This way the bean can be used for other things and also used for dropdowns. For the dropdowns have a common method that handles them or even struts has the LabelValue bean. Rgds Prashanth. --- Pascal DeMilly wrote: > Well. It seems logical to me. Why would iBatis go into great length at > trying to map result in the SqlMap file then if it was not to limit the > knowledge of your database to that XML file. The dependency have to stop > somewhere and it seems to me the SqlMap file is the place where it > should stop. The DAO implementation classes should only know about the > iBatis map id and its expected POJO results not how your database > columns are named or it seems to me. > > Anyway, in my case while this solve one of my problem, queryForMap is > still not as efficient as it could be since it relies on queryForList. > So basically it is building two list. One with each element being a Map > of column name/value, then another map of only values. Would it be more > efficient to rewrite queryForMap to use a RowHandler? > > > > On Mon, 2005-01-24 at 10:15, Brandon Goodin wrote: > > Why is it a problem to have a code dependency in an "implementation" > > class? It is suppossed to be aware of IBatis SQLMap semantics. You > > interface over your DAO class should hide the specifics of your > > implementation code within your Dao. > > > > Brandon > > > > > > > > > > On Mon, 24 Jan 2005 09:22:49 -0800, Pascal DeMilly > > wrote: > > > Thanks Larry, > > > > > > I tried it and it works. However this still leave some dependencies in > > > my DAO code as I have to specify the column names there as in: > > > > > > return getSqlMapClientTemplate().queryForMap("getItemNameMap", null, "SKU", "Description"); > > > > > > How will you do about moving that code into the SqlMap. Should I create > > > a custom resultMap with key/value as properties and refer to it in my > > > DAO code? > > > > > > I am going to give it a try and see what happened. > > > > > > Thanks for you help. > > > > > > Pascal > > > > > > On Mon, 2005-01-24 at 08:44, Larry Meadors wrote: > > > > Try executeQueryForMap() instead. > > > > > > > > > > > > On Mon, 24 Jan 2005 08:42:25 -0800, Pascal DeMilly > > > > wrote: > > > > > Hi, > > > > > > > > > > I would like to retrieve a Map with whose key is the 1st column of my > > > > > query and the value is the 2nd column. For example right now I do: > > > > > > > > > > > > > > > > > > > > However this returns a list of maps with the key being the column name > > > > > and the value the column value which seems wasteful in term of space (I > > > > > am using remoting to retrieve that info). > > > > > > > > > > I currently solve it by using a custom rowHandler in my DAO as follow: > > > > > > > > > > public Map getItemNames () throws DataAccessException { > > > > > final KeyValueHandler rowHandler = new KeyValueHandler (); > > > > > getSqlMapClientTemplate().queryWithRowHandler("getItemNameMap", null, > rowHandler); > > > > > return rowHandler.getMap(); > > > > > } > > > > > > > > > > private class KeyValueHandler implements RowHandler { > > > > > final Map map = new HashMap (); > > > > > > > > > > public void handleRow(Object valueObject) { > > > > > final Map row = (Map) valueObject; > > > > > map.put (row.get("SKU"), row.get("Description")); > > > > > } > > > > > > > > > > public Map getMap () { > > > > > return map; > > > > > } > > > > > > > > > > } > > > > > > > > > > But I would like to move possibly that code out of my DAO code and into > > > > > iBatis SqlMap file. > > > > > > > > > > How could I do that > > > > > > > > > > TIA > > > > > > > > > > Pascal > > > > > > > > > > > > > > > > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com