1 20 package net.mlw.vlh.adapter.jdbc.util.setter; 21 22 import java.sql.PreparedStatement ; 23 import java.sql.SQLException ; 24 import java.sql.Timestamp ; 25 import java.text.ParseException ; 26 import java.util.Calendar ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 39 public class Hibernate20CalendarSetter extends AbstractSetter 40 { 41 44 private static final Log LOGGER = LogFactory.getLog(Hibernate20CalendarSetter.class); 45 46 57 public int set(PreparedStatement query, int index, Object value) throws SQLException , ParseException 58 { 59 long timeInMillis = 0; 60 if (value instanceof Calendar ) 61 { 62 timeInMillis = ((Calendar ) value).getTimeInMillis(); 63 } 64 else 65 { 66 if (LOGGER.isWarnEnabled()) 67 { 68 LOGGER.warn("The key's index's='" + index + "' value='" + value + "' was expected as Calendar. Using actual time."); 69 } 70 timeInMillis = Calendar.getInstance().getTimeInMillis(); 71 } 72 73 query.setTimestamp(index++, new Timestamp (timeInMillis)); 74 return index; 75 } 76 } | Popular Tags |