KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dml > declarecursor


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 /**
13  * This Class determines the properties of the Cursor being created, and
14  * creates a new instance of Cursor Class and sets the Cursor properties
15  * and other information to newly created cursor object.
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author unascribed
21  * @version 1.0
22  */

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    /**
40     * This method determines the parameters in query specification specified.
41     * @param object
42     * @return
43     * @throws DException
44     */

45    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
46       return _cursorspecification0.getParameters(object);
47    }
48
49    /**
50     * Calls the check sementic of the queryspecification to check validity of
51     * table and column names specified.
52     * @param serverSession
53     * @return
54     * @throws DException
55     */

56    public _Reference[] checkSemantic(_ServerSession serverSession) throws DException {
57       _cursorspecification0.setUserRight(checkUserRight);
58       return _cursorspecification0.checkSemantic(serverSession);
59    }
60
61    /**
62     * This method determines the sensitivity, holdability, returnability,
63     * scrollability ,updatability and cursor name and creates a new instance
64     * of Cursor Class and sets related information of cursor in Cursor instance.
65     * @param object
66     * @return
67     * @throws DException
68     */

69    public Object JavaDoc run(Object JavaDoc object) throws DException {
70       _StatementExecutionContext sec = (_StatementExecutionContext) object;
71       _ServerSession serverSession = sec.getServerSession();
72       String JavaDoc Cname = (String JavaDoc) _cursorname7.run(object);
73       String JavaDoc sensitivity = null;
74       if (serverSession.cursorAlreadyCreated(Cname)) {
75          throw new DException("DSE1260", new Object JavaDoc[] {Cname});
76       }
77       if (_Optcursorsensitivity6 != null) {
78          sensitivity = (String JavaDoc) _Optcursorsensitivity6.run(object);
79       } else {
80          sensitivity = CursorCodes.ASENSITIVE;
81       }
82       boolean holdability = false, returnability = false, scrollability = false;
83       if (_Optcursorholdability3 == null || ( (String JavaDoc) (_Optcursorholdability3.run(object))).equals(CursorCodes.WITHOUTHOLD)) {
84          holdability = false;
85       } else {
86          holdability = true;
87       }
88       if (_Optcursorreturnability2 == null || ( (String JavaDoc) (_Optcursorreturnability2.run(object))).equals(CursorCodes.WITHOUTRETURN)) {
89          returnability = false;
90       } else {
91          returnability = true;
92       }
93       if (_Optcursorscrollability5 == null || ( (String JavaDoc) (_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 JavaDoc[] returnArray = (Object JavaDoc[]) _cursorspecification0.run(object);
101       Object JavaDoc updateClauseValue = returnArray[0];
102       Object JavaDoc 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 JavaDoc[])null);
112          }
113          if (updateClauseValue instanceof String JavaDoc) {
114             cursor.setUpdatabilityClause(false, null);
115          } else {
116             String JavaDoc[] columnNames = (String JavaDoc[]) ( ( (Object JavaDoc[]) 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    /**
126     * Checks the sensitiviy of the declared cursor, wraps the iterator if
127     * cursor is insensitve otherwise iterator instance is used
128     * as itself to reflect the changed peformed to iterator.
129     * @param vv
130     * @return
131     * @throws DException
132     */

133    public Object JavaDoc 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 JavaDoc execute(Object JavaDoc[] obj) throws DException {
145       throw new RuntimeException JavaDoc(" Execute method with Object Array Not supported ");
146    }
147
148    /**
149     * Creates a clone object of this object.
150     * @return
151     * @throws CloneNotSupportedException
152     */

153    /*public Object clone() throws CloneNotSupportedException {
154      SRESERVEDWORD1206543922 sDECLARE_20346426148 = (SRESERVEDWORD1206543922)_SRESERVEDWORD12065439228.clone();
155      cursorname Cursorname7 = (cursorname)_cursorname7.clone();
156      cursorsensitivity Cursorsensitivity = null;
157      if ( _Optcursorsensitivity6 != null )
158        Cursorsensitivity = (cursorsensitivity)_Optcursorsensitivity6.clone();
159      cursorscrollability Cursorscrollability = null;
160      if ( _Optcursorscrollability5 != null )
161        Cursorscrollability = (cursorscrollability)_Optcursorscrollability5.clone();
162      SRESERVEDWORD1206543922 sCURSOR19991775584 = (SRESERVEDWORD1206543922)_SRESERVEDWORD12065439224.clone();
163      cursorholdability Cursorholdability = null;
164      if ( _Optcursorholdability3 != null )
165        Cursorholdability = (cursorholdability)_Optcursorholdability3.clone();
166      cursorreturnability Cursorreturnability = null;
167      if ( _Optcursorreturnability2 != null )
168        Cursorreturnability = (cursorreturnability)_Optcursorreturnability2.clone();
169      SRESERVEDWORD1206543922 sFOR698011 = (SRESERVEDWORD1206543922)_SRESERVEDWORD12065439221.clone();
170      cursorspecification Cursorspecification0 = (cursorspecification)_cursorspecification0.clone();
171      declarecursor Declarecursor = new declarecursor();
172      Declarecursor._SRESERVEDWORD12065439228 = sDECLARE_20346426148;
173      Declarecursor._cursorname7 = Cursorname7;
174      if ( _Optcursorsensitivity6 != null )
175        Declarecursor._Optcursorsensitivity6 = Cursorsensitivity;
176      if ( _Optcursorscrollability5 != null )
177        Declarecursor._Optcursorscrollability5 = Cursorscrollability;
178      Declarecursor._SRESERVEDWORD12065439224 = sCURSOR19991775584;
179      if ( _Optcursorholdability3 != null )
180        Declarecursor._Optcursorholdability3 = Cursorholdability;
181      if ( _Optcursorreturnability2 != null )
182        Declarecursor._Optcursorreturnability2 = Cursorreturnability;
183      Declarecursor._SRESERVEDWORD12065439221 = sFOR698011;
184      Declarecursor._cursorspecification0 = Cursorspecification0;
185      return Declarecursor;
186       }*/

187
188    public String JavaDoc toString() {
189       StringBuffer JavaDoc clause = new StringBuffer JavaDoc();
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    /**
220     * Returns the iterator i.e. Dummy iterator created with the values that of
221     * the iterator got from query specification so that changes to the iterator
222     * would not reflect on itearator of Cursor instance.
223     * @param iterator
224     * @return
225     * @throws DException
226     */

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 JavaDoc executeForFresh(Object JavaDoc[] values) throws DException {
240       throw new java.lang.UnsupportedOperationException JavaDoc("Method executeForFresh() not yet implemented.");
241    }
242
243    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
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