1 package com.daffodilwoods.daffodildb.server.sql99.dml.declarecursor; 2 3 import com.daffodilwoods.daffodildb.server.serversystem.*; 4 import com.daffodilwoods.daffodildb.server.sql99.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dml.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.token.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.database.general.*; 10 import com.daffodilwoods.database.resource.*; 11 12 23 public class declarecursor implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, SQL99, _Executer { 24 25 public cursorspecification _cursorspecification0; 26 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221; 27 public cursorreturnability _Optcursorreturnability2; 28 public cursorholdability _Optcursorholdability3; 29 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224; 30 public cursorscrollability _Optcursorscrollability5; 31 public cursorsensitivity _Optcursorsensitivity6; 32 public cursorname _cursorname7; 33 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439228; 34 35 private Cursor cursor; 36 private _Executer executer; 37 boolean checkUserRight = true; 38 private _Iterator iterator; 39 45 public Object [] getParameters(Object object) throws DException { 46 return _cursorspecification0.getParameters(object); 47 } 48 49 56 public _Reference[] checkSemantic(_ServerSession serverSession) throws DException { 57 _cursorspecification0.setUserRight(checkUserRight); 58 return _cursorspecification0.checkSemantic(serverSession); 59 } 60 61 69 public Object run(Object object) throws DException { 70 _StatementExecutionContext sec = (_StatementExecutionContext) object; 71 _ServerSession serverSession = sec.getServerSession(); 72 String Cname = (String ) _cursorname7.run(object); 73 String sensitivity = null; 74 if (serverSession.cursorAlreadyCreated(Cname)) { 75 throw new DException("DSE1260", new Object [] {Cname}); 76 } 77 if (_Optcursorsensitivity6 != null) { 78 sensitivity = (String ) _Optcursorsensitivity6.run(object); 79 } else { 80 sensitivity = CursorCodes.ASENSITIVE; 81 } 82 boolean holdability = false, returnability = false, scrollability = false; 83 if (_Optcursorholdability3 == null || ( (String ) (_Optcursorholdability3.run(object))).equals(CursorCodes.WITHOUTHOLD)) { 84 holdability = false; 85 } else { 86 holdability = true; 87 } 88 if (_Optcursorreturnability2 == null || ( (String ) (_Optcursorreturnability2.run(object))).equals(CursorCodes.WITHOUTRETURN)) { 89 returnability = false; 90 } else { 91 returnability = true; 92 } 93 if (_Optcursorscrollability5 == null || ( (String ) (_Optcursorscrollability5.run(object))).equals(CursorCodes.NOSCROLL)) { 94 scrollability = false; 95 } else { 96 scrollability = true; 97 } 98 cursor = new Cursor(sensitivity, holdability, returnability, scrollability, Cname, _cursorspecification0); 99 serverSession.addCursor(Cname, cursor); 100 Object [] returnArray = (Object []) _cursorspecification0.run(object); 101 Object updateClauseValue = returnArray[0]; 102 Object orderByClause = returnArray[1]; 103 if (updateClauseValue == null) { 104 if (sensitivity.equals(CursorCodes.INSENSITIVE) || scrollability == true || orderByClause != null) { 105 cursor.setUpdatabilityClause(false, null); 106 } else { 107 cursor.setUpdatabilityClause(true, null); 108 } 109 } else { 110 if (sensitivity.equalsIgnoreCase(CursorCodes.INSENSITIVE)) { 111 throw new DException("DSE1263", (Object [])null); 112 } 113 if (updateClauseValue instanceof String ) { 114 cursor.setUpdatabilityClause(false, null); 115 } else { 116 String [] columnNames = (String []) ( ( (Object []) updateClauseValue)[1]); 117 cursor.setUpdatabilityClause(true, columnNames); 118 } 119 } 120 cursor.setCursorState(false); 121 executer = (_Executer) _cursorspecification0._queryexpression2.run(serverSession); 122 return this; 123 } 124 125 133 public Object execute(_VariableValues vv) throws DException { 134 iterator = null; 135 if (cursor.getCursorSensitivity().equalsIgnoreCase("INSENSITIVE")) { 136 iterator = getWrapperOverIterator( (_Iterator) executer.execute(vv)); 137 } else { 138 iterator = (_Iterator) executer.execute(vv); 139 } 140 cursor.addIterator(iterator); 141 return null; 142 } 143 144 public Object execute(Object [] obj) throws DException { 145 throw new RuntimeException (" Execute method with Object Array Not supported "); 146 } 147 148 153 187 188 public String toString() { 189 StringBuffer clause = new StringBuffer (); 190 clause.append(" "); 191 clause.append(_SRESERVEDWORD12065439228.toString()); 192 clause.append(" "); 193 clause.append(_cursorname7.toString()); 194 if (_Optcursorsensitivity6 != null) { 195 clause.append(" "); 196 clause.append(_Optcursorsensitivity6.toString()); 197 } 198 if (_Optcursorscrollability5 != null) { 199 clause.append(" "); 200 clause.append(_Optcursorscrollability5.toString()); 201 } 202 clause.append(" "); 203 clause.append(_SRESERVEDWORD12065439224.toString()); 204 if (_Optcursorholdability3 != null) { 205 clause.append(" "); 206 clause.append(_Optcursorholdability3.toString()); 207 } 208 if (_Optcursorreturnability2 != null) { 209 clause.append(" "); 210 clause.append(_Optcursorreturnability2.toString()); 211 } 212 clause.append(" "); 213 clause.append(_SRESERVEDWORD12065439221.toString()); 214 clause.append(" "); 215 clause.append(_cursorspecification0.toString()); 216 return clause.toString().trim(); 217 } 218 219 227 private _Iterator getWrapperOverIterator(_Iterator iterator) throws DException { 228 CursorTableCharacteristics ctc = new CursorTableCharacteristics(_cursorspecification0._queryexpression2.getColumnDetails().length); 229 MemoryTable mt = new MemoryTable(new QualifiedIdentifier(cursor.getCursorName()), ctc); 230 if (iterator.first()) { 231 do { 232 mt.insert(iterator.getColumnValues()); 233 } while (iterator.next()); 234 } 235 _Iterator iterToReturn = new CursorIterator(mt.getIterator()); 236 return iterToReturn; 237 } 238 239 public Object executeForFresh(Object [] values) throws DException { 240 throw new java.lang.UnsupportedOperationException ("Method executeForFresh() not yet implemented."); 241 } 242 243 public Object clone() throws CloneNotSupportedException { 244 return this; 245 } 246 public void setUserRight(boolean rights) { 247 checkUserRight = rights; 248 } 249 250 public _Iterator getIterator() throws DException{ 251 return iterator; 252 } 253 } 254 | Popular Tags |