1 package com.daffodilwoods.daffodildb.server.sql99.utils; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata.*; 12 import com.daffodilwoods.daffodildb.server.sql99.token.*; 13 import com.daffodilwoods.daffodildb.utils.*; 14 import com.daffodilwoods.daffodildb.utils.field.*; 15 import com.daffodilwoods.database.general.*; 16 import com.daffodilwoods.database.resource.*; 17 18 public class VariableValueOperations extends VariableValues implements _VariableValueOperations { 19 20 Object [][] systemReferenceMapping; 21 HashMap tableRecordMapping; 22 ColumnMappingHandler columnMappingHandler; 23 private boolean flag = false; 24 private _VariableValues vv; 25 private Object row; 26 private _AllColumnRowReader rowReader; 27 private boolean checkingOfValuesIgnored; 28 29 public VariableValueOperations(_ServerSession serverSession) { 30 super(serverSession); 31 } 32 33 public VariableValueOperations(_Reference[] references, _ServerSession serverSession) { 34 super(references, serverSession); 35 } 36 37 public void setSystemReferencesMappiung(_Reference[] references, Object [] values, Integer integer) throws DException { 38 if (systemReferenceMapping == null) { 39 int length = references.length; 40 systemReferenceMapping = new Object [length][3]; 41 for (int i = 0; i < length; i++) { 42 systemReferenceMapping[i][0] = references[i]; 43 systemReferenceMapping[i][1] = values[i]; 44 systemReferenceMapping[i][2] = integer; 45 } 46 return; 47 } 48 addInSystemReferencesMapping(references, values, integer); 49 } 50 51 public void addColumnValues(_Reference[] references, Object [] values, int priority) throws DException { 52 int len = references.length; 53 if (len != values.length) { 54 throw new DException("DSE3562", null); 55 } 56 String columnName = null; 57 TableDetails td = null; 58 ColumnMapping cmg = null; 59 for (int i = 0; i < len; i++) { 60 td = ( (ColumnDetails) references[i]).getTableDetails(); 61 if (td == null) { 62 throw new DException("DSE1272", null); 63 } 64 cmg = columnMappingHandler.getColumnMappingForTableDetail(td); 65 if (cmg != null) { 66 cmg.addColumnsAndValues( (ColumnDetails) references[i], values[i]); 67 } else { 68 TableKeyMapping tkm = (TableKeyMapping) tableRecordMapping.get(td); 69 if (tkm != null || flag) { 70 ColumnMapping cm = new ColumnMapping( (ColumnDetails) references[i], values[i]); 71 columnMappingHandler.addColumnMapping(cm); 72 } 73 } 74 } 75 } 76 77 private void addInSystemReferencesMapping(_Reference[] references, Object [] values, Integer integer) throws DException { 78 int length = references.length; 79 int lengthOfExisting = systemReferenceMapping.length; 80 int totalLength = length + lengthOfExisting; 81 Object [][] newSystemReferenceMapping = new Object [totalLength][3]; 82 System.arraycopy(systemReferenceMapping, 0, newSystemReferenceMapping, 0, lengthOfExisting); 83 for (int i = lengthOfExisting, j = 0; i < totalLength && j < length; i++, j++) { 84 newSystemReferenceMapping[i][0] = references[j]; 85 newSystemReferenceMapping[i][1] = values[j]; 86 newSystemReferenceMapping[i][2] = integer; 87 } 88 systemReferenceMapping = newSystemReferenceMapping; 89 } 90 91 public Object getColumnValues(_Reference[] reference) throws DException { 92 93 Object [] values = new Object [reference.length]; 94 for (int i = 0; i < reference.length; i++) { 95 values[i] = getColumnValues(reference[i]); 96 } 97 return values; 98 99 } 100 101 102 public Object getColumnValues(_Reference reference) throws DException { 103 if (reference instanceof variablecolumn) { 104 return vv.getColumnValues(reference); 105 } 106 String columnName = reference.getColumn(); 107 TableDetails td = ( (ColumnDetails) reference).getTable(); 108 if (td == null) { 109 return ( (ColumnDetails) reference).run(this); 110 } 111 112 QualifiedIdentifier qualifiedName = td.getQualifiedIdentifier(); 113 if (columnMappingHandler != null) { 114 int index = 0; 115 if ( (index = columnMappingHandler.containsTableAndColumnInMapping(td, columnName)) != -1) { 116 return columnMappingHandler.getValueAtIndex(td, index); 117 } 118 } 119 if (tableRecordMapping.containsKey(td)) { 120 _Record record = ( (TableKeyMapping) tableRecordMapping.get(td)).getRecord(); 121 if (record != null) { 122 Object obj = record.getObject(columnName); 123 if (obj != null) { 124 return obj; 125 } 126 } 127 if (row != null) { 128 Object obj = rowReader.getObject(td.getTableInfo(), columnName, row); 129 if (obj != null) { 130 return obj; 131 } 132 } 133 134 } 135 return null; 136 } 137 138 public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException { 139 140 if (reference instanceof variablecolumn) { 141 return vv.field(reference); 142 } 143 String columnName = reference.getColumn(); 144 TableDetails td = ( (ColumnDetails) reference).getTable(); 145 if (td == null) { 146 return (FieldBase) ( (ColumnDetails) reference).run(this); 147 } 148 149 QualifiedIdentifier qualifiedName = td.getQualifiedIdentifier(); 150 if (columnMappingHandler != null) { 151 int index = 0; 152 if ( (index = columnMappingHandler.containsTableAndColumnInMapping(td, columnName)) != -1) { 153 ColumnMapping cm = columnMappingHandler.getColumnMappingForTableDetail(td); 154 ColumnDetails cd = cm.getColumnDetailsAt(index); 155 return FieldUtility.getField(cd.getDatatype(), cm.getValueAtIndex(index)); 156 } 157 } 158 if (tableRecordMapping.containsKey(td)) { 159 _Record record = ( (TableKeyMapping) tableRecordMapping.get(td)).getRecord(); 160 if (record != null) { 161 Object obj = record.getObject(columnName); 162 if (obj != null) { 163 return (FieldBase) obj; 164 } 165 } 166 if (row != null) { 167 Object obj = rowReader.getObject(td.getTableInfo(), columnName, row); 168 if (obj != null) { 169 return (FieldBase) obj; 170 } 171 } 172 173 } 174 return null; 175 } 176 177 public void setIterator(_Iterator iterator) throws DException { 178 this.iterator = iterator; 179 } 180 181 182 public void setConditionVariableValue(_Reference[] references, Object [] values, int priority) throws DException { 183 Thread.dumpStack(); 184 } 185 186 public void setDefaultValues(_VariableValueOperations variableValueOperations) throws DException { 187 188 189 } 190 191 public _Reference[] getReferences() throws DException { 192 throw new UnsupportedOperationException (" This method has no validity is our case "); 193 } 194 195 public Object [] getReferenceValues() throws DException { 196 if (mapping == null) { 197 return null; 198 } 199 int len = mapping.length; 200 Object [] referenceValues = new Object [len]; 201 for (int i = 0; i < len; i++) { 202 referenceValues[i] = mapping[i][1]; 203 } 204 return referenceValues; 205 } 206 207 public String toString() { 208 String str = "VARIABLEVALUEOPERATION"; 209 if (mapping != null) { 210 for (int i = 0; i < mapping.length; i++) { 211 str += "[" + Arrays.asList(mapping[i]) + "]"; 212 } 213 } 214 return str; 215 } 216 217 public boolean ifExists(String qualifiedTableName) throws DException { 218 if (mapping != null) { 219 return checkInMapping(qualifiedTableName, mapping) ? true : systemReferenceMapping == null 220 ? false : checkInMapping(qualifiedTableName, systemReferenceMapping); 221 } 222 return false; 223 } 224 225 private boolean checkInMapping(String qualifiedTableName, Object [][] mapping) throws DException { 226 int length = mapping.length; 227 for (int i = 0; i < length; i++) { 228 StringReference reference = (StringReference) mapping[i][0]; 229 if (reference.getTableName().equalsIgnoreCase(qualifiedTableName)) { 230 return true; 231 } 232 } 233 return false; 234 } 235 236 public void showForRohit() throws DException { 237 ColumnMapping[] cmp = columnMappingHandler.getColumnMappings(); 238 int len = cmp.length; 239 for (int i = 0; i < len; i++) { 240 cmp[i].show(); 241 } 242 243 } 244 245 public void show() throws DException { 246 if (mapping != null) { 247 int length = mapping.length; 248 for (int i = 0; i < length; i++) { 249 ; } 251 } 252 if (systemReferenceMapping != null) { 253 int length = systemReferenceMapping.length; 254 for (int i = 0; i < length; i++) { 255 ; } 257 } 258 } 259 260 public Object [][] getReferenceAndValuePair() throws DException { 261 if (mapping != null) { 262 int length = mapping.length; 263 Object [][] referenceAndValue = new Object [length][2]; 264 for (int i = 0; i < length; i++) { 265 referenceAndValue[i][0] = mapping[i][0]; 266 referenceAndValue[i][1] = mapping[i][1]; 267 } 268 return referenceAndValue; 269 } 270 return null; 271 } 272 273 public void setTableKeyMappings(HashMap tableRecordMapping) { 274 this.tableRecordMapping = tableRecordMapping; 275 } 276 277 public void setColumnMappingHandler(ColumnMappingHandler columnMappingHandler) { 278 this.columnMappingHandler = columnMappingHandler; 279 } 280 281 public void setFlag(boolean flg) { 282 flag = flg; 283 } 284 285 public void setVariableValue(_VariableValues vv) { 286 this.vv = vv; 287 } 288 289 public void setRow(Object row0, _AllColumnRowReader rowReader0) { 290 row = row0; 291 rowReader = rowReader0; 292 } 293 294 public void setCheckingIgnored(boolean b) { 295 checkingOfValuesIgnored = b; 296 } 297 298 public boolean isCheckingToBeIgnored() { 299 return checkingOfValuesIgnored; 300 } 301 302 public void releaseResource() throws DException { 303 } 304 305 } 306 | Popular Tags |