KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.ResultSet JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.Vector JavaDoc;
27 import org.netbeans.api.db.explorer.DatabaseException;
28 import org.netbeans.lib.ddl.impl.DriverSpecification;
29 import org.netbeans.modules.db.explorer.nodes.DatabaseNode;
30
31 public class ForeignKeyListNodeInfo extends DatabaseNodeInfo {
32     static final long serialVersionUID =5809643799834921044L;
33
34     public void initChildren(Vector JavaDoc children) throws DatabaseException {
35         try {
36             String JavaDoc table = (String JavaDoc)get(DatabaseNode.TABLE);
37
38             DriverSpecification drvSpec = getDriverSpecification();
39             drvSpec.getImportedKeys(table);
40             ResultSet JavaDoc rs = drvSpec.getResultSet();
41             if (rs != null) {
42                 Set JavaDoc fkmap = new HashSet JavaDoc();
43                 HashMap JavaDoc rset = new HashMap JavaDoc();
44                 ForeignKeyNodeInfo info;
45                 while (rs.next()) {
46                     rset = drvSpec.getRow();
47                     if (rset.get(new Integer JavaDoc(12)) != null) {
48                         info = (ForeignKeyNodeInfo)DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.IMPORTED_KEY, rset);
49                         if (info != null) {
50                             String JavaDoc fkName = info.getName();
51                             if (fkName == null || fkName.trim().equals("")) {// NOI18N
52
String JavaDoc refName = (String JavaDoc) rset.get(new Integer JavaDoc(3));
53                                 info.setName("GENERATED_FK_" + refName); // NOI18N
54
}
55                             if (!fkmap.contains(info.getName())) {
56                                 fkmap.add(info.getName());
57                                 info.put(DatabaseNode.IMPORTED_KEY, info.getName());
58                                 children.add(info);
59                             }
60                         } else
61                             throw new Exception JavaDoc(bundle().getString("EXC_UnableToCreateForeignNodeInfo")); //NOI18N
62
}
63                     rset.clear();
64                 }
65                 rs.close();
66             }
67         } catch (Exception JavaDoc e) {
68             throw new DatabaseException(e.getMessage());
69         }
70     }
71
72 }
73
Popular Tags