01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999-2004 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 5396 2004-09-09 13:55:39Z joaninh $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas_ejb.lib;
25:
26: /**
27: * Conversion java.util.Date <-> java.sql.Date. <br>
28: * The StorageType is the JORM type, and the MemoryType is the JOnAS type (bean field type).
29: * @author Helene Joanin
30: */
31: public class SqlDateFieldMapping {
32:
33: /**
34: * Retrieves the java type corresponding to the type into the data support.
35: * @return a Class object (never null).
36: */
37: public static Class getStorageType() {
38: return java.util.Date.class;
39: }
40:
41: /**
42: * Retrieves the java type corresponding to the type in memory.
43: * @return a Class object (never null).
44: */
45: public static Class getMemoryType() {
46: return java.sql.Date.class;
47: }
48:
49: /**
50: * Converts a value from the data support into a value in memory
51: * @param storagevalue is the value store in the support (can be null).
52: * @return the value in memory (can be null).
53: */
54: public static Object toMemory(Object storagevalue) {
55: if (storagevalue == null) {
56: return null;
57: }
58: return (storagevalue instanceof java.sql.Date ? storagevalue
59: : new java.sql.Date(((java.util.Date) storagevalue)
60: .getTime()));
61: }
62:
63: /**
64: * Converts a value from the data support into a value in memory
65: * @param memoryvalue the value in memory (can be null).
66: * @return is the value store in the support (can be null).
67: */
68: public static Object toStorage(Object memoryvalue) {
69: return memoryvalue;
70: }
71: }
|