KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > sco > SqlTimestamp


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: SqlTimestamp.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.sco;
12
13 import com.triactive.jdo.SCO;
14 import java.io.ObjectStreamException JavaDoc;
15 import javax.jdo.JDOHelper;
16
17
18 /**
19  * A mutable second-class SQL timestamp object.
20  *
21  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
22  * @version $Revision: 1.6 $
23  */

24
25 public class SqlTimestamp extends java.sql.Timestamp JavaDoc implements SCO
26 {
27     private transient Object JavaDoc owner;
28     private transient String JavaDoc fieldName;
29
30
31     /**
32      * Creates a <code>SqlTimestamp</code> object that represents the same time
33      * as the given <tt>java.sql.Timestamp</tt>. Assigns owning object and field
34      * name.
35      *
36      * @param owner the owning object
37      * @param fieldName the owning field name
38      * @param ts the initial timestamp value
39      */

40
41     public SqlTimestamp(Object JavaDoc owner, String JavaDoc fieldName, java.sql.Timestamp JavaDoc ts)
42     {
43         super(ts.getTime());
44         super.setNanos(ts.getNanos());
45
46         this.owner = owner;
47         this.fieldName = fieldName;
48     }
49
50
51     public Object JavaDoc getOwner()
52     {
53         return owner;
54     }
55
56
57     public String JavaDoc getFieldName()
58     {
59         return fieldName;
60     }
61
62
63     public void makeDirty()
64     {
65         if (owner != null)
66             JDOHelper.makeDirty(owner, fieldName);
67     }
68
69
70     public void applyUpdates()
71     {
72     }
73
74
75     public void unsetOwner()
76     {
77         owner = null;
78         fieldName = null;
79     }
80
81
82     /**
83      * Creates and returns a copy of this object.
84      *
85      * <P>Mutable second-class Objects are required to provide a public
86      * clone method in order to allow for copying PersistenceCapable
87      * objects. In contrast to Object.clone(), this method must not throw a
88      * CloneNotSupportedException.
89      */

90
91     public Object JavaDoc clone()
92     {
93         Object JavaDoc obj = super.clone();
94
95         ((SqlTimestamp)obj).unsetOwner();
96
97         return obj;
98     }
99
100
101     public void setTime(long time)
102     {
103         super.setTime(time);
104         makeDirty();
105     }
106
107
108     public void setNanos(int n)
109     {
110         super.setNanos(n);
111         makeDirty();
112     }
113
114
115     /**
116      * Sets the year of this <tt>Date</tt> object to be the specified
117      * value plus 1900. This <code>Date</code> object is modified so
118      * that it represents a point in time within the specified year,
119      * with the month, date, hour, minute, and second the same as
120      * before, as interpreted in the local time zone. (Of course, if
121      * the date was February 29, for example, and the year is set to a
122      * non-leap year, then the new date will be treated as if it were
123      * on March 1.)
124      *
125      * @param year the year value.
126      * @see java.util.Calendar
127      * @deprecated As of JDK version 1.1,
128      * replaced by <code>Calendar.set(Calendar.YEAR, year + 1900)</code>.
129      */

130
131     public void setYear(int year)
132     {
133         super.setYear(year);
134         makeDirty();
135     }
136
137
138     /**
139      * Sets the month of this date to the specified value. This
140      * <tt>Date</tt> object is modified so that it represents a point
141      * in time within the specified month, with the year, date, hour,
142      * minute, and second the same as before, as interpreted in the
143      * local time zone. If the date was October 31, for example, and
144      * the month is set to June, then the new date will be treated as
145      * if it were on July 1, because June has only 30 days.
146      *
147      * @param month the month value between 0-11.
148      * @see java.util.Calendar
149      * @deprecated As of JDK version 1.1,
150      * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
151      */

152
153     public void setMonth(int month)
154     {
155         super.setMonth(month);
156         makeDirty();
157     }
158
159
160     /**
161      * Sets the day of the month of this <tt>Date</tt> object to the
162      * specified value. This <tt>Date</tt> object is modified so that
163      * it represents a point in time within the specified day of the
164      * month, with the year, month, hour, minute, and second the same
165      * as before, as interpreted in the local time zone. If the date
166      * was April 30, for example, and the date is set to 31, then it
167      * will be treated as if it were on May 1, because April has only
168      * 30 days.
169      *
170      * @param date the day of the month value between 1-31.
171      * @see java.util.Calendar
172      * @deprecated As of JDK version 1.1,
173      * replaced by <code>Calendar.set(Calendar.DAY_OF_MONTH, int date)</code>.
174      */

175
176     public void setDate(int date)
177     {
178         super.setDate(date);
179         makeDirty();
180     }
181
182
183     /**
184      * Sets the hour of this <tt>Date</tt> object to the specified value.
185      * This <tt>Date</tt> object is modified so that it represents a point
186      * in time within the specified hour of the day, with the year, month,
187      * date, minute, and second the same as before, as interpreted in the
188      * local time zone.
189      *
190      * @param hours the hour value.
191      * @see java.util.Calendar
192      * @deprecated As of JDK version 1.1,
193      * replaced by <code>Calendar.set(Calendar.HOUR_OF_DAY, int hours)</code>.
194      */

195
196     public void setHours(int hours)
197     {
198         super.setHours(hours);
199         makeDirty();
200     }
201
202
203     /**
204      * Sets the minutes of this <tt>Date</tt> object to the specified value.
205      * This <tt>Date</tt> object is modified so that it represents a point
206      * in time within the specified minute of the hour, with the year, month,
207      * date, hour, and second the same as before, as interpreted in the
208      * local time zone.
209      *
210      * @param minutes the value of the minutes.
211      * @see java.util.Calendar
212      * @deprecated As of JDK version 1.1,
213      * replaced by <code>Calendar.set(Calendar.MINUTE, int minutes)</code>.
214      */

215
216     public void setMinutes(int minutes)
217     {
218         super.setMinutes(minutes);
219         makeDirty();
220     }
221
222
223     /**
224      * Sets the seconds of this <tt>Date</tt> to the specified value.
225      * This <tt>Date</tt> object is modified so that it represents a
226      * point in time within the specified second of the minute, with
227      * the year, month, date, hour, and minute the same as before, as
228      * interpreted in the local time zone.
229      *
230      * @param seconds the seconds value.
231      * @see java.util.Calendar
232      * @deprecated As of JDK version 1.1,
233      * replaced by <code>Calendar.set(Calendar.SECOND, int seconds)</code>.
234      */

235
236     public void setSeconds(int seconds)
237     {
238         super.setSeconds(seconds);
239         makeDirty();
240     }
241
242
243     /**
244      * Replaces the object to be serialized with a java.sql.Timestamp object.
245      * Invoked by the serialization mechanism to obtain an alternative object
246      * to be used when writing an object to the stream.
247      *
248      * @return
249      * The <code>java.sql.Timestamp</code> to be serialized instead of this
250      * object.
251      */

252
253     protected Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc
254     {
255         java.sql.Timestamp JavaDoc ts = new java.sql.Timestamp JavaDoc(getTime());
256
257         ts.setNanos(getNanos());
258
259         return ts;
260     }
261 }
262
Popular Tags