001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.db.explorer.infos;
043:
044: import java.io.IOException;
045: import java.sql.DatabaseMetaData;
046: import java.sql.ResultSet;
047: import java.util.HashMap;
048: import java.util.Vector;
049:
050: import org.openide.NotifyDescriptor;
051:
052: import org.netbeans.lib.ddl.impl.AbstractCommand;
053: import org.netbeans.lib.ddl.impl.DriverSpecification;
054: import org.netbeans.lib.ddl.impl.Specification;
055:
056: import org.netbeans.api.db.explorer.DatabaseException;
057: import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
058:
059: public class ProcedureNodeInfo extends DatabaseNodeInfo {
060: static final long serialVersionUID = -5984072379104199563L;
061:
062: public void initChildren(Vector children) throws DatabaseException {
063: try {
064: String name = (String) get(DatabaseNode.PROCEDURE);
065:
066: DriverSpecification drvSpec = getDriverSpecification();
067:
068: //workaround for issue #21409 (http://db.netbeans.org/issues/show_bug.cgi?id=21409)
069: String pac = null;
070: if (drvSpec.getDBName().indexOf("Oracle") != -1) {
071: int pos = name.indexOf(".");
072: if (pos != -1) {
073: pac = name.substring(0, pos);
074: name = name.substring(pos + 1);
075: }
076: }
077:
078: drvSpec.getProcedureColumns(name, "%");
079: ResultSet rs = drvSpec.getResultSet();
080: if (rs != null) {
081: HashMap rset = new HashMap();
082: DatabaseNodeInfo info;
083: while (rs.next()) {
084: rset = drvSpec.getRow();
085:
086: if (rset.get(new Integer(4)) == null)
087: continue;
088:
089: //workaround for issue #21409 (http://db.netbeans.org/issues/show_bug.cgi?id=21409)
090: if (drvSpec.getDBName().indexOf("Oracle") != -1) {
091: String pac1 = (String) rset.get(new Integer(1));
092: if ((pac == null && pac1 != null)
093: || (pac != null && pac1 == null)
094: || (pac != null && pac1 != null && !pac1
095: .equals(pac)))
096: continue;
097: }
098:
099: info = DatabaseNodeInfo.createNodeInfo(this ,
100: DatabaseNode.PROCEDURE_COLUMN, rset);
101: if (info != null) {
102: Object ibase = null;
103: String itype = "unknown"; //NOI18N
104:
105: // int type = ((Number)info.get("type")).intValue(); //NOI18N
106:
107: //cannot use previous line because of MSSQL ODBC problems - see DriverSpecification.getRow() for more info
108: int type;
109: try {
110: type = (new Integer(info.get("type")
111: .toString())).intValue(); //NOI18N
112: } catch (NumberFormatException exc) {
113: throw new IllegalArgumentException(exc
114: .getMessage());
115: }
116: //end of MSSQL hack
117:
118: switch (type) {
119: case DatabaseMetaData.procedureColumnIn:
120: ibase = info.get("iconbase_in"); //NOI18N
121: itype = "in"; //NOI18N
122: break;
123: case DatabaseMetaData.procedureColumnOut:
124: ibase = info.get("iconbase_out"); //NOI18N
125: itype = "out"; //NOI18N
126: break;
127: case DatabaseMetaData.procedureColumnInOut:
128: ibase = info.get("iconbase_inout"); //NOI18N
129: itype = "in/out"; //NOI18N
130: break;
131: case DatabaseMetaData.procedureColumnReturn:
132: ibase = info.get("iconbase_return"); //NOI18N
133: itype = "return"; //NOI18N
134: break;
135: case DatabaseMetaData.procedureColumnResult:
136: ibase = info.get("iconbase_result"); //NOI18N
137: itype = "result"; //NOI18N
138: break;
139: }
140: if (ibase != null)
141: info.put("iconbase", ibase); //NOI18N
142: info.put("type", itype); //NOI18N
143: children.add(info);
144: } else
145: throw new Exception(
146: bundle()
147: .getString(
148: "EXC_UnableToCreateProcedureColumnNodeInfo"));
149: rset.clear();
150: }
151: rs.close();
152: }
153: } catch (Exception e) {
154: throw new DatabaseException(e.getMessage());
155: }
156: }
157:
158: /* delete procedure from list of procedures and drop procedure in the database */
159: public void delete() throws IOException {
160: try {
161: Specification spec = (Specification) getSpecification();
162: AbstractCommand cmd = spec
163: .createCommandDropProcedure((String) get(DatabaseNode.PROCEDURE));
164: cmd.setObjectOwner((String) get(DatabaseNodeInfo.SCHEMA));
165: cmd.execute();
166: } catch (Exception e) {
167: org.openide.DialogDisplayer.getDefault().notify(
168: new NotifyDescriptor.Message(e.getMessage(),
169: NotifyDescriptor.ERROR_MESSAGE));
170: }
171: }
172: }
|