Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

DatabaseProcedureParameter.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): Marc Wick
00023  */
00024 
00025 package org.objectweb.cjdbc.common.sql.schema;
00026 
00027 import java.io.Serializable;
00028 import java.sql.Types;
00029 
00030 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00031 
00032 /**
00033  * Represents a parameter of procedure
00034  * 
00035  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00036  */
00037 public class DatabaseProcedureParameter implements Serializable
00038 {
00039   /** kind of column/parameter */
00040 
00041   /** nobody knows */
00042   public static final int ProcedureColumnUnknown   = 0;
00043   /** IN parameter */
00044   public static final int ProcedureColumnIn        = 1;
00045   /** INOUT parameter */
00046   public static final int ProcedureColumnInOut     = 2;
00047   /** OUT parameter */
00048   public static final int ProcedureColumnOut       = 3;
00049   /** procedure return value */
00050   public static final int ProcedureColumnReturn    = 4;
00051   /** procedure return value */
00052   public static final int ProcedureColumnResult    = 5;
00053 
00054   /** Can it contain NULL ? */
00055   /** does not allow NULL values */
00056   public static final int ProcedureNoNulls         = 0;
00057   /** allows NULL values */
00058   public static final int ProcedureNullable        = 1;
00059   /** nullability unknown */
00060   public static final int ProcedureNullableUnknown = 2;
00061 
00062   private String          name;
00063   private int             columnType;
00064   private int             dataType;
00065   private String          typeName;
00066   private float           precision;
00067   private int             length;
00068   private int             scale;
00069   private int             radix;
00070   private int             nullable;
00071   private String          remarks;
00072 
00073   /**
00074    * get null ability given a string
00075    * 
00076    * @param nullable recognized are "nonulls" and "nullable"
00077    * @return value given the java specification
00078    */
00079   public static int getNullFromString(String nullable)
00080   {
00081     if (nullable.equalsIgnoreCase(DatabasesXmlTags.VAL_noNulls))
00082       return ProcedureNoNulls;
00083     if (nullable.equalsIgnoreCase(DatabasesXmlTags.VAL_nullable))
00084       return ProcedureNullable;
00085     else
00086       return ProcedureNullableUnknown;
00087   }
00088 
00089   /**
00090    * get null ability given an int
00091    * 
00092    * @param nullable as an integer
00093    * @return a string conformed to dtd
00094    */
00095   public static String getNullFromInt(int nullable)
00096   {
00097     switch (nullable)
00098     {
00099       case ProcedureNoNulls :
00100         return DatabasesXmlTags.VAL_noNulls;
00101       case ProcedureNullable :
00102         return DatabasesXmlTags.VAL_nullable;
00103       case ProcedureNullableUnknown :
00104       default :
00105         return DatabasesXmlTags.VAL_nullableUnknown;
00106     }
00107   }
00108 
00109   /**
00110    * get column type given an int
00111    * 
00112    * @param type as an int from the java specification
00113    * @return a description as a string
00114    */
00115   public static String getColumnTypeFromInt(int type)
00116   {
00117     switch (type)
00118     {
00119       case ProcedureColumnIn :
00120         return DatabasesXmlTags.VAL_in;
00121       case ProcedureColumnOut :
00122         return DatabasesXmlTags.VAL_out;
00123       case ProcedureColumnInOut :
00124         return DatabasesXmlTags.VAL_inout;
00125       case ProcedureColumnReturn :
00126         return DatabasesXmlTags.VAL_return;
00127       case ProcedureColumnResult :
00128         return DatabasesXmlTags.VAL_result;
00129       case ProcedureColumnUnknown :
00130       default :
00131         return DatabasesXmlTags.VAL_unknown;
00132     }
00133   }
00134 
00135   /**
00136    * get type from string
00137    * 
00138    * @param type of the parameter
00139    * @return value given the java specification
00140    */
00141   public static int getColumnTypeFromString(String type)
00142   {
00143     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_in))
00144       return ProcedureColumnIn;
00145     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_out))
00146       return ProcedureColumnOut;
00147     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_inout))
00148       return ProcedureColumnInOut;
00149     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_return))
00150       return ProcedureColumnReturn;
00151     if (type.equalsIgnoreCase(DatabasesXmlTags.VAL_result))
00152       return ProcedureColumnResult;
00153     else
00154       return ProcedureColumnUnknown;
00155   }
00156 
00157   /**
00158    * Reduced version of constructor for static schemas
00159    * 
00160    * @param name column/parameter name
00161    * @param columnType kind of column/parameter
00162    * @param nullable can it contain NULL?
00163    */
00164   public DatabaseProcedureParameter(String name, int columnType, int nullable)
00165   {
00166     this(name, columnType, Types.VARCHAR, "VARCHAR", 0, 0, 0, 0, nullable, "");
00167   }
00168 
00169   /**
00170    * @param name column/parameter name
00171    * @param columnType kind of column/parameter
00172    * @param dataType SQL type from java.sql.Types
00173    * @param typeName SQL type name, for a UDT type the type name is fully
00174    *          qualified
00175    * @param precision precision
00176    * @param length length in bytes of data
00177    * @param scale scale
00178    * @param radix radix
00179    * @param nullable can it contain NULL?
00180    * @param remarks comment describing parameter/column
00181    */
00182   public DatabaseProcedureParameter(String name, int columnType, int dataType,
00183       String typeName, float precision, int length, int scale, int radix,
00184       int nullable, String remarks)
00185   {
00186     this.name = name;
00187     this.columnType = columnType;
00188     this.dataType = dataType;
00189     this.typeName = typeName;
00190     this.precision = precision;
00191     this.length = length;
00192     this.scale = scale;
00193     this.radix = radix;
00194     this.nullable = nullable;
00195     this.remarks = remarks;
00196   }
00197 
00198   /**
00199    * @return Returns the columnType.
00200    */
00201   public final int getColumnType()
00202   {
00203     return columnType;
00204   }
00205 
00206   /**
00207    * @param columnType The columnType to set.
00208    */
00209   public final void setColumnType(int columnType)
00210   {
00211     this.columnType = columnType;
00212   }
00213 
00214   /**
00215    * @return Returns the dataType.
00216    */
00217   public final int getDataType()
00218   {
00219     return dataType;
00220   }
00221 
00222   /**
00223    * @param dataType The dataType to set.
00224    */
00225   public final void setDataType(int dataType)
00226   {
00227     this.dataType = dataType;
00228   }
00229 
00230   /**
00231    * @return Returns the length.
00232    */
00233   public final int getLength()
00234   {
00235     return length;
00236   }
00237 
00238   /**
00239    * @param length The length to set.
00240    */
00241   public final void setLength(int length)
00242   {
00243     this.length = length;
00244   }
00245 
00246   /**
00247    * @return Returns the name.
00248    */
00249   public final String getName()
00250   {
00251     return name;
00252   }
00253 
00254   /**
00255    * @param name The name to set.
00256    */
00257   public final void setName(String name)
00258   {
00259     this.name = name;
00260   }
00261 
00262   /**
00263    * @return Returns the nullable.
00264    */
00265   public final int getNullable()
00266   {
00267     return nullable;
00268   }
00269 
00270   /**
00271    * @param nullable The nullable to set.
00272    */
00273   public final void setNullable(int nullable)
00274   {
00275     this.nullable = nullable;
00276   }
00277 
00278   /**
00279    * @return Returns the precision.
00280    */
00281   public final float getPrecision()
00282   {
00283     return precision;
00284   }
00285 
00286   /**
00287    * @param precision The precision to set.
00288    */
00289   public final void setPrecision(int precision)
00290   {
00291     this.precision = precision;
00292   }
00293 
00294   /**
00295    * @return Returns the radix.
00296    */
00297   public final int getRadix()
00298   {
00299     return radix;
00300   }
00301 
00302   /**
00303    * @param radix The radix to set.
00304    */
00305   public final void setRadix(int radix)
00306   {
00307     this.radix = radix;
00308   }
00309 
00310   /**
00311    * @return Returns the remarks.
00312    */
00313   public final String getRemarks()
00314   {
00315     return remarks;
00316   }
00317 
00318   /**
00319    * @param remarks The remarks to set.
00320    */
00321   public final void setRemarks(String remarks)
00322   {
00323     this.remarks = remarks;
00324   }
00325 
00326   /**
00327    * @return Returns the scale.
00328    */
00329   public final int getScale()
00330   {
00331     return scale;
00332   }
00333 
00334   /**
00335    * @param scale The scale to set.
00336    */
00337   public final void setScale(int scale)
00338   {
00339     this.scale = scale;
00340   }
00341 
00342   /**
00343    * @return Returns the typeName.
00344    */
00345   public final String getTypeName()
00346   {
00347     return typeName;
00348   }
00349 
00350   /**
00351    * @param typeName The typeName to set.
00352    */
00353   public final void setTypeName(String typeName)
00354   {
00355     this.typeName = typeName;
00356   }
00357 
00358   /**
00359    * Two <code>DatabaseProcedureParameter</code> are considered equal if they
00360    * have the same name and the same descriptive attributes.
00361    * 
00362    * @param other the object to compare with
00363    * @return <code>true</code> if the DatabaseProcedureParameter are equal
00364    */
00365   public boolean equals(Object other)
00366   {
00367     if ((other == null) || !(other instanceof DatabaseProcedureParameter))
00368       return false;
00369 
00370     DatabaseProcedureParameter p = (DatabaseProcedureParameter) other;
00371 
00372     // first we check simple types
00373     if (!(p.columnType == columnType && p.dataType == dataType
00374         && p.precision == precision && p.length == length && p.scale == scale
00375         && p.radix == radix && p.nullable == nullable))
00376     {
00377       return false;
00378     }
00379 
00380     // now we compare object types
00381     if (!(name == null ? p.name == null : name.equals(p.name)))
00382     {
00383       return false;
00384     }
00385 
00386     if (!(typeName == null ? p.typeName == null : typeName.equals(p.typeName)))
00387     {
00388       return false;
00389     }
00390 
00391     return remarks == null ? p.remarks == null : remarks.equals(p.remarks);
00392   }
00393 
00394   /**
00395    * Get xml information about this procedure.
00396    * 
00397    * @return xml formatted information on this database procedure.
00398    */
00399   public String getXml()
00400   {
00401     StringBuffer info = new StringBuffer();
00402     info.append("<" + DatabasesXmlTags.ELT_DatabaseProcedureColumn + " "
00403         + DatabasesXmlTags.ATT_name + "=\"" + name + "\"" + " "
00404         + DatabasesXmlTags.ATT_paramType + "=\""
00405         + getColumnTypeFromInt(columnType) + "\"" + " "
00406         + DatabasesXmlTags.ATT_nullable + "=\"" + getNullFromInt(nullable)
00407         + "\"/>");
00408     return info.toString();
00409   }
00410 
00411 }

Generated on Mon Apr 11 22:01:31 2005 for C-JDBC by  doxygen 1.3.9.1