Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 90650 invoked from network); 20 Jan 2006 08:42:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jan 2006 08:42:12 -0000 Received: (qmail 50243 invoked by uid 500); 20 Jan 2006 08:42:03 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 50196 invoked by uid 500); 20 Jan 2006 08:42:03 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 50142 invoked by uid 99); 20 Jan 2006 08:42:02 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 00:42:02 -0800 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [217.12.10.186] (HELO web25801.mail.ukl.yahoo.com) (217.12.10.186) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 20 Jan 2006 00:42:00 -0800 Received: (qmail 3297 invoked by uid 60001); 20 Jan 2006 08:41:37 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.uk; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=pqysft5HH2wnrCLUDWpnpHT8ZO6EVlhUqKw381CEC9Is0F34kjVK+X9D1oupD6XpzNuGHgS3Dqbewlc/Cne9uZ4JOhF6hj7PFBc0s6hJIljikNggkYt/1LrTyR9Ue2BNJneSiPtociWV/KBMqAzU12Dw+PNcXy9OAUGgmeFMc/w= ; Message-ID: <20060120084137.3295.qmail@web25801.mail.ukl.yahoo.com> Received: from [82.109.70.230] by web25801.mail.ukl.yahoo.com via HTTP; Fri, 20 Jan 2006 08:41:37 GMT Date: Fri, 20 Jan 2006 08:41:37 +0000 (GMT) From: Gareth Moorst Subject: RE: boolean JavaType and mapping To: user-java@ibatis.apache.org In-Reply-To: <50CA25BD6EEA954FA592C097399942E309313EE1@CM1.wis.local> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-205679953-1137746497=:1599" Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --0-205679953-1137746497=:1599 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Here's one I wrote to do just that. Feel free to use it (just don't tell my boss) package com.phones4u.datamanagement.datamodel.ibatis.typehandler; import java.sql.SQLException; import java.sql.Types; import com.ibatis.sqlmap.client.extensions.ParameterSetter; import com.ibatis.sqlmap.client.extensions.ResultGetter; import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback; /** * Custom type handler for ibatis to convert between boolean and smallint values * @author gareth.moorst * */ public class SmallIntBooleanTypeHandler implements TypeHandlerCallback { public void setParameter(ParameterSetter setter, Object parameter) throws SQLException { if (parameter == null) { setter.setInt(0); } else { Boolean bool = (Boolean) parameter; short boolVal = 0; if (bool.booleanValue()) boolVal = 1; setter.setShort(boolVal); } } public Object getResult(ResultGetter getter) throws SQLException { if (getter.wasNull()) return Boolean.FALSE; short dbVal = getter.getShort(); if (dbVal == 1) return Boolean.TRUE; return Boolean.FALSE; } public Object valueOf(String s) { return s; } } Niels Beekman wrote: You could use a typehandler to do that: http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+ use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration Niels -----Original Message----- From: Olivier Antoine [mailto:oli.antoine@gmail.com] Sent: donderdag 19 januari 2006 23:20 To: user-java@ibatis.apache.org Subject: boolean JavaType and mapping Hello everyone, I have to re-write a website with an existant MySQL database with an important number of data ...so i could not change database structure (column type and so on) I m'a sking if it's possible and so ...How to? make a mapping between a boolean from my java bean class and an integer in my database column associated? for example when in my database I have 1 it return true in my boolean and inverse. thanks a lot, Olivier --------------------------------- Yahoo! Photos � NEW, now offering a quality print service from just 8p a photo. --0-205679953-1137746497=:1599 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
Here's one I wrote to do just that. Feel free to use it (just don't tell my boss)

package com.phones4u.datamanagement.datamodel.ibatis.typehandler;

import java.sql.SQLException;
import java.sql.Types;

import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

/**
 * Custom type handler for ibatis to convert between boolean and smallint values
 * @author gareth.moorst
 *
 */
public class SmallIntBooleanTypeHandler implements TypeHandlerCallback
{

    public void setParameter(ParameterSetter setter, Object parameter) throws SQLException
    {
        if (parameter == null) {
            setter.setInt(0);
        } else {
            Boolean bool = (Boolean) parameter;
            short boolVal = 0;
            if (bool.booleanValue())
                boolVal = 1;
            setter.setShort(boolVal);
        }
    }

    public Object getResult(ResultGetter getter) throws SQLException
    {
        if (getter.wasNull())
            return Boolean.FALSE;
       
        short dbVal = getter.getShort();
       
        if (dbVal == 1)
            return Boolean.TRUE;
       
        return Boolean.FALSE;
    }

    public Object valueOf(String s)
    {
        return s;
    }

}


Niels Beekman <n.beekman@wis.nl> wrote:
You could use a typehandler to do that:
http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+
use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration

Niels

-----Original Message-----
From: Olivier Antoine [mailto:oli.antoine@gmail.com]
Sent: donderdag 19 januari 2006 23:20
To: user-java@ibatis.apache.org
Subject: boolean JavaType and mapping

Hello everyone,
I have to re-write a website with an existant MySQL database with an
important number of data ...so i could not change database structure
(column type and so on)

I m'a sking if it's possible and so ...How to?

make a mapping between
a boolean from my java bean class and an integer in my database column
associated?

for example when in my database I have 1 it return true in my boolean
and inverse.

thanks a lot,
Olivier



Yahoo! PhotosNEW, now offering a quality print service from just 8p a photo. --0-205679953-1137746497=:1599--