KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > lib > SqlTimeFieldMapping


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SqlTimeFieldMapping.java,v 1.2 2004/09/17 08:25:02 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.lib;
27
28 /**
29  * Conversion java.util.Date <-> java.sql.Time. <br>
30  * The StorageType is the JORM type, and the MemoryType is the JOnAS type (bean field type).
31  * @author Helene Joanin
32  */

33 public class SqlTimeFieldMapping {
34
35     /**
36      * Retrieves the java type corresponding to the type into the data support.
37      * @return a Class object (never null).
38      */

39     public static Class JavaDoc getStorageType() {
40         return java.util.Date JavaDoc.class;
41     }
42
43     /**
44      * Retrieves the java type corresponding to the type in memory.
45      * @return a Class object (never null).
46      */

47     public static Class JavaDoc getMemoryType() {
48         return java.sql.Time JavaDoc.class;
49     }
50
51     /**
52      * Converts a value from the data support into a value in memory
53      * @param storagevalue is the value store in the support (can be null).
54      * @return the value in memory (can be null).
55      */

56     public static Object JavaDoc toMemory(Object JavaDoc storagevalue) {
57         if (storagevalue == null) {
58             return null;
59         }
60         return (storagevalue instanceof java.sql.Time JavaDoc
61                 ? storagevalue
62                 : new java.sql.Time JavaDoc(((java.util.Date JavaDoc) storagevalue).getTime()));
63     }
64
65     /**
66      * Converts a value from the data support into a value in memory
67      * @param memoryvalue the value in memory (can be null).
68      * @return is the value store in the support (can be null).
69      */

70     public static Object JavaDoc toStorage(Object JavaDoc memoryvalue) {
71         return memoryvalue;
72     }
73 }
74
Popular Tags