KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dml;
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.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.utility.P;
12 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
13
14 public class setclauselist implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter {
15    public setclause[] _OptRepScomma94843605setclause0;
16
17    private Object JavaDoc result;
18
19    /**
20     * This method returns An Object two-d Array specifying the columns and the corresponding values
21     * that are in picture.
22     * @param object
23     * @return Object Object[][]
24     * @throws com.daffodilwoods.database.resource.DException
25     */

26
27    public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.DException {
28       if (result != null) {
29          return result;
30       }
31       int length = _OptRepScomma94843605setclause0.length;
32       ArrayList arr = new ArrayList(length);
33       for (int i = 0; i < length; i++) {
34          Object JavaDoc[] columnExpression1 = (Object JavaDoc[]) _OptRepScomma94843605setclause0[i].run(object);
35          arr.add(columnExpression1);
36       }
37       return result = (Object JavaDoc[][]) arr.toArray(new Object JavaDoc[length][]);
38    }
39
40    public ColumnDetails[] getColumnDetails(Object JavaDoc obj) throws DException {
41       Object JavaDoc[][] result = (Object JavaDoc[][]) run(obj);
42       ArrayList arrList = new ArrayList();
43       for (int i = 0; i < result.length; i++) {
44         ColumnDetails[] cd = null;
45         if(result[i][1] instanceof valueexpression)
46           cd = ( (valueexpression) result[i][1]).getColumnDetails();
47         else
48           cd = ( (subquery) result[i][1]).getColumnDetails();
49          if (cd != null && cd.length > 0) {
50             arrList.addAll(Arrays.asList(cd));
51          }
52       }
53       return arrList.size() > 0 ? (ColumnDetails[]) arrList.toArray(new ColumnDetails[0]) : null;
54    }
55
56    public ColumnDetails[] getLeftColumnDetails(Object JavaDoc obj) throws DException {
57       Object JavaDoc[][] result = (Object JavaDoc[][]) run(obj);
58       ArrayList arrList = new ArrayList();
59       for (int i = 0; i < result.length; i++) {
60           if (result[i][0] instanceof ColumnDetails) {
61             arrList.add( (ColumnDetails) result[i][0]);
62           }
63           else {
64             Object JavaDoc[] cds = (Object JavaDoc[] )result[i][0];
65             for (int j = 0; j < cds.length; j++) {
66               arrList.add( (ColumnDetails) cds[j]);
67             }
68         }
69       }
70       return (ColumnDetails[]) arrList.toArray(new ColumnDetails[0]);
71    }
72
73    /* This method returns all the Parameters invloved in the statement by calling getParameters of
74     * all the Setclauses, making a batch of them and returning
75     * @param object
76     * @return Object[]
77     * @throws DException
78     */

79
80    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
81       int length = _OptRepScomma94843605setclause0.length;
82       ArrayList arr = new ArrayList(length);
83       for (int i = 0; i < length; i++) {
84          Object JavaDoc[] result = _OptRepScomma94843605setclause0[i].getParameters(object);
85          if (result != null) {
86             arr.addAll(Arrays.asList(result));
87          }
88       }
89       return arr.size() > 0 ? arr.toArray(new Object JavaDoc[arr.size()]) : null;
90    }
91
92    /**
93     * This method returns the Parameter Info Array by calling the getParameterInfo of SetClause.
94     * @return
95     * @throws DException
96     */

97
98    public ParameterInfo[] getParameterInfo() throws DException {
99       int length = _OptRepScomma94843605setclause0.length;
100       ArrayList arr = new ArrayList(length);
101       ParameterInfo[] param;
102       for (int i = 0; i < length; i++) {
103        param = _OptRepScomma94843605setclause0[i].getParameterInfo();
104       for (int j = 0; j < param.length; j++) {
105        param[j].setOrdinalPosition(i);
106      }
107          arr.addAll(Arrays.asList(param));
108       }
109       return arr.size() > 0 ? (ParameterInfo[]) arr.toArray(new ParameterInfo[0]) : null;
110    }
111
112    /**
113     * This method returns a self instance of the class by making all the required initialisations.
114     * @return
115     * @throws CloneNotSupportedException
116     */

