KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > TimestampConverter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcTypeRegistry;
16 import com.versant.core.jdbc.metadata.JdbcColumn;
17
18 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
19
import java.sql.SQLException JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21 import java.sql.PreparedStatement JavaDoc;
22 import java.sql.Timestamp JavaDoc;
23
24 /**
25  * This converts java.sql.Timestamp's to and from a column using setTimestamp
26  * and getTimestamp.
27  * @keep-all
28  */

29 public class TimestampConverter extends JdbcConverterBase {
30
31     public static class Factory extends NoArgJdbcConverterFactory {
32
33         private TimestampConverter converter;
34
35         /**
36          * Create a converter for col using props as parameters. Return null if
37          * no converter is required.
38          */

39         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
40                 JdbcTypeRegistry jdbcTypeRegistry) {
41             if (converter == null) converter = new TimestampConverter();
42             return converter;
43         }
44
45     }
46
47     /**
48      * Get the value of col from rs at position index.
49      * @exception SQLException on SQL errors
50      * @exception JDOFatalDataStoreException if the ResultSet value is invalid
51      */

52     public Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
53             throws SQLException JavaDoc, JDOFatalDataStoreException {
54         return rs.getTimestamp(index);
55     }
56
57     /**
58      * Set parameter index on ps to value (for col).
59      * @exception SQLException on SQL errors
60      * @exception JDOFatalDataStoreException if value is invalid
61      */

62     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, Object JavaDoc value)
63             throws SQLException JavaDoc, JDOFatalDataStoreException {
64         if (value == null) {
65             ps.setNull(index, col.jdbcType);
66         } else {
67             ps.setTimestamp(index, (Timestamp JavaDoc)value);
68         }
69     }
70
71     /**
72      * Get the type of our expected value objects (e.g. java.util.Locale
73      * for a converter for Locale's).
74      */

75     public Class JavaDoc getValueType() {
76         return Timestamp JavaDoc.class;
77     }
78
79 }
80
81
Popular Tags