You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Clinton Begin (JIRA)" <ib...@incubator.apache.org> on 2009/08/15 15:21:15 UTC
[jira] Closed: (IBATIS-299) Add a type mapper callback for
java.net.URL
[ https://issues.apache.org/jira/browse/IBATIS-299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Clinton Begin closed IBATIS-299.
--------------------------------
Resolution: Won't Fix
> Add a type mapper callback for java.net.URL
> -------------------------------------------
>
> Key: IBATIS-299
> URL: https://issues.apache.org/jira/browse/IBATIS-299
> Project: iBatis for Java
> Issue Type: Wish
> Affects 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 <code>null</code>.
> * <p>
> * @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.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ibatis.apache.org
For additional commands, e-mail: dev-help@ibatis.apache.org