001/** 002 * Copyright (C) 2010-2015 The Roslin Institute <contact andy.law@roslin.ed.ac.uk> 003 * 004 * This file is part of JEnsembl: a Java API to Ensembl data sources developed by the 005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of 006 * Veterinary Studies, University of Edinburgh. 007 * 008 * Project hosted at: http://jensembl.sourceforge.net 009 * 010 * This is free software: you can redistribute it and/or modify 011 * it under the terms of the GNU General Public License (version 3) as published by 012 * the Free Software Foundation. 013 * 014 * This software is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * in this software distribution. If not, see: http://opensource.org/licenses/gpl-3.0.html 021 */ 022package uk.ac.roslin.ensembl.mapper.handler; 023 024import org.apache.ibatis.type.TypeHandler; 025import java.sql.CallableStatement; 026import java.sql.PreparedStatement; 027import java.sql.ResultSet; 028import java.sql.SQLException; 029import java.util.ArrayList; 030import java.util.List; 031import org.apache.ibatis.type.JdbcType; 032import uk.ac.roslin.ensembl.dao.factory.DAOVariationFactory; 033import uk.ac.roslin.ensembl.model.variation.VariationType; 034 035public class ConsequencesHandler implements TypeHandler { 036 037 DAOVariationFactory factory= null;; 038 039 public ConsequencesHandler() { 040 super(); 041 } 042 043 public void setFactory(DAOVariationFactory factory) { 044 this.factory=factory; 045 } 046 047 @Override 048 public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) 049 throws SQLException { 050 } 051 052 @Override 053 public List<VariationType> getResult(ResultSet rs, String columnName) 054 throws SQLException { 055 056 List<VariationType> out = new ArrayList<VariationType>(); 057 058 if (factory==null) { 059 return null; 060 } 061 062 String s; 063 064 try { 065 s = rs.getString(columnName); 066 } catch (SQLException sQLException) { 067 return out; 068 } 069 070 if (s==null || s.isEmpty()) { 071 return out; 072 } 073 074 String [] ss = s.split(","); 075 076 for (int i=0; i<ss.length;i++) { 077 out.add(factory.getVarTypeBySOTerm(ss[i])); 078 } 079 080 return out; 081 082 083 } 084 085 @Override 086 public Object getResult(CallableStatement cs, int columnIndex) 087 throws SQLException { 088 return null; 089 //return cs.getString(columnIndex); 090 } 091}