1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.sql.*; 23 import java.util.*; 24 25 import org.openide.nodes.Node; 26 27 import org.netbeans.lib.ddl.*; 28 import org.netbeans.api.db.explorer.DatabaseException; 29 import org.netbeans.lib.ddl.impl.*; 30 import org.netbeans.modules.db.explorer.DatabaseNodeChildren; 31 import org.netbeans.modules.db.explorer.infos.*; 32 import org.netbeans.modules.db.explorer.nodes.*; 33 34 public class ForeignKeyNodeInfo extends TableNodeInfo { 35 static final long serialVersionUID =-8633867970381524742L; 36 37 public void initChildren(Vector children) throws DatabaseException { 38 try { 39 String table = (String )get(DatabaseNode.TABLE); 40 String fk_name = (String )get(DatabaseNode.IMPORTED_KEY); 41 DriverSpecification drvSpec = getDriverSpecification(); 42 drvSpec.getImportedKeys(table); 43 ResultSet rs = drvSpec.getResultSet(); 44 if (rs != null) { 45 HashMap rset = new HashMap(); 46 ColumnNodeInfo info; 47 while (rs.next()) { 48 rset = drvSpec.getRow(); 49 if (rset.get(new Integer (8)) != null) 50 if (((String ) rset.get(new Integer (12))).startsWith(fk_name)) { 51 info = (ColumnNodeInfo)DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.FOREIGN_COLUMN, rset); 52 53 if (info != null) { 54 String tempTName = (String ) rset.get(new Integer (3)); 55 tempTName = (tempTName == "") ? "" : tempTName + "."; info.setName(info.getName() + " -> " + tempTName + ((String ) rset.get(new Integer (4)))); children.add(info); 58 } else 59 throw new Exception (bundle().getString("EXC_UnableToCreateForeignNodeInfo")); } 61 rset.clear(); 62 } 63 rs.close(); 64 } 65 } catch (Exception e) { 66 throw new DatabaseException(e.getMessage()); 67 } 68 } 69 70 public void refreshChildren() throws DatabaseException 71 { 72 Vector charr = new Vector(); 74 put(DatabaseNodeInfo.CHILDREN, charr); 75 initChildren(charr); 76 77 try { 79 80 Node[] subTreeNodes = new Node[charr.size()]; 81 82 DatabaseNodeChildren children = (DatabaseNodeChildren)getNode().getChildren(); 84 85 children.remove(children.getNodes()); 87 88 for(int i=0; i<charr.size(); i++) 90 subTreeNodes[i] = children.createNode((DatabaseNodeInfo)charr.elementAt(i)); 91 92 children.add(subTreeNodes); 94 95 } catch (Exception ex) { 96 org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex); 97 } 98 } 99 100 } 101 | Popular Tags |