KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > genic > VcParamWhere


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: VcParamWhere.java,v 1.6 2004/09/21 14:28:46 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.genic;
28
29 import org.objectweb.jonas_ejb.lib.JavaType;
30
31 /**
32  * This class is the "Velocity context" for a parameter of a where clause of finder method for CMP1 only,
33  * used in the Velocity Templates.
34  * @author Helene Joanin : Initial developer
35  */

36 public class VcParamWhere {
37
38     /**
39      * name of the parameter (ie "p1")
40      */

41     private String JavaDoc mName;
42
43     /**
44      * type's name of the parameter
45      */

46     private String JavaDoc mTypeName;
47
48     /**
49      * SQL type's name of the parameter
50      */

51     private String JavaDoc mSqlTypeName;
52
53     /**
54      * SQL setter method name for this parameter
55      */

56     private String JavaDoc mSqlSetMethod;
57
58     /**
59      * true if the parameter hasn't a java primitive type
60      */

61     private boolean hasNotPrimitiveType;
62
63     /**
64      * true if the parameter has the java.math.BigInteger type
65      */

66     private boolean hasBigIntegerType;
67
68     /**
69      * true if the parameter has a Serializable type
70      */

71     private boolean hasSerializableType;
72
73     /**
74      * true if the parameter has a java.lang.* type except java.lang.string
75      */

76     private boolean hasJavaLangTypeExceptString;
77
78     /**
79      * VcParamWhere Constructor
80      * @param type parameter's type
81      * @param position parameter's position in the where clause
82      */

83     VcParamWhere(Class JavaDoc type, int position) {
84
85         mName = new String JavaDoc("p" + position);
86         mTypeName = JavaType.getName(type);
87         mSqlTypeName = JavaType.getSQLType(type);
88         mSqlSetMethod = JavaType.getSQLSetMethod(type);
89         if (mSqlSetMethod == null) {
90             throw new Error JavaDoc("Cannot container persistence manage the type '"
91                             + type.getName() + "'");
92         }
93         hasNotPrimitiveType = !type.isPrimitive();
94         hasBigIntegerType = type.equals(java.math.BigInteger JavaDoc.class);
95         hasSerializableType = "setSerializable".equals(mSqlSetMethod);
96         hasJavaLangTypeExceptString = false;
97         if (type.getPackage() != null) {
98             if ("java.lang".equals(type.getPackage().getName())
99                 && !java.lang.String JavaDoc.class.equals(type)) {
100                 hasJavaLangTypeExceptString = true;
101             }
102         }
103
104         // System.out.print("VcParamWhere: "+type.toString());
105
// System.out.println(toString());
106
}
107
108     /**
109      * @return Returns the name of the parameter (ie "p1")
110      */

111     public String JavaDoc getName() {
112         return mName;
113     }
114
115     /**
116      * @return Returns the type's name of the parameter
117      */

118     public String JavaDoc getTypeName() {
119         return mTypeName;
120     }
121
122     /**
123      * @return Returns the SQL type's name of the parameter
124      */

125     public String JavaDoc getSqlTypeName() {
126         return mSqlTypeName;
127     }
128
129     /**
130      * @return Returns the SQL setter method associated to the parameter
131      */

132     public String JavaDoc getSqlSetMethod() {
133         return mSqlSetMethod;
134     }
135
136     /**
137      * @return Returns true if the parameter's type is not a java primitive type
138      */

139     public boolean hasNotPrimitiveType() {
140         return hasNotPrimitiveType;
141     }
142
143     /**
144      * @return Returns true if the parameter's type is java.math.BigInteger
145      */

146     public boolean hasBigIntegerType() {
147         return hasBigIntegerType;
148     }
149
150     /**
151      * @return Returns true if the parameter's type is Serializable
152      */

153     public boolean hasSerializableType() {
154         return hasSerializableType;
155     }
156
157     /**
158      * @return true if the parameter's type is a java.lang.* type except java.lang.string
159      */

160     public boolean hasJavaLangTypeExceptString() {
161         return hasJavaLangTypeExceptString;
162     }
163
164     /**
165      * @return Returns a string representation of the VcParamWhere object to debug use
166      */

167     public String JavaDoc toString() {
168         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
169         ret.append("\n Name = " + getName());
170         ret.append("\n TypeName = " + getTypeName());
171         ret.append("\n SqlTypeName = " + getSqlTypeName());
172         ret.append("\n SqlSetMethod = " + getSqlSetMethod());
173         ret.append("\n hasNotPrimitiveType = " + hasNotPrimitiveType());
174         ret.append("\n hasBigIntegerType = " + hasBigIntegerType());
175         ret.append("\n hasSerializableType = " + hasSerializableType());
176         ret.append("\n hasJavaLangTypeExceptString = " + hasJavaLangTypeExceptString());
177         return (ret.toString());
178     }
179
180 }
181
Popular Tags