1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.types.TypeId; 25 import org.apache.derby.iapi.types.DataValueFactory; 26 import org.apache.derby.iapi.types.DataTypeDescriptor; 27 import org.apache.derby.iapi.services.compiler.MethodBuilder; 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 31 32 import org.apache.derby.iapi.reference.ClassName; 33 import org.apache.derby.iapi.reference.SQLState; 34 35 import org.apache.derby.iapi.services.classfile.VMOpcode; 36 37 import java.sql.Types ; 38 39 import java.util.Vector ; 40 41 44 45 public class TimestampOperatorNode extends BinaryOperatorNode 46 { 47 48 54 55 public void init( Object date, 56 Object time) 57 { 58 leftOperand = (ValueNode) date; 59 rightOperand = (ValueNode) time; 60 operator = "timestamp"; 61 methodName = "getTimestamp"; 62 } 63 64 65 78 79 public ValueNode bindExpression( 80 FromList fromList, SubqueryList subqueryList, 81 Vector aggregateVector) 82 throws StandardException 83 { 84 leftOperand = leftOperand.bindExpression(fromList, subqueryList, 85 aggregateVector); 86 rightOperand = rightOperand.bindExpression(fromList, subqueryList, 87 aggregateVector); 88 89 if (leftOperand.requiresTypeFromContext()) 91 leftOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.DATE)); 92 if (rightOperand.requiresTypeFromContext()) 94 rightOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.TIME)); 95 96 TypeId leftTypeId = leftOperand.getTypeId(); 97 TypeId rightTypeId = rightOperand.getTypeId(); 98 if( !(leftOperand.requiresTypeFromContext() || leftTypeId.isStringTypeId() || leftTypeId.getJDBCTypeId() == Types.DATE)) 99 throw StandardException.newException(SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED, 100 operator, leftTypeId.getSQLTypeName(), rightTypeId.getSQLTypeName()); 101 if( !(rightOperand.requiresTypeFromContext() || rightTypeId.isStringTypeId() || rightTypeId.getJDBCTypeId() == Types.TIME)) 102 throw StandardException.newException(SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED, 103 operator, leftTypeId.getSQLTypeName(), rightTypeId.getSQLTypeName()); 104 setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.TIMESTAMP)); 105 return genSQLJavaSQLTree(); 106 } 108 117 118 public void generateExpression(ExpressionClassBuilder acb, 119 MethodBuilder mb) 120 throws StandardException 121 { 122 acb.pushDataValueFactory(mb); 123 leftOperand.generateExpression(acb, mb); 124 mb.cast( ClassName.DataValueDescriptor); 125 rightOperand.generateExpression(acb, mb); 126 mb.cast( ClassName.DataValueDescriptor); 127 mb.callMethod( VMOpcode.INVOKEINTERFACE, null, methodName, ClassName.DateTimeDataValue, 2); 128 } } 130 | Popular Tags |