KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > sql > schema > DatabaseProcedureParameter


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): Marc Wick, Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.common.sql.schema;
26
27 import java.sql.Types JavaDoc;
28
29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
30
31 /**
32  * Represents a parameter of procedure
33  *
34  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
35  */

36 public class DatabaseProcedureParameter
37 {
38   /** kind of column/parameter */
39
40   /** nobody knows */
41   public static final int ProcedureColumnUnknown = 0;
42   /** IN parameter */
43   public static final int ProcedureColumnIn = 1;
44   /** INOUT parameter */
45   public static final int ProcedureColumnInOut = 2;
46   /** OUT parameter */
47   public static final int ProcedureColumnOut = 3;
48   /** procedure return value */
49   public static final int ProcedureColumnReturn = 4;
50   /** procedure return value */
51   public static final int ProcedureColumnResult = 5;
52
53   /** Can it contain NULL ? */
54   /** does not allow NULL values */
55   public static final int ProcedureNoNulls = 0;
56   /** allows NULL values */
57   public static final int ProcedureNullable = 1;
58   /** nullability unknown */
59   public static final int ProcedureNullableUnknown = 2;
60
61   private String JavaDoc name;
62   private int columnType;
63   private int dataType;
64   private String JavaDoc typeName;
65   private float precision;
66   private int length;
67   private int scale;
68   private int radix;
69   private int nullable;
70   private String JavaDoc remarks;
71
72   /**
73    * get null ability given a string
74    *
75    * @param nullable recognized are "nonulls" and "nullable"
76    * @return value given the java specification
77    */

78   public static int getNullFromString(String JavaDoc nullable)
79   {
80     if (nullable.equalsIgnoreCase(DatabasesXmlTags.VAL_noNulls))
81       return ProcedureNoNulls;
82     if (nullable.equalsIgnoreCase(DatabasesXmlTags.VAL_nullable))
83       return ProcedureNullable;
84     else
85       return ProcedureNullableUnknown;
86   }
87
88   /**
89    * get null ability given an int
90    *
91    * @param nullable as an integer
92    * @return a string conformed to dtd
93    */

94   public static String JavaDoc getNullFromInt(int nullable)
95   {
96     switch (nullable)
97     {
98       case ProcedureNoNulls :
99         return DatabasesXmlTags.VAL_noNulls;
100       case ProcedureNullable :
101         return DatabasesXmlTags.VAL_nullable;
102       case ProcedureNullableUnknown :
103       default :
104         return DatabasesXmlTags.VAL_nullableUnknown;
105     }
106   }
107
108   /**
109    * get column type given an int
110    *
111    * @param type as an int from the java specification
112    * @return a description as a string
113    */

114   public static String JavaDoc getColumnTypeFromInt(int type)
115   {
116     switch (type)
117     {
118       case ProcedureColumnIn :
119         return DatabasesXmlTags.VAL_in;
120       case ProcedureColumnOut :
121         return DatabasesXmlTags.VAL_out;
122       case ProcedureColumnInOut :
123         return DatabasesXmlTags.VAL_inout;
124       case ProcedureColumnReturn :
125         return DatabasesXmlTags.VAL_return;
126       case ProcedureColumnResult :
127         return DatabasesXmlTags.VAL_result;
128       case ProcedureColumnUnknown :
129       default :
130         return DatabasesXmlTags.VAL_unknown;
131     }
132   }
133
134   /**
135    * get type from string
136    *
137    * @param type of the parameter
138    * @return value given the java specification
139    */

140   public static int getColumnTypeFromString(String JavaDoc type)
141   {
142     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_in))
143       return ProcedureColumnIn;
144     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_out))
145       return ProcedureColumnOut;
146     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_inout))
147       return ProcedureColumnInOut;
148     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_return))
149       return ProcedureColumnReturn;
150     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_result))
151       return ProcedureColumnResult;
152     else
153       return ProcedureColumnUnknown;
154   }
155
156   /**
157    * Reduced version of constructor for static schemas
158    *
159    * @param name column/parameter name
160    * @param columnType kind of column/parameter
161    * @param nullable can it contain NULL?
162    */

163   public DatabaseProcedureParameter(String JavaDoc name, int columnType, int nullable)
164   {
165     this(name, columnType, Types.VARCHAR, "VARCHAR", 0, 0, 0, 0, nullable, "");
166   }
167
168   /**
169    * @param name column/parameter name
170    * @param columnType kind of column/parameter
171    * @param dataType SQL type from java.sql.Types
172    * @param typeName SQL type name, for a UDT type the type name is fully
173    * qualified
174    * @param precision precision
175    * @param length length in bytes of data
176    * @param scale scale
177    * @param radix radix
178    * @param nullable can it contain NULL?
179    * @param remarks comment describing parameter/column
180    */

