1 package com.daffodilwoods.daffodildb.server.sql99.dcl.sqlcontrolstatement; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.serversystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dml.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dml.declarecursor.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 10 import com.daffodilwoods.daffodildb.server.sql99.token.*; 11 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 12 import com.daffodilwoods.daffodildb.utils.parser.*; 13 import com.daffodilwoods.database.resource.*; 14 import com.daffodilwoods.database.utility.*; 15 16 public class forstatement implements SQLcontrolstatement { 17 public endinglabel _Optendinglabel0; 18 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221; 19 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222; 20 public SQLstatementlist _SQLstatementlist3; 21 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224; 22 public cursorspecification _cursorspecification5; 23 public 24 cursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD1206543922 _OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226; 25 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439227; 26 public forloopvariablename _forloopvariablename8; 27 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439229; 28 public beginninglabelScolon94842719 _OptbeginninglabelScolon9484271910; 29 30 private SQLcontrolstatement outerControlStatement; 31 private String beginningLabel; 32 private declarecursor declareCursor; 33 private openstatement openStt; 34 private fetchstatement fetchStt; 35 private closestatement closeStt; 36 private cursorpredicate cursorPredicate; 37 private _Reference[] declareCursorRefs; 38 private _Reference[] openSttRefs; 39 private _Reference[] fetchSttRefs; 40 private _Reference[] closeSttRefs; 41 private _Reference[] cursorPredicateRefs; 42 private _ServerSession serverSession; 43 private boolean forAlias; 44 private _Reference[] forAliasRefernces; 45 46 public void setOuterControlStatement(SQLcontrolstatement outerst) { 47 outerControlStatement = outerst; 48 } 49 50 public Object run(Object object) throws DException { 51 _StatementExecutionContext sec = (_StatementExecutionContext) object; 52 _ServerSession serverSession = sec.getServerSession(); 53 checkSystax(serverSession); 54 _SQLstatementlist3.run(object); 55 return this; 56 } 57 58 public void makeCursor() throws DException { 59 String decCurQuery = " declare "; 60 declareCursor = new declarecursor(); 61 if (_OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226 == null) { 62 decCurQuery += (" cursor" + this.hashCode() + " "); 63 } else { 64 decCurQuery += _OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226._cursorname3.run(null); 65 cursorsensitivity cursen = _OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226._Optcursorsensitivity2; 66 if (cursen != null) { 67 decCurQuery += (" " + cursen.run(null) + " "); 68 } 69 } 70 decCurQuery += " cursor for " + _cursorspecification5.toString(); 71 declareCursor = (declarecursor) Parser.parseQuery(decCurQuery); 72 73 declareCursor.setUserRight(false); 74 75 76 cursorPredicate = new cursorpredicate(); 77 cursorPredicate._cursorname2 = declareCursor._cursorname7; 78 SRESERVEDWORD1206543922 sr = new SRESERVEDWORD1206543922(); 79 sr._SRESERVEDWORD12065439220 = SqlKeywords.FOUND; 80 cursorPredicate._cursorstatus0 = sr; 81 82 openStt = new openstatement(); 83 openStt._cursorname0 = declareCursor._cursorname7; 84 85 String fetch = "FETCH " + declareCursor._cursorname7.run(null) 86 + " INTO " + _forloopvariablename8.toString(); 87 fetchStt = (fetchstatement) Parser.parseQuery(fetch); 88 89 closeStt = new closestatement(); 90 closeStt._cursorname0 = declareCursor._cursorname7; 91 } 92 93 private void checkSystax(_ServerSession serverSession) throws DException { 94 checkMatchingBeginningAndEndingLabel(serverSession); 95 if (_OptbeginninglabelScolon9484271910 == null) { assignImplicitBeginningLabel(); 97 } else { 98 beginningLabel = "@" + 99 (String ) _OptbeginninglabelScolon9484271910.getIdentifier(); 100 } 101 scopeManagement(serverSession); 102 } 103 104 private void checkMatchingBeginningAndEndingLabel(_ServerSession 105 serverSession) throws DException { 106 if (_Optendinglabel0 != null) { 107 if (_OptbeginninglabelScolon9484271910 == null) { 108 throw new DException("DSE8036", null); 109 } 110 else if (! ( (String ) _Optendinglabel0.getIdentifier()).equalsIgnoreCase 111 ( (String ) _OptbeginninglabelScolon9484271910.getIdentifier())) { 112 throw new DException("DSE8037", null); 113 } 114 } 115 } 116 117 private void scopeManagement(_ServerSession serverSession) throws DException { 118 } 119 120 private void assignImplicitBeginningLabel() throws DException { 121 beginningLabel = "@internalLabel" + this.hashCode(); 122 } 123 124 public Object [] getParameters(Object object) throws DException { 125 126 ArrayList list = new ArrayList(); 127 if (declareCursor == null) { 128 makeCursor(); 129 } 130 Object [] par1 = declareCursor.getParameters(object); 131 if (par1 != null) { 132 list.addAll(Arrays.asList(par1)); 133 } 134 Object [] par2 = _SQLstatementlist3.getParameters(object); 135 if (par2 != null) { 136 list.addAll(Arrays.asList(par2)); 137 } 138 return list.toArray(); 139 } 140 141 237 238 public Object execute(_VariableValues variableValues1) throws DException { 239 _StatementExecutionContext sec = variableValues1.getServerSession(). 240 getStatementExecutionContext(); 241 declareCursor.run(sec); 242 openStt.run(sec); 243 try { 244 fetchStt.run(sec); 245 } catch (DException ex) { 246 if (! (forAlias && ex.getDseCode().equalsIgnoreCase("DSE1185"))) 247 throw ex; 248 } 249 closeStt.run(sec); 250 ArrayList returningResultList = new ArrayList(); 251 _SQLstatementlist3.setOuterControlStatement(this); 252 addCursorInVariableValue(variableValues1); 253 SearchConditionUtility.executeStatements(declareCursor, declareCursorRefs, variableValues1, serverSession); 254 SearchConditionUtility.executeStatements(openStt, openSttRefs, variableValues1, serverSession); 255 _VariableValues variableValues = null; 256 if (forAlias) { 257 _Iterator iter = declareCursor.getIterator(); 258 variableValues = new ForLoopVariableValues(iter, forAliasRefernces, variableValues1); 259 fetchStt.setForAlias(true); 260 SearchConditionUtility.executeForAliasStatements(fetchStt, fetchSttRefs, variableValues, serverSession); 261 } else { 262 variableValues = variableValues1; 263 SearchConditionUtility.executeStatements(fetchStt, fetchSttRefs, variableValues, serverSession); 264 } 265 266 try { 267 while (SearchConditionUtility.executeExpression(cursorPredicate, new _Reference[0], 268 variableValues, serverSession).hashCode() == 0) { 269 Object listResult = _SQLstatementlist3.execute(variableValues); 270 if (listResult instanceof SqlStatementListResult) { 271 SqlStatementListResult result = (SqlStatementListResult) listResult; 272 if (result.hasIterateLeaveResult()) { 273 IterateLeaveResult temp = result.getIterateLeaveResult(); 274 if (temp.getLabel().equalsIgnoreCase(beginningLabel)) { 275 returningResultList.add(result.getResult()); 276 if (temp.getType() == IterateLeaveResult.ITERATETYPE) { 277 continue; 278 } else if (temp.getType() == IterateLeaveResult.LEAVETYPE) { 279 break; 280 } 281 } else { 282 SqlStatementListResult returningResult = new SqlStatementListResult(0); 283 returningResult.setResult(returningResultList.toArray()); 284 returningResult.setIterateLeaveResult(temp); 285 if (outerControlStatement == null) { 286 throw new DException("DSE8038", null); 287 } 288 return returningResult; 289 } 290 } else { 291 returningResultList.add(result.getResult()); 292 } 293 } else if (listResult instanceof ReturnResult) { 294 return listResult; 295 } 296 if (forAlias) { 297 SearchConditionUtility.executeForAliasStatements(fetchStt, fetchSttRefs, variableValues, serverSession); 298 } else { 299 SearchConditionUtility.executeStatements(fetchStt, fetchSttRefs, variableValues, serverSession); 300 } 301 } 302 } finally { 303 SearchConditionUtility.executeStatements(closeStt, closeSttRefs, variableValues1, serverSession); 304 } 305 return returningResultList; 306 } 307 308 public Object execute(Object [] values) throws DException { 309 throw new UnsupportedOperationException (); 310 } 311 312 public Object executeForFresh(Object [] values) throws DException { 313 throw new UnsupportedOperationException (); 314 } 315 316 public void addCursorInVariableValue(_VariableValues variableValues) throws 317 DException { 318 String curName = (String ) declareCursor._cursorname7.run(null); 319 _Reference ref = new ProcedureStringReference(curName); 320 ref.setDatatype(Datatypes.BOOLEAN); 321 _Reference[] refs = new _Reference[] {ref}; 322 variableValues.addReferences(refs); 323 variableValues.setConditionVariableValue(refs, new Object [] {IntegerPool.Integer0} 324 , 1); 325 } 326 327 public ParameterInfo[] getParameterInfo() throws DException { 328 throw new UnsupportedOperationException (); 329 } 330 331 public String toString() { 332 StringBuffer sb = new StringBuffer (); 333 sb.append(" "); 334 if (_OptbeginninglabelScolon9484271910 != null) { 335 sb.append(_OptbeginninglabelScolon9484271910); 336 } 337 sb.append(" "); 338 sb.append(_SRESERVEDWORD12065439229); 339 sb.append(" "); 340 sb.append(_forloopvariablename8); 341 sb.append(" "); 342 sb.append(_SRESERVEDWORD12065439227); 343 sb.append(" "); 344 if (_OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226 != null) { 345 sb.append(_OptcursornameOptcursorsensitivitySRESERVEDWORD1206543922SRESERVEDWORD12065439226); 346 } 347 sb.append(" "); 348 sb.append(_cursorspecification5); 349 sb.append(" "); 350 sb.append(_SRESERVEDWORD12065439224); 351 sb.append(" "); 352 sb.append(_SQLstatementlist3); 353 sb.append(" "); 354 sb.append(_SRESERVEDWORD12065439222); 355 sb.append(" "); 356 sb.append(_SRESERVEDWORD12065439221); 357 sb.append(" "); 358 if (_Optendinglabel0 != null) { 359 sb.append(_Optendinglabel0); 360 } 361 return sb.toString().trim(); 362 } 363 364 public Object clone() throws CloneNotSupportedException { 365 return this; 366 } 367 368 public ColumnDetails[] getColumnDetails() throws DException { 369 return _SQLstatementlist3.getColumnDetails(); 370 } 371 372 public _Reference[] checkSemantic(_ServerSession object) throws DException { 373 boolean found = false; 374 serverSession = object; 375 checkMatchingBeginningAndEndingLabel(serverSession); 376 ArrayList set = new ArrayList(); 377 if (declareCursor == null) { 378 makeCursor(); 379 } 380 _Reference[] par1 = declareCursor.checkSemantic(object); 381 if (par1 != null) { 382 set.addAll(Arrays.asList(par1)); 383 } 384 385 _Reference[] cursorRefs = _cursorspecification5.checkSemantic(object); 386 if (cursorRefs != null) { 387 set.addAll(Arrays.asList(cursorRefs)); 388 } 389 390 ArrayList varNames = _forloopvariablename8.getVariableNames(); 391 ColumnDetails sqlStatementColumnDetails[] = _SQLstatementlist3.getColumnDetails(); 392 ArrayList refList = new ArrayList(); 393 GeneralPurposeStaticClass.addRecursively(sqlStatementColumnDetails, refList); 394 ColumnDetails[] selectedColumns = declareCursor._cursorspecification0._queryexpression2.getSelectedColumns(); 395 if (refList != null) { 396 for (int i = 0; i < refList.size(); i++) { 397 ColumnDetails cd = (ColumnDetails) refList.get(i); 398 for (int m = 0; m < varNames.size(); m++) { 399 if (cd.getQualifiedColumnName().toString().startsWith(varNames.get(m).toString())) { 400 for (int k = 0; k < selectedColumns.length; k++) { 401 if (selectedColumns[k].getColumn().equalsIgnoreCase(cd.getColumn())) { 402 cd.setDatatype(selectedColumns[k].getDatatype()); 403 cd.setSize(selectedColumns[k].getSize()); 404 } 405 } 406 } 407 } 408 } 409 } 410 _Reference[] par2 = _SQLstatementlist3.checkSemantic(object); 411 ArrayList aList = new ArrayList(); 412 if (varNames.size() == 1) { 413 if (par2 != null) { 414 for (int j = 0; j < par2.length; j++) { 415 if (par2[j].getTriggerTableAlias() != null && 416 par2[j].getTriggerTableAlias().equalsIgnoreCase(varNames.get(0).toString())) { 417 aList.add(par2[j]); 418 forAlias = true; 419 found = true; 420 } else { 421 set.add(par2[j]); 422 } 423 } 424 if (!found) { 425 set.add(new ProcedureStringReference( (String ) varNames.get(0))); 426 } 427 } else { 428 set.add(new ProcedureStringReference( (String ) varNames.get(0))); 429 } 430 } else { 431 if (varNames.size() != selectedColumns.length) { 432 throw new DException("DSE8197", null); 433 } 434 if (par2 != null) { 435 set.addAll(Arrays.asList(par2)); 436 } 437 for (int i = 0; i < varNames.size(); i++) { 438 set.add(new ProcedureStringReference( (String ) varNames.get(i))); 439 } 440 } 441 442 boolean refFound; 443 for (int p = 0; p < aList.size(); p++) { 444 refFound = false; 445 _Reference ref = (_Reference) aList.get(p); 446 for (int q = 0; q < selectedColumns.length; q++) { 447 if (ref.getColumn().equalsIgnoreCase(selectedColumns[q].getColumn())) { 448 refFound = true; 449 break; 450 } 451 } 452 if (!refFound) { 453 throw new DException("DSE8196", new Object [] {ref.getQualifiedColumnName()}); 454 } 455 } 456 457 forAliasRefernces = (_Reference[]) aList.toArray(new _Reference[0]); 458 String curName = (String ) declareCursor._cursorname7.run(null); 459 ArrayList newSet = new ArrayList(); 460 if (set != null) { 461 for (int i = 0; i < set.size(); i++) { 462 _Reference ref = (_Reference) set.get(i); 463 if (ref.getQualifiedColumnName().equalsIgnoreCase(curName) == false) { 464 newSet.add(ref); 465 } 466 } 467 } 468 declareCursorRefs = declareCursor.checkSemantic(object); 469 openSttRefs = openStt.checkSemantic(object); 470 fetchSttRefs = fetchStt.checkSemantic(object); 471 closeSttRefs = closeStt.checkSemantic(object); 472 473 cursorPredicateRefs = cursorPredicate.getReferences(dummyTableDetail); 474 return (_Reference[]) newSet.toArray(new _Reference[0]); 475 } 476 477 public void getTableIncluded(ArrayList aList) throws DException { 478 _cursorspecification5.getTableIncluded(aList); 479 } 480 481 public void getColumnsIncluded(ArrayList aList) throws DException { 482 _cursorspecification5.getColumnsIncluded(aList); 483 } 484 } 485 | Popular Tags |