org.apache.derby.iapi.types
Class NumberDataType

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataType
      extended byorg.apache.derby.iapi.types.NumberDataType
All Implemented Interfaces:
CloneableObject, DataValueDescriptor, java.io.Externalizable, Formatable, NumberDataValue, Orderable, java.io.Serializable, Storable, TypedFormat
Direct Known Subclasses:
SQLDecimal, SQLDouble, SQLInteger, SQLLongint, SQLReal, SQLSmallint, SQLTinyint

public abstract class NumberDataType
extends DataType
implements NumberDataValue

NumberDataType is the superclass for all exact and approximate numeric data types. It exists for the purpose of allowing classification of types for supported implicit conversions among them.

Author:
ames
See Also:
DataType, Serialized Form

Field Summary
 
Fields inherited from interface org.apache.derby.iapi.types.NumberDataValue
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALE
 
Fields inherited from interface org.apache.derby.iapi.types.Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
 
Constructor Summary
NumberDataType()
           
 
Method Summary
 NumberDataValue absolute(NumberDataValue result)
          Numbers check for isNegative first and negate it if negative.
 int compare(DataValueDescriptor arg)
          Compare this Orderable with a given Orderable for the purpose of index positioning.
 boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV)
          Compare this Orderable with a given Orderable for the purpose of qualification and sorting.
 NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale)
          This is dummy parent divide method.
protected abstract  boolean isNegative()
          The isNegative abstract method.
 NumberDataValue mod(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result)
          The SQL mod operator.
static double normalizeDOUBLE(double v)
          normalizeDOUBLE checks the validity of the given java double that it fits within the range of DB2 DOUBLEs.
static float normalizeREAL(double v)
          normalizeREAL checks the validity of the given java double that it fits within the range of DB2 REALs.
static float normalizeREAL(float v)
          normalizeREAL checks the validity of the given java float that it fits within the range of DB2 REALs.
protected  boolean objectNull(java.lang.Object o)
           
 void setValue(java.math.BigDecimal theValue)
          setValue for integral exact numerics.
 void setValue(java.lang.Boolean theValue)
          Set the value.
 void setValue(java.lang.Byte theValue)
          Set the value of this NumberDataValue to the given byte value
 void setValue(java.lang.Double theValue)
          Set the value of this NumberDataValue to the given double value
 void setValue(java.lang.Float theValue)
          Set the value of this NumberDataValue to the given float value
 void setValue(java.lang.Integer theValue)
          Set the value of this NumberDataValue to the given int value
 void setValue(java.lang.Long theValue)
          Set the value of this NumberDataValue to the given long value
 void setValue(java.lang.Short theValue)
          Set the value of this NumberDataValue to the given short value
 NumberDataValue sqrt(NumberDataValue result)
          This is the sqrt method.
protected abstract  int typeCompare(DataValueDescriptor arg)
          Compare this (not null) to a non-null value.
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, cloneObject, coalesce, dataTypeConversion, equals, equals, flip, genericSetObject, getBigDecimal, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLong, getNationalString, getObject, getShort, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, setFrom, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch, typePrecedence
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.types.NumberDataValue
divide, minus, minus, plus, times
 
Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
checkHostVariable, coalesce, equals, estimateMemoryUsage, getBigDecimal, getBoolean, getByte, getBytes, getClone, getDate, getDouble, getFloat, getInt, getLength, getLong, getNewNull, getObject, getShort, getStream, getString, getTime, getTimestamp, getTypeName, greaterOrEquals, greaterThan, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, readExternalFromArray, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, typePrecedence
 
Methods inherited from interface org.apache.derby.iapi.services.io.Storable
isNull, restoreToNull
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface org.apache.derby.iapi.services.io.TypedFormat
getTypeFormatId
 

Constructor Detail

NumberDataType

public NumberDataType()
Method Detail

absolute

public NumberDataValue absolute(NumberDataValue result)
                         throws StandardException
Numbers check for isNegative first and negate it if negative.

Specified by:
absolute in interface NumberDataValue
Parameters:
result - The result of the previous call to this method, null if not called yet.
Returns:
this object's absolute value. Null if object is null.
Throws:
StandardException - thrown on error.

sqrt

public NumberDataValue sqrt(NumberDataValue result)
                     throws StandardException
This is the sqrt method.

Specified by:
sqrt in interface NumberDataValue
Parameters:
result - The result of the previous call to this method, null if not call yet.
Returns:
this object's sqrt value. Null if object is null. Note: -0.0f and -0.0d returns 0.0f and 0.0d.
Throws:
StandardException - thrown on a negative number.

divide

public NumberDataValue divide(NumberDataValue dividend,
                              NumberDataValue divisor,
                              NumberDataValue result,
                              int scale)
                       throws StandardException
This is dummy parent divide method. Put it here for all the children that don't need this. @see NumberDataValue#divide

