1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 25 26 import org.apache.derby.iapi.sql.compile.CompilerContext; 27 28 import org.apache.derby.iapi.types.TypeId; 29 import org.apache.derby.iapi.types.DataTypeDescriptor; 30 31 import org.apache.derby.iapi.services.compiler.MethodBuilder; 32 import org.apache.derby.iapi.services.compiler.LocalField; 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 35 import org.apache.derby.iapi.store.access.Qualifier; 36 37 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 38 39 import java.lang.reflect.Modifier ; 40 41 import org.apache.derby.iapi.error.StandardException; 42 43 import java.sql.Types ; 44 45 import java.util.Vector ; 46 47 53 public class CurrentDatetimeOperatorNode extends ValueNode { 54 55 public static final int CURRENT_DATE = 0; 56 public static final int CURRENT_TIME = 1; 57 public static final int CURRENT_TIMESTAMP = 2; 58 59 static private final int jdbcTypeId[] = { 60 Types.DATE, 61 Types.TIME, 62 Types.TIMESTAMP 63 }; 64 static private final String methodName[] = { "CURRENT DATE", 66 "CURRENT TIME", 67 "CURRENT TIMSTAMP" 68 }; 69 70 private int whichType; 71 72 public void init(Object whichType) { 73 this.whichType = ((Integer ) whichType).intValue(); 74 75 if (SanityManager.DEBUG) 76 SanityManager.ASSERT(this.whichType >= 0 && this.whichType <= 2); 77 } 78 79 83 98 public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, 99 Vector aggregateVector) 100 throws StandardException 101 { 102 checkReliability( methodName[whichType], CompilerContext.DATETIME_ILLEGAL ); 103 104 setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( 105 jdbcTypeId[whichType], 106 false 107 ) 108 ); 109 return this; 110 } 111 112 124 protected int getOrderableVariantType() 125 { 126 return Qualifier.QUERY_INVARIANT; 128 } 129 130 143 public void generateExpression(ExpressionClassBuilder acb, 144 MethodBuilder mb) 145 throws StandardException 146 { 147 acb.pushDataValueFactory(mb); 148 149 153 switch (whichType) { 154 case CURRENT_DATE: 155 acb.getCurrentDateExpression(mb); 156 break; 157 case CURRENT_TIME: 158 acb.getCurrentTimeExpression(mb); 159 break; 160 case CURRENT_TIMESTAMP: 161 acb.getCurrentTimestampExpression(mb); 162 break; 163 } 164 165 String fieldType = getTypeCompiler().interfaceName(); 166 LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, fieldType); 167 getTypeCompiler().generateDataValue(mb, field); 168 } 169 170 173 public String toString() { 174 if (SanityManager.DEBUG) 175 { 176 return super.toString()+"method = "+methodName[whichType]+"\n"; 177 } 178 else 179 { 180 return ""; 181 } 182 } 183 184 187 protected boolean isEquivalent(ValueNode o) 188 { 189 if (isSameNodeType(o)) 190 { 191 CurrentDatetimeOperatorNode other = (CurrentDatetimeOperatorNode)o; 192 return other.whichType == whichType; 193 } 194 return false; 195 } 196 } 197 | Popular Tags |