Return-Path: Delivered-To: apmail-ibatis-dev-archive@www.apache.org Received: (qmail 39177 invoked from network); 30 May 2006 04:00:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 May 2006 04:00:22 -0000 Received: (qmail 90301 invoked by uid 500); 30 May 2006 04:00:22 -0000 Delivered-To: apmail-ibatis-dev-archive@ibatis.apache.org Received: (qmail 90168 invoked by uid 500); 30 May 2006 04:00:21 -0000 Mailing-List: contact dev-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ibatis.apache.org Delivered-To: mailing list dev@ibatis.apache.org Received: (qmail 90157 invoked by uid 99); 30 May 2006 04:00:21 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 May 2006 21:00:21 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [209.237.227.198] (HELO brutus.apache.org) (209.237.227.198) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 May 2006 21:00:19 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 99E9E7142EF for ; Tue, 30 May 2006 03:59:30 +0000 (GMT) Message-ID: <6618643.1148961570627.JavaMail.jira@brutus> Date: Tue, 30 May 2006 03:59:30 +0000 (GMT+00:00) From: "Nathan Maves (JIRA)" To: dev@ibatis.apache.org Subject: [jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL In-Reply-To: <33442004.1148869049832.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/IBATIS-299?page=comments#action_12413753 ] Nathan Maves commented on IBATIS-299: ------------------------------------- Ken, This is a perfect example of how to extend the framework for your specific requirements. I am not saying that this is a no go but do you believe that this is a common data type that people would be writing this type of CTH for? We can not include a type handler for every different type of java object. Just my 2 cents. Nathan > Add a type mapper callback for java.net.URL > ------------------------------------------- > > Key: IBATIS-299 > URL: http://issues.apache.org/jira/browse/IBATIS-299 > Project: iBatis for Java > Type: Wish > Versions: 2.1.7 > Reporter: Ken Weiner > > It would be nice if iBATIS came with a TypeHandlerCallback implementation for mapping URL object properties to their String representation stored in a database field. Here is some code that could be used to implement this: > package com.ibatis.sqlmap.client.extensions; > import java.net.MalformedURLException; > import java.net.URL; > import java.sql.SQLException; > import java.sql.Types; > /** > * An iBATIS type handler callback for java.net.URLs that are mapped to > * Strings in the database. If a URL cannot be constructed based on the > * String, then the URL will be set to null. > *

> * @author Ken Weiner > */ > public class UrlTypeHandlerCallback implements TypeHandlerCallback { > public Object getResult(ResultGetter getter) throws SQLException { > String value = getter.getString(); > if (getter.wasNull()) { > return null; > } > return this.valueOf(value); > } > public void setParameter(ParameterSetter setter, Object parameter) throws SQLException { > if (parameter == null) { > setter.setNull(Types.VARCHAR); > } else { > URL url = (URL) parameter; > setter.setString(url.toExternalForm()); > } > } > public Object valueOf(String s) { > URL url; > try { > url = new URL(s); > } catch (MalformedURLException e) { > url = null; > } > return url; > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira