1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.sql.Connection ; 23 import java.sql.DatabaseMetaData ; 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Set ; 29 import java.util.Vector ; 30 31 import org.openide.ErrorManager; 32 33 import org.netbeans.lib.ddl.impl.DriverSpecification; 34 import org.netbeans.api.db.explorer.DatabaseException; 35 import org.netbeans.modules.db.explorer.DatabaseNodeChildren; 36 import org.netbeans.modules.db.explorer.nodes.DatabaseNode; 37 38 public class IndexListNodeInfo extends DatabaseNodeInfo { 39 static final long serialVersionUID =5809643799834921044L; 40 41 public void initChildren(Vector children) throws DatabaseException { 42 try { 43 String table = (String ) get(DatabaseNode.TABLE); 44 DriverSpecification drvSpec = getDriverSpecification(); 45 Connection con = getConnection(); 46 DatabaseMetaData dmd = con.getMetaData(); 47 ResultSet rs = dmd.getIndexInfo(drvSpec.getCatalog(), drvSpec.getSchema(), table, false, true); 48 if (rs != null) { 49 Set ixmap = new HashSet (); 50 IndexNodeInfo info; 51 while (rs.next()) { 52 HashMap rset = getRow(rs); 53 if (rset == null) 54 continue; 55 if (rset.get(new Integer (6)) != null) { 56 info = (IndexNodeInfo)DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.INDEX, rset); 57 if (info != null) { 58 if (!ixmap.contains(info.getName())) { 59 ixmap.add(info.getName()); 60 info.put("index", info.getName()); children.add(info); 62 } 63 } else 64 throw new Exception (bundle().getString("EXC_UnableToCreateIndexNodeInfo")); } 66 } 67 rs.close(); 68 } 69 } catch (Exception e) { 70 throw new DatabaseException(e.getMessage()); 71 } 72 } 73 74 public HashMap getRow(ResultSet rs) { 75 HashMap rset = new HashMap (); 76 Object value; 77 78 try { 79 int count = rs.getMetaData().getColumnCount(); 80 81 for (int i = 1; i <= count; i++) { 82 value = null; 83 try { 84 value = rs.getString(i); 85 } catch (SQLException exc) { 86 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc); 87 rset = null; 88 break; 89 } 90 rset.put(new Integer (i), value); 91 } 92 } catch (SQLException exc) { 93 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc); 94 rset = null; 95 } 96 97 return rset; 98 } 99 100 public void addIndex(String name) throws DatabaseException { 101 try { 102 String table = (String )get(DatabaseNode.TABLE); 103 104 DriverSpecification drvSpec = getDriverSpecification(); 105 drvSpec.getIndexInfo(table, false, true); 106 ResultSet rs = drvSpec.getResultSet(); 107 if (rs != null) { 108 HashMap rset = new HashMap (); 109 IndexNodeInfo info = null; 110 String findex; 111 while (rs.next()) { 112 rset = drvSpec.getRow(); 113 findex = (String ) rset.get(new Integer (6)); 114 if (findex != null) 115 if(findex.equalsIgnoreCase(name)) 116 info = (IndexNodeInfo)DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.INDEX, rset); 117 rset.clear(); 118 } 119 rs.close(); 120 121 if (info != null) ((DatabaseNodeChildren)getNode().getChildren()).createSubnode(info,true); 122 getParent().refreshChildren(); 124 } 125 } catch (Exception e) { 126 e.printStackTrace(); 127 throw new DatabaseException(e.getMessage()); 128 } 129 } 130 131 } 132 | Popular Tags |