Code example for Type

Methods: getReturnedClass

0
				expectedType = rhType; 
			} 
			( ( ExpectedTypeAwareNode ) lhs ).setExpectedType( expectedType ); 
		} 
		else if ( ParameterNode.class.isAssignableFrom( rhs.getClass() ) && lhType != null ) { 
			Type expectedType = null; 
			// we have something like : "lhs [op] ?" 
			if ( isDateTimeType( lhType ) ) { 
				// more specifically : "datetime [op] ?" 
				//      1) if the operator is MINUS, we really cannot determine 
				//          the expected type as either another datetime or 
				//          numeric would be valid 
				//      2) if the operator is PLUS, the param needs to be of 
				//          some numeric type 
				if ( getType() == HqlSqlTokenTypes.PLUS ) { 
					expectedType = StandardBasicTypes.DOUBLE; 
				} 
			} 
			else { 
				expectedType = lhType; 
			} 
			( ( ExpectedTypeAwareNode ) rhs ).setExpectedType( expectedType ); 
		} 
	} 
 
	/** 
	 * Figure out the type of the binary expression by looking at 
	 * the types of the operands. Sometimes we don't know both types, 
	 * if, for example, one is a parameter. 
	 */ 
	public Type getDataType() { 
		if ( super.getDataType() == null ) { 
			super.setDataType( resolveDataType() ); 
		} 
		return super.getDataType(); 
	} 
 
	private Type resolveDataType() { 
		// TODO : we may also want to check that the types here map to exactly one column/JDBC-type 
		//      can't think of a situation where arithmetic expression between multi-column mappings 
		//      makes any sense. 
		Node lhs = getLeftHandOperand(); 
		Node rhs = getRightHandOperand(); 
		Type lhType = ( lhs instanceof SqlNode ) ? ( ( SqlNode ) lhs ).getDataType() : null; 
		Type rhType = ( rhs instanceof SqlNode ) ? ( ( SqlNode ) rhs ).getDataType() : null; 
		if ( isDateTimeType( lhType ) || isDateTimeType( rhType ) ) { 
			return resolveDateTimeArithmeticResultType( lhType, rhType ); 
		} 
		else { 
			if ( lhType == null ) { 
				if ( rhType == null ) { 
					// we do not know either type 
					return StandardBasicTypes.DOUBLE; //BLIND GUESS! 
				} 
				else { 
					// we know only the rhs-hand type, so use that 
					return rhType; 
				} 
			} 
			else { 
				if ( rhType == null ) { 
					// we know only the lhs-hand type, so use that 
					return lhType; 
				} 
				else { 
					if ( lhType== StandardBasicTypes.DOUBLE || rhType==StandardBasicTypes.DOUBLE ) { 
						return StandardBasicTypes.DOUBLE; 
					} 
					if ( lhType==StandardBasicTypes.FLOAT || rhType==StandardBasicTypes.FLOAT ) { 
						return StandardBasicTypes.FLOAT; 
					} 
					if ( lhType==StandardBasicTypes.BIG_DECIMAL || rhType==StandardBasicTypes.BIG_DECIMAL ) { 
						return StandardBasicTypes.BIG_DECIMAL; 
					} 
					if ( lhType==StandardBasicTypes.BIG_INTEGER || rhType==StandardBasicTypes.BIG_INTEGER ) { 
						return StandardBasicTypes.BIG_INTEGER; 
					} 
					if ( lhType==StandardBasicTypes.LONG || rhType==StandardBasicTypes.LONG ) { 
						return StandardBasicTypes.LONG; 
					} 
					if ( lhType==StandardBasicTypes.INTEGER || rhType==StandardBasicTypes.INTEGER ) { 
						return StandardBasicTypes.INTEGER; 
					} 
					return lhType; 
				} 
			} 
		} 
	} 
 
	private boolean isDateTimeType(Type type) { 
		if ( type == null ) { 
			return false; 
		} 
		return java.util.Date.class.isAssignableFrom( type.getReturnedClass() ) || 
	           java.util.Calendar.class.isAssignableFrom( type.getReturnedClass() ); 
	} 
 
	private Type resolveDateTimeArithmeticResultType(Type lhType, Type rhType) { 
		// here, we work under the following assumptions: 
		//      ------------ valid cases -------------------------------------- 
		//      1) datetime + {something other than datetime} : always results 
		//              in a datetime ( db will catch invalid conversions ) 
		//      2) datetime - datetime : always results in a DOUBLE