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: /**
036: * Class to hold prepared statement metadata.
037: *
038: * @author Susan Chen
039: * @version
040: */
041: public class PrepStmt {
042: private String name = ""; // name of prepared statement
043: private String javaName = ""; // java name of prepared statement
044: private String catalog = ""; // catalog
045: private String schema = ""; // schema
046: private String sqlText = ""; // SQL text
047: private int numParameters = 0; // number of parameters
048: private Parameter[] parameters; // array of parameters
049: private int numResultSetColumns = 0; // number of resultset columns
050: private ResultSetColumn[] resultsetColumns; // array of resultset columns
051:
052: /**
053: * Creates a new instance of PrepStmt.
054: */
055: public PrepStmt() {
056: name = "";
057: catalog = "";
058: schema = "";
059: sqlText = "";
060: numParameters = 0;
061: parameters = null;
062: numResultSetColumns = 0;
063: resultsetColumns = null;
064: }
065:
066: /**
067: * Creates a new instance of PrepStmt with the given name.
068: * @param pname Prepared statement name.
069: */
070: public PrepStmt(String pname) {
071: name = pname;
072: catalog = "";
073: schema = "";
074: sqlText = "";
075: numParameters = 0;
076: parameters = null;
077: numResultSetColumns = 0;
078: resultsetColumns = null;
079: }
080:
081: /**
082: * Creates a new instance of PrepStmt with the given attributes.
083: *
084: * @param pname Prepared statement name
085: * @param pcatalog Catalog name
086: * @param pschema Schema name
087: * @param psqltext Prepared statement SQL text
088: */
089: public PrepStmt(String pname, String pcatalog, String pschema,
090: String psqltext) {
091: name = pname;
092: javaName = "";
093: catalog = pcatalog;
094: schema = pschema;
095: sqlText = psqltext;
096: numParameters = 0;
097: parameters = null;
098: numResultSetColumns = 0;
099: resultsetColumns = null;
100: }
101:
102: /**
103: * Creates a new instance of PrepStmt with the given attributes.
104: *
105: * @param pname Prepared statement name
106: * @param pname Prepared statement java name
107: * @param pcatalog Catalog name
108: * @param pschema Schema name
109: * @param psqltext Prepared statement SQL text
110: */
111: public PrepStmt(String pname, String jname, String pcatalog,
112: String pschema, String psqltext) {
113: name = pname;
114: javaName = jname;
115: catalog = pcatalog;
116: schema = pschema;
117: sqlText = psqltext;
118: numParameters = 0;
119: parameters = null;
120: numResultSetColumns = 0;
121: resultsetColumns = null;
122: }
123:
124: public PrepStmt(PrepStmt p) {
125: name = p.getName();
126: javaName = p.getJavaName();
127: catalog = p.getCatalog();
128: schema = p.getSchema();
129: sqlText = p.getSQLText();
130: cloneParameters(p.getParameters());
131: cloneResultSetColumns(p.getResultSetColumns());
132: }
133:
134: /**
135: * Get the prepared statement name.
136: *
137: * @return Prepared statement name
138: */
139: public String getName() {
140: return name;
141: }
142:
143: /**
144: * Get the prepared statement java name.
145: *
146: * @return Prepared statement java name
147: */
148: public String getJavaName() {
149: return javaName;
150: }
151:
152: /**
153: * Get the catalog name.
154: *
155: * @return Catalog name
156: */
157: public String getCatalog() {
158: return catalog;
159: }
160:
161: /**
162: * Get the schema name.
163: *
164: * @return Schema name
165: */
166: public String getSchema() {
167: return schema;
168: }
169:
170: /**
171: * Get the Prepared statement SQL text.
172: *
173: * @return Prepared statement SQL text.
174: */
175: public String getSQLText() {
176: return sqlText;
177: }
178:
179: /**
180: * Get the number of parameters in the prepared statement.
181: *
182: * @return Number of parameters
183: */
184: public int getNumParameters() {
185: return numParameters;
186: }
187:
188: /**
189: * Get the Prepared Statement parameter list.
190: *
191: * @return Parameter list
192: */
193: public Parameter[] getParameters() {
194: return parameters;
195: }
196:
197: /**
198: * Get the number of resultset columns.
199: *
200: * @return Number of resultset columns
201: */
202: public int getNumResultSetColumns() {
203: return numResultSetColumns;
204: }
205:
206: /**
207: * Get the Prepared Statement resultset columns list.
208: *
209: * @return ResultSet column list
210: */
211: public ResultSetColumn[] getResultSetColumns() {
212: return resultsetColumns;
213: }
214:
215: /**
216: * Set the prepared statement name.
217: *
218: * @param newName Prepared statement name
219: */
220: public void setName(String newName) {
221: name = newName;
222: }
223:
224: /**
225: * Set the prepared statement java name.
226: *
227: * @param newJavaName Prepared statement java name
228: */
229: public void setJavaName(String newJavaName) {
230: javaName = newJavaName;
231: }
232:
233: /**
234: * Set the catalog name.
235: *
236: * @param newCatalog Catalog name
237: */
238: public void setCatalog(String newCatalog) {
239: catalog = newCatalog;
240: }
241:
242: /**
243: * Set the schema name.
244: *
245: * @param newSchema Schema name
246: */
247: public void setSchema(String newSchema) {
248: schema = newSchema;
249: }
250:
251: /**
252: * Set the SQL text.
253: *
254: * @param newSQLText SQL text
255: */
256: public void setSQLText(String newSQLText) {
257: sqlText = newSQLText;
258: }
259:
260: /**
261: * Set the prepared statement parameter list.
262: *
263: * @param newParameters Parameter list
264: */
265: public void setParameters(Parameter[] newParameters) {
266: parameters = newParameters;
267:
268: // update the number of parameters
269: if (parameters != null) {
270: numParameters = parameters.length;
271: }
272: }
273:
274: public void cloneParameters(Parameter[] newParameters) {
275: if (newParameters != null) {
276: numParameters = newParameters.length;
277: if (numParameters > 0) {
278: parameters = new Parameter[numParameters];
279: for (int i = 0; i < numParameters; i++) {
280: parameters[i] = new Parameter(newParameters[i]);
281: }
282: }
283: }
284: }
285:
286: /**
287: * Set the prepared statement resultset column list.
288: *
289: * @param newResultSetColumns Resultset column list
290: */
291: public void setResultSetColumns(
292: ResultSetColumn[] newResultSetColumns) {
293: resultsetColumns = newResultSetColumns;
294:
295: // update the number of resultset columns
296: if (resultsetColumns != null) {
297: numResultSetColumns = resultsetColumns.length;
298: }
299: }
300:
301: public void cloneResultSetColumns(
302: ResultSetColumn[] newResultSetColumns) {
303: if (newResultSetColumns != null) {
304: numResultSetColumns = newResultSetColumns.length;
305: if (numResultSetColumns > 0) {
306: resultsetColumns = new ResultSetColumn[numResultSetColumns];
307: for (int i = 0; i < numResultSetColumns; i++) {
308: resultsetColumns[i] = new ResultSetColumn(
309: newResultSetColumns[i]);
310: }
311: }
312: }
313: }
314: }
|