KickJava   Java API By Example, From Geeks To Geeks.

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


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 whilestatement implements SQLcontrolstatement {
12
13    public endinglabel _Optendinglabel0;
14    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
15    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222;
16    public SQLstatementlist _SQLstatementlist3;
17    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224;
18    public searchcondition _searchcondition5;
19    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439226;
20    public beginninglabelScolon94842719 _OptbeginninglabelScolon948427197;
21
22    private SQLcontrolstatement outerControlStatement;
23    private String JavaDoc beginningLabel;
24    private _Reference[] searchConditionRefs;
25    private _ServerSession serverSession;
26
27    public void setOuterControlStatement(SQLcontrolstatement outerst) {
28       outerControlStatement = outerst;
29    }
30
31    public Object JavaDoc run(Object JavaDoc object) throws DException {
32       _StatementExecutionContext sec = (_StatementExecutionContext) object;
33       _ServerSession serverSession = sec.getServerSession();
34       checkSystax(serverSession);
35       _searchcondition5.getColumnDetails();
36       _SQLstatementlist3.run(object);
37       return this;
38    }
39
40    private void checkSystax(_ServerSession serverSession) throws DException {
41       checkMatchingBeginningAndEndingLabel(serverSession);
42       if (_OptbeginninglabelScolon948427197 == null) { // && outerControlStatement!=null)
43
assignImplicitBeginningLabel();
44       } else {
45          beginningLabel = "@" +
46              (String JavaDoc) _OptbeginninglabelScolon948427197.getIdentifier();
47       }
48       scopeManagement(serverSession);
49    }
50
51    private void checkMatchingBeginningAndEndingLabel(_ServerSession
52        serverSession) throws DException {
53       if (_Optendinglabel0 != null) {
54          if (_OptbeginninglabelScolon948427197 == null) {
55             throw new DException("DSE8036", null);
56          }
57          else if (! ( (String JavaDoc) _Optendinglabel0.getIdentifier()).equalsIgnoreCase
58                   ( (String JavaDoc) _OptbeginninglabelScolon948427197.getIdentifier())) {
59             throw new DException("DSE8037", null);
60          }
61       }
62    }
63
64    private void scopeManagement(_ServerSession serverSession) throws DException {
65    }
66
67    private void assignImplicitBeginningLabel() throws DException {
68       beginningLabel = "@internalLabel" + this.hashCode();
69    }
70
71    private Object JavaDoc executeStatements(_VariableValues variableValues) throws DException {
72       ArrayList returningResultList = new ArrayList();
73       _SQLstatementlist3.setOuterControlStatement(this);
74       while (SearchConditionUtility.executeExpression(_searchcondition5,
75           searchConditionRefs, variableValues, serverSession).hashCode() == 0) {
76          Object JavaDoc listResult = _SQLstatementlist3.execute(variableValues);
77          if (listResult instanceof SqlStatementListResult) {
78             SqlStatementListResult result = (SqlStatementListResult) listResult;
79             if (result.hasIterateLeaveResult()) {
80                IterateLeaveResult temp = result.getIterateLeaveResult();
81                if (temp.getLabel().equalsIgnoreCase(beginningLabel)) {
82                   returningResultList.add(result.getResult());
83                   if (temp.getType() == IterateLeaveResult.ITERATETYPE) {
84                      continue;
85                   } else if (temp.getType() == IterateLeaveResult.LEAVETYPE) {
86                      break;
87                   }
88                } else {
89                   SqlStatementListResult returningResult = new SqlStatementListResult(0);
90                   returningResult.setResult(returningResultList.toArray());
91                   returningResult.setIterateLeaveResult(temp);
92                   if (outerControlStatement == null) {
93                      throw new DException("DSE8038", null);
94                   }
95                   return returningResult;
96                }
97             } else {
98                returningResultList.add(result.getResult());
99             }
100          } else if (listResult instanceof ReturnResult) {
101             return listResult;
102          }
103       }
104       return returningResultList.toArray();
105    }
106
107    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
108       ArrayList list = new ArrayList();
109       Object JavaDoc[] par1 = _searchcondition5.getParameters(object);
110       if (par1 != null) {
111          list.addAll(Arrays.asList(par1));
112       }
113       Object JavaDoc[] par2 = _SQLstatementlist3.getParameters(object);
114       if (par2 != null) {
115          list.addAll(Arrays.asList(par2));
116       }
117       return list.toArray();
118    }
119
120    /* public _Reference[] checkSemantic(_ServerSession object) throws DException {
121          serverSession = object;
122          if (_searchcondition5.hasContainClause())
123             throw new DException("DSE8138", null);
124          checkMatchingBeginningAndEndingLabel(serverSession);
125          TreeSet set = new TreeSet(ReferenceComparator.comparator);
126          searchConditionRefs = _searchcondition5.getReferences(SQLcontrolstatement.dummyTableDetail);
127          if (searchConditionRefs != null) {
128             if (searchConditionRefs[0].getReferenceType() != SimpleConstants.SUBQUERY)
129                set.addAll(Arrays.asList(searchConditionRefs));
130          }
131          /**
132      * call checkSemantic of searchCondition in try catch Suggest by Mr. Parveen Agarwal. Related to bug 11653.
133             try {
134                _searchcondition5.getColumnDetails();
135                _searchcondition5.checkSemantic(serverSession);
136             } catch (DException ex) {
137                if (!ex.getDseCode().equalsIgnoreCase("DSE4115")) {
138                   throw ex;
139                }
140             }
141             _Reference[] par2 = _SQLstatementlist3.checkSemantic(object);
142             if (par2 != null) {
143                set.addAll(Arrays.asList(par2));
144             }
145             return (_Reference[]) set.toArray(new _Reference[0]);
146          }*/

