KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > expressionprimary > SQLargumentOptRepScomma94843605SQLargument


1 package com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary;
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.expression.rowvalueexpression.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.database.resource.*;
10
11 public class SQLargumentOptRepScomma94843605SQLargument extends AbstractRowValueExpression implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter {
12
13    public SQLargument[] _OptRepScomma94843605SQLargument0;
14
15    private _Reference[][] sqlArgumentRefs;
16
17    public Object JavaDoc run(Object JavaDoc object) throws DException {
18       _VariableValues variableValues = (_VariableValues) object;
19       if (sqlArgumentRefs == null)
20          checkSemantic(variableValues.getServerSession());
21       int length = _OptRepScomma94843605SQLargument0.length;
22       ArrayList arr = new ArrayList(length);
23       for (int i = 0; i < length; i++) {
24          if (_OptRepScomma94843605SQLargument0[i] instanceof generalsetfunction) {
25             throw new DException("DSE8174", null);
26          }
27          if (sqlArgumentRefs[i] != null) {
28             VariableValues tempVV = new VariableValues(variableValues.getServerSession());
29             tempVV.setIterator( ( (VariableValues) variableValues).getIterator());
30             if (sqlArgumentRefs[i] != null) {
31                ArrayList refsToBeAdded = new ArrayList(sqlArgumentRefs[i].length);
32                ArrayList valuesToBeAdded = new ArrayList(sqlArgumentRefs[i].length);
33
34                Object JavaDoc[][] beforeExecuteRefValuePair = variableValues.getReferenceAndValuePair();
35                if (beforeExecuteRefValuePair != null) {
36                   for (int j = 0; j < beforeExecuteRefValuePair.length; j++) {
37                      _Reference vvRef = (_Reference) beforeExecuteRefValuePair[j][0];
38                      if (vvRef.getReferenceType() == SimpleConstants.COLUMNDETAIL) {
39                         for (int k = 0; k < sqlArgumentRefs[i].length; k++) {
40                            if (sqlArgumentRefs[i][k].getReferenceType() ==
41                                SimpleConstants.COLUMNDETAIL &&
42                                vvRef.getQualifiedColumnName().equalsIgnoreCase(sqlArgumentRefs[i][k].getQualifiedColumnName())) {
43                               sqlArgumentRefs[i][k].setDatatype(vvRef.getDatatype());
44                               refsToBeAdded.add(sqlArgumentRefs[i][k]);
45                               valuesToBeAdded.add(beforeExecuteRefValuePair[j][1]);
46                            }
47                         }
48                      } else {
49                         for (int k = 0; k < sqlArgumentRefs[i].length; k++) {
50                            if (sqlArgumentRefs[i][k] == vvRef) {
51                               refsToBeAdded.add(sqlArgumentRefs[i][k]);
52                               valuesToBeAdded.add(beforeExecuteRefValuePair[j][1]);
53                            }
54                         }
55                      }
56                   }
57                }
58                if (refsToBeAdded.size() > 0)
59                   tempVV.addColumnValues( (_Reference[]) refsToBeAdded.toArray(new _Reference[refsToBeAdded.size()]), valuesToBeAdded.toArray(), 1);
60             }
61             Object JavaDoc returnValue = null;
62             try {
63                returnValue = _OptRepScomma94843605SQLargument0[i].run(tempVV);
64             } catch (DException ex) {
65                if (ex.getDseCode().equalsIgnoreCase("DSE4115")) {
66                   throw new DException("DSE8173", new Object JavaDoc[] {_OptRepScomma94843605SQLargument0[i].toString()});
67                }
68                throw ex;
69             }
70             arr.add(returnValue);
71          } else {
72             Object JavaDoc returnValue = _OptRepScomma94843605SQLargument0[i].run(variableValues);
73             arr.add(returnValue);
74          }
75       }
76       return arr.toArray();
77    }
78
79    public ArrayList getParamters() throws DException {
80       ArrayList obj = new ArrayList();
81       for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
82          Object JavaDoc[] ref = _OptRepScomma94843605SQLargument0[i].getParameters(null);
83          for (int j = 0; j < ref.length; j++) {
84             obj.add(ref[j]);
85          }
86       }
87       return obj;
88    }
89
90    public ArrayList getParamtersForParameterInfo() throws DException {
91       ArrayList obj = new ArrayList();
92       for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
93          Object JavaDoc[] ref = _OptRepScomma94843605SQLargument0[i].getParameters(null);
94          if (ref != null) {
95             for (int j = 0; j < ref.length; j++) {
96                obj.add(new Object JavaDoc[] {new Integer JavaDoc(i + 1), ref[j]});
97             }
98          }
99       }
100       return obj;
101    }
102
103    public ArrayList getSqlArguments() throws DException {
104       ArrayList obj = new ArrayList();
105       for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
106          obj.add(_OptRepScomma94843605SQLargument0[i]);
107       }
108       return obj;
109    }
110
111    public _Reference[] getParameterReferences() throws DException {
112       ArrayList ref = new ArrayList();
113       for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
114          /** @todo current here only question mark are handled
115           * user/local variable in Psm has to be taken care*/

116          Object JavaDoc[] temp = _OptRepScomma94843605SQLargument0[i].getParameters(null);
117          if (temp != null) {
118             ref.addAll(Arrays.asList(temp));
119          }
120       }
121       return (_Reference[]) ref.toArray(new _Reference[0]);
122    }
123
124    public AbstractRowValueExpression[] getChilds() {
125       if (_OptRepScomma94843605SQLargument0 != null) {
126          AbstractRowValueExpression[] childs = new AbstractRowValueExpression[_OptRepScomma94843605SQLargument0.length];
127          for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
128             childs[i] = (AbstractRowValueExpression) _OptRepScomma94843605SQLargument0[i];
129          }
130          return childs;
131       }
132       return null;
133    }
134
135    public String JavaDoc toString() {
136       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
137       sb.append(" ");
138       sb.append(_OptRepScomma94843605SQLargument0[0]);
139       for (int i = 1; i < _OptRepScomma94843605SQLargument0.length; i++) {
140          sb.append(",").append(_OptRepScomma94843605SQLargument0[i]);
141       }
142       return sb.toString();
143    }
144
145    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
146       SQLargumentOptRepScomma94843605SQLargument tempClass = new
147           SQLargumentOptRepScomma94843605SQLargument();
148       if (_OptRepScomma94843605SQLargument0 != null) {
149          SQLargument[] temp_OptRepScomma94843605SQLargument0 = new SQLargument[
150              _OptRepScomma94843605SQLargument0.length];
151          for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
152             temp_OptRepScomma94843605SQLargument0[i] = (SQLargument)
153                 _OptRepScomma94843605SQLargument0[i].clone();
154          }
155          tempClass._OptRepScomma94843605SQLargument0 =
156              temp_OptRepScomma94843605SQLargument0;
157       }
158       return tempClass;
159    }
160
161    public int getNumberOfParametersInArgumentList() {
162       return _OptRepScomma94843605SQLargument0.length;
163    }
164
165    public _Reference[] checkSemantic(_ServerSession object) throws DException {
166       sqlArgumentRefs = new _Reference[_OptRepScomma94843605SQLargument0.length][];
167       ArrayList set = new ArrayList();
168       ArrayList set1 = new ArrayList();
169       for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
170          _OptRepScomma94843605SQLargument0[i].checkSemantic(object);
171          sqlArgumentRefs[i] = _OptRepScomma94843605SQLargument0[i].getReferences(new TableDetails[0]);
172          if (sqlArgumentRefs[i] != null) {
173             for (int j = 0; j < sqlArgumentRefs[i].length; j++) {
174                if (sqlArgumentRefs[i][j].getReferenceType() == SimpleConstants.COLUMNDETAIL) {
175                   String JavaDoc aa = sqlArgumentRefs[i][j].getQualifiedColumnName().trim().toUpperCase();
176                   if (!set1.contains(aa)) {
177                      set1.add(aa);
178                      set.add(sqlArgumentRefs[i][j]);
179                   }
180                } else if (sqlArgumentRefs[i][j].getReferenceType() == SimpleConstants.SUBQUERY) {
181                   throw new DException("DSE8184", null);
182                } else {
183                   set.add(sqlArgumentRefs[i][j]);
184                }
185             }
186          }
187       }
188       return (_Reference[]) set.toArray(new _Reference[0]);
189    }
190
191    public ColumnDetails[] getChildColumnDetails() throws DException {
192       return null;
193    }
194
195    public ColumnDetails[] getColumnDetails() throws DException {
196       if (_OptRepScomma94843605SQLargument0 != null) {
197          ArrayList listOfSqlArgumentCD = new ArrayList();
198          for (int i = 0; i < _OptRepScomma94843605SQLargument0.length; i++) {
199             ColumnDetails[] cd = _OptRepScomma94843605SQLargument0[i].getColumnDetails();
200             if (cd != null)
201                listOfSqlArgumentCD.addAll(Arrays.asList(cd));
202          }
203          return (ColumnDetails[]) listOfSqlArgumentCD.toArray(new ColumnDetails[0]);
204       }
205       return new ColumnDetails[0];
206    }
207 }
208
Popular Tags