KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > DateMapping


1 /*
2  * Copyright 2002 (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: DateMapping.java,v 1.3 2003/08/04 16:40:35 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.PersistenceManager;
14 import java.sql.PreparedStatement JavaDoc;
15 import java.sql.ResultSet JavaDoc;
16 import java.sql.Timestamp JavaDoc;
17 import java.util.Date JavaDoc;
18
19
20 public class DateMapping extends SqlTimestampMapping
21 {
22     public DateMapping(DatabaseAdapter dba, Class JavaDoc type)
23     {
24         super(dba, type);
25     }
26
27     public DateMapping(Column col)
28     {
29         super(col);
30     }
31
32     public DateMapping(ClassBaseTable table, int relativeFieldNumber)
33     {
34         super(table, relativeFieldNumber);
35     }
36
37     public void setObject(PersistenceManager pm, PreparedStatement JavaDoc ps, int param, Object JavaDoc value)
38     {
39         super.setObject(pm, ps, param, value == null ? null : new Timestamp JavaDoc(((Date JavaDoc)value).getTime()));
40     }
41
42     public Object JavaDoc getObject(PersistenceManager pm, ResultSet JavaDoc rs, int param)
43     {
44         Timestamp JavaDoc value = getTimestamp(rs, param);
45
46         if (value == null)
47             return null;
48         else
49             return new Date JavaDoc(value.getTime());
50     }
51
52     public SQLExpression newSQLLiteral(QueryStatement qs, Object JavaDoc value)
53     {
54         return super.newSQLLiteral(qs, new Timestamp JavaDoc(((Date JavaDoc)value).getTime()));
55     }
56 }
57
Popular Tags