[jira] Created: (IBATIS-299) Add a type mapper callback for java.net.URL

View: New views
7 Messages — Rating Filter:   Alert me  

[jira] Created: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <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.
-
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


[jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    [ http://issues.apache.org/jira/browse/IBATIS-299?page=comments#action_12413657 ]

Ken Weiner commented on IBATIS-299:
-----------------------------------

Sorry, I meant to say "type handler callback" rather than "type mapper callback" in the issue title.

> 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 <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.
-
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


[jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    [ 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 <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.
-
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


[jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    [ http://issues.apache.org/jira/browse/IBATIS-299?page=comments#action_12413754 ]

Larry Meadors commented on IBATIS-299:
--------------------------------------

I'd have to agree with Nathan on this one - there are literally hundeds of types in the core Java API that people could use with SQL maps, but IMO, we can not and should not support them all.

If you think that this would be useful to others, feel free to implement it and put it on the WIKI.

Larry



> 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 <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.
-
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


[jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    [ http://issues.apache.org/jira/browse/IBATIS-299?page=comments#action_12413774 ]

Ken Weiner commented on IBATIS-299:
-----------------------------------

Okay, I understand.  I'll add it to the Wiki.  Frameworks like Spring include property editors for common, straightforward objects like java.net.URL and java.lang.Class so I thought that it was a reasonable suggestion for iBATIS to include these kinds of Type Handlers.  Thanks, anyways.

> 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 <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.
-
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


[jira] Commented: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    [ http://issues.apache.org/jira/browse/IBATIS-299?page=comments#action_12413986 ]

Ken Weiner commented on IBATIS-299:
-----------------------------------

Added a wiki page to track custom handlers here: http://opensource.atlassian.com/confluence/oss/display/IBATIS/Type+Handler+Callbacks

I still think it would be appropriate to include common handlers (analagous to Spring property editors shown here http://www.springframework.org/docs/api/org/springframework/beans/propertyeditors/package-summary.html)  in the framework itself so people like me would have to write less custom code, but I respect your opinions.


> 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 <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.
-
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


[jira] Closed: (IBATIS-299) Add a type mapper callback for java.net.URL

by JIRA ibatis-dev@incubator.apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ 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@...
For additional commands, e-mail: dev-help@...