⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlinteger.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			throw outOfRange();		float floorValue = (float)Math.floor(theValue);		value = (int)floorValue;		isnull = false;	}	/**	 * @see NumberDataValue#setValue	 *	 * @exception StandardException		Thrown on error	 */	public void setValue(double theValue) throws StandardException	{		theValue = NumberDataType.normalizeDOUBLE(theValue);		if (theValue > Integer.MAX_VALUE || theValue < Integer.MIN_VALUE)			throw outOfRange();		double floorValue = Math.floor(theValue);		value = (int)floorValue;		isnull = false;	}	public void setValue(boolean theValue)	{		value = theValue?1:0;		isnull = false;	}	/**	 * @see DataValueDescriptor#setValue	 *	 * @exception StandardException on failure of intValue on Number	 *	 */		public void setValue(Object theValue) 		throws StandardException	{		if (theValue == null)		{			setToNull();		}		else if (theValue instanceof Number)		{			this.setValue(((Number)theValue).intValue());		}		else		{			genericSetObject(theValue);		}	}	protected void setFrom(DataValueDescriptor theValue) throws StandardException {		setValue(theValue.getInt());	}	/*	 * DataValueDescriptor interface	 */	/** @see DataValueDescriptor#typePrecedence */	public int typePrecedence()	{		return TypeId.INT_PRECEDENCE;	}	/*	** SQL Operators	*/	/**	 * The = operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the =	 * @param right			The value on the right side of the =	 *	 * @return	A SQL boolean value telling whether the two parameters are equal	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue equals(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() == right.getInt());	}	/**	 * The <> operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the <>	 * @param right			The value on the right side of the <>	 *	 * @return	A SQL boolean value telling whether the two parameters	 *			are not equal	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue notEquals(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() != right.getInt());	}	/**	 * The < operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the <	 * @param right			The value on the right side of the <	 *	 * @return	A SQL boolean value telling whether the first operand is less	 *			than the second operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue lessThan(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() < right.getInt());	}	/**	 * The > operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the >	 * @param right			The value on the right side of the >	 *	 * @return	A SQL boolean value telling whether the first operand is greater	 *			than the second operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue greaterThan(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() > right.getInt());	}	/**	 * The <= operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the <=	 * @param right			The value on the right side of the <=	 *	 * @return	A SQL boolean value telling whether the first operand is less	 *			than or equal to the second operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue lessOrEquals(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() <= right.getInt());	}	/**	 * The >= operator as called from the language module, as opposed to	 * the storage module.	 *	 * @param left			The value on the left side of the >=	 * @param right			The value on the right side of the >=	 *	 * @return	A SQL boolean value telling whether the first operand is greater	 *			than or equal to the second operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue greaterOrEquals(DataValueDescriptor left,							DataValueDescriptor right)			throws StandardException	{		return SQLBoolean.truthValue(left,									 right,									 left.getInt() >= right.getInt());	}	/**	 * This method implements the * operator for "int * int".	 *	 * @param left	The first value to be multiplied	 * @param right	The second value to be multiplied	 * @param result	The result of a previous call to this method, null	 *					if not called yet	 *	 * @return	A SQLInteger containing the result of the multiplication	 *	 * @exception StandardException		Thrown on error	 */	public NumberDataValue times(NumberDataValue left,							NumberDataValue right,							NumberDataValue result)				throws StandardException	{		if (result == null)		{			result = new SQLInteger();		}		if (left.isNull() || right.isNull())		{			result.setToNull();			return result;		}		/*		** Java does not check for overflow with integral types. We have to		** check the result ourselves.		**		** We can't use sign checking tricks like we do for '+' and '-' since		** the product of 2 integers can wrap around multiple times.  So, we		** do long arithmetic and then verify that the result is within the 		** range of an int, throwing an error if it isn't.		*/		long tempResult = left.getLong() * right.getLong();		result.setValue(tempResult);		return result;	}	/**		mod(int, int)	*/	public NumberDataValue mod(NumberDataValue dividend,								NumberDataValue divisor,								NumberDataValue result)								throws StandardException {		if (result == null)		{			result = new SQLInteger();		}		if (dividend.isNull() || divisor.isNull())		{			result.setToNull();			return result;		}		/* Catch divide by 0 */		int intDivisor = divisor.getInt();		if (intDivisor == 0)		{			throw StandardException.newException(SQLState.LANG_DIVIDE_BY_ZERO);		}		result.setValue(dividend.getInt() % intDivisor);		return result;	}	/**	 * This method implements the unary minus operator for int.	 *	 * @param result	The result of a previous call to this method, null	 *					if not called yet	 *	 * @return	A SQLInteger containing the result of the division	 *	 * @exception StandardException		Thrown on error	 */	public NumberDataValue minus(NumberDataValue result)									throws StandardException	{		int		operandValue;		if (result == null)		{			result = new SQLInteger();		}		if (this.isNull())		{			result.setToNull();			return result;		}		operandValue = this.getInt();		/*		** In two's complement arithmetic, the minimum value for a number		** can't be negated, since there is no representation for its		** positive value.  For integers, the minimum value is -2147483648,		** and the maximum value is 2147483647.		*/		if (operandValue == Integer.MIN_VALUE)		{			throw outOfRange();		}		result.setValue(-operandValue);		return result;	}    /**     * This method implements the isNegative method.     *     * @return  A boolean.  If this.value is negative, return true.     *          For positive values or null, return false.     */    protected boolean isNegative()    {        return !isNull() && value < 0;    }	/*	 * String display of value	 */	public String toString()	{		if (isNull())			return "NULL";		else			return Integer.toString(value);	}	/*	 * Hash code	 */	public int hashCode()	{		return value;	}	/*	 * useful constants...	 */	static final int INTEGER_LENGTH		= 4; // must match the number of bytes written by DataOutput.writeInt()    private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( SQLInteger.class);    public int estimateMemoryUsage()    {        return BASE_MEMORY_USAGE;    }	/*	 * object state	 */	private int		value;	private boolean	isnull;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -