001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * Sun Public License Notice
022: *
023: * The contents of this file are subject to the Sun Public License
024: * Version 1.0 (the "License"). You may not use this file except in
025: * compliance with the License. A copy of the License is available at
026: * http://www.sun.com/
027: *
028: * The Original Code is NetBeans. The Initial Developer of the Original
029: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
030: * Microsystems, Inc. All Rights Reserved.
031: */
032:
033: package org.netbeans.modules.sql.project.dbmodel;
034:
035: import java.util.ArrayList;
036: import java.util.Iterator;
037:
038: /**
039: * Class to hold procedure metadata.
040: *
041: * @author Susan Chen
042: * @version
043: */
044: public class Procedure {
045: /** Procedure type */
046: public static final String PROCEDURE = "PROCEDURE";
047:
048: /** Function type */
049: public static final String FUNCTION = "FUNCTION";
050:
051: /** Unknown type */
052: public static final String UNKNOWN = "UNKNOWN";
053:
054: /** Parameter type IN */
055: public static final String IN = "IN";
056:
057: /** Parameter type IN/OUT */
058: public static final String INOUT = "INOUT";
059:
060: /** Parameter type OUT */
061: public static final String OUT = "OUT";
062:
063: /** Parameter type RETURN */
064: public static final String RETURN = "RETURN";
065:
066: /** Parameter type RESULT */
067: public static final String RESULT = "RESULT";
068:
069: /** Procedure types */
070: public static final String[] PROCTYPES = { PROCEDURE, FUNCTION,
071: UNKNOWN };
072:
073: /** Procedure parameter types */
074: public static final String[] PARAMTYPES = { IN, INOUT, OUT, RETURN,
075: RESULT };
076:
077: private String name = ""; // original name of procedure
078: private String javaName = ""; // java name of procedure
079: private String catalog = ""; // catalog
080: private String schema = ""; // schema
081: private String type = ""; // type: PROCEDURE, FUNCTION, UNKNOWN
082: private int numParameters = 0; // number of parameters
083: private Parameter[] parameters; // array of parameters
084: private boolean hasReturn = false; // indicates whether has any out parameters
085:
086: /**
087: * Creates an instance of Procedure with the given attributes.
088: *
089: * @param pname Procedure name
090: * @param pcatalog Catalog name
091: * @param pschema Schema name
092: * @param ptype Procedure type
093: */
094: public Procedure(String pname, String pcatalog, String pschema,
095: String ptype) {
096: name = pname;
097: catalog = pcatalog;
098: schema = pschema;
099: type = ptype;
100: }
101:
102: /**
103: * Creates an instance of Procedure with the given attributes.
104: *
105: * @param pname Procedure name
106: * @param jname Procedure java name
107: * @param pcatalog Catalog name
108: * @param pschema Schema name
109: * @param ptype Procedure type
110: */
111: public Procedure(String pname, String jname, String pcatalog,
112: String pschema, String ptype) {
113: name = pname;
114: javaName = jname;
115: catalog = pcatalog;
116: schema = pschema;
117: type = ptype;
118: }
119:
120: public Procedure(Procedure p) {
121: name = p.getName();
122: javaName = p.getJavaName();
123: catalog = p.getCatalog();
124: schema = p.getSchema();
125: type = p.getType();
126: hasReturn = p.getHasReturn();
127: cloneParameters(p.getParameters());
128: }
129:
130: /**
131: * Get the procedure name.
132: *
133: * @return Procedure name
134: */
135: public String getName() {
136: return name;
137: }
138:
139: /**
140: * Get the procedure java name.
141: *
142: * @return Procedure java name
143: */
144: public String getJavaName() {
145: return javaName;
146: }
147:
148: /**
149: * Get the catalog name.
150: *
151: * @return Catalog name
152: */
153: public String getCatalog() {
154: return catalog;
155: }
156:
157: /**
158: * Get the schema name.
159: *
160: * @return Schema name
161: */
162: public String getSchema() {
163: return schema;
164: }
165:
166: /**
167: * Get the Procedure type.
168: *
169: * @return Procedure type
170: */
171: public String getType() {
172: return type;
173: }
174:
175: /**
176: * Get the number of procedure parameters.
177: *
178: * @return Number of procedure parameters
179: */
180: public int getNumParameters() {
181: return numParameters;
182: }
183:
184: /**
185: * Get the procedure parameter list.
186: *
187: * @return Procedure parameter list
188: */
189: public Parameter[] getParameters() {
190: return parameters;
191: }
192:
193: /**
194: * Indicates whether the procedure has a return.
195: *
196: * @return Indicates whether the procedure has a return.
197: */
198: public boolean getHasReturn() {
199: return hasReturn;
200: }
201:
202: /**
203: * Set the procedure name.
204: *
205: * @param newName Procedure name
206: */
207: public void setName(String newName) {
208: name = newName;
209: }
210:
211: /**
212: * Set the procedure java name.
213: *
214: * @param newJavaName Procedure java name
215: */
216: public void setJavaName(String newJavaName) {
217: javaName = newJavaName;
218: }
219:
220: /**
221: * Set the catalog name.
222: *
223: * @param newCatalog Catalog name
224: */
225: public void setCatalog(String newCatalog) {
226: catalog = newCatalog;
227: }
228:
229: /**
230: * Set the schema name.
231: *
232: * @param newSchema Schema name
233: */
234: public void setSchema(String newSchema) {
235: schema = newSchema;
236: }
237:
238: /**
239: * Set the procedure type.
240: *
241: * @param newType Procedure type
242: */
243: public void setType(String newType) {
244: type = newType;
245: }
246:
247: /**
248: * Set the procedure parameter list.
249: *
250: * @param newParameters Procedure parameter list
251: */
252: public void setParameters(Parameter[] newParameters) {
253: parameters = newParameters;
254:
255: // update the number of parameters
256: if (parameters != null) {
257: numParameters = parameters.length;
258: } else {
259: numParameters = 0;
260: }
261: }
262:
263: /**
264: * Clone the procedure parameter list.
265: *
266: * @param newParameters Procedure parameter list
267: */
268: public void cloneParameters(Parameter[] newParameters) {
269: if (newParameters != null) {
270: numParameters = newParameters.length;
271: if (numParameters > 0) {
272: parameters = new Parameter[numParameters];
273: for (int i = 0; i < numParameters; i++) {
274: parameters[i] = new Parameter(newParameters[i]);
275: }
276: }
277: }
278: }
279:
280: /**
281: * Set the Procedure has return flag.
282: *
283: * @param newHasReturn Has Return Flag
284: */
285: public void setHasReturn(boolean newHasReturn) {
286: hasReturn = newHasReturn;
287: }
288:
289: //added abey for allowing ResultSets to be added to a Procedure.
290: private ArrayList resultSetColumns = new ArrayList();
291:
292: /**
293: * Set the ResultSet Columns of the Procedure.
294: *
295: * @param rsCols array of the ResultSetColumns of this Procedure.
296: */
297: public void setResultSetColumns(ResultSetColumns[] rsCols) {
298: this .resultSetColumns = new ArrayList();
299: for (int i = 0; i < rsCols.length; i++) {
300: resultSetColumns.add(rsCols[i]);
301: }
302: }
303:
304: /**
305: * Set the ResultSet Columns of the Procedure.
306: *
307: * @param rsCols the Arraylist containing the ResultSetColumns of this Procedure.
308: */
309: public void setResultSetColumns(ArrayList rsCols) {
310: this .resultSetColumns = rsCols;
311: }
312:
313: /**
314: * Add a ResultSetColumns to this Procedure.
315: *
316: * @param rs ResultSetColumns to be added to this Procedure.
317: */
318: public void addResultSet(ResultSetColumns rs) {
319: this .resultSetColumns.add(rs);
320: }
321:
322: public boolean removeResultSet(ResultSetColumns rs) {
323: ResultSetColumns rsCols = searchResultSetColumns(rs.getName());
324: if (rsCols != null) {
325: this .resultSetColumns.remove(rsCols);
326: return true;
327: }
328: return false;
329: }
330:
331: /**
332: * get the ResultSet Columns of the Procedure.
333: *
334: * @return an array containing the ResultSetColumns of this Procedure.
335: */
336: public ResultSetColumns[] getResultSetColumnsArray() {
337: Object[] objArray = resultSetColumns.toArray();
338: ResultSetColumns[] result = new ResultSetColumns[objArray.length];
339:
340: for (int i = 0; i < objArray.length; i++) {
341: ResultSetColumns rsCols = (ResultSetColumns) objArray[i];
342: result[i] = rsCols;
343: }
344: return result;
345: }
346:
347: /**
348: * get the ResultSet Columns of the Procedure.
349: *
350: * @return an Arraylist containing the ResultSetColumns of this Procedure.
351: */
352: public ArrayList getResultSetColumns() {
353: return resultSetColumns;
354: }
355:
356: /**
357: * Searches this Procedure for any ResultSet Columns of the given name.
358: *
359: * @return ResultSetColumns added to this Procedure if its name matches, else null.
360: */
361: public ResultSetColumns searchResultSetColumns(String rsName) {
362: if (resultSetColumns != null) {
363: Iterator rsColsIter = resultSetColumns.iterator();
364:
365: while (rsColsIter.hasNext()) {
366: ResultSetColumns rsCols = (ResultSetColumns) rsColsIter
367: .next();
368: if (rsCols.getName().equals(rsName)) {
369: return rsCols;
370: }
371: }
372: }
373: return null;
374: }
375:
376: }
|