Class NumberDataType
java.lang.Object
org.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.NumberDataType
- All Implemented Interfaces:
Externalizable, Serializable, Comparable, Formatable, Storable, TypedFormat, DataValueDescriptor, NumberDataValue, Orderable
- Direct Known Subclasses:
SQLDecimal, SQLDouble, SQLInteger, SQLLongint, SQLReal, SQLSmallint, SQLTinyint
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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final BigDecimal(package private) static final BigDecimalFields inherited from interface DataValueDescriptor
UNKNOWN_LOGICAL_LENGTHFields inherited from interface NumberDataValue
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALEFields inherited from interface Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal NumberDataValueabsolute(NumberDataValue result) Numbers check for isNegative first and negate it if negative.final booleancompare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV) Compare this Orderable with a given Orderable for the purpose of qualification and sorting.final intCompare this Orderable with a given Orderable for the purpose of index positioning.divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) This method implements the / operator for TINYINT, SMALLINT and INTEGER.divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) Suitable for integral types that ignore scale.private static ContextgetContextOrNull(String contextID) Privileged lookup of a Context.protected abstract booleanThe isNegative abstract method.minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) This method implements the - operator for TINYINT, SMALLINT and INTEGER.mod(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) The SQL mod operator.static doublenormalizeDOUBLE(double v) normalizeDOUBLE normalizes the value, so that negative zero (-0.0) becomes positive.static floatnormalizeREAL(double v) normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.static floatnormalizeREAL(float v) normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.protected final booleanobjectNull(Object o) plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) This method implements the + operator for TINYINT,SMALLINT,INT.voidsetBigDecimal(BigDecimal bigDecimal) setValue for integral exact numerics.(package private) voidSet the value from a correctly typed Integer object.voidsetValue(byte theValue) Common code to handle converting a byte to this value by using the int to this value conversion.voidsetValue(short theValue) Common code to handle converting a short to this value by using the int to this value conversion.voidCommon code to handle java.lang.Integer as a Number, used for TINYINT, SMALLINT, INTEGERsqrt(NumberDataValue result) This is the sqrt method.protected abstract intCompare this (not null) to a non-null value.intImplementation for integral types.private static booleanControls use of old DB2 limits (DERBY-3398).Methods inherited from class DataType
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLong, getObject, getShort, getStream, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, readExternalFromArray, recycle, 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, typePrecedenceMethods inherited from class Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataValueDescriptor
checkHostVariable, cloneHolder, cloneValue, coalesce, compare, compare, equals, estimateMemoryUsage, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLength, getLong, getNewNull, getObject, getShort, getStream, getString, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, readExternalFromArray, recycle, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, typePrecedenceMethods inherited from interface Externalizable
readExternal, writeExternalMethods inherited from interface NumberDataValue
minus, timesMethods inherited from interface Storable
isNull, restoreToNullMethods inherited from interface TypedFormat
getTypeFormatId
-
Field Details
-
MAXLONG_PLUS_ONE
-
MINLONG_MINUS_ONE
-
-
Constructor Details
-
NumberDataType
public NumberDataType()
-
-
Method Details
-
absolute
Numbers check for isNegative first and negate it if negative.- Specified by:
absolutein interfaceNumberDataValue- 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
This is the sqrt method.- Specified by:
sqrtin interfaceNumberDataValue- 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.
-
plus
public NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException This method implements the + operator for TINYINT,SMALLINT,INT.- Specified by:
plusin interfaceNumberDataValue- Parameters:
addend1- One of the addendsaddend2- The other addendresult- The result of a previous call to this method, null if not called yet- Returns:
- A NumberDataValue containing the result of the addition
- Throws:
StandardException- Thrown on error
-
minus
public NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException This method implements the - operator for TINYINT, SMALLINT and INTEGER.- Specified by:
minusin interfaceNumberDataValue- Parameters:
left- The value to be subtracted fromright- The value to be subtractedresult- The result of a previous call to this method, null if not called yet- Returns:
- A SQLInteger containing the result of the subtraction
- Throws:
StandardException- Thrown on error
-
divide
public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws StandardException 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.- Specified by:
dividein interfaceNumberDataValue- Parameters:
dividend- The numeratordivisor- The denominatorresult- The result of a previous call to this method, null if not called yet- Returns:
- A SQLInteger containing the result of the division
- Throws:
StandardException- Thrown on error
-
divide
public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException Suitable for integral types that ignore scale.- Specified by:
dividein interfaceNumberDataValue- Parameters:
dividend- The numeratordivisor- The denominatorresult- 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:NumberDataValueThe SQL mod operator.- Specified by:
modin interfaceNumberDataValue- Parameters:
dividend- The numeratordivisor- The denominatorresult- 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
Description copied from interface:DataValueDescriptorCompare 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.- Specified by:
comparein interfaceDataValueDescriptor- 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
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:DataValueDescriptorCompare 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:
comparein interfaceDataValueDescriptor- Overrides:
comparein classDataType- Parameters:
op- 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- The DataValueDescriptor to compare this one to.orderedNulls- 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- 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:
- true if the comparison is true (duh!)
- 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
Common code to handle converting a short to this value by using the int to this value conversion. Simply calls setValue(int).- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
Common code to handle converting a byte to this value by using the int to this value conversion. Simply calls setValue(int).- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType- Parameters:
theValue- The value to set this DataValueDescriptor to- Throws:
StandardException- Thrown on error
-
setValue
Common code to handle java.lang.Integer as a Number, used for TINYINT, SMALLINT, INTEGER- Specified by:
setValuein interfaceNumberDataValue- Parameters:
theValue- An Number containing the value to set this NumberDataValue to. Null means set the value to SQL null.- Throws:
StandardException- Thrown on error- See Also:
-
setObject
Set the value from a correctly typed Integer object. Used for TINYINT, SMALLINT, INTEGER.- Overrides:
setObjectin classDataType- Throws:
StandardException
-
setBigDecimal
setValue for integral exact numerics. Converts the BigDecimal to a long to preserve precision- Specified by:
setBigDecimalin interfaceDataValueDescriptor- Overrides:
setBigDecimalin classDataType- Parameters:
bigDecimal- required to be a BigDecimal or null.- Throws:
StandardException
-
typeToBigDecimal
public int typeToBigDecimal()Implementation for integral types. Convert to a BigDecimal using long- Specified by:
typeToBigDecimalin interfaceDataValueDescriptor- Overrides:
typeToBigDecimalin classDataType- Returns:
- Types.CHAR for String conversion through getString Types.DECIMAL for BigDecimal through getObject or Types.BIGINT for long conversion through getLong
-
objectNull
-
normalizeREAL
normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.- Throws:
StandardException- if the value is not a number (NaN) or is infinite.
-
normalizeREAL
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.- Throws:
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).
-
normalizeDOUBLE
normalizeDOUBLE normalizes the value, so that negative zero (-0.0) becomes positive.- Throws:
StandardException- if v is not a number (NaN) or is infinite.
-
useDB2Limits
Controls use of old DB2 limits (DERBY-3398).- Returns:
- false if dictionary is new enough, see DD_Version.
- Throws:
StandardException
-
getContextOrNull
-