KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > infos > ProcedureNodeInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.explorer.infos;
21
22 import java.io.IOException JavaDoc;
23 import java.sql.DatabaseMetaData JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import org.openide.NotifyDescriptor;
29
30 import org.netbeans.lib.ddl.impl.AbstractCommand;
31 import org.netbeans.lib.ddl.impl.DriverSpecification;
32 import org.netbeans.lib.ddl.impl.Specification;
33
34 import org.netbeans.api.db.explorer.DatabaseException;
35 import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
36
37 public class ProcedureNodeInfo extends DatabaseNodeInfo {
38     static final long serialVersionUID =-5984072379104199563L;
39
40     public void initChildren(Vector JavaDoc children) throws DatabaseException {
41         try {
42             String JavaDoc name = (String JavaDoc)get(DatabaseNode.PROCEDURE);
43             
44             DriverSpecification drvSpec = getDriverSpecification();
45             
46             //workaround for issue #21409 (http://db.netbeans.org/issues/show_bug.cgi?id=21409)
47
String JavaDoc pac = null;
48             if (drvSpec.getDBName().indexOf("Oracle") != -1) {
49                 int pos = name.indexOf(".");
50                 if (pos != -1) {
51                     pac = name.substring(0, pos);
52                     name = name.substring(pos + 1);
53                 }
54             }
55
56             drvSpec.getProcedureColumns(name, "%");
57             ResultSet JavaDoc rs = drvSpec.getResultSet();
58             if (rs != null) {
59                 HashMap JavaDoc rset = new HashMap JavaDoc();
60                 DatabaseNodeInfo info;
61                 while (rs.next()) {
62                     rset = drvSpec.getRow();
63                     
64                     if (rset.get(new Integer JavaDoc(4)) == null)
65                         continue;
66                     
67                     //workaround for issue #21409 (http://db.netbeans.org/issues/show_bug.cgi?id=21409)
68
if (drvSpec.getDBName().indexOf("Oracle") != -1) {
69                         String JavaDoc pac1 = (String JavaDoc) rset.get(new Integer JavaDoc(1));
70                         if ((pac == null && pac1 != null) || (pac != null && pac1 == null) || (pac != null && pac1 != null && ! pac1.equals(pac)))
71                             continue;
72                     }
73                     
74                     info = DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.PROCEDURE_COLUMN, rset);
75                     if (info != null) {
76                         Object JavaDoc ibase = null;
77                         String JavaDoc itype = "unknown"; //NOI18N
78

79 // int type = ((Number)info.get("type")).intValue(); //NOI18N
80

81 //cannot use previous line because of MSSQL ODBC problems - see DriverSpecification.getRow() for more info
82
int type;
83                         try {
84                             type = (new Integer JavaDoc(info.get("type").toString())).intValue(); //NOI18N
85
} catch (NumberFormatException JavaDoc exc) {
86                             throw new IllegalArgumentException JavaDoc(exc.getMessage());
87                         }
88 //end of MSSQL hack
89

90                         switch (type) {
91                         case DatabaseMetaData.procedureColumnIn:
92                             ibase = info.get("iconbase_in"); //NOI18N
93
itype = "in"; //NOI18N
94
break;
95                         case DatabaseMetaData.procedureColumnOut:
96                             ibase = info.get("iconbase_out"); //NOI18N
97
itype = "out"; //NOI18N
98
break;
99                         case DatabaseMetaData.procedureColumnInOut:
100                             ibase = info.get("iconbase_inout"); //NOI18N
101
itype = "in/out"; //NOI18N
102
break;
103                         case DatabaseMetaData.procedureColumnReturn:
104                             ibase = info.get("iconbase_return"); //NOI18N
105
itype = "return"; //NOI18N
106
break;
107                         case DatabaseMetaData.procedureColumnResult:
108                             ibase = info.get("iconbase_result"); //NOI18N
109
itype = "result"; //NOI18N
110
break;
111                         }
112                         if (ibase != null)
113                             info.put("iconbase", ibase); //NOI18N
114
info.put("type", itype); //NOI18N
115
children.add(info);
116                     } else
117                         throw new Exception JavaDoc(bundle().getString("EXC_UnableToCreateProcedureColumnNodeInfo"));
118                     rset.clear();
119                 }
120                 rs.close();
121             }
122         } catch (Exception JavaDoc e) {
123             throw new DatabaseException(e.getMessage());
124         }
125     }
126
127     /* delete procedure from list of procedures and drop procedure in the database */
128     public void delete() throws IOException JavaDoc {
129         try {
130             Specification spec = (Specification) getSpecification();
131             AbstractCommand cmd = spec.createCommandDropProcedure((String JavaDoc) get(DatabaseNode.PROCEDURE));
132             cmd.setObjectOwner((String JavaDoc) get(DatabaseNodeInfo.SCHEMA));
133             cmd.execute();
134         } catch (Exception JavaDoc e) {
135             org.openide.DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
136         }
137     }
138 }
139
Popular Tags