117
118    /**
119     * This method returns a String specifying all the information by calling
120     * toString Method of all the active SetClauses
121     * @return String
122     */

123
124    public _Reference[] checkSemantic(_ServerSession serverSession) throws DException {
125       ArrayList arr = new ArrayList();
126       int len = _OptRepScomma94843605setclause0.length;
127       _Reference[] refToReturn;
128       for (int i = 0; i < len; i++) {
129          refToReturn = _OptRepScomma94843605setclause0[i].checkSemantic(serverSession);
130          if (refToReturn != null) {
131             arr.addAll(Arrays.asList(refToReturn));
132          }
133       }
134       return arr.size() > 0 ? (_Reference[]) arr.toArray(new _Reference[0]) : null;
135    }
136
137    public Object JavaDoc getReferenceIteratorMapping(TableDetails td, _ServerSession object) throws DException {
138       Object JavaDoc[][] refValue = (Object JavaDoc[][]) result;
139       int len = refValue.length;
140       ArrayList arr = new ArrayList(5);
141       for (int i = 0; i < len; i++) {
142          _Reference[] ref = null;
143          if(refValue[i][1] instanceof valueexpression)
144              ref =( (valueexpression) refValue[i][1]).getReferences(new TableDetails[] {td});
145          else
146            ref =( (subquery) refValue[i][1]).getReferences(new TableDetails[] {td});
147          if (ref != null) {
148             arr.addAll(Arrays.asList(ref));
149          }
150       }
151       if (arr.size() > 0) {
152          _Reference[] references = (_Reference[]) arr.toArray(new _Reference[0]);
153          if (checkForSubQuery(references)) {
154             return getSubQueryIteratorMapping(references, object);
155          }
156       }
157       return null;
158    }
159
160    private Object JavaDoc initializeVariableValues(_Reference[] references, _ServerSession object) throws DException {
161       if (checkForSubQuery(references)) {
162          Object JavaDoc[][] subQueryIteratorMapping = getSubQueryIteratorMapping(references, object);
163          return new SubQueryVariableValues(null, subQueryIteratorMapping, object);
164       }
165       return null;
166    }
167
168    private boolean checkForSubQuery(_Reference[] references) throws DException {
169       if (references != null) {
170          int length = references.length;
171          for (int i = 0; i < length; i++) {
172             if (references[i].getReferenceType() == com.daffodilwoods.daffodildb.server.sql99.common.SimpleConstants.SUBQUERY) {
173                return true;
174             }
175          }
176       }
177       return false;
178    }
179
180    private Object JavaDoc[][] getSubQueryIteratorMapping(_Reference[] references, _ServerSession object) throws DException {
181       int length = references.length;
182       ArrayList aList = new ArrayList(length);
183       for (int i = 0; i < length; i++) {
184          if (references[i].getReferenceType() == com.daffodilwoods.daffodildb.server.sql99.common.SimpleConstants.SUBQUERY) {
185             _Iterator iterator = ( (com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.subquery) references[i]).getSelectIterator(object);
186             aList.add(new Object JavaDoc[] {references[i], iterator}); // make provision of getting _SelectIterator from _Executer
187
}
188       }
189       return (Object JavaDoc[][]) aList.toArray(new Object JavaDoc[0][]);
190    }
191
192    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
193       return this;
194    }
195
196    public String JavaDoc toString() {
197       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
198       sb.append(" ");
199       sb.append(_OptRepScomma94843605setclause0[0]);
200       for (int i = 1; i < _OptRepScomma94843605setclause0.length; i++) {
201          sb.append(",").append(_OptRepScomma94843605setclause0[i]);
202       }
203       return sb.toString();
204    }
205
206    public void getTablesIncluded(ArrayList arrayList) throws DException {
207       if (_OptRepScomma94843605setclause0 != null)
208          for (int i = 0; i < _OptRepScomma94843605setclause0.length; i++) {
209             _OptRepScomma94843605setclause0[i].getTablesIncluded(arrayList);
210          }
211    }
212 }
213
Popular Tags