KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > sql > schema > DatabaseProcedure


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Copyright (C) 2005 Continuent, Inc.
7  * Contact: sequoia@continuent.org
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): Emmanuel Cecchet, Edward Archibald
23  */

24
25 package org.continuent.sequoia.controller.sql.schema;
26
27 import java.util.ArrayList JavaDoc;
28
29 /**
30  * Represents a database stored procedure and its metadata.
31  *
32  * @author <a HREF="mailto:ed.archibald@continuent.com">Edward Archibald</a>
33  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet
34  * </a>
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  */

37 public class DatabaseProcedure
38 {
39   /** May return a result */
40   public static final int ProcedureResultUnknown = 0;
41   /** Does not return a result */
42   public static final int ProcedureNoResult = 1;
43   /** Returns a result */
44   public static final int ProcedureReturnsResult = 2;
45
46   ArrayList JavaDoc parameters;
47   private String JavaDoc name;
48   private String JavaDoc remarks;
49   private int procedureType;
50
51   /**
52    * @param name of the procedure
53    * @param remarks of the procedure
54    * @param procedureType see above types
55    */

56   public DatabaseProcedure(String JavaDoc name, String JavaDoc remarks, int procedureType)
57   {
58     this.name = name;
59     this.remarks = remarks;
60     this.procedureType = procedureType;
61     this.parameters = new ArrayList JavaDoc();
62   }
63
64   /**
65    * Add a parameter to this procedure
66    *
67    * @param param to add
68    */

69   public void addParameter(DatabaseProcedureParameter param)
70   {
71     parameters.add(param);
72   }
73
74   /**
75    * Build a unique key based on a stored procedure name and its number of
76    * parameters. Please note that this is enough for some DBMS: Postgresql 8 for
77    * instance allows full function overloading.
78    *
79    * @param storedProcedureName stored procedure name
80    * @param nbOfParameters number of parameters
81    * @return a String representation of the key (used by HashMap in schema)
82    */

83   public static String JavaDoc buildKey(String JavaDoc storedProcedureName, int nbOfParameters)
84   {
85     return storedProcedureName + "(" + nbOfParameters + ")";
86   }
87
88   /**
89    * Returns a unique key identifying this stored procedure.
90    *
91    * @return the unique key
92    */

93   public String JavaDoc getKey()
94   {
95     if (procedureType == ProcedureReturnsResult)
96       // Strip return value from the parameter list
97
return buildKey(name, parameters.size() - 1);
98     else
99       return buildKey(name, parameters.size());
100   }
101
102   /**
103    * @return Returns the name.
104    */

105   public String JavaDoc getName()
106   {
107     return name;
108   }
109
110   /**
111    * @param name The name to set.
112    */

113   public void setName(String JavaDoc name)
114   {
115     this.name = name;
116   }
117
118   /**
119    * @return Returns the parameters.
120    */

121   public ArrayList JavaDoc getParameters()
122   {
123     return parameters;
124   }
125
126   /**
127    * @param parameters The parameters to set.
128    */

129   public void setParameters(ArrayList JavaDoc parameters)
130   {
131     this.parameters = parameters;
132   }
133
134   /**
135    * @return Returns the procedureType.
136    */

137   public int getProcedureType()
138   {
139     return procedureType;
140   }
141
142   /**
143    * @param procedureType The procedureType to set.
144    */

145   public void setProcedureType(int procedureType)
146   {
147     this.procedureType = procedureType;
148   }
149
150   /**
151    * @return Returns the remarks.
152    */

153   public String JavaDoc getRemarks()
154   {
155     return remarks;
156   }
157
158   /**
159    * @param remarks The remarks to set.
160    */

161   public void setRemarks(String JavaDoc remarks)
162   {
163     this.remarks = remarks;
164   }
165
166   /**
167    * Returns the procedureNoResult value.
168    *
169    * @return Returns the procedureNoResult.
170    */

171   public static int getProcedureNoResult()
172   {
173     return ProcedureNoResult;
174   }
175
176   /**
177    * Two <code>DatabaseProcedure</code> are considered equal if they have the
178    * same name and the same parameters.
179    *
180    * @param other the object to compare with
181    * @return <code>true</code> if the DatabaseProcedures are equal
182    */

183   public boolean equals(Object JavaDoc other)
184   {
185     if ((other == null) || !(other instanceof DatabaseProcedure))
186       return false;
187
188     DatabaseProcedure p = (DatabaseProcedure) other;
189     return getKey().equals(p.getKey());
190   }
191
192   /**
193    * @see java.lang.Object#toString()
194    */

195   public String JavaDoc toString()
196   {
197     return getKey();
198   }
199
200 }
201
Popular Tags