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