1 19 package org.openharmonise.commons.dsi.dml; 20 21 22 import java.util.*; 23 24 import org.openharmonise.commons.dsi.*; 25 26 34 public abstract class AbstractDMLStatement { 35 36 39 protected WhereConditionGroup m_where = null; 40 41 44 protected Vector m_Tables = null; 45 46 49 protected Vector m_TableAliases = null; 50 51 54 protected boolean m_bIsAliasListComplete = false; 55 56 60 protected AbstractDMLStatement() { 61 } 62 63 70 public void addTableAlias(String sTable, String sAlias) 71 throws DataStoreException { 72 if (m_Tables == null) { 73 m_Tables = new Vector(16); 74 m_TableAliases = new Vector(16); 75 } 76 77 if (m_TableAliases.contains(sAlias)) { 78 throw new DataStoreException("Alias already exists"); 79 } 80 81 m_Tables.add(sTable); 82 m_TableAliases.add(sAlias); 83 } 84 85 91 public String getTableAlias(String sTable) { 92 String sReturn = null; 93 94 int index = m_Tables.indexOf(sTable); 95 96 if (index >= 0) { 97 sReturn = (String ) m_TableAliases.elementAt(index); 98 } 99 100 return sReturn; 101 } 102 103 111 public boolean isAlias(String sAlias) throws DataStoreException { 112 boolean bIsAlias = false; 113 114 if (m_TableAliases != null) { 115 bIsAlias = m_TableAliases.contains(sAlias); 116 } 117 118 if (bIsAlias == false && m_bIsAliasListComplete == false && m_where != null) { 119 List cols = m_where.getColumnRefs(); 120 121 Iterator iter = cols.iterator(); 122 123 while (iter.hasNext()) { 124 ColumnRef col = (ColumnRef) iter.next(); 125 126 if (col.hasTableAlias() == true) { 127 addTableAlias(col.getTable(), col.getTableAlias()); 128 } 129 } 130 131 m_bIsAliasListComplete = true; 132 if (m_TableAliases != null) { 133 bIsAlias = m_TableAliases.contains(sAlias); 134 } 135 } 136 137 return bIsAlias; 138 } 139 140 146 public String getTableName(String sAlias) { 147 String sReturn = null; 148 149 int index = m_TableAliases.indexOf(sAlias); 150 151 if (index >= 0) { 152 sReturn = (String ) m_Tables.elementAt(index); 153 } 154 155 return sReturn; 156 } 157 158 166 public void addWhereCondition(ColumnRef colref, String sOperator, int val) 167 throws DataStoreException { 168 Vector vec = new Vector(1); 169 vec.add(new Integer (val)); 170 171 addWhereCondition(colref, sOperator, vec); 172 } 173 174 183 public void addWhereCondition( 184 ColumnRef colref, 185 String sOperator, 186 Object val) 187 throws DataStoreException { 188 Vector vec = new Vector(1); 189 vec.add(val); 190 191 addWhereCondition(colref, sOperator, vec); 192 } 193 194 202 public void addWhereCondition( 203 ColumnRef colref, 204 String sOperator, 205 List vals) 206 throws DataStoreException { 207 if (m_where == null) { 208 m_where = new WhereConditionGroup(); 209 } 210 211 if(vals == null) { 212 vals = new Vector(); 213 vals.add(null); 214 } 215 216 m_where.addCondition(colref, sOperator, vals); 217 } 218 219 225 public void addWhereCondition(WhereConditionGroup where) 226 throws DataStoreException { 227 if (m_where == null) { 228 m_where = new WhereConditionGroup(); 229 } 230 231 m_where.addCondition(where); 232 } 233 234 240 public void addWhereCondition(WhereCondition where) 241 throws DataStoreException { 242 if (m_where == null) { 243 m_where = new WhereConditionGroup(); 244 } 245 246 m_where.addCondition(where); 247 } 248 249 255 public void setWhereConditionStringingOperator(String sOp) 256 throws DataStoreException { 257 m_where.setStringingOperator(sOp); 258 } 259 260 265 public boolean hasWhereClause() { 266 return (m_where != null); 267 } 268 269 274 public boolean hasWhereConditions() { 275 if ((m_where == null) || (m_where.size() == 0)) { 276 return false; 277 } else { 278 return true; 279 } 280 } 281 282 286 public WhereConditionGroup getWhereConditions() { 287 return m_where; 288 } 289 290 294 public void clear() { 295 m_where = null; 296 297 if (m_Tables != null) { 298 m_Tables.removeAllElements(); 299 m_TableAliases.removeAllElements(); 300 } 301 } 302 } | Popular Tags |