1 19 20 package org.netbeans.modules.dbschema.jdbcimpl; 21 22 import java.sql.*; 23 import java.util.Arrays ; 24 25 import org.netbeans.modules.dbschema.*; 26 27 public class ForeignKeyElementImpl extends KeyElementImpl implements ForeignKeyElement.Impl { 28 29 private TableElementImpl tei; 30 31 public ForeignKeyElementImpl() { 32 this(null, null); 33 } 34 35 public ForeignKeyElementImpl(TableElementImpl tei, String name) { 36 super(name); 37 38 this.tei = tei; 39 } 40 41 protected DBElementsCollection initializeCollection() { 42 return new DBElementsCollection(this, new ColumnPairElement[0]); 43 } 44 45 public ColumnPairElement[] getColumnPairs() { 46 DBElement[] dbe = getColumnCollection().getElements(); 47 return (ColumnPairElement[]) Arrays.asList(dbe).toArray(new ColumnPairElement[dbe.length]); 48 } 49 50 public ColumnPairElement getColumnPair(DBIdentifier name) { 51 return (ColumnPairElement) getColumnCollection().find(name); 52 } 53 54 public void changeColumnPairs(ColumnPairElement[] pairs,int action) throws DBException { 55 getColumnCollection().changeElements(pairs, action); 56 } 57 58 public ColumnElement[] getColumns() { 59 ColumnPairElement[] cpe = getColumnPairs(); 60 61 if (cpe == null || cpe.length == 0) 62 return null; 63 64 ColumnElement[] ce = new ColumnElement[cpe.length]; 65 66 for (int i = 0; i < cpe.length; i++) { 67 String localColumn = cpe[i].getName().getFullName(); 68 int pos = localColumn.indexOf(";"); 69 localColumn = localColumn.substring(0, pos); 70 71 ce[i] = ((ForeignKeyElement) element).getDeclaringTable().getColumn(DBIdentifier.create(localColumn)); 72 } 73 74 return ce; 75 } 76 77 public ColumnElement getColumn(DBIdentifier name) { 78 ColumnPairElement[] cpe = getColumnPairs(); 79 80 if (cpe == null || cpe.length == 0) 81 return null; 82 83 for (int i = 0; i < cpe.length; i++) { 84 String localColumn = cpe[i].getName().getFullName(); 85 int pos = localColumn.indexOf(";"); 86 localColumn = localColumn.substring(0, pos); 87 88 if (name.getName().equals(DBIdentifier.create(localColumn).getName())) return ((ForeignKeyElement) element).getDeclaringTable().getColumn(name); 90 } 91 92 return null; 93 } 94 95 } 96 | Popular Tags |