1 19 20 package org.netbeans.modules.db.explorer.infos; 21 22 import java.sql.ResultSet ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 import java.util.Vector ; 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 children) throws DatabaseException { 35 try { 36 String table = (String )get(DatabaseNode.TABLE); 37 38 DriverSpecification drvSpec = getDriverSpecification(); 39 drvSpec.getImportedKeys(table); 40 ResultSet rs = drvSpec.getResultSet(); 41 if (rs != null) { 42 Set fkmap = new HashSet (); 43 HashMap rset = new HashMap (); 44 ForeignKeyNodeInfo info; 45 while (rs.next()) { 46 rset = drvSpec.getRow(); 47 if (rset.get(new Integer (12)) != null) { 48 info = (ForeignKeyNodeInfo)DatabaseNodeInfo.createNodeInfo(this, DatabaseNode.IMPORTED_KEY, rset); 49 if (info != null) { 50 String fkName = info.getName(); 51 if (fkName == null || fkName.trim().equals("")) { String refName = (String ) rset.get(new Integer (3)); 53 info.setName("GENERATED_FK_" + refName); } 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 (bundle().getString("EXC_UnableToCreateForeignNodeInfo")); } 63 rset.clear(); 64 } 65 rs.close(); 66 } 67 } catch (Exception e) { 68 throw new DatabaseException(e.getMessage()); 69 } 70 } 71 72 } 73 | Popular Tags |