KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > infos > IndexNodeInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.explorer.infos;
21
22 import java.io.IOException JavaDoc;
23 import java.sql.ResultSet JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Vector JavaDoc;
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 JavaDoc children) throws DatabaseException {
44         try {
45             String JavaDoc table = (String JavaDoc)get(DatabaseNode.TABLE);
46
47             DriverSpecification drvSpec = getDriverSpecification();
48             drvSpec.getIndexInfo(table, false, true);
49             ResultSet JavaDoc rs = drvSpec.getResultSet();
50             if (rs != null) {
51                 HashMap JavaDoc rset = new HashMap JavaDoc();
52                 DatabaseNodeInfo info;
53                 while (rs.next()) {
54                     rset = drvSpec.getRow();
55                     String JavaDoc ixname = (String JavaDoc)get("index"); //NOI18N
56
info = DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.INDEXCOLUMN, rset);
57                     String JavaDoc newixname = (String JavaDoc)info.get("ixname"); //NOI18N
58
if (ixname != null && newixname != null && newixname.equals(ixname)) {
59                         String JavaDoc way;
60                         if (info.get("ord") instanceof java.lang.Boolean JavaDoc) //NOI18N //HACK for PointBase
61
way = "A"; //NOI18N
62
else
63                             way = (String JavaDoc) info.get("ord"); //NOI18N
64
if (way == null) way = "A"; //NOI18N
65
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 JavaDoc(bundle().getString("EXC_UnableToCreateIndexNodeInfo")); //NOI18N
71
}
72                     }
73                     rset.clear();
74                 }
75                 rs.close();
76             }
77         } catch (Exception JavaDoc e) {
78             throw new DatabaseException(e.getMessage());
79         }
80     }
81
82     public void refreshChildren() throws DatabaseException {
83         // create list (infos)
84
Vector JavaDoc charr = new Vector JavaDoc();
85         put(DatabaseNodeInfo.CHILDREN, charr);
86         initChildren(charr);
87         
88         // create sub-tree (by infos)
89
try {
90             Node[] subTreeNodes = new Node[charr.size()];
91
92             // current sub-tree
93
DatabaseNodeChildren children = (DatabaseNodeChildren)getNode().getChildren();
94
95             // remove current sub-tree
96
children.remove(children.getNodes());
97
98             // build refreshed sub-tree
99
for(int i=0; i<charr.size(); i++)
100                 subTreeNodes[i] = children.createNode((DatabaseNodeInfo)charr.elementAt(i));
101
102             // add built sub-tree
103
children.add(subTreeNodes);
104         } catch (Exception JavaDoc ex) {
105             org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
106         }
107     }
108
109     public void delete() throws IOException JavaDoc {
110         try {
111             String JavaDoc table = (String JavaDoc)get(DatabaseNode.TABLE);
112             Specification spec = (Specification)getSpecification();
113             DropIndex cmd = (DropIndex)spec.createCommandDropIndex(getName());
114             cmd.setTableName(table);
115             cmd.setObjectOwner((String JavaDoc)get(DatabaseNodeInfo.SCHEMA));
116             cmd.execute();
117             //refresh list of columns due to the column's icons
118
getParent(DatabaseNode.TABLE).refreshChildren();
119         } catch (DDLException e) {
120             DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
121         } catch (Exception JavaDoc e) {
122             throw new IOException JavaDoc(e.getMessage());
123         }
124     }
125 }
126
Popular Tags