1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.io.IOException ; 23 import java.sql.ResultSet ; 24 import java.util.HashMap ; 25 import java.util.Vector ; 26 27 import org.openide.DialogDisplayer; 28 import org.openide.NotifyDescriptor; 29 import org.openide.nodes.Node; 30 31 import org.netbeans.lib.ddl.DDLException; 32 import org.netbeans.lib.ddl.impl.DriverSpecification; 33 import org.netbeans.lib.ddl.impl.DropIndex; 34 import org.netbeans.lib.ddl.impl.Specification; 35 36 import org.netbeans.api.db.explorer.DatabaseException; 37 import org.netbeans.modules.db.explorer.DatabaseNodeChildren; 38 import org.netbeans.modules.db.explorer.nodes.DatabaseNode; 39 40 public class IndexNodeInfo extends TableNodeInfo { 41 static final long serialVersionUID =-8633867970381524742L; 42 43 public void initChildren(Vector children) throws DatabaseException { 44 try { 45 String table = (String )get(DatabaseNode.TABLE); 46 47 DriverSpecification drvSpec = getDriverSpecification(); 48 drvSpec.getIndexInfo(table, false, true); 49 ResultSet rs = drvSpec.getResultSet(); 50 if (rs != null) { 51 HashMap rset = new HashMap (); 52 DatabaseNodeInfo info; 53 while (rs.next()) { 54 rset = drvSpec.getRow(); 55 String ixname = (String )get("index"); info = DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.INDEXCOLUMN, rset); 57 String newixname = (String )info.get("ixname"); if (ixname != null && newixname != null && newixname.equals(ixname)) { 59 String way; 60 if (info.get("ord") instanceof java.lang.Boolean ) way = "A"; else 63 way = (String ) info.get("ord"); if (way == null) way = "A"; info.put(DatabaseNodeInfo.ICONBASE, info.get(DatabaseNodeInfo.ICONBASE+way)); 66 if (info != null) 67 children.add(info); 68 else { 69 rs.close(); 70 throw new Exception (bundle().getString("EXC_UnableToCreateIndexNodeInfo")); } 72 } 73 rset.clear(); 74 } 75 rs.close(); 76 } 77 } catch (Exception e) { 78 throw new DatabaseException(e.getMessage()); 79 } 80 } 81 82 public void refreshChildren() throws DatabaseException { 83 Vector charr = new Vector (); 85 put(DatabaseNodeInfo.CHILDREN, charr); 86 initChildren(charr); 87 88 try { 90 Node[] subTreeNodes = new Node[charr.size()]; 91 92 DatabaseNodeChildren children = (DatabaseNodeChildren)getNode().getChildren(); 94 95 children.remove(children.getNodes()); 97 98 for(int i=0; i<charr.size(); i++) 100 subTreeNodes[i] = children.createNode((DatabaseNodeInfo)charr.elementAt(i)); 101 102 children.add(subTreeNodes); 104 } catch (Exception ex) { 105 org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex); 106 } 107 } 108 109 public void delete() throws IOException { 110 try { 111 String table = (String )get(DatabaseNode.TABLE); 112 Specification spec = (Specification)getSpecification(); 113 DropIndex cmd = (DropIndex)spec.createCommandDropIndex(getName()); 114 cmd.setTableName(table); 115 cmd.setObjectOwner((String )get(DatabaseNodeInfo.SCHEMA)); 116 cmd.execute(); 117 getParent(DatabaseNode.TABLE).refreshChildren(); 119 } catch (DDLException e) { 120 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 121 } catch (Exception e) { 122 throw new IOException (e.getMessage()); 123 } 124 } 125 } 126 | Popular Tags |