Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public abstract Class NumberDataType

extends DataType
implements NumberDataValue
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.types.NumberDataValue, org.apache.derby.iapi.types.DataValueDescriptor, org.apache.derby.iapi.types.Orderable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Known Direct Subclasses
org.apache.derby.iapi.types.SQLDecimal, org.apache.derby.iapi.types.SQLDouble, org.apache.derby.iapi.types.SQLInteger, org.apache.derby.iapi.types.SQLLongint, org.apache.derby.iapi.types.SQLReal, org.apache.derby.iapi.types.SQLSmallint, org.apache.derby.iapi.types.SQLTinyint
Imports
java.math.BigDecimal, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.Context, .ContextService, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.reference.SQLState, .Limits, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.DataDictionary

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.
See Also
DataType

Field Summary

Modifier and TypeField and Description
pack-priv static final BigDecimal
pack-priv static final BigDecimal

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final NumberDataValue

Returns:

this object's absolute value. Null if object is null.
absolute
(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.absolute.

Numbers check for isNegative first and negate it if negative.

public final int
compare(DataValueDescriptor
The Orderable to compare this one to.
arg
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of index positioning.

public final boolean
compare(int
Orderable.ORDER_OP_EQUALS means do an = comparison. Orderable.ORDER_OP_LESSTHAN means compare this < other. Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.
op
,
DataValueDescriptor
The DataValueDescriptor to compare this one to.
other
,
boolean
True means to treat nulls as ordered values, that is, treat SQL null as equal to null, and less than all other values. False means to treat nulls as unknown values, that is, the result of any comparison with a null is the UNKNOWN truth value.
orderedNulls
,
boolean
The return value to use if the result of the comparison is the UNKNOWN truth value. In other words, if orderedNulls is false, and a null is involved in the comparison, return unknownRV. This parameter is not used orderedNulls is true.
unknownRV
)

Overrides org.apache.derby.iapi.types.DataType.compare.

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of qualification and sorting.

public NumberDataValue

Returns:

A SQLInteger containing the result of the division
divide
(NumberDataValue
The numerator
dividend
,
NumberDataValue
The denominator
divisor
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

This method implements the / operator for TINYINT, SMALLINT and INTEGER.

public NumberDataValue
divide(NumberDataValue
The numerator
dividend
,
NumberDataValue
The denominator
divisor
,
NumberDataValue
The result of the previous call to this method, null if not called yet.
result
,
int
The scale of the result, for decimal type. If pass in value < 0, can calculate it dynamically.
scale
)

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

Suitable for integral types that ignore scale.

private static Context
getContextOrNull(final String contextID)

Must be private so that user code can't call this entry point.

protected abstract boolean

Returns:

A boolean. If this.value is negative, return true. For positive values or null, return false.
isNegative
()

The isNegative abstract method.

public NumberDataValue

Returns:

A SQLInteger containing the result of the subtraction
minus
(NumberDataValue
The value to be subtracted from
left
,
NumberDataValue
The value to be subtracted
right
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.minus.

This method implements the - operator for TINYINT, SMALLINT and INTEGER.

public NumberDataValue
mod(NumberDataValue
The numerator
dividend
,
NumberDataValue
The denominator
divisor
,
NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.mod.

The SQL mod operator.

public static double
normalizeDOUBLE(double v)

normalizeDOUBLE normalizes the value, so that negative zero (-0.0) becomes positive.

public static float
normalizeREAL(float v)

normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.

public static float
normalizeREAL(final double v)

normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.

protected final boolean
public NumberDataValue

Returns:

A NumberDataValue containing the result of the addition
plus
(NumberDataValue
One of the addends
addend1
,
NumberDataValue
The other addend
addend2
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.plus.

This method implements the + operator for TINYINT,SMALLINT,INT.

public void
setBigDecimal(BigDecimal
required to be a BigDecimal or null.
bigDecimal
)

Overrides org.apache.derby.iapi.types.DataType.setBigDecimal.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setBigDecimal.

setValue for integral exact numerics.

pack-priv void
setObject(Object theValue)

Overrides org.apache.derby.iapi.types.DataType.setObject.

Set the value from a correctly typed Integer object.

public void
setValue(short
The value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Common code to handle converting a short to this value by using the int to this value conversion.

public void
setValue(byte
The value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Common code to handle converting a byte to this value by using the int to this value conversion.

public void
setValue(Number
An Number containing the value to set this NumberDataValue to. Null means set the value to SQL null.
theValue
)

Implements org.apache.derby.iapi.types.NumberDataValue.setValue.

Common code to handle java.lang.Integer as a Number, used for TINYINT, SMALLINT, INTEGER

public NumberDataValue

Returns:

this object's sqrt value. Null if object is null.

Note

-0.0f and -0.0d returns 0.0f and 0.0d.

sqrt
(NumberDataValue
The result of the previous call to this method, null if not call yet.
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.sqrt.

This is the sqrt method.

protected abstract int
typeCompare(DataValueDescriptor arg)

Compare this (not null) to a non-null value.

public int
private static boolean

Returns:

false if dictionary is new enough, see DD_Version.
useDB2Limits
()

Controls use of old DB2 limits (DERBY-3398).

Inherited from org.apache.derby.iapi.types.DataType:
checkHostVariablecloneHoldercoalescecomparecomparecompareTodataTypeConversionequalsequalsflipgenericSetObjectgetBooleangetBytegetBytesgetDategetDoublegetFloatgetIntgetLonggetObjectgetShortgetStreamgetTimegetTimestampgetTraceStringgetTypeNamegreaterOrEqualsgreaterThanhasStreamininvalidFormatisNotNullisNullOplessOrEqualslessThannormalizenotEqualsoutOfRangereadExternalFromArrayrecyclesetFromsetIntosetIntosetObjectForCastsetToNullsetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuethrowLangSetMismatchthrowLangSetMismatchtypePrecedence

Field Detail

MAXLONG_PLUS_ONEback to summary
pack-priv static final BigDecimal MAXLONG_PLUS_ONE
MINLONG_MINUS_ONEback to summary
pack-priv static final BigDecimal MINLONG_MINUS_ONE

Constructor Detail

NumberDataTypeback to summary
public NumberDataType()

Method Detail

absoluteback to summary
public final NumberDataValue absolute(NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.absolute.

Numbers check for isNegative first and negate it if negative.

Parameters
result:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.absolute.

The result of the previous call to this method, null if not called yet.

Returns:NumberDataValue

this object's absolute value. Null if object is null.

Exceptions
StandardException:
thrown on error.
compareback to summary
public final int compare(DataValueDescriptor arg) throws StandardException

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Doc from org.apache.derby.iapi.types.DataValueDescriptor.compare.

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 greater than all other values.

Parameters
arg:DataValueDescriptor

The Orderable to compare this one to.

Returns:int

<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.

Exceptions
StandardException:
Thrown on error
compareback to summary
public final boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV) throws StandardException

Overrides org.apache.derby.iapi.types.DataType.compare.

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Doc from org.apache.derby.iapi.types.DataValueDescriptor.compare.

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.

Parameters
op:int

Orderable.ORDER_OP_EQUALS means do an = comparison. Orderable.ORDER_OP_LESSTHAN means compare this < other. Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.

other:DataValueDescriptor

The DataValueDescriptor to compare this one to.

orderedNulls:boolean

True means to treat nulls as ordered values, that is, treat SQL null as equal to null, and less than all other values. False means to treat nulls as unknown values, that is, the result of any comparison with a null is the UNKNOWN truth value.

unknownRV:boolean

The return value to use if the result of the comparison is the UNKNOWN truth value. In other words, if orderedNulls is false, and a null is involved in the comparison, return unknownRV. This parameter is not used orderedNulls is true.

Returns:boolean

true if the comparison is true (duh!)

Exceptions
StandardException:
thrown on error
divideback to summary
public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

This method implements the / operator for TINYINT, SMALLINT and INTEGER. Specialized methods are not required for TINYINT and SMALLINT as the Java virtual machine always executes byte and int division as integer.

Parameters
dividend:NumberDataValue

The numerator

divisor:NumberDataValue

The denominator

result:NumberDataValue

The result of a previous call to this method, null if not called yet

Returns:NumberDataValue

A SQLInteger containing the result of the division

Exceptions
StandardException:
Thrown on error
divideback to summary
public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

Suitable for integral types that ignore scale.

Parameters
dividend:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

The numerator

divisor:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

The denominator

result:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

The result of the previous call to this method, null if not called yet.

scale:int

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

The scale of the result, for decimal type. If pass in value < 0, can calculate it dynamically.

Returns:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

dividend / divisor

Exceptions
StandardException:

Doc from org.apache.derby.iapi.types.NumberDataValue.divide.

Thrown on error, if result is non-null then its value will be unchanged.

getContextOrNullback to summary
private static Context getContextOrNull(final String contextID)

Must be private so that user code can't call this entry point.

isNegativeback to summary
protected abstract boolean isNegative()

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

Returns:boolean

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

minusback to summary
public NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.minus.

This method implements the - operator for TINYINT, SMALLINT and INTEGER.

Parameters
left:NumberDataValue

The value to be subtracted from

right:NumberDataValue

The value to be subtracted

result:NumberDataValue

The result of a previous call to this method, null if not called yet

Returns:NumberDataValue

A SQLInteger containing the result of the subtraction

Exceptions
StandardException:
Thrown on error
modback to summary
public NumberDataValue mod(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.mod.

Doc from org.apache.derby.iapi.types.NumberDataValue.mod.

The SQL mod operator.

Parameters
dividend:NumberDataValue

The numerator

divisor:NumberDataValue

The denominator

result:NumberDataValue

The result of the previous call to this method, null if not called yet.

Returns:NumberDataValue

dividend / divisor

Exceptions
StandardException:
Thrown on error, if result is non-null then its value will be unchanged.
normalizeDOUBLEback to summary
public static double normalizeDOUBLE(double v) throws StandardException

normalizeDOUBLE normalizes the value, so that negative zero (-0.0) becomes positive.

Exceptions
StandardException:
if v is not a number (NaN) or is infinite.
normalizeREALback to summary
public static float normalizeREAL(float v) throws StandardException

normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.

Exceptions
StandardException:
if the value is not a number (NaN) or is infinite.
normalizeREALback to summary
public static float normalizeREAL(final double v) throws StandardException

normalizeREAL 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 accidentally called with a casted (float)<double value> since this can introduce an undetected underflow values to 0.0f.

Exceptions
StandardException:
if the value is not a number (NaN) or is infinite or on underflow (the value has magnitude too small to be represented as a float).
objectNullback to summary
protected final boolean objectNull(Object o)
plusback to summary
public NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.plus.

This method implements the + operator for TINYINT,SMALLINT,INT.

Parameters
addend1:NumberDataValue

One of the addends

addend2:NumberDataValue

The other addend

result:NumberDataValue

The result of a previous call to this method, null if not called yet

Returns:NumberDataValue

A NumberDataValue containing the result of the addition

Exceptions
StandardException:
Thrown on error
setBigDecimalback to summary
public void setBigDecimal(BigDecimal bigDecimal) throws StandardException

Overrides org.apache.derby.iapi.types.DataType.setBigDecimal.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setBigDecimal.

setValue for integral exact numerics. Converts the BigDecimal to a long to preserve precision

Parameters
bigDecimal:BigDecimal

Doc from org.apache.derby.iapi.types.DataValueDescriptor.setBigDecimal.

required to be a BigDecimal or null.

setObjectback to summary
pack-priv void setObject(Object theValue) throws StandardException

Overrides org.apache.derby.iapi.types.DataType.setObject.

Set the value from a correctly typed Integer object. Used for TINYINT, SMALLINT, INTEGER.

setValueback to summary
public void setValue(short theValue) throws StandardException

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Common code to handle converting a short to this value by using the int to this value conversion. Simply calls setValue(int).

Parameters
theValue:short

Doc from org.apache.derby.iapi.types.DataValueDescriptor.setValue.

The value to set this DataValueDescriptor to

Exceptions
StandardException:

Doc from org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Thrown on error

setValueback to summary
public void setValue(byte theValue) throws StandardException

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Common code to handle converting a byte to this value by using the int to this value conversion. Simply calls setValue(int).

Parameters
theValue:byte

Doc from org.apache.derby.iapi.types.DataValueDescriptor.setValue.

The value to set this DataValueDescriptor to

Exceptions
StandardException:

Doc from org.apache.derby.iapi.types.DataType.setValue.

Thrown on error

setValueback to summary
public void setValue(Number theValue) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.setValue.

Common code to handle java.lang.Integer as a Number, used for TINYINT, SMALLINT, INTEGER

Parameters
theValue:Number

Doc from org.apache.derby.iapi.types.NumberDataValue.setValue.

An Number containing the value to set this NumberDataValue to. Null means set the value to SQL null.

Exceptions
StandardException:
Thrown on error
See Also
NumberDataValue#setValue
sqrtback to summary
public NumberDataValue sqrt(NumberDataValue result) throws StandardException

Implements org.apache.derby.iapi.types.NumberDataValue.sqrt.

This is the sqrt method.

Parameters
result:NumberDataValue

Doc from org.apache.derby.iapi.types.NumberDataValue.sqrt.

The result of the previous call to this method, null if not call yet.

Returns:NumberDataValue

this object's sqrt value. Null if object is null.

Note

-0.0f and -0.0d returns 0.0f and 0.0d.

Exceptions
StandardException:
thrown on a negative number.
typeCompareback to summary
protected abstract int typeCompare(DataValueDescriptor arg) throws StandardException

Compare this (not null) to a non-null value.

Exceptions
StandardException:
Thrown on error
typeToBigDecimalback to summary
public int typeToBigDecimal()

Overrides org.apache.derby.iapi.types.DataType.typeToBigDecimal.

Implements org.apache.derby.iapi.types.DataValueDescriptor.typeToBigDecimal.

Implementation for integral types. Convert to a BigDecimal using long

Returns:int

Doc from org.apache.derby.iapi.types.DataValueDescriptor.typeToBigDecimal.

Types.CHAR for String conversion through getString Types.DECIMAL for BigDecimal through getObject or Types.BIGINT for long conversion through getLong

useDB2Limitsback to summary
private static boolean useDB2Limits() throws StandardException

Controls use of old DB2 limits (DERBY-3398).

Returns:boolean

false if dictionary is new enough, see DD_Version.