1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.compiler.MethodBuilder; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.types.DataTypeDescriptor; 29 import org.apache.derby.iapi.error.StandardException; 30 31 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 32 33 43 44 public class VirtualColumnNode extends ValueNode 45 { 46 50 ResultSetNode sourceResultSet; 51 ResultColumn sourceColumn; 52 53 56 int columnId; 57 58 boolean correlated = false; 59 60 61 68 69 public void init( 70 Object sourceResultSet, 71 Object sourceColumn, 72 Object columnId) throws StandardException 73 { 74 ResultColumn source = (ResultColumn) sourceColumn; 75 76 this.sourceResultSet = (ResultSetNode) sourceResultSet; 77 this.sourceColumn = source; 78 this.columnId = ((Integer ) columnId).intValue(); 79 setType(source.getTypeServices()); 80 } 81 82 83 89 90 public void printSubNodes(int depth) 91 { 92 if (SanityManager.DEBUG) 93 { 94 super.printSubNodes(depth); 95 96 if (sourceColumn != null) 97 { 98 printLabel(depth, "sourceColumn: "); 99 sourceColumn.treePrint(depth + 1); 100 } 101 } 102 } 103 104 109 public ResultSetNode getSourceResultSet() 110 { 111 return sourceResultSet; 112 } 113 114 119 public ResultColumn getSourceColumn() 120 { 121 return sourceColumn; 122 } 123 124 134 public String getTableName() 135 { 136 return ( ( sourceColumn != null) ? sourceColumn.getTableName() : null ); 137 } 138 139 149 public String getSchemaName() throws StandardException 150 { 151 return ( ( sourceColumn != null) ? sourceColumn.getSchemaName() : null ); 152 } 153 154 160 public boolean updatableByCursor() 161 { 162 return ((sourceColumn != null) ? sourceColumn.updatableByCursor() : false); 163 } 164 165 170 public ResultColumn getSourceResultColumn() 171 { 172 return sourceColumn; 173 } 174 175 179 void setCorrelated() 180 { 181 correlated = true; 182 } 183 184 189 boolean getCorrelated() 190 { 191 return correlated; 192 } 193 194 199 public boolean isCloneable() 200 { 201 return true; 202 } 203 204 217 public void generateExpression(ExpressionClassBuilder acb, 218 MethodBuilder mb) 219 throws StandardException 220 { 221 int sourceResultSetNumber = sourceColumn.getResultSetNumber(); 222 223 226 if (sourceColumn.isRedundant()) 227 { 228 sourceColumn.getExpression().generateExpression(acb, mb); 229 return; 230 } 231 232 if (SanityManager.DEBUG) 233 SanityManager.ASSERT(sourceResultSetNumber >= 0, 234 "sourceResultSetNumber expected to be >= 0 for virtual column "+sourceColumn.getName()); 235 236 246 acb.pushColumnReference(mb, 247 sourceResultSetNumber, 248 sourceColumn.getVirtualColumnId()); 249 250 mb.cast(sourceColumn.getTypeCompiler().interfaceName()); 251 } 252 253 266 protected int getOrderableVariantType() throws StandardException 267 { 268 271 return sourceColumn.getOrderableVariantType(); 272 } 273 274 280 public DataTypeDescriptor getTypeServices() throws StandardException 281 { 282 DataTypeDescriptor dtd = super.getTypeServices(); 283 if( dtd == null && sourceColumn != null) 284 { 285 dtd = sourceColumn.getTypeServices(); 286 if( dtd != null) 287 setType( dtd); 288 } 289 return dtd; 290 } 292 protected boolean isEquivalent(ValueNode o) throws StandardException 293 { 294 if (isSameNodeType(o)) { 295 VirtualColumnNode other = (VirtualColumnNode)o; 296 return sourceColumn.isEquivalent(other.sourceColumn); 297 } 298 return false; 299 } 300 } 301 | Popular Tags |