java.io.Externalizable, java.io.Serializable, java.lang.Comparable, Formatable, Storable, TypedFormat, DataValueDescriptor, NumberDataValue, Orderable, VariableSizeDataValuepublic final class SQLDecimal extends NumberDataType implements VariableSizeDataValue
Because OrderableDataType is a subtype of DataType, SQLDecimal can play a role in either a DataType/Row or a OrderableDataType/Row, interchangeably.
We assume the store has a flag for nullness of the value, and simply return a 0-length array for the stored form when the value is null.
| Modifier and Type | Field | Description |
|---|---|---|
private static int |
BASE_MEMORY_USAGE |
|
private static int |
BIG_DECIMAL_MEMORY_USAGE |
|
private byte[] |
rawData |
See comments for value
|
private int |
rawScale |
See comments for value
|
private java.math.BigDecimal |
value |
object state.
|
UNKNOWN_LOGICAL_LENGTHMAXLONG_PLUS_ONE, MINLONG_MINUS_ONEMAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALEORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHANIGNORE_PRECISION| Constructor | Description |
|---|---|
SQLDecimal() |
no-arg constructor, required by Formattable
|
SQLDecimal(java.lang.String val) |
|
SQLDecimal(java.math.BigDecimal val) |
|
SQLDecimal(java.math.BigDecimal val,
int nprecision,
int scale) |
| Modifier and Type | Method | Description |
|---|---|---|
DataValueDescriptor |
cloneValue(boolean forceMaterialization) |
Clone this DataValueDescriptor.
|
NumberDataValue |
divide(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result) |
This method implements the / operator for BigDecimal/BigDecimal
|
NumberDataValue |
divide(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result,
int scale) |
This method implements the / operator for BigDecimal/BigDecimal
|
int |
estimateMemoryUsage() |
Estimate the memory usage in bytes of the data value and the overhead of the class.
|
private java.math.BigDecimal |
getBigDecimal() |
|
static java.math.BigDecimal |
getBigDecimal(DataValueDescriptor value) |
Get a BigDecimal representing the value of a DataValueDescriptor
|
boolean |
getBoolean() |
Gets the value in the data value descriptor as a boolean.
|
byte |
getByte() |
Gets the value in the data value descriptor as a byte.
|
int |
getDecimalValuePrecision() |
Return the SQL scale of this value, number of digits after the
decimal point, or zero for a whole number.
|
int |
getDecimalValueScale() |
Return the SQL scale of this value, number of digits after the
decimal point, or zero for a whole number.
|
double |
getDouble() |
If we have a value that is greater than the maximum double,
exception is thrown.
|
float |
getFloat() |
Gets the value in the data value descriptor as a float.
|
int |
getInt() |
Gets the value in the data value descriptor as a int.
|
int |
getLength() |
Gets the length of the data value.
|
long |
getLong() |
Gets the value in the data value descriptor as a long.
|
DataValueDescriptor |
getNewNull() |
Get a new null value of the same type as this data value.
|
java.lang.Object |
getObject() |
Gets the value in the data value descriptor as a int.
|
short |
getShort() |
Gets the value in the data value descriptor as a short.
|
java.lang.String |
getString() |
Gets the value in the data value descriptor as a String.
|
int |
getTypeFormatId() |
Return my format identifier.
|
java.lang.String |
getTypeName() |
Get the SQL name of the datatype
|
private static int |
getWholeDigits(java.math.BigDecimal decimalValue) |
Calculate the number of digits to the left of the decimal point
of the passed in value.
|
int |
hashCode() |
|
protected boolean |
isNegative() |
This method implements the isNegative method.
|
boolean |
isNull() |
Return whether the value is null or not.
|
NumberDataValue |
minus(NumberDataValue result) |
This method implements the unary minus operator for double.
|
NumberDataValue |
minus(NumberDataValue left,
NumberDataValue right,
NumberDataValue result) |
This method implements the - operator for "decimal - decimal".
|
void |
normalize(DataTypeDescriptor desiredType,
DataValueDescriptor source) |
Normalization method - this method may be called when putting
a value into a SQLDecimal, for example, when inserting into a SQLDecimal
column.
|
NumberDataValue |
plus(NumberDataValue addend1,
NumberDataValue addend2,
NumberDataValue result) |
This method implements the + operator for DECIMAL.
|
void |
readExternal(java.io.ObjectInput in) |
Note the use of rawData: we reuse the array if the
incoming array is the same length or smaller than
the array length.
|
void |
restoreToNull() |
Restore this object to its (SQL)null value.
|
void |
setBigDecimal(java.math.BigDecimal theValue) |
Only to be called when the application sets a value using BigDecimal
through setBigDecimal calls.
|
private void |
setCoreValue(double theValue) |
|
private void |
setCoreValue(java.math.BigDecimal theValue) |
|
protected void |
setFrom(DataValueDescriptor theValue) |
Set the value of this DataValueDescriptor based on the value
of the specified DataValueDescriptor.
|
void |
setInto(java.sql.PreparedStatement ps,
int position) |
Set the value into a PreparedStatement.
|
(package private) void |
setObject(java.lang.Object theValue) |
Set the value from a correctly typed BigDecimal object.
|
void |
setValue(boolean theValue) |
Set the value.
|
void |
setValue(double theValue) |
Set the value of this DataValueDescriptor to the given double value
At DataType level just throws an error lower classes will override
|
void |
setValue(float theValue) |
Set the value of this DataValueDescriptor to the given float value
At DataType level just throws an error lower classes will override
|
void |
setValue(int theValue) |
Set the value of this DataValueDescriptor to the given int value
At DataType level just throws an error lower classes will override
|
void |
setValue(long theValue) |
Set the value of this DataValueDescriptor to the given long value
At DataType level just throws an error lower classes will override
|
void |
setValue(java.lang.Number theValue) |
Called when setting a DECIMAL value internally or from
through a procedure or function.
|
void |
setValue(java.lang.String theValue) |
WARNING there is no checking to make sure
that theValue doesn't exceed the precision/scale of
the current SQLDecimal.
|
void |
setValueFromResultSet(java.sql.ResultSet resultSet,
int colNumber,
boolean isNullable) |
Set the value based on the value for the specified DataValueDescriptor
from the specified ResultSet.
|
void |
setWidth(int desiredPrecision,
int desiredScale,
boolean errorOnTrunc) |
Set the precision/scale of the to the desired values.
|
NumberDataValue |
times(NumberDataValue left,
NumberDataValue right,
NumberDataValue result) |
This method implements the * operator for "double * double".
|
java.lang.String |
toString() |
|
protected int |
typeCompare(DataValueDescriptor arg) |
Compare this (not null) to a non-null value.
|
int |
typePrecedence() |
Each built-in type in JSQL has a precedence.
|
int |
typeToBigDecimal() |
DECIMAL implementation.
|
void |
writeExternal(java.io.ObjectOutput out) |
Distill the BigDecimal to a byte array and
write out:
scale (zero or positive) as a byte
length of byte array as a byte
the byte array
|
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, genericSetObject, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, outOfRange, readExternalFromArray, recycle, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatchcheckHostVariable, cloneHolder, coalesce, compare, compare, equals, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, greaterOrEquals, greaterThan, hasStream, in, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, readExternalFromArray, recycle, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueabsolute, compare, compare, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setValue, setValue, sqrtprivate java.math.BigDecimal value
This means that this field must be accessed for read indirectly through the getBigDecimal() method, and when setting it the rawData field must be set to null.
private byte[] rawData
private int rawScale
private static final int BASE_MEMORY_USAGE
private static final int BIG_DECIMAL_MEMORY_USAGE
public SQLDecimal()
public SQLDecimal(java.math.BigDecimal val)
public SQLDecimal(java.math.BigDecimal val,
int nprecision,
int scale)
throws StandardException
StandardExceptionpublic SQLDecimal(java.lang.String val)
public int estimateMemoryUsage()
DataValueDescriptorestimateMemoryUsage in interface DataValueDescriptorpublic int getInt()
throws StandardException
DataTypegetInt in interface DataValueDescriptorgetInt in class DataTypeStandardException - thrown on failure to convertpublic byte getByte()
throws StandardException
DataTypegetByte in interface DataValueDescriptorgetByte in class DataTypeStandardException - thrown on failure to convertpublic short getShort()
throws StandardException
DataTypegetShort in interface DataValueDescriptorgetShort in class DataTypeStandardException - thrown on failure to convertpublic long getLong()
throws StandardException
DataTypegetLong in interface DataValueDescriptorgetLong in class DataTypeStandardException - thrown on failure to convertpublic float getFloat()
throws StandardException
DataTypegetFloat in interface DataValueDescriptorgetFloat in class DataTypeStandardException - thrown on failure to convertpublic double getDouble()
throws StandardException
getDouble in interface DataValueDescriptorgetDouble in class DataTypeStandardException - thrown on failure to convertprivate java.math.BigDecimal getBigDecimal()
public int typeToBigDecimal()
typeToBigDecimal in interface DataValueDescriptortypeToBigDecimal in class NumberDataTypepublic boolean getBoolean()
DataTypegetBoolean in interface DataValueDescriptorgetBoolean in class DataTypepublic java.lang.String getString()
DataValueDescriptorgetString in interface DataValueDescriptorpublic java.lang.Object getObject()
DataTypegetObject in interface DataValueDescriptorgetObject in class DataTypevoid setObject(java.lang.Object theValue)
throws StandardException
setObject in class NumberDataTypeStandardExceptionprotected void setFrom(DataValueDescriptor theValue) throws StandardException
DataTypesetFrom in class DataTypetheValue - The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.StandardExceptionpublic int getLength()
DataValueDescriptorgetLength in interface DataValueDescriptorpublic java.lang.String getTypeName()
DataValueDescriptorgetTypeName in interface DataValueDescriptorpublic int getTypeFormatId()
getTypeFormatId in interface TypedFormatTypedFormat.getTypeFormatId()public boolean isNull()
StorableisNull in interface StorableStorable.isNull()public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal in interface java.io.Externalizablejava.io.IOExceptionpublic void readExternal(java.io.ObjectInput in)
throws java.io.IOException
readExternal in interface java.io.Externalizablejava.io.IOExceptionExternalizable.readExternal(java.io.ObjectInput)public void restoreToNull()
StorablerestoreToNull in interface StorableStorable.restoreToNull()protected int typeCompare(DataValueDescriptor arg) throws StandardException
NumberDataTypetypeCompare in class NumberDataTypeStandardException - Thrown on errorpublic DataValueDescriptor cloneValue(boolean forceMaterialization)
DataValueDescriptor
Even though the objects can be modified independently regardless of the
value of forceMaterialization, both the clone and the
original may be dependent on the store state if
forceMaterialization is set to false. An example is if
you need to access the value you just read using cloneValue
after the current transaction has ended, or after the source result set
has been closed.
cloneValue in interface DataValueDescriptorforceMaterialization - any streams representing the data value will
be materialized if true, the data value will be kept as a
stream if possible if falseDataValueDescriptor with the same initial
value as this.DataValueDescriptor.cloneValue(boolean)public DataValueDescriptor getNewNull()
DataValueDescriptorgetNewNull in interface DataValueDescriptorDataValueDescriptor.getNewNull()public void setValueFromResultSet(java.sql.ResultSet resultSet,
int colNumber,
boolean isNullable)
throws java.sql.SQLException
DataValueDescriptorsetValueFromResultSet in interface DataValueDescriptorresultSet - The specified ResultSet.colNumber - The 1-based column # into the resultSet.isNullable - Whether or not the column is nullable
(No need to call wasNull() if not)java.sql.SQLException - Thrown on errorDataValueDescriptor.setValueFromResultSet(java.sql.ResultSet, int, boolean)public final void setInto(java.sql.PreparedStatement ps,
int position)
throws java.sql.SQLException
setInto in interface DataValueDescriptorsetInto in class DataTypejava.sql.SQLException - Error setting value in PreparedStatementpublic void setValue(java.lang.String theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The BigDecimal value to set this DataValueDescriptor toStandardException - throws NumberFormatException
when the String format is not recognized.public void setValue(double theValue)
throws StandardException
DataTypesetValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toStandardException - Thrown on errorNumberDataValue.setValue(java.lang.Number)public void setValue(float theValue)
throws StandardException
DataTypesetValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toStandardException - Thrown on errorNumberDataValue.setValue(java.lang.Number)public void setValue(long theValue)
DataTypesetValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toNumberDataValue.setValue(java.lang.Number)public void setValue(int theValue)
DataTypesetValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toNumberDataValue.setValue(java.lang.Number)public void setBigDecimal(java.math.BigDecimal theValue)
throws StandardException
setBigDecimal in interface DataValueDescriptorsetBigDecimal in class NumberDataTypetheValue - required to be a BigDecimal or null.StandardExceptionpublic void setValue(java.lang.Number theValue)
throws StandardException
setValue in interface NumberDataValuesetValue in class NumberDataTypetheValue - An Number containing the value to set this
NumberDataValue to. Null means set the value
to SQL null.StandardException - Thrown on errorNumberDataValue.setValue(java.lang.Number)public void setValue(boolean theValue)
DataTypesetValue in interface DataValueDescriptorsetValue in class DataTypetheValue - Contains the boolean value to set this toNumberDataValue.setValue(java.lang.Number)public int typePrecedence()
DataTypetypePrecedence in interface DataValueDescriptortypePrecedence in class DataTypeDataValueDescriptor.typePrecedence()private void setCoreValue(java.math.BigDecimal theValue)
private void setCoreValue(double theValue)
public void normalize(DataTypeDescriptor desiredType, DataValueDescriptor source) throws StandardException
Note that truncation is allowed on the decimal portion of a numeric only.
normalize in interface DataValueDescriptornormalize in class DataTypedesiredType - The type to normalize the source column tosource - The value to normalizeStandardException - Thrown for null into
non-nullable column, and for
truncation errorpublic NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
plus in interface NumberDataValueplus in class NumberDataTypeaddend1 - One of the addendsaddend2 - The other addendresult - The result of a previous call to this method, null
if not called yetStandardException - Thrown on errorpublic NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
minus in interface NumberDataValueminus in class NumberDataTypeleft - The value to be subtracted fromright - The value to be subtractedresult - The result of a previous call to this method, null
if not called yetStandardException - Thrown on errorpublic NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
times in interface NumberDataValueleft - The first value to be multipliedright - The second value to be multipliedresult - The result of a previous call to this method, null
if not called yetStandardException - Thrown on errorpublic NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws StandardException
divide in interface NumberDataValuedivide in class NumberDataTypedividend - The numeratordivisor - The denominatorresult - The result of a previous call to this method, null
if not called yetStandardException - Thrown on errorpublic NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException
divide in interface NumberDataValuedivide in class NumberDataTypedividend - The numeratordivisor - The denominatorresult - The result of a previous call to this method, null
if not called yetscale - The result scale, if < 0, calculate the scale according
to the actual values' sizesStandardException - Thrown on errorpublic NumberDataValue minus(NumberDataValue result) throws StandardException
minus in interface NumberDataValueresult - The result of a previous call to this method, null
if not called yetStandardException - Thrown on errorprotected boolean isNegative()
isNegative in class NumberDataTypepublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void setWidth(int desiredPrecision,
int desiredScale,
boolean errorOnTrunc)
throws StandardException
setWidth in interface VariableSizeDataValuedesiredPrecision - the desired precision -- IGNORE_PREICISION
if it is to be ignored.desiredScale - the desired scaleerrorOnTrunc - throw error on truncation (ignored --
always thrown if we truncate the non-decimal part of
the value)StandardException - Thrown on non-zero truncation
if errorOnTrunc is truepublic int getDecimalValuePrecision()
public int getDecimalValueScale()
public static java.math.BigDecimal getBigDecimal(DataValueDescriptor value) throws StandardException
value - Non-null value to be convertedStandardException - Invalid conversion or out of range.private static int getWholeDigits(java.math.BigDecimal decimalValue)
decimalValue - Value to get whole digits from, never null.Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.