01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: DateMapping.java,v 1.3 2003/08/04 16:40:35 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import com.triactive.jdo.PersistenceManager;
14: import java.sql.PreparedStatement;
15: import java.sql.ResultSet;
16: import java.sql.Timestamp;
17: import java.util.Date;
18:
19: public class DateMapping extends SqlTimestampMapping {
20: public DateMapping(DatabaseAdapter dba, Class type) {
21: super (dba, type);
22: }
23:
24: public DateMapping(Column col) {
25: super (col);
26: }
27:
28: public DateMapping(ClassBaseTable table, int relativeFieldNumber) {
29: super (table, relativeFieldNumber);
30: }
31:
32: public void setObject(PersistenceManager pm, PreparedStatement ps,
33: int param, Object value) {
34: super .setObject(pm, ps, param, value == null ? null
35: : new Timestamp(((Date) value).getTime()));
36: }
37:
38: public Object getObject(PersistenceManager pm, ResultSet rs,
39: int param) {
40: Timestamp value = getTimestamp(rs, param);
41:
42: if (value == null)
43: return null;
44: else
45: return new Date(value.getTime());
46: }
47:
48: public SQLExpression newSQLLiteral(QueryStatement qs, Object value) {
49: return super .newSQLLiteral(qs, new Timestamp(((Date) value)
50: .getTime()));
51: }
52: }
|