1 19 20 package org.netbeans.modules.db.explorer.nodes; 21 22 import java.awt.datatransfer.Transferable ; 23 import java.io.IOException ; 24 import java.sql.*; 25 import java.text.MessageFormat ; 26 import java.util.*; 27 28 import org.openide.nodes.NodeTransfer; 29 import org.openide.nodes.Node; 30 import org.openide.util.NbBundle; 31 import org.openide.util.datatransfer.PasteType; 32 33 import org.netbeans.lib.ddl.*; 34 import org.netbeans.lib.ddl.impl.*; 35 import org.netbeans.modules.db.*; 36 import org.netbeans.modules.db.explorer.*; 37 import org.netbeans.modules.db.explorer.infos.*; 38 39 public class IndexNode extends DatabaseNode { 40 56 57 protected void createPasteTypes(Transferable t, List s) 58 { 59 super.createPasteTypes(t, s); 60 Node node = NodeTransfer.node(t, NodeTransfer.MOVE); 61 if (node != null) { 62 ColumnNodeInfo nfo = (ColumnNodeInfo)node.getCookie(ColumnNodeInfo.class); 63 if (nfo != null) s.add(new IndexPasteType((ColumnNodeInfo)nfo, null)); 64 } 65 } 66 67 class IndexPasteType extends PasteType 68 { 69 70 private DatabaseNodeInfo info; 71 72 73 private Node node; 74 75 77 public IndexPasteType(ColumnNodeInfo info, Node node) 78 { 79 this.info = info; 80 this.node = node; 81 } 82 83 84 public String getName() { 85 return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("IndexPasteTypeName"); } 87 88 93 public Transferable paste() throws IOException { 94 IndexNodeInfo destinfo = (IndexNodeInfo)getInfo(); 95 96 if (info != null) { 97 Specification spec; 98 99 try { 100 spec = (Specification)info.getSpecification(); 101 DriverSpecification drvSpec = info.getDriverSpecification(); 102 drvSpec.getIndexInfo(info.getTable(), false, true); 103 ResultSet rs = drvSpec.getResultSet(); 104 if (rs != null) { 105 String index = destinfo.getName(); 106 HashSet ixrm = new HashSet(); 107 HashMap rset = new HashMap(); 108 109 while (rs.next()) { 110 rset = drvSpec.getRow(); 111 String ixname = (String ) rset.get(new Integer (6)); 112 String colname = (String ) rset.get(new Integer (9)); 113 if (ixname.equals(index)) 114 ixrm.add(colname); 115 rset.clear(); 116 } 117 rs.close(); 118 119 if (ixrm.contains(info.getName())) { 120 String message = MessageFormat.format(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_IndexContainsColumn"), new String [] {index, info.getName()}); throw new IOException (message); 122 } 123 124 CreateIndex icmd = spec.createCommandCreateIndex(info.getTable()); 125 icmd.setIndexName(destinfo.getName()); 126 Iterator enu = ixrm.iterator(); 127 while (enu.hasNext()) { 128 icmd.specifyColumn((String )enu.next()); 129 } 130 131 icmd.specifyColumn(info.getName()); 132 DropIndex dicmd = spec.createCommandDropIndex(index); 133 dicmd.setObjectOwner((String )destinfo.get(DatabaseNodeInfo.SCHEMA)); 134 dicmd.execute(); 135 icmd.setObjectOwner((String )destinfo.get(DatabaseNodeInfo.SCHEMA)); 136 icmd.execute(); 137 138 drvSpec.getIndexInfo(destinfo.getTable(), false, true); 139 rs = drvSpec.getResultSet(); 140 if (rs != null) { 141 IndexNodeInfo ixinfo; 142 while (rs.next()) { 143 rset = drvSpec.getRow(); 144 String ixname = (String ) rset.get(new Integer (6)); 145 String colname = (String ) rset.get(new Integer (9)); 146 if (ixname.equals(index) && colname.equals(info.getName())) { 147 ixinfo = (IndexNodeInfo) DatabaseNodeInfo.createNodeInfo(destinfo, DatabaseNode.INDEX, rset); 148 if (ixinfo != null) 149 ((DatabaseNodeChildren)destinfo.getNode().getChildren()).createSubnode(ixinfo,true); 150 else 151 throw new Exception (NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_UnableToCreateIndexNodeInfo")); } 153 rset.clear(); 154 } 155 rs.close(); 156 } 157 } 158 } catch (Exception e) { 159 throw new IOException (e.getMessage()); 160 } 161 162 } else 163 throw new IOException (NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_CannotFindIndexOwnerInformation")); 164 165 return null; 166 } 167 } 168 169 public String getShortDescription() { 170 return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_Index"); } 172 173 } 174 | Popular Tags |