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

📄 sqlboolean.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (cleanedValue.equals("TRUE"))			{				value = true;			}			else if (cleanedValue.equals("FALSE"))			{				value = false;			}			else			{ 				throw invalidFormat();			}			isnull = false;		}	}	private void setValueCore(Number theValue)	{		if (SanityManager.DEBUG)			SanityManager.ASSERT( ! immutable,						"Attempt to set the value of an immutable SQLBoolean");		if (theValue == null)		{			isnull = true;			value = false;		}		else		{			value = (theValue.intValue() != 0);			isnull = false;		}	}	/**	 * @see DataValueDescriptor#setValue	 */		public void setValue(Object theValue)		throws StandardException	{		if ((theValue instanceof Boolean) ||			(theValue == null))		{			this.setValue((Boolean)theValue);		}		else if (theValue instanceof Number) {			setValueCore((Number) theValue);		}		else		{			genericSetObject(theValue);		}	}	protected void setFrom(DataValueDescriptor theValue) throws StandardException {		setValue(theValue.getBoolean());	}	/*	** 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 truthValue(left,							right,							left.getBoolean() == right.getBoolean());	}	/**	 * 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 truthValue(left,							right,							left.getBoolean() != right.getBoolean());	}	/**	 * 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 left operand is	 *			less than the right operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue lessThan(DataValueDescriptor left,							 DataValueDescriptor right)				throws StandardException	{		/* We must call getBoolean() on both sides in order		 * to catch any invalid casts.		 */		boolean leftBoolean = left.getBoolean();		boolean rightBoolean = right.getBoolean();		/* By convention, false is less than true */		return truthValue(left,							right,							leftBoolean == false && rightBoolean == true);	}	/**	 * 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 left operand is	 *			greater than the right operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue greaterThan(DataValueDescriptor left,							 DataValueDescriptor right)				throws StandardException	{		/* We must call getBoolean() on both sides in order		 * to catch any invalid casts.		 */		boolean leftBoolean = left.getBoolean();		boolean rightBoolean = right.getBoolean();		/* By convention, true is greater than false */		return truthValue(left,							right,							leftBoolean == true && rightBoolean == false);	}	/**	 * 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 left operand is	 *			less than or equal to the right operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue lessOrEquals(DataValueDescriptor left,							 DataValueDescriptor right)				throws StandardException	{		/* We must call getBoolean() on both sides in order		 * to catch any invalid casts.		 */		boolean leftBoolean = left.getBoolean();		boolean rightBoolean = right.getBoolean();		/* By convention, false is less than true */		return truthValue(left,							right,							leftBoolean == false || rightBoolean == true);	}	/**	 * 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 left operand is	 *			greater than or equal to the right operand	 *	 * @exception StandardException		Thrown on error	 */	public BooleanDataValue greaterOrEquals(DataValueDescriptor left,							 DataValueDescriptor right)				throws StandardException	{		/* We must call getBoolean() on both sides in order		 * to catch any invalid casts.		 */		boolean leftBoolean = left.getBoolean();		boolean rightBoolean = right.getBoolean();		/* By convention, true is greater than false */		return truthValue(left,							right,							leftBoolean == true || rightBoolean == false);	}	/**	 * The AND operator.  This implements SQL semantics for AND with unknown	 * truth values - consult any standard SQL reference for an explanation.	 *	 * @param otherValue	The other boolean to AND with this one	 *	 * @return	this AND otherValue	 *	 */	public BooleanDataValue and(BooleanDataValue otherValue)	{		/*		** Catch those cases where standard SQL null semantics don't work.		*/		if (this.equals(false) || otherValue.equals(false))		{			return BOOLEAN_FALSE;		}		else		{			return truthValue(this,							otherValue,							this.getBoolean() && otherValue.getBoolean());		}	}	/**	 * The OR operator.  This implements SQL semantics for OR with unknown	 * truth values - consult any standard SQL reference for an explanation.	 *	 * @param otherValue	The other boolean to OR with this one	 *	 * @return	this OR otherValue	 *	 */	public BooleanDataValue or(BooleanDataValue otherValue)	{		/*		** Catch those cases where standard SQL null semantics don't work.		*/		if (this.equals(true) || otherValue.equals(true))		{			return BOOLEAN_TRUE;		}		else		{			return truthValue(this,							otherValue,							this.getBoolean() || otherValue.getBoolean());		}	}	/**	 * The SQL IS operator - consult any standard SQL reference for an explanation.	 *	 *	Implements the following truth table:	 *	 *	         otherValue	 *	        | TRUE    | FALSE   | UNKNOWN	 *	this    |----------------------------	 *	        |	 *	TRUE    | TRUE    | FALSE   | FALSE	 *	FALSE   | FALSE   | TRUE    | FALSE	 *	UNKNOWN | FALSE   | FALSE   | TRUE	 *	 *	 * @param otherValue	BooleanDataValue to compare to. May be TRUE, FALSE, or UNKNOWN.	 *	 * @return	whether this IS otherValue	 *	 */	public BooleanDataValue is(BooleanDataValue otherValue)	{		if ( this.equals(true) && otherValue.equals(true) )		{ return BOOLEAN_TRUE; }		if ( this.equals(false) && otherValue.equals(false) )		{ return BOOLEAN_TRUE; }		if ( this.isNull() && otherValue.isNull() )		{ return BOOLEAN_TRUE; }		return BOOLEAN_FALSE;	}	/**	 * Implements NOT IS. This reverses the sense of the is() call.	 *	 *	 * @param otherValue	BooleanDataValue to compare to. May be TRUE, FALSE, or UNKNOWN.	 *	 * @return	NOT( this IS otherValue )	 *	 */	public BooleanDataValue isNot(BooleanDataValue otherValue)	{		BooleanDataValue	isValue = is( otherValue );		if ( isValue.equals(true) ) { return BOOLEAN_FALSE; }		else { return BOOLEAN_TRUE; }	}	/**	 * Throw an exception with the given SQLState if this BooleanDataValue	 * is false. This method is useful for evaluating constraints.	 *	 * @param SQLState		The SQLState of the exception to throw if	 *						this SQLBoolean is false.	 * @param tableName		The name of the table to include in the exception	 *						message.	 * @param constraintName	The name of the failed constraint to include	 *							in the exception message.	 *	 * @return	this	 *	 * @exception	StandardException	Thrown if this BooleanDataValue	 *									is false.	 */	public BooleanDataValue throwExceptionIfFalse(									String sqlState,									String tableName,									String constraintName)							throws StandardException	{		if ( ( ! isNull() ) && (value == false) )		{			throw StandardException.newException(sqlState,												tableName,												constraintName);		}		return this;	}	/*	 * DataValueDescriptor interface	 */	/** @see DataValueDescriptor#typePrecedence */	public int typePrecedence()	{		return TypeId.BOOLEAN_PRECEDENCE;	}	/*	** Support functions	*/	/**	 * Return the SQL truth value for a comparison.	 *	 * This method first looks at the operands - if either is null, it	 * returns the unknown truth value.  This implements "normal" SQL	 * null semantics, where if any operand is null, the result is null.	 * Note that there are cases where these semantics are incorrect -	 * for example, NULL AND FALSE is supposed to be FALSE, not NULL	 * (the NULL truth value is the same as the UNKNOWN truth value).	 *	 * If neither operand is null, it returns a static final variable	 * containing the SQLBoolean truth value.  It returns different values	 * depending on whether the truth value is supposed to be nullable.	 *	 * This method always returns a pre-allocated static final SQLBoolean.	 * This is practical because there are so few possible return values.	 * Using pre-allocated values allows us to avoid constructing new	 * SQLBoolean values during execution.	 *	 * @param leftOperand	The left operand of the binary comparison	 * @param rightOperand	The right operand of the binary comparison	 * @param truth			The truth value of the comparison	 *	 * @return	A SQLBoolean containing the desired truth value.	 */	public static SQLBoolean truthValue(								DataValueDescriptor leftOperand,								DataValueDescriptor rightOperand,								boolean truth)	{		/* Return UNKNOWN if either operand is null */		if (leftOperand.isNull() || rightOperand.isNull())		{			return unknownTruthValue();		}		/* Return the appropriate SQLBoolean for the given truth value */		if (truth == true)		{			return BOOLEAN_TRUE;		}		else		{			return BOOLEAN_FALSE;		}	}    /**     * same as above, but takes a Boolean, if it is null, unknownTruthValue is returned     */	public static SQLBoolean truthValue(								DataValueDescriptor leftOperand,								DataValueDescriptor rightOperand,								Boolean truth)	{		/* Return UNKNOWN if either operand is null */		if (leftOperand.isNull() || rightOperand.isNull() || truth==null)		{			return unknownTruthValue();		}		/* Return the appropriate SQLBoolean for the given truth value */		if (truth == Boolean.TRUE)		{			return BOOLEAN_TRUE;		}		else		{			return BOOLEAN_FALSE;		}	}	/**	 * Get a truth value.	 *	 * @param value	The value of the SQLBoolean	 * 	 * @return	A SQLBoolean with the given truth value	 */	public static SQLBoolean truthValue(boolean value)	{		/*		** Return the non-nullable versions of TRUE and FALSE, since they		** can never be null.		*/		if (value == true)			return BOOLEAN_TRUE;		else			return BOOLEAN_FALSE;	}	/**	 * Return an unknown truth value.  Check to be sure the return value is	 * nullable.	 *	 * @return	A SQLBoolean representing the UNKNOWN truth value	 */	public static SQLBoolean unknownTruthValue()	{		return UNKNOWN;	}	/**	 * Return a false truth value.	 *	 *	 * @return	A SQLBoolean representing the FALSE truth value	 */	public static SQLBoolean falseTruthValue()	{		return BOOLEAN_FALSE;	}	/**	 * Return a true truth value.	 *	 *	 * @return	A SQLBoolean representing the TRUE truth value	 */	public static SQLBoolean trueTruthValue()	{		return BOOLEAN_TRUE;	}		/**	 * Determine whether this SQLBoolean contains the given boolean value.	 *	 * This method is used by generated code to determine when to do	 * short-circuiting for an AND or OR.	 *	 * @param val	The value to look for	 *	 * @return	true if the given value equals the value in this SQLBoolean,	 *			false if not	 */	public boolean equals(boolean val)	{		if (isNull())			return false;		else			return value == val;	}	/*	 * String display of value	 */	public String toString()	{		if (isNull())			return "NULL";		else if (value == true)			return "true";		else			return "false";	}	/*	 * Hash code	 */	public int hashCode()	{		if (isNull())		{			return -1;		}		return (value) ? 1 : 0;	}	/*	 * useful constants...	 */	static final int BOOLEAN_LENGTH		= 1;	// must match the number of bytes written by DataOutput.writeBoolean()	private static final SQLBoolean BOOLEAN_TRUE = new SQLBoolean(true);	private static final SQLBoolean BOOLEAN_FALSE = new SQLBoolean(false);	static final SQLBoolean UNKNOWN = new SQLBoolean();	/* Static initialization block */	static	{		/* Mark all the static SQLBooleans as immutable */		BOOLEAN_TRUE.immutable = true;		BOOLEAN_FALSE.immutable = true;		UNKNOWN.immutable = true;	}    private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( SQLBoolean.class);    public int estimateMemoryUsage()    {        return BASE_MEMORY_USAGE;    }	/*	 * object state	 */	protected boolean value;	protected boolean isnull;	protected boolean immutable;}

⌨️ 快捷键说明

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