KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dcl > sqlcontrolstatement > compoundstatement


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.token.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.database.resource.*;
10
11 public class compoundstatement implements SQLcontrolstatement {
12    public endinglabel _Optendinglabel0;
13    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
14    public SQLstatementlist _OptSQLstatementlist2;
15    public localcursordeclarationlist _Optlocalcursordeclarationlist3;
16    public localdeclarationlist _Optlocaldeclarationlist4;
17    public OptSRESERVEDWORD1206543922SNONRESERVEDWORD136444255
18        _OptOptSRESERVEDWORD1206543922SNONRESERVEDWORD1364442555;
19    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439226;
20    public beginninglabelScolon94842719 _OptbeginninglabelScolon948427197;
21
22    private SQLcontrolstatement outerControlStatement;
23    private boolean isAtomic = false;
24    private String JavaDoc beginningLabel;
25    private _ServerSession serverSession;
26    private ArrayList parameterList;
27
28    public void setOuterControlStatement(SQLcontrolstatement outerst) {
29       outerControlStatement = outerst;
30    }
31
32    public Object JavaDoc run(Object JavaDoc object) throws DException {
33       _StatementExecutionContext sec = (_StatementExecutionContext) object;
34       _ServerSession serverSession = sec.getServerSession();
35       checkSyntax(serverSession);
36       if (_Optlocalcursordeclarationlist3 != null) {
37          _Optlocalcursordeclarationlist3.run(object);
38       }
39       if (_OptSQLstatementlist2 != null) {
40          _OptSQLstatementlist2.setOuterControlStatement(this);
41          _OptSQLstatementlist2.run(object);
42       }
43       return this;
44    }
45
46    private void checkSyntax(_ServerSession serverSession) throws DException {
47       checkMatchingBeginningAndEndingLabel();
48       if (_OptbeginninglabelScolon948427197 == null) { // && outerControlStatement!=null)
49
assignImplicitBeginningLabel();
50       } else {
51          beginningLabel = "@" +
52              (String JavaDoc) _OptbeginninglabelScolon948427197.getIdentifier();
53       }
54       assignAtomicValue(serverSession);
55       checkAtomicCondition(serverSession);
56       checkCommitRollbackStatement(serverSession);
57    }
58
59    private void checkMatchingBeginningAndEndingLabel() throws DException {
60       if (_Optendinglabel0 != null) {
61          if (_OptbeginninglabelScolon948427197 == null) {
62             throw new DException("DSE8036", null);
63          } else if (! ( (String JavaDoc) _Optendinglabel0.getIdentifier()).equalsIgnoreCase
64                     ( (String JavaDoc) _OptbeginninglabelScolon948427197.getIdentifier())) {
65             throw new DException("DSE8037", null);
66          }
67       }
68    }
69
70    private void scopeManagement(_ServerSession serverSession) throws DException {
71    }
72
73    private void assignImplicitBeginningLabel() throws DException {
74       beginningLabel = "@internalLabel" + this.hashCode();
75    }
76
77    private void assignAtomicValue(_ServerSession serverSession) throws
78        DException {
79       if (_OptOptSRESERVEDWORD1206543922SNONRESERVEDWORD1364442555 != null) {
80          String JavaDoc t = _OptOptSRESERVEDWORD1206543922SNONRESERVEDWORD1364442555.
81              toString();
82          if (t.equalsIgnoreCase("ATOMIC")) {
83             isAtomic = true;
84          }
85       }
86    }
87
88    private void checkAtomicCondition(_ServerSession serverSession) throws
89        DException {
90    }
91
92    private void checkCommitRollbackStatement(_ServerSession serverSession) throws
93        DException {
94    }
95
96    private void insertLabelIntoMap(HashMap variableMap) throws DException {
97       if (variableMap.containsKey(beginningLabel)) {
98          throw new DException("DSE8039", new Object JavaDoc[] {beginningLabel});
99       }
100       variableMap.put(beginningLabel, null);
101    }
102
103    private void deleteLabelFromMap(HashMap variablesMap) throws DException {
104       variablesMap.remove(beginningLabel);
105    }
106
107    private Object JavaDoc executeStatements(_VariableValues vv) throws DException {
108       if (_OptSQLstatementlist2 != null) {
109
110          Object JavaDoc result = _OptSQLstatementlist2.execute(vv);
111          if (result instanceof SqlStatementListResult) {
112             SqlStatementListResult temp = (SqlStatementListResult) result;
113             if (outerControlStatement == null && temp.hasIterateLeaveResult()) {
114                throw new DException("DSE8038", null);
115             }
116             return temp.getResult();
117          } else if (result instanceof ReturnResult) {
118             return result;
119          }
120       }
121       return null;
122    }
123
124    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
125       ArrayList list = new ArrayList();
126       if (_OptSQLstatementlist2 != null) {
127          Object JavaDoc[] parm1 = _OptSQLstatementlist2.getParameters(object);
128          if (parm1 != null) {
129             list.addAll(Arrays.asList(parm1));
130          }
131       }
132       if (_Optlocalcursordeclarationlist3 != null) {
133          Object JavaDoc[] parm1 = _Optlocalcursordeclarationlist3.getParameters(object);
134          if (parm1 != null) {
135             list.addAll(Arrays.asList(parm1));
136          }
137       }
138       return list.toArray();
139    }
140
141    /**
142     * it will return all references got from containing sql statement except
143     * those whose name matches with local variables or cursor
144     */

145    /* public _Reference[] checkSemantic(_ServerSession object) throws DException {
146         serverSession = object;
147         TreeSet set = new TreeSet(ReferenceComparator.comparator);
148         /**
149      * Done by harvinder
150      * checkMatchingBeginningAndEndingLabel call here related to bug 11595.
151                 checkMatchingBeginningAndEndingLabel();
152                 setDataTypeOfLocalDeclaredVariables(object);
153                 if (_OptSQLstatementlist2 != null) {
154                    _Reference[] parm1 = _OptSQLstatementlist2.checkSemantic(object);
155                    if (parm1 != null) {
156                       setDataTypeOfLocalDeclaredVariables(object, parm1);
157                       set.addAll(Arrays.asList(parm1));
158                    }
159                 }
160                 if (_Optlocalcursordeclarationlist3 != null) {
161                    _Reference[] parm1 = _Optlocalcursordeclarationlist3.checkSemantic(object);
162                    if (parm1 != null) {
163                       set.addAll(Arrays.asList(parm1));
164                    }
165                 }
166                 ArrayList referencesToIgnore = new ArrayList();
167                 if (_Optlocalcursordeclarationlist3 != null) {
168                    ArrayList cursorNames = _Optlocalcursordeclarationlist3.getCursorNames();
169                    referencesToIgnore.addAll(cursorNames);
170                 }
171                 if (_Optlocaldeclarationlist4 != null) {
172                    ArrayList names = _Optlocaldeclarationlist4.getVariableNames();
173                    /**
174       * Add following six lines by harvinder related to bug 12015.
175                            for (int i = 0; i < names.size(); i++) {
176                               if (referencesToIgnore.contains(names.get(i))) {
177                                  throw new DException("DSE8183", new Object[] {names.get(i).toString()});
178                               } else {
179                                  referencesToIgnore.add(names.get(i));
180                               }
181                            }
182                         }
183                         int namesSize = referencesToIgnore.size();
184                         if (namesSize > 0) {
185                            TreeSet newSet = new TreeSet(ReferenceComparator.comparator);
186                            Iterator iter = set.iterator();
187                            while (iter.hasNext()) {
188                               _Reference ref = (_Reference) iter.next();
189                               boolean flag = false;
190                               for (int j = 0; j < namesSize; j++) {
191                                  String name = (String) referencesToIgnore.get(j);
192                                  if (ref.getQualifiedColumnName().equalsIgnoreCase(name)) {
193
194                                     flag = true;
195                                     break;
196                                  }
197                               }
198                               if (flag == false) {
199                                  newSet.add(ref);
200                               }
201                            }
202                            return (_Reference[]) newSet.toArray(new _Reference[0]);
203                         }
204                         return (_Reference[]) set.toArray(new _Reference[0]);
205                      }*/

206
207      public Object JavaDoc execute(_VariableValues variableValues) throws DException {
208         Object JavaDoc[][] refValuePair = variableValues.getReferenceAndValuePair();
209         VariableValues newVV = null;
210         if (refValuePair != null) {
211            _Reference[] refs = new _Reference[refValuePair.length];
212            Object JavaDoc[] values = new Object JavaDoc[refValuePair.length];
213            for (int i = 0; i < refValuePair.length; i++) {
214               refs[i] = (_Reference) refValuePair[i][0];
215               values[i] = refValuePair[i][1];
216            }
217
218            newVV = new VariableValues(refs, variableValues.getServerSession());
219            newVV.setConditionVariableValue(refs, values, 0);
220         } else {
221            newVV = new VariableValues(variableValues.getServerSession());
222         }
223         newVV.setServerSession(serverSession);
224         if (_Optlocaldeclarationlist4 != null) {
225            _Optlocaldeclarationlist4.addVariableInVV(newVV);
226         }
227         if (_Optlocalcursordeclarationlist3 != null) {
228            _Optlocalcursordeclarationlist3.execute(newVV);
229            _Optlocalcursordeclarationlist3.addCursorInVV(newVV);
230         }
231
232         Object JavaDoc result = executeStatements(newVV);
233
234         setVariableValues(newVV, variableValues);
235         return result;
236      }
237
238    /**
239     * Write new method by harvinder for set old variable values. */

240    public void setVariableValues(VariableValues newVV, _VariableValues variableValues) throws DException {
241       Object JavaDoc[][] afterExecuteRefValuePair = newVV.getReferenceAndValuePair();
242       Object JavaDoc[][] valueToSetPair = variableValues.getReferenceAndValuePair();
243       if (afterExecuteRefValuePair != null) {
244          for (int i = 0; i < afterExecuteRefValuePair.length; i++) {
245             _Reference vvRef = (_Reference) afterExecuteRefValuePair[i][0];
246             boolean existingRef = false;
247             if (valueToSetPair != null) {
248                for (int j = 0; j < valueToSetPair.length; j++) {
249                   _Reference toSetRef = (_Reference) valueToSetPair[j][0];
250                   if (vvRef.getQualifiedColumnName().equalsIgnoreCase(toSetRef.getQualifiedColumnName())) {
251                      existingRef = true;
252                      variableValues.setConditionVariableValue(
253                          new _Reference[] {toSetRef}
254                          , new Object JavaDoc[] {afterExecuteRefValuePair[i][1]}
255                          , 1);
256                   }
257                }
258             }
259             if (existingRef == false) {
260                variableValues.setConditionVariableValue(new _Reference[] {vvRef}
261                    , new Object JavaDoc[] {afterExecuteRefValuePair[i][1]}
262                    , 1);
263             }
264          }
265       }
266    }
267
268    public Object JavaDoc execute(Object JavaDoc[] values) throws DException {
269       throw new UnsupportedOperationException JavaDoc();
270    }
271
272    public Object JavaDoc executeForFresh(Object JavaDoc[] values) throws DException {
273       throw new UnsupportedOperationException JavaDoc();
274    }
275
276    public ParameterInfo[] getParameterInfo() throws DException {
277       throw new UnsupportedOperationException JavaDoc();
278    }
279
280    public String JavaDoc toString() {
281       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
282       sb.append(" ");
283       if (_OptbeginninglabelScolon948427197 != null) {
284          sb.append(_OptbeginninglabelScolon948427197);
285       }
286       sb.append(" ");
287       sb.append(_SRESERVEDWORD12065439226);
288       sb.append(" ");
289       if (_OptOptSRESERVEDWORD1206543922SNONRESERVEDWORD1364442555 != null) {
290          sb.append(_OptOptSRESERVEDWORD1206543922SNONRESERVEDWORD1364442555);
291       }
292       sb.append(" ");
293       if (_Optlocaldeclarationlist4 != null) {
294          sb.append(_Optlocaldeclarationlist4);
295       }
296       sb.append(" ");
297       if (_Optlocalcursordeclarationlist3 != null) {
298          sb.append(_Optlocalcursordeclarationlist3);
299       }
300       sb.append(" ");
301       if (_OptSQLstatementlist2 != null) {
302          sb.append(_OptSQLstatementlist2);
303       }
304       sb.append(" ");
305       sb.append(_SRESERVEDWORD12065439221);
306       sb.append(" ");
307       if (_Optendinglabel0 != null) {
308          sb.append(_Optendinglabel0);
309       }
310       return sb.toString().trim();
311    }
312
313    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
314       return this;
315    }
316
317    public ColumnDetails[] getColumnDetails() throws DException {
318       if (_OptSQLstatementlist2 != null) {
319          ColumnDetails[] compoundCD = _OptSQLstatementlist2.getColumnDetails();
320          for (int i = 0; i < compoundCD.length; i++) {
321             if (compoundCD[i].isReturnStatementCD()) {
322                setDataTypeOfReturnStatement(compoundCD[i], serverSession);
323             }
324          }
325          return compoundCD;
326       }
327       return new ColumnDetails[0];
328    }
329
330    private void setDataTypeOfReturnStatement(ColumnDetails cd, _ServerSession currentSession) throws DException {
331       if (_Optlocaldeclarationlist4 != null) {
332          VariableValues vv = new VariableValues(currentSession);
333          _Optlocaldeclarationlist4.addVariableInVV(vv);
334          _Reference[] ref = vv.getReferences();
335          for (int j = 0; j < ref.length; j++) {
336             if (cd.getQualifiedColumnName().equalsIgnoreCase(ref[j].getColumn())) {
337                cd.setDatatype(ref[j].getDatatype());
338                cd.setSize(ref[j].getSize());
339                break;
340             }
341          }
342       }
343    }
344
345    private void setDataTypeOfLocalDeclaredVariables(_ServerSession currentSession) throws DException {
346       if (_Optlocaldeclarationlist4 != null) {
347          ColumnDetails[] cd = getColumnDetails();
348          ArrayList refList = new ArrayList();
349          GeneralPurposeStaticClass.addRecursively(cd, refList);
350          VariableValues vv = new VariableValues(currentSession);
351          _Optlocaldeclarationlist4.addVariableInVV(vv);
352          _Reference[] ref = vv.getReferences();
353          for (int i = 0; i < refList.size(); i++) {
354             ColumnDetails cd1 = (ColumnDetails) refList.get(i);
355             for (int j = 0; j < ref.length; j++) {
356                if (cd1.getQualifiedColumnName().equalsIgnoreCase(ref[j].getColumn())) {
357                   cd1.setDatatype(ref[j].getDatatype());
358                   cd1.setSize(ref[j].getSize());
359                   break;
360                }
361             }
362          }
363       }
364    }
365
366    private void setDataTypeOfLocalDeclaredVariables(_ServerSession currentSession, _Reference[] parm1) throws DException {
367       if (_Optlocaldeclarationlist4 != null) {
368          VariableValues vv = new VariableValues(currentSession);
369          _Optlocaldeclarationlist4.addVariableInVV(vv);
370          _Reference[] ref = vv.getReferences();
371          for (int i = 0; i < parm1.length; i++) {
372             for (int j = 0; j < ref.length; j++) {
373                if (ref[j].getColumn().equalsIgnoreCase(parm1[i].getColumn())) {
374                   parm1[i].setDatatype(ref[j].getDatatype());
375                   parm1[i].setSize(ref[j].getSize());
376                   break;
377                }
378             }
379          }
380       }
381    }
382
383    public _Reference[] checkSemantic(_ServerSession object) throws DException {
384       serverSession = object;
385       ArrayList set = new ArrayList();
386       checkMatchingBeginningAndEndingLabel();
387       setDataTypeOfLocalDeclaredVariables(object);
388       if (_OptSQLstatementlist2 != null) {
389          _Reference[] parm1 = _OptSQLstatementlist2.checkSemantic(object);
390          if (parm1 != null) {
391             setDataTypeOfLocalDeclaredVariables(object, parm1);
392             set.addAll(Arrays.asList(parm1));
393          }
394       }
395       if (_Optlocalcursordeclarationlist3 != null) {
396          _Reference[] parm1 = _Optlocalcursordeclarationlist3.checkSemantic(object);
397          if (parm1 != null) {
398             set.addAll(Arrays.asList(parm1));
399          }
400       }
401       ArrayList referencesToIgnore = new ArrayList();
402       if (_Optlocalcursordeclarationlist3 != null) {
403          ArrayList cursorNames = _Optlocalcursordeclarationlist3.getCursorNames();
404          referencesToIgnore.addAll(cursorNames);
405       }
406
407       if (_Optlocaldeclarationlist4 != null) {
408          ArrayList names = _Optlocaldeclarationlist4.getVariableNames();
409          for (int i = 0; i < names.size(); i++) {
410             if (referencesToIgnore.contains(names.get(i))) {
411                throw new DException("DSE8183", new Object JavaDoc[] {names.get(i).toString()});
412             } else {
413                referencesToIgnore.add(names.get(i));
414             }
415          }
416          if (parameterList != null && parameterList.size() != 0) {
417             for (int k = 0; k < names.size(); k++) {
418                for (int j = 0; j < parameterList.size(); j++) {
419                   if (parameterList.get(j).toString().equalsIgnoreCase(names.get(k).toString())) {
420                      throw new DException("DSE8210", new Object JavaDoc[] {names.get(k).toString(), parameterList.toString()});
421                   }
422                }
423             }
424          }
425       }
426
427       int namesSize = referencesToIgnore.size();
428       if (namesSize > 0) {
429          ArrayList newSet = new ArrayList();
430          if (set != null) {
431             for (int i = 0; i < set.size(); i++) {
432                _Reference ref = (_Reference) set.get(i);
433                boolean flag = false;
434                for (int j = 0; j < namesSize; j++) {
435                   String JavaDoc name = (String JavaDoc) referencesToIgnore.get(j);
436                   if (ref.getQualifiedColumnName().equalsIgnoreCase(name)) {
437                      flag = true;
438                      break;
439                   }
440                }
441                if (flag == false) {
442                   newSet.add(ref);
443                }
444             }
445          }
446          return (_Reference[]) newSet.toArray(new _Reference[0]);
447       }
448       return (_Reference[]) set.toArray(new _Reference[0]);
449    }
450
451    public void getTableIncluded(ArrayList aList) throws DException {
452    }
453
454    public void getColumnsIncluded(ArrayList aList) throws DException {
455    }
456
457    public void setParameterInDeclarationList(ArrayList parameterList0) throws DException {
458       parameterList = parameterList0;
459    }
460
461    public void setServerSession(_ServerSession currentSession) throws DException {
462       serverSession = currentSession;
463    }
464 }
465
Popular Tags