001    /**
002     * Copyright (C) 2011 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003     *
004     * This file is part of the Ensembl Java API demonstration project developed by the
005     * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006     * Veterinary Studies, University of Edinburgh.
007     *
008     * This is free software: you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (version 3) as published by
010     * the Free Software Foundation.
011     *
012     * This software is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * in this software distribution. If not, see <http://www.gnu.org/licenses/gpl-3.0.html/>.
019     */
020    
021    package uk.ac.roslin.ensembl.mapper.handler;
022    
023    import org.apache.ibatis.type.TypeHandler;
024    import java.sql.CallableStatement;
025    import java.sql.PreparedStatement;
026    import java.sql.ResultSet;
027    import java.sql.SQLException;
028    import org.apache.ibatis.type.JdbcType;
029    
030    public class BooleanTypeHandler implements TypeHandler {
031    
032        @Override
033        public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
034                throws SQLException {
035        }
036    
037        public Object getResult(ResultSet rs, String columnName)
038                throws SQLException {
039    
040            int i;      
041            
042            try {
043                i = rs.getInt(columnName);
044            } catch (SQLException sQLException) {
045                return Boolean.FALSE;
046            }
047    
048            if (i==1) {
049                return Boolean.TRUE;
050            } else {
051                return Boolean.FALSE;
052            }
053        }
054    
055        public Object getResult(CallableStatement cs, int columnIndex)
056                throws SQLException {
057            return null;
058            //return cs.getString(columnIndex);
059        }
060    }