Specified by:
divide in interface NumberDataValue
Parameters:
dividend - The numerator
divisor - The denominator
result - The result of the previous call to this method, null if not called yet.
scale - The scale of the result, for decimal type. If pass in value < 0, can calculate it dynamically.
Returns:
dividend / divisor
Throws:
StandardException - Thrown on error, if result is non-null then its value will be unchanged.

mod

public NumberDataValue mod(NumberDataValue dividend,
                           NumberDataValue divisor,
                           NumberDataValue result)
                    throws StandardException
Description copied from interface: NumberDataValue
The SQL mod operator.

Specified by:
mod in interface NumberDataValue
Parameters:
dividend - The numerator
divisor - The denominator
result - The result of the previous call to this method, null if not called yet.
Returns:
dividend / divisor
Throws:
StandardException - Thrown on error, if result is non-null then its value will be unchanged.

compare

public final int compare(DataValueDescriptor arg)
                  throws StandardException
Description copied from interface: DataValueDescriptor
Compare this Orderable with a given Orderable for the purpose of index positioning. This method treats nulls as ordered values - that is, it treats SQL null as equal to null and less than all other values.

Specified by:
compare in interface DataValueDescriptor
Parameters:
arg - The Orderable to compare this one to.
Returns:
<0 - this Orderable is less than other. 0 - this Orderable equals other. >0 - this Orderable is greater than other. The code should not explicitly look for -1, or 1.
Throws:
StandardException - Thrown on error

typeCompare

protected abstract int typeCompare(DataValueDescriptor arg)
                            throws StandardException
Compare this (not null) to a non-null value.

Throws:
StandardException - Thrown on error

compare

public final boolean compare(int op,
                             DataValueDescriptor other,
                             boolean orderedNulls,
                             boolean unknownRV)
                      throws StandardException
Description copied from interface: DataValueDescriptor
Compare this Orderable with a given Orderable for the purpose of qualification and sorting. The caller gets to determine how nulls should be treated - they can either be ordered values or unknown values.

Specified by:
compare in interface DataValueDescriptor
Overrides:
compare in class DataType
Throws:
StandardException - thrown on error

isNegative

protected abstract boolean isNegative()
The isNegative abstract method. Checks to see if this.value is negative. To be implemented by each NumberDataType.

Returns:
A boolean. If this.value is negative, return true. For positive values or null, return false.

setValue

public final void setValue(java.lang.Byte theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given byte value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - A Byte containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public final void setValue(java.lang.Short theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given short value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - A Short containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public final void setValue(java.lang.Integer theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given int value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - An Integer containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public final void setValue(java.lang.Long theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given long value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - A Long containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public final void setValue(java.lang.Double theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given double value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - A Double containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public void setValue(java.math.BigDecimal theValue)
              throws StandardException
setValue for integral exact numerics. Converts the BigDecimal to a long to preserve precision

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The BigDecimal value to set this DataValueDescriptor to
Returns:
This DataValueDescriptor
Throws:
StandardException

setValue

public final void setValue(java.lang.Float theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value of this NumberDataValue to the given float value

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - A Float containing the value to set this NumberDataValue to. Null means set the value to SQL null.
Returns:
This NumberDataValue
Throws:
StandardException - Thrown on error
See Also:
NumberDataValue.setValue(java.lang.Integer)

setValue

public final void setValue(java.lang.Boolean theValue)
                    throws StandardException
Description copied from interface: NumberDataValue
Set the value.

Specified by:
setValue in interface NumberDataValue
Parameters:
theValue - Contains the boolean value to set this to
Returns:
This value
Throws:
StandardException
See Also:
NumberDataValue.setValue(java.lang.Integer)

objectNull

protected final boolean objectNull(java.lang.Object o)

normalizeREAL

public static float normalizeREAL(float v)
                           throws StandardException
normalizeREAL checks the validity of the given java float that it fits within the range of DB2 REALs. In addition it normalizes the value, so that negative zero (-0.0) becomes positive.

Throws:
StandardException

normalizeREAL

public static float normalizeREAL(double v)
                           throws StandardException
normalizeREAL checks the validity of the given java double that it fits within the range of DB2 REALs. In addition it normalizes the value, so that negative zero (-0.0) becomes positive. The reason for having normalizeREAL with two signatures is to avoid that normalizeREAL is called with a casted (float)doublevalue, since this invokes an unwanted rounding (of underflow values to 0.0), in contradiction to DB2s casting semantics.

Throws:
StandardException

normalizeDOUBLE

public static double normalizeDOUBLE(double v)
                              throws StandardException
normalizeDOUBLE checks the validity of the given java double that it fits within the range of DB2 DOUBLEs. In addition it normalizes the value, so that negative zero (-0.0) becomes positive.

Throws:
StandardException


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.