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