1 package xdoclet.modules.ojb.model; 2 3 17 18 import java.util.*; 19 20 import org.apache.commons.collections.SequencedHashMap; 21 22 27 public class TableDef extends DefBase 28 { 29 30 private SequencedHashMap _columns = new SequencedHashMap(); 31 32 private ArrayList _indices = new ArrayList(); 33 34 private ArrayList _foreignkeys = new ArrayList(); 35 36 41 public TableDef(String name) 42 { 43 super(name); 44 } 45 46 51 public Iterator getColumns() 52 { 53 return _columns.values().iterator(); 54 } 55 56 62 public ColumnDef getColumn(String name) 63 { 64 return (ColumnDef)_columns.get(name); 65 } 66 67 72 public void addColumn(ColumnDef columnDef) 73 { 74 columnDef.setOwner(this); 75 _columns.put(columnDef.getName(), columnDef); 76 } 77 78 83 public void addIndex(IndexDef indexDef) 84 { 85 indexDef.setOwner(this); 86 _indices.add(indexDef); 87 } 88 89 95 public IndexDef getIndex(String name) 96 { 97 String realName = (name == null ? "" : name); 98 IndexDef def = null; 99 100 for (Iterator it = getIndices(); it.hasNext();) 101 { 102 def = (IndexDef)it.next(); 103 if (def.getName().equals(realName)) 104 { 105 return def; 106 } 107 } 108 return null; 109 } 110 111 116 public Iterator getIndices() 117 { 118 return _indices.iterator(); 119 } 120 121 129 public void addForeignkey(String relationName, String remoteTable, List localColumns, List remoteColumns) 130 { 131 ForeignkeyDef foreignkeyDef = new ForeignkeyDef(relationName, remoteTable); 132 133 for (int idx = 0; idx < localColumns.size(); idx++) 135 { 136 foreignkeyDef.addColumnPair((String )localColumns.get(idx), 137 (String )remoteColumns.get(idx)); 138 } 139 140 ForeignkeyDef def = null; 142 143 for (Iterator it = getForeignkeys(); it.hasNext();) 144 { 145 def = (ForeignkeyDef)it.next(); 146 if (foreignkeyDef.equals(def)) 147 { 148 return; 149 } 150 } 151 foreignkeyDef.setOwner(this); 152 _foreignkeys.add(foreignkeyDef); 153 } 154 155 161 public boolean hasForeignkey(String name) 162 { 163 String realName = (name == null ? "" : name); 164 ForeignkeyDef def = null; 165 166 for (Iterator it = getForeignkeys(); it.hasNext();) 167 { 168 def = (ForeignkeyDef)it.next(); 169 if (realName.equals(def.getName())) 170 { 171 return true; 172 } 173 } 174 return false; 175 } 176 177 184 public ForeignkeyDef getForeignkey(String name, String tableName) 185 { 186 String realName = (name == null ? "" : name); 187 ForeignkeyDef def = null; 188 189 for (Iterator it = getForeignkeys(); it.hasNext();) 190 { 191 def = (ForeignkeyDef)it.next(); 192 if (realName.equals(def.getName()) && 193 def.getTableName().equals(tableName)) 194 { 195 return def; 196 } 197 } 198 return null; 199 } 200 201 206 public Iterator getForeignkeys() 207 { 208 return _foreignkeys.iterator(); 209 } 210 } 211 | Popular Tags |