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 LongSetter extends AbstractSetter 36 { 37 38 41 private static final Log LOGGER = LogFactory.getLog(LongSetter.class); 42 43 46 public void set(Query query, String key, Object value) throws HibernateException, ParseException 47 { 48 if (value instanceof Long ) 49 { 50 if (LOGGER.isInfoEnabled()) 51 { 52 LOGGER.info("The key='" + key + "'s value is instance of a Long, now is converting to long."); 53 } 54 query.setLong(key, ((Long ) value).longValue()); 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 long."); 61 } 62 long longValue = Long.parseLong((String ) value); 63 query.setLong(key, longValue); 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 long (key=" + key + ")"); 76 } 77 } 78 } | Popular Tags |