1 21 package net.mlw.vlh.adapter.hibernate3.util.setter; 22 23 import java.text.ParseException ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.hibernate.HibernateException; 28 import org.hibernate.Query; 29 30 35 public class IntegerSetter extends AbstractSetter 36 { 37 40 private static final Log LOGGER = LogFactory.getLog(IntegerSetter.class); 41 42 45 public void set(Query query, String key, Object value) throws HibernateException, ParseException 46 { 47 if (value instanceof Integer ) 48 { 49 if (LOGGER.isInfoEnabled()) 50 { 51 LOGGER.info("The key='" + key + "'s value is instance of a Integer, now is parsing to int."); 52 } 53 int intValue = ((Integer ) value).intValue(); 54 query.setInteger(key, intValue); 55 } 56 else if (value instanceof String ) 57 { 58 if (LOGGER.isInfoEnabled()) 59 { 60 LOGGER.info("The key='" + key + "'s value is instance of a String, now is parsing to int."); 61 } 62 int intValue = Integer.parseInt((String ) value); 63 query.setInteger(key, intValue); 64 } 65 else if (value == null) 66 { 67 if (LOGGER.isInfoEnabled()) 68 { 69 LOGGER.info("The key='" + key + "'s value is null."); 70 } 71 query.setParameter(key, null); 72 } 73 else 74 { 75 throw new IllegalArgumentException ("Cannot convert value of class " + value.getClass().getName() + " to int (key=" + key + ")"); 76 } 77 } 78 } | Popular Tags |