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.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 9 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 10 import com.daffodilwoods.database.resource.*; 11 12 public class fromconstructor implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, insertcolumnsandsource { 13 public contextuallytypedtablevalueconstructor _contextuallytypedtablevalueconstructor0; 14 public dummyrule _Optdummyrule1; 15 public pareninsertcolumnlist _Optpareninsertcolumnlist2; 16 private int cardinality = 0; 17 private ColumnDetails[] columnDetails; 18 19 public Object run(Object obj) throws com.daffodilwoods.database.resource.DException { 20 _contextuallytypedtablevalueconstructor0.getColumnDetails(); 21 if (_Optpareninsertcolumnlist2 != null) { 22 _Optpareninsertcolumnlist2.getColumnDetails(); 23 } 24 return _contextuallytypedtablevalueconstructor0.run(obj); 25 } 26 27 public ColumnDetails[] getColumnDetails() throws DException { 28 if (_Optpareninsertcolumnlist2 != null) { 29 if (columnDetails == null) { 30 columnDetails = _Optpareninsertcolumnlist2 == null ? null : _Optpareninsertcolumnlist2.getColumnDetails(); 31 } 32 return columnDetails; 33 } 34 return null; 35 } 36 37 43 44 public Object [] getParameters(Object object) throws DException { 45 return _contextuallytypedtablevalueconstructor0.getParameters(object); 46 } 47 48 53 54 public void checkcolumnsValidity(int columnLength) throws DException { 55 checkCardinality(columnLength); 56 } 57 58 64 65 public ParameterInfo[] getParameterInfo() throws DException { 66 ArrayList list = new ArrayList(); 67 ParameterInfo[] values = _contextuallytypedtablevalueconstructor0.getParameterInfo(); 68 if (_Optpareninsertcolumnlist2 == null) { 69 return values; 70 } 71 if (values == null) 72 return new ParameterInfo[] {}; 73 ParameterInfo[] columns = _Optpareninsertcolumnlist2.getParameterInfo(); 74 for (int i = 0; i < values.length; i++) { 75 if (values[i].getQuestionMark()) { 76 values[i].setName(columns[values[i].getOridinalPosition()].getName()); 77 list.add(values[i]); 78 } else if (values[i].getSubQuery()) { 79 ParameterInfo[] pp = values[i].getParameterInfoArray(); 80 if (pp != null) { 81 list.addAll(Arrays.asList(pp)); 82 } 83 } 84 } 85 ParameterInfo[] temp = new ParameterInfo[list.size()]; 86 list.toArray(temp); 87 return temp; 88 } 89 90 95 96 public int getCardinality() { 97 return cardinality; 98 } 99 100 private void checkCardinality(int columnLength) throws DException { 101 cardinality = _contextuallytypedtablevalueconstructor0.getCardinality(); 102 if (cardinality == -1) { 103 return; 104 } 105 if (cardinality != columnLength) { 106 throw new DException("DSE1256", new Object [] {new Integer (columnLength), new Integer (cardinality)}); 107 } 108 } 109 110 private void privateSyntaxChecking(Object object) throws DException { 111 Object [][] values = (Object [][]) _contextuallytypedtablevalueconstructor0.run(object); 112 String [] columnNames = null; 113 if (_Optpareninsertcolumnlist2 != null) { 114 columnNames = (String []) _Optpareninsertcolumnlist2.run(object); 115 if (columnNames.length != values[0].length) { 116 throw new DException("DSE214", null); 117 } 118 } 119 } 120 121 public _Reference[] getReferences(TableDetails[] tableDetails) throws DException { 122 _Reference[] result = _contextuallytypedtablevalueconstructor0.getReferences(tableDetails); 123 return result; 124 } 125 126 131 public _Reference[] checkSemantic(_ServerSession serverSession) throws DException { 132 ColumnDetails[] cd = _contextuallytypedtablevalueconstructor0.getColumnDetails(); 133 _Reference[] ref2 = getAllReferences(cd); 134 _Reference[] ref1 = _contextuallytypedtablevalueconstructor0.checkSemantic(serverSession); 135 return GeneralPurposeStaticClass.getJointReferences(ref1, ref2); 136 } 137 138 private _Reference[] getAllReferences(ColumnDetails[] cd) throws DException { 139 ArrayList aList = new ArrayList(5); 140 addRecursively(cd, aList); 141 int size = aList.size(); 142 return size == 0 ? null : (_Reference[]) aList.toArray(new _Reference[size]); 143 } 144 145 private void addRecursively(ColumnDetails[] cd, ArrayList aList) throws DException { 146 if (cd == null) { 147 return; 148 } 149 for (int i = 0; i < cd.length; i++) { 150 int type = cd[i].getType(); 151 if (type == TypeConstants.REFERENCE) { 152 cd[i].setUnderLyingReference(true); 153 aList.add(cd[i]); 154 } else if (type == TypeConstants.SCALARFUNCTION || type == TypeConstants.CASEEXPRESSION || type == TypeConstants.FUNCTIONAL) { 155 addRecursively(cd[i].getExistingColumnDetails(), aList); 156 } else if (type == TypeConstants.GROUPING) { 157 throw new DException("DSE3551", null); 158 } 159 } 160 } 161 162 public Object getReferenceIteratorMapping(TableDetails td, _ServerSession object) throws DException { 163 _Reference[] references = getReferences(new TableDetails[] {td}); 164 if (checkForSubQuery(references)) { 165 return getSubQueryIteratorMapping(references, object); 166 } 167 return null; 168 } 169 170 private Object initializeVariableValues(_Reference[] references, _ServerSession object) throws DException { 171 if (checkForSubQuery(references)) { 172 Object [][] subQueryIteratorMapping = getSubQueryIteratorMapping(references, object); 173 return new SubQueryVariableValues(null, subQueryIteratorMapping, object); 174 } 175 return null; 176 } 177 178 private boolean checkForSubQuery(_Reference[] references) throws DException { 179 if (references != null) { 180 int length = references.length; 181 for (int i = 0; i < length; i++) { 182 if (references[i].getReferenceType() == com.daffodilwoods.daffodildb.server.sql99.common.SimpleConstants.SUBQUERY) { 183 return true; 184 } 185 } 186 } 187 return false; 188 } 189 190 private Object [][] getSubQueryIteratorMapping(_Reference[] references, _ServerSession object) throws DException { 191 int length = references.length; 192 ArrayList aList = new ArrayList(length); 193 for (int i = 0; i < length; i++) { 194 if (references[i].getReferenceType() == com.daffodilwoods.daffodildb.server.sql99.common.SimpleConstants.SUBQUERY) { 195 _Iterator iterator = ( (com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.subquery) references[i]).getSelectIterator(object); 196 aList.add(new Object [] {references[i], iterator}); } 198 } 199 return (Object [][]) aList.toArray(new Object [0][]); 200 } 201 202 public Object clone() throws CloneNotSupportedException { 203 return this; 204 } 205 206 public String toString() { 207 StringBuffer sb = new StringBuffer (); 208 sb.append(" "); 209 if (_Optpareninsertcolumnlist2 != null) { 210 sb.append(_Optpareninsertcolumnlist2); 211 } 212 sb.append(" "); 213 if (_Optdummyrule1 != null) { 214 sb.append(_Optdummyrule1); 215 } 216 sb.append(" "); 217 sb.append(_contextuallytypedtablevalueconstructor0); 218 return sb.toString(); 219 } 220 221 public void getTablesIncluded(ArrayList arrayList) throws DException { 222 _contextuallytypedtablevalueconstructor0.getTablesIncluded(arrayList); 223 } 224 } 225 | Popular Tags |