KickJava   Java API By Example, From Geeks To Geeks.

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


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.Vector JavaDoc;
25 import org.netbeans.api.db.explorer.DatabaseException;
26 import org.netbeans.lib.ddl.impl.AbstractCommand;
27 import org.netbeans.lib.ddl.impl.DriverSpecification;
28 import org.netbeans.lib.ddl.impl.Specification;
29 import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
30
31 public class ViewNodeInfo extends DatabaseNodeInfo {
32     static final long serialVersionUID =8370676447530973161L;
33
34     public void initChildren(Vector JavaDoc children) throws DatabaseException {
35         try {
36             String JavaDoc view = (String JavaDoc)get(DatabaseNode.VIEW);
37
38             // Columns
39
DriverSpecification drvSpec = getDriverSpecification();
40             drvSpec.getColumns(view, "%");
41
42             ResultSet JavaDoc rs = drvSpec.getResultSet();
43             if (rs != null) {
44                 DatabaseNodeInfo nfo;
45                 while (rs.next()) {
46                     nfo = DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.VIEWCOLUMN, drvSpec.getRow());
47                     if (nfo != null)
48                         children.add(nfo);
49                 }
50                 rs.close();
51             }
52         } catch (Exception JavaDoc e) {
53             throw new DatabaseException(e.getMessage());
54         }
55     }
56
57     public void setProperty(String JavaDoc key, Object JavaDoc obj) {
58         try {
59             if (key.equals("remarks")) setRemarks((String JavaDoc)obj); //NOI18N
60
put(key, obj);
61         } catch (Exception JavaDoc ex) {
62             ex.printStackTrace();
63         }
64     }
65
66     public void setRemarks(String JavaDoc rem) throws DatabaseException {
67         String JavaDoc viewname = (String JavaDoc)get(DatabaseNode.VIEW);
68         Specification spec = (Specification)getSpecification();
69         try {
70             AbstractCommand cmd = spec.createCommandCommentView(viewname, rem);
71             cmd.setObjectOwner((String JavaDoc)get(DatabaseNodeInfo.SCHEMA));
72             cmd.execute();
73         } catch (Exception JavaDoc e) {
74             throw new DatabaseException(e.getMessage());
75         }
76     }
77
78     public void delete() throws IOException JavaDoc {
79         try {
80             String JavaDoc code = getCode();
81             String JavaDoc table = (String JavaDoc)get(DatabaseNode.TABLE);
82             Specification spec = (Specification)getSpecification();
83             AbstractCommand cmd = spec.createCommandDropView(getName());
84             cmd.setObjectOwner((String JavaDoc)get(DatabaseNodeInfo.SCHEMA));
85             cmd.execute();
86         } catch (Exception JavaDoc e) {
87             throw new IOException JavaDoc(e.getMessage());
88         }
89     }
90 }
91
Popular Tags