KickJava   Java API By Example, From Geeks To Geeks.

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


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: SqlDateFieldMapping.java,v 1.2 2004/09/09 13:55:39 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

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

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

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

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

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

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