001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: VcParamWhere.java 5468 2004-09-21 14:28:46Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.genic;
025:
026: import org.objectweb.jonas_ejb.lib.JavaType;
027:
028: /**
029: * This class is the "Velocity context" for a parameter of a where clause of finder method for CMP1 only,
030: * used in the Velocity Templates.
031: * @author Helene Joanin : Initial developer
032: */
033: public class VcParamWhere {
034:
035: /**
036: * name of the parameter (ie "p1")
037: */
038: private String mName;
039:
040: /**
041: * type's name of the parameter
042: */
043: private String mTypeName;
044:
045: /**
046: * SQL type's name of the parameter
047: */
048: private String mSqlTypeName;
049:
050: /**
051: * SQL setter method name for this parameter
052: */
053: private String mSqlSetMethod;
054:
055: /**
056: * true if the parameter hasn't a java primitive type
057: */
058: private boolean hasNotPrimitiveType;
059:
060: /**
061: * true if the parameter has the java.math.BigInteger type
062: */
063: private boolean hasBigIntegerType;
064:
065: /**
066: * true if the parameter has a Serializable type
067: */
068: private boolean hasSerializableType;
069:
070: /**
071: * true if the parameter has a java.lang.* type except java.lang.string
072: */
073: private boolean hasJavaLangTypeExceptString;
074:
075: /**
076: * VcParamWhere Constructor
077: * @param type parameter's type
078: * @param position parameter's position in the where clause
079: */
080: VcParamWhere(Class type, int position) {
081:
082: mName = new String("p" + position);
083: mTypeName = JavaType.getName(type);
084: mSqlTypeName = JavaType.getSQLType(type);
085: mSqlSetMethod = JavaType.getSQLSetMethod(type);
086: if (mSqlSetMethod == null) {
087: throw new Error(
088: "Cannot container persistence manage the type '"
089: + type.getName() + "'");
090: }
091: hasNotPrimitiveType = !type.isPrimitive();
092: hasBigIntegerType = type.equals(java.math.BigInteger.class);
093: hasSerializableType = "setSerializable".equals(mSqlSetMethod);
094: hasJavaLangTypeExceptString = false;
095: if (type.getPackage() != null) {
096: if ("java.lang".equals(type.getPackage().getName())
097: && !java.lang.String.class.equals(type)) {
098: hasJavaLangTypeExceptString = true;
099: }
100: }
101:
102: // System.out.print("VcParamWhere: "+type.toString());
103: // System.out.println(toString());
104: }
105:
106: /**
107: * @return Returns the name of the parameter (ie "p1")
108: */
109: public String getName() {
110: return mName;
111: }
112:
113: /**
114: * @return Returns the type's name of the parameter
115: */
116: public String getTypeName() {
117: return mTypeName;
118: }
119:
120: /**
121: * @return Returns the SQL type's name of the parameter
122: */
123: public String getSqlTypeName() {
124: return mSqlTypeName;
125: }
126:
127: /**
128: * @return Returns the SQL setter method associated to the parameter
129: */
130: public String getSqlSetMethod() {
131: return mSqlSetMethod;
132: }
133:
134: /**
135: * @return Returns true if the parameter's type is not a java primitive type
136: */
137: public boolean hasNotPrimitiveType() {
138: return hasNotPrimitiveType;
139: }
140:
141: /**
142: * @return Returns true if the parameter's type is java.math.BigInteger
143: */
144: public boolean hasBigIntegerType() {
145: return hasBigIntegerType;
146: }
147:
148: /**
149: * @return Returns true if the parameter's type is Serializable
150: */
151: public boolean hasSerializableType() {
152: return hasSerializableType;
153: }
154:
155: /**
156: * @return true if the parameter's type is a java.lang.* type except java.lang.string
157: */
158: public boolean hasJavaLangTypeExceptString() {
159: return hasJavaLangTypeExceptString;
160: }
161:
162: /**
163: * @return Returns a string representation of the VcParamWhere object to debug use
164: */
165: public String toString() {
166: StringBuffer ret = new StringBuffer();
167: ret.append("\n Name = " + getName());
168: ret.append("\n TypeName = " + getTypeName());
169: ret.append("\n SqlTypeName = " + getSqlTypeName());
170: ret.append("\n SqlSetMethod = " + getSqlSetMethod());
171: ret.append("\n hasNotPrimitiveType = "
172: + hasNotPrimitiveType());
173: ret.append("\n hasBigIntegerType = "
174: + hasBigIntegerType());
175: ret.append("\n hasSerializableType = "
176: + hasSerializableType());
177: ret.append("\n hasJavaLangTypeExceptString = "
178: + hasJavaLangTypeExceptString());
179: return (ret.toString());
180: }
181:
182: }
|