KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 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: FloatPkFieldMapping.java,v 1.2 2004/09/17 08:25:02 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ejb.lib;
26
27
28 /**
29  * Conversion java.lang.Float <-> java.lang.String. <br>
30  * This conversion is useful only for primary key field because JORM does not support float as primary key field.
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 FloatPkFieldMapping {
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 String 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 Float 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 Float JavaDoc ? storagevalue : new Float JavaDoc((String JavaDoc) storagevalue));
62     }
63
64     /**
65      * Converts a value from the data support into a value in memory
66      * @param memoryvalue the value in memory (can be null).
67      * @return is the value store in the support (can be null).
68      */

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