181   public DatabaseProcedureParameter(String JavaDoc name, int columnType, int dataType,
182       String JavaDoc typeName, float precision, int length, int scale, int radix,
183       int nullable, String JavaDoc remarks)
184   {
185     this.name = name;
186     this.columnType = columnType;
187     this.dataType = dataType;
188     this.typeName = typeName;
189     this.precision = precision;
190     this.length = length;
191     this.scale = scale;
192     this.radix = radix;
193     this.nullable = nullable;
194     this.remarks = remarks;
195   }
196
197   /**
198    * @return Returns the columnType.
199    */

200   public final int getColumnType()
201   {
202     return columnType;
203   }
204
205   /**
206    * @param columnType The columnType to set.
207    */

208   public final void setColumnType(int columnType)
209   {
210     this.columnType = columnType;
211   }
212
213   /**
214    * @return Returns the dataType.
215    */

216   public final int getDataType()
217   {
218     return dataType;
219   }
220
221   /**
222    * @param dataType The dataType to set.
223    */

224   public final void setDataType(int dataType)
225   {
226     this.dataType = dataType;
227   }
228
229   /**
230    * @return Returns the length.
231    */

232   public final int getLength()
233   {
234     return length;
235   }
236
237   /**
238    * @param length The length to set.
239    */

240   public final void setLength(int length)
241   {
242     this.length = length;
243   }
244
245   /**
246    * @return Returns the name.
247    */

248   public final String JavaDoc getName()
249   {
250     return name;
251   }
252
253   /**
254    * @param name The name to set.
255    */

256   public final void setName(String JavaDoc name)
257   {
258     this.name = name;
259   }
260
261   /**
262    * @return Returns the nullable.
263    */

264   public final int getNullable()
265   {
266     return nullable;
267   }
268
269   /**
270    * @param nullable The nullable to set.
271    */

272   public final void setNullable(int nullable)
273   {
274     this.nullable = nullable;
275   }
276
277   /**
278    * @return Returns the precision.
279    */

280   public final float getPrecision()
281   {
282     return precision;
283   }
284
285   /**
286    * @param precision The precision to set.
287    */

288   public final void setPrecision(int precision)
289   {
290     this.precision = precision;
291   }
292
293   /**
294    * @return Returns the radix.
295    */

296   public final int getRadix()
297   {
298     return radix;
299   }
300
301   /**
302    * @param radix The radix to set.
303    */

304   public final void setRadix(int radix)
305   {
306     this.radix = radix;
307   }
308
309   /**
310    * @return Returns the remarks.
311    */

312   public final String JavaDoc getRemarks()
313   {
314     return remarks;
315   }
316
317   /**
318    * @param remarks The remarks to set.
319    */

320   public final void setRemarks(String JavaDoc remarks)
321   {
322     this.remarks = remarks;
323   }
324
325   /**
326    * @return Returns the scale.
327    */

328   public final int getScale()
329   {
330     return scale;
331   }
332
333   /**
334    * @param scale The scale to set.
335    */

336   public final void setScale(int scale)
337   {
338     this.scale = scale;
339   }
340
341   /**
342    * @return Returns the typeName.
343    */

344   public final String JavaDoc getTypeName()
345   {
346     return typeName;
347   }
348
349   /**
350    * @param typeName The typeName to set.
351    */

352   public final void setTypeName(String JavaDoc typeName)
353   {
354     this.typeName = typeName;
355   }
356
357   /**
358    * Two <code>DatabaseProcedureParameter</code> are considered equal if they
359    * have the same name and the same descriptive attributes.
360    *
361    * @param other the object to compare with
362    * @return <code>true</code> if the DatabaseProcedureParameter are equal
363    */

364   public boolean equals(Object JavaDoc other)
365   {
366     if ((other == null) || !(other instanceof DatabaseProcedureParameter))
367       return false;
368
369     DatabaseProcedureParameter p = (DatabaseProcedureParameter) other;
370
371     // first we check simple types
372
if (!(p.columnType == columnType && p.dataType == dataType
373         && p.precision == precision && p.length == length && p.scale == scale
374         && p.radix == radix && p.nullable == nullable))
375     {
376       return false;
377     }
378
379     // now we compare object types
380
if (!(name == null ? p.name == null : name.equals(p.name)))
381     {
382       return false;
383     }
384
385     if (!(typeName == null ? p.typeName == null : typeName.equals(p.typeName)))
386     {
387       return false;
388     }
389
390     return remarks == null ? p.remarks == null : remarks.equals(p.remarks);
391   }
392
393   /**
394    * Get xml information about this procedure.
395    *
396    * @return xml formatted information on this database procedure.
397    */

398   public String JavaDoc getXml()
399   {
400     StringBuffer JavaDoc info = new StringBuffer JavaDoc();
401     info.append("<" + DatabasesXmlTags.ELT_DatabaseProcedureColumn + " "
402         + DatabasesXmlTags.ATT_name + "=\"" + name + "\"" + " "
403         + DatabasesXmlTags.ATT_paramType + "=\""
404         + getColumnTypeFromInt(columnType) + "\"" + " "
405         + DatabasesXmlTags.ATT_nullable + "=\"" + getNullFromInt(nullable)
406         + "\"/>");
407     return info.toString();
408   }
409
410 }
Popular Tags