KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > value > ValueTime


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.value;
6
7 import java.sql.PreparedStatement JavaDoc;
8 import java.sql.SQLException JavaDoc;
9 import java.sql.Time JavaDoc;
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 JavaDoc value;
17
18     private ValueTime(Time JavaDoc value) {
19         this.value = value;
20     }
21
22     public static Time JavaDoc parseTime(String JavaDoc s) throws SQLException JavaDoc {
23         return (Time JavaDoc) DateTimeUtils.parseDateTime(s, Value.TIME, Message.TIME_CONSTANT_1);
24     }
25
26     public Time JavaDoc getTime() {
27         // this class is mutable - must copy the object
28
return (Time JavaDoc)value.clone();
29     }
30     
31     public Time JavaDoc getTimeNoCopy() {
32         return value;
33     }
34
35     public String JavaDoc 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 JavaDoc 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 JavaDoc getObject() {
62         return getTime();
63     }
64
65     public void set(PreparedStatement JavaDoc prep, int parameterIndex) throws SQLException JavaDoc {
66         prep.setTime(parameterIndex, value);
67     }
68
69     public static ValueTime get(Time JavaDoc time) {
70         time = DateTimeUtils.cloneAndNormalizeTime(time);
71         return getNoCopy(time);
72     }
73     
74     public static ValueTime getNoCopy(Time JavaDoc time) {
75         return (ValueTime) Value.cache(new ValueTime(time));
76     }
77
78 // public String getJavaString() {
79
// return "Time.valueOf(\"" + toString() + "\")";
80
// }
81

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