1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.io.IOException ; 23 import java.sql.DatabaseMetaData ; 24 import java.sql.ResultSet ; 25 import java.util.HashMap ; 26 import java.util.Vector ; 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 children) throws DatabaseException { 41 try { 42 String name = (String )get(DatabaseNode.PROCEDURE); 43 44 DriverSpecification drvSpec = getDriverSpecification(); 45 46 String 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 rs = drvSpec.getResultSet(); 58 if (rs != null) { 59 HashMap rset = new HashMap (); 60 DatabaseNodeInfo info; 61 while (rs.next()) { 62 rset = drvSpec.getRow(); 63 64 if (rset.get(new Integer (4)) == null) 65 continue; 66 67 if (drvSpec.getDBName().indexOf("Oracle") != -1) { 69 String pac1 = (String ) rset.get(new Integer (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 ibase = null; 77 String itype = "unknown"; 79 81 int type; 83 try { 84 type = (new Integer (info.get("type").toString())).intValue(); } catch (NumberFormatException exc) { 86 throw new IllegalArgumentException (exc.getMessage()); 87 } 88 90 switch (type) { 91 case DatabaseMetaData.procedureColumnIn: 92 ibase = info.get("iconbase_in"); itype = "in"; break; 95 case DatabaseMetaData.procedureColumnOut: 96 ibase = info.get("iconbase_out"); itype = "out"; break; 99 case DatabaseMetaData.procedureColumnInOut: 100 ibase = info.get("iconbase_inout"); itype = "in/out"; break; 103 case DatabaseMetaData.procedureColumnReturn: 104 ibase = info.get("iconbase_return"); itype = "return"; break; 107 case DatabaseMetaData.procedureColumnResult: 108 ibase = info.get("iconbase_result"); itype = "result"; break; 111 } 112 if (ibase != null) 113 info.put("iconbase", ibase); info.put("type", itype); children.add(info); 116 } else 117 throw new Exception (bundle().getString("EXC_UnableToCreateProcedureColumnNodeInfo")); 118 rset.clear(); 119 } 120 rs.close(); 121 } 122 } catch (Exception e) { 123 throw new DatabaseException(e.getMessage()); 124 } 125 } 126 127 128 public void delete() throws IOException { 129 try { 130 Specification spec = (Specification) getSpecification(); 131 AbstractCommand cmd = spec.createCommandDropProcedure((String ) get(DatabaseNode.PROCEDURE)); 132 cmd.setObjectOwner((String ) get(DatabaseNodeInfo.SCHEMA)); 133 cmd.execute(); 134 } catch (Exception e) { 135 org.openide.DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 136 } 137 } 138 } 139 | Popular Tags |