1 19 package org.openharmonise.commons.dsi.dml; 20 21 import java.util.*; 22 import java.util.logging.*; 23 24 import org.openharmonise.commons.dsi.*; 25 26 27 36 public class JoinConditions { 37 38 41 private List m_LeftCols = null; 42 43 46 private List m_RightCols = null; 47 48 51 private List m_outerjoins = null; 52 53 56 private static final Logger m_logger = Logger.getLogger(JoinConditions.class.getName()); 57 58 61 public JoinConditions() { 62 m_LeftCols = new Vector(16); 64 m_RightCols = new Vector(16); 65 m_outerjoins = new Vector(); 66 } 67 68 75 public void addCondition(ColumnRef Col1, ColumnRef Col2) 76 throws DataStoreException { 77 78 m_LeftCols.add(Col1); 80 m_RightCols.add(Col2); 81 } 82 83 90 public void addOuterJoin(ColumnRef Col1, ColumnRef Col2) 91 throws DataStoreException { 92 addCondition(Col1, Col2); 93 m_outerjoins.add(new Integer (m_LeftCols.size() - 1)); 94 } 95 96 103 public boolean isOuterJoin(int index) { 104 return (m_outerjoins.contains(new Integer (index))); 105 } 106 107 114 public ColumnRef getLeftColumnRef(int index) { 115 return (ColumnRef) m_LeftCols.get(index); 116 } 117 118 125 public ColumnRef getRightColumnRef(int index) { 126 return (ColumnRef) m_RightCols.get(index); 127 } 128 129 136 public String getLeftTableName(int index) { 137 return (((ColumnRef) m_LeftCols.get(index)).getTable()); 138 } 139 140 147 public String getLeftColumnName(int index) { 148 return (((ColumnRef) m_LeftCols.get(index)).getColumn()); 149 } 150 151 158 public String getLeftFullColumnRef(int index) { 159 return (((ColumnRef) m_LeftCols.get(index)).getFullRef()); 160 } 161 162 169 public String getRightColumnName(int index) { 170 return (((ColumnRef) m_RightCols.get(index)).getColumn()); 171 } 172 173 180 public String getRightTableName(int index) { 181 return (((ColumnRef) m_RightCols.get(index)).getTable()); 182 } 183 184 191 public String getRightFullColumnRef(int index) { 192 return (((ColumnRef) m_RightCols.get(index)).getFullRef()); 193 } 194 195 200 public List getTableList() { 201 Vector vec1 = new Vector(16); 202 Vector vec2 = new Vector(16); 203 Vector vecr = null; 204 205 for (int i = 0; i < m_RightCols.size(); i++) { 206 vec1.add(getLeftTableName(i)); 207 vec2.add(getRightTableName(i)); 208 } 209 210 vecr = new Vector(16); 211 212 for (int i = 0; i < vec1.size(); i++) { 213 if (!vecr.contains(vec1.elementAt(i))) { 214 vecr.add(vec1.elementAt(i)); 215 } 216 } 217 218 for (int i = 0; i < vec2.size(); i++) { 219 if (!vecr.contains(vec2.elementAt(i))) { 220 vecr.add(vec2.elementAt(i)); 221 } 222 } 223 224 return vecr; 225 } 226 227 232 public int size() { 233 return (m_RightCols.size()); 234 } 235 236 240 public void empty() { 241 if (m_LeftCols != null) { 242 m_LeftCols.clear(); 243 m_RightCols.clear(); 244 m_outerjoins.clear(); 245 } 246 } 247 248 254 public void merge(JoinConditions join) throws DataStoreException { 255 for (int i = 0; i < join.size(); i++) { 256 if (join.isOuterJoin(i)) { 257 addOuterJoin(join.getLeftColumnRef(i), 258 join.getRightColumnRef(i)); 259 } else { 260 addCondition(join.getLeftColumnRef(i), 261 join.getRightColumnRef(i)); 262 } 263 } 264 } 265 266 271 public JoinConditions getInnerJoins() { 272 JoinConditions innerJoins = new JoinConditions(); 273 274 for (int i = 0; i < size(); i++) { 275 if (isOuterJoin(i) == false) { 276 try { 277 innerJoins.addCondition(getLeftColumnRef(i), getRightColumnRef(i)); 278 } catch (DataStoreException e) { 279 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 280 } 281 } 282 } 283 284 return innerJoins; 285 } 286 287 291 public JoinConditions getOuterJoins() { 292 JoinConditions outerJoins = new JoinConditions(); 293 294 for (int i = 0; i < m_outerjoins.size(); i++) { 295 int index = ((Integer )m_outerjoins.get(i)).intValue(); 296 297 if (isOuterJoin(index) == true) { 298 try { 299 outerJoins.addCondition(getLeftColumnRef(index), getRightColumnRef(index)); 300 } catch (DataStoreException e) { 301 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 302 } 303 } 304 } 305 306 return outerJoins; 307 } 308 } | Popular Tags |