1 5 package org.h2.value; 6 7 import java.sql.PreparedStatement ; 8 import java.sql.SQLException ; 9 import java.sql.Time ; 10 11 import org.h2.message.Message; 12 import org.h2.util.DateTimeUtils; 13 14 public class ValueTime extends Value { 15 public static final int PRECISION = 6; 16 private Time value; 17 18 private ValueTime(Time value) { 19 this.value = value; 20 } 21 22 public static Time parseTime(String s) throws SQLException { 23 return (Time ) DateTimeUtils.parseDateTime(s, Value.TIME, Message.TIME_CONSTANT_1); 24 } 25 26 public Time getTime() { 27 return (Time )value.clone(); 29 } 30 31 public Time getTimeNoCopy() { 32 return value; 33 } 34 35 public String getSQL() { 36 return "TIME '" + getString() + "'"; 37 } 38 39 public int getType() { 40 return Value.TIME; 41 } 42 43 protected int compareSecure(Value o, CompareMode mode) { 44 ValueTime v = (ValueTime) o; 45 int c = value.compareTo(v.value); 46 return c == 0 ? 0 : (c < 0 ? -1 : 1); 47 } 48 49 public String getString() { 50 return value.toString(); 51 } 52 53 public long getPrecision() { 54 return PRECISION; 55 } 56 57 public int hashCode() { 58 return value.hashCode(); 59 } 60 61 public Object getObject() { 62 return getTime(); 63 } 64 65 public void set(PreparedStatement prep, int parameterIndex) throws SQLException { 66 prep.setTime(parameterIndex, value); 67 } 68 69 public static ValueTime get(Time time) { 70 time = DateTimeUtils.cloneAndNormalizeTime(time); 71 return getNoCopy(time); 72 } 73 74 public static ValueTime getNoCopy(Time time) { 75 return (ValueTime) Value.cache(new ValueTime(time)); 76 } 77 78 82 public int getDisplaySize() { 83 return "23:59:59".length(); 84 } 85 86 protected boolean isEqual(Value v) { 87 return v instanceof ValueTime && value.equals(((ValueTime)v).value); 88 } 89 90 } 91 | Popular Tags |