147
148     public Object JavaDoc execute(_VariableValues variableValues) throws DException {
149        Object JavaDoc result = null;
150        result = executeStatements(variableValues);
151        return result;
152     }
153
154    public Object JavaDoc execute(Object JavaDoc[] values) throws DException {
155       throw new UnsupportedOperationException JavaDoc();
156    }
157
158    public Object JavaDoc executeForFresh(Object JavaDoc[] values) throws DException {
159       throw new UnsupportedOperationException JavaDoc();
160    }
161
162    public ParameterInfo[] getParameterInfo() throws DException {
163       throw new UnsupportedOperationException JavaDoc();
164    }
165
166    public String JavaDoc toString() {
167       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
168       sb.append(" ");
169       if (_OptbeginninglabelScolon948427197 != null) {
170          sb.append(_OptbeginninglabelScolon948427197);
171       }
172       sb.append(" ");
173       sb.append(_SRESERVEDWORD12065439226);
174       sb.append(" ");
175       sb.append(_searchcondition5);
176       sb.append(" ");
177       sb.append(_SRESERVEDWORD12065439224);
178       sb.append(" ");
179       sb.append(_SQLstatementlist3);
180       sb.append(" ");
181       sb.append(_SRESERVEDWORD12065439222);
182       sb.append(" ");
183       sb.append(_SRESERVEDWORD12065439221);
184       sb.append(" ");
185       if (_Optendinglabel0 != null) {
186          sb.append(_Optendinglabel0);
187       }
188       return sb.toString().trim();
189    }
190
191    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
192       return this;
193    }
194
195    public ColumnDetails[] getColumnDetails() throws DException {
196       return GeneralPurposeStaticClass.getJointColumnDetails(_searchcondition5.getColumnDetails(), _SQLstatementlist3.getColumnDetails());
197    }
198
199    public _Reference[] checkSemantic(_ServerSession object) throws DException {
200       serverSession = object;
201       if (_searchcondition5.hasContainClause())
202          throw new DException("DSE8138", null);
203       checkMatchingBeginningAndEndingLabel(serverSession);
204       ArrayList set = new ArrayList();
205       searchConditionRefs = _searchcondition5.getReferences(SQLcontrolstatement.dummyTableDetail);
206       if (searchConditionRefs != null) {
207          for (int i = 0; i < searchConditionRefs.length; i++) {
208             if (searchConditionRefs[i].getReferenceType() != SimpleConstants.SUBQUERY)
209                set.add(searchConditionRefs[i]);
210          }
211       }
212       /**
213        * call checkSemantic of searchCondition in try catch Suggest by Mr. Parveen Agarwal. Related to bug 11653. */

214       try {
215          _searchcondition5.getColumnDetails();
216          _searchcondition5.checkSemantic(serverSession);
217       } catch (DException ex) {
218          if (!ex.getDseCode().equalsIgnoreCase("DSE4115")) {
219             throw ex;
220          }
221       }
222       _Reference[] par2 = _SQLstatementlist3.checkSemantic(object);
223       if (par2 != null) {
224          set.addAll(Arrays.asList(par2));
225       }
226       return (_Reference[]) set.toArray(new _Reference[0]);
227    }
228
229    public void getTableIncluded(ArrayList aList) throws DException {
230       _searchcondition5.getTablesIncluded(aList);
231    }
232
233    public void getColumnsIncluded(ArrayList aList) throws DException {
234       _searchcondition5.getColumnsIncluded(aList);
235    }
236 }
237
Popular Tags