Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / engine / values / TimestampValue.java @ 4851

History | View | Annotate | Download (4.2 KB)

1
package com.hardcode.gdbms.engine.values;
2

    
3
import java.io.Serializable;
4
import java.sql.Timestamp;
5
import java.sql.Types;
6
import java.text.SimpleDateFormat;
7

    
8
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
9

    
10

    
11
/**
12
 * Wrapper sobre el tipo Date
13
 *
14
 * @author Fernando Gonz?lez Cort?s
15
 */
16
public class TimestampValue extends AbstractValue implements Serializable {
17
        private Timestamp value;
18

    
19
        /**
20
         * Creates a new DateValue object.
21
         *
22
         * @param d DOCUMENT ME!
23
         */
24
        TimestampValue(Timestamp d) {
25
                value = d;
26
        }
27

    
28
        /**
29
         * Creates a new DateValue object.
30
         */
31
        TimestampValue() {
32
        }
33

    
34
        /**
35
         * Establece el valor
36
         *
37
         * @param d valor
38
         */
39
        public void setValue(Timestamp d) {
40
                value = d;
41
        }
42

    
43
        /**
44
         * @see com.hardcode.gdbms.engine.values.Operations#equals(com.hardcode.gdbms.engine.values.DateValue)
45
         */
46
        public Value equals(Value value) throws IncompatibleTypesException {
47
                if (value instanceof NullValue) {
48
                        return ValueFactory.createValue(false);
49
                }
50

    
51
                if (value instanceof TimestampValue) {
52
                        return new BooleanValue(this.value.equals(
53
                                        ((TimestampValue) value).value));
54
                } else {
55
                        throw new IncompatibleTypesException();
56
                }
57
        }
58

    
59
        /**
60
         * @see com.hardcode.gdbms.engine.values.Operations#greater(com.hardcode.gdbms.engine.values.DateValue)
61
         */
62
        public Value greater(Value value) throws IncompatibleTypesException {
63
                if (value instanceof NullValue) {
64
                        return ValueFactory.createValue(false);
65
                }
66

    
67
                if (value instanceof TimestampValue) {
68
                        return new BooleanValue(this.value.compareTo(
69
                                        ((TimestampValue) value).value) > 0);
70
                } else {
71
                        throw new IncompatibleTypesException();
72
                }
73
        }
74

    
75
        /**
76
         * @see com.hardcode.gdbms.engine.values.Operations#greaterEqual(com.hardcode.gdbms.engine.values.DateValue)
77
         */
78
        public Value greaterEqual(Value value) throws IncompatibleTypesException {
79
                if (value instanceof NullValue) {
80
                        return ValueFactory.createValue(false);
81
                }
82

    
83
                if (value instanceof TimestampValue) {
84
                        return new BooleanValue(this.value.compareTo(
85
                                        ((TimestampValue) value).value) >= 0);
86
                } else {
87
                        throw new IncompatibleTypesException();
88
                }
89
        }
90

    
91
        /**
92
         * @see com.hardcode.gdbms.engine.values.Operations#less(com.hardcode.gdbms.engine.values.DateValue)
93
         */
94
        public Value less(Value value) throws IncompatibleTypesException {
95
                if (value instanceof NullValue) {
96
                        return ValueFactory.createValue(false);
97
                }
98

    
99
                if (value instanceof TimestampValue) {
100
                        return new BooleanValue(this.value.compareTo(
101
                                        ((TimestampValue) value).value) < 0);
102
                } else {
103
                        throw new IncompatibleTypesException();
104
                }
105
        }
106

    
107
        /**
108
         * @see com.hardcode.gdbms.engine.values.Operations#lessEqual(com.hardcode.gdbms.engine.values.DateValue)
109
         */
110
        public Value lessEqual(Value value) throws IncompatibleTypesException {
111
                if (value instanceof NullValue) {
112
                        return ValueFactory.createValue(false);
113
                }
114

    
115
                if (value instanceof TimestampValue) {
116
                        return new BooleanValue(this.value.compareTo(
117
                                        ((TimestampValue) value).value) <= 0);
118
                } else {
119
                        throw new IncompatibleTypesException();
120
                }
121
        }
122

    
123
        /**
124
         * @see com.hardcode.gdbms.engine.values.Operations#notEquals(com.hardcode.gdbms.engine.values.DateValue)
125
         */
126
        public Value notEquals(Value value) throws IncompatibleTypesException {
127
                if (value instanceof NullValue) {
128
                        return ValueFactory.createValue(false);
129
                }
130

    
131
                if (value instanceof TimestampValue) {
132
                        return new BooleanValue(!this.value.equals(
133
                                        ((TimestampValue) value).value));
134
                } else {
135
                        throw new IncompatibleTypesException();
136
                }
137
        }
138

    
139
        /**
140
         * DOCUMENT ME!
141
         *
142
         * @return DOCUMENT ME!
143
         */
144
        public String toString() {
145
                return value.toString();
146
        }
147

    
148
        /**
149
         * @see com.hardcode.gdbms.engine.values.Value#doHashCode()
150
         */
151
        public int doHashCode() {
152
                return value.hashCode();
153
        }
154

    
155
    /**
156
     * @return
157
     */
158
    public Timestamp getValue() {
159
        return value;
160
    }
161

    
162
    /**
163
     * @see com.hardcode.gdbms.engine.values.Value#getStringValue(com.hardcode.gdbms.engine.data.driver.ValueWriter)
164
     */
165
    public String getStringValue(ValueWriter writer) {
166
        return writer.getStatementString(value);
167
    }
168

    
169
    /**
170
     * @see com.hardcode.gdbms.engine.values.Value#getSQLType()
171
     */
172
    public int getSQLType() {
173
        return Types.TIMESTAMP;
174
    }
175

    
176
        public int getWidth() {
177
                return this.toString().length();
178
        }
179
}