abstract class BinaryDecimal extends NumberDataType implements VariableSizeDataValue
The on-disk format must match the SQLDecimal format so that databases are portable across J2ME and J2SE environments.
The format of the byte array is defined by the return of the java.math.BigInteger.toByteArray:, extracted here. Returns a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element. This is the format for DECIMAL even if BigINteger is not available, e.g. OSGi ee.minimum.
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
data2c
The unscaled value as a binary two's complement array.
|
private static byte[] |
ONE_2C
An unscaled value of 1 in two's complement
|
protected int |
sqlScale
The SQL scale, zero or positive, of the value
|
MAXLONG_PLUS_ONE, MINLONG_MINUS_ONE, ONE, ZERO, ZERO_DECIMALIGNORE_PRECISIONMAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALEUNKNOWN_LOGICAL_LENGTHORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN| Constructor and Description |
|---|
BinaryDecimal() |
| Modifier and Type | Method and Description |
|---|---|
DataValueDescriptor |
cloneValue(boolean forceMaterialization)
Clone this DataValueDescriptor.
|
NumberDataValue |
divide(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result)
This method implements the / operator for TINYINT, SMALLINT and INTEGER.
|
NumberDataValue |
divide(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result,
int scale)
This method implements the / operator for BigDecimal/BigDecimal
|
abstract NumberDataValue |
divideNN(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result,
int scale)
Divide two non-nullable values using DECIMAL arithmetic.
|
int |
estimateMemoryUsage()
Estimate the memory usage in bytes of the data value and the overhead of the class.
|
byte |
getByte()
Return a byte from this value.
|
int |
getDecimalValueScale()
Return the SQL scale of this value, number of digits after the
decimal point, or zero for a whole number.
|
int |
getInt()
Return a int from this value.
|
int |
getLength()
Gets the length of the data value.
|
short |
getShort()
Return a short from this value.
|
int |
getTypeFormatId()
Return my format identifier.
|
java.lang.String |
getTypeName()
Get the SQL name of the datatype
|
int |
hashCode() |
protected boolean |
isNegative()
The isNegative abstract method.
|
boolean |
isNull()
see if the decimal value is null.
|
NumberDataValue |
minus(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
This method implements the - operator for TINYINT, SMALLINT and INTEGER.
|
NumberDataValue |
minusNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
Implement subtraction using addition and negation of the right value.
|
NumberDataValue |
plus(NumberDataValue addend1,
NumberDataValue addend2,
NumberDataValue result)
This method implements the + operator for DECIMAL.
|
abstract NumberDataValue |
plusNN(NumberDataValue addend1,
NumberDataValue addend2,
NumberDataValue result)
Add two non-nullable values using DECIMAL arithmetic.
|
void |
readExternal(java.io.ObjectInput in)
Note the use of data2c: we reuse the array if the
incoming array is the same length or smaller than
the array length.
|
private static byte[] |
reduceBytes2c(byte[] rd,
int offset,
int dataLength)
Compress the passed in byte array so that leading
0x00 and 0xff are removed when possible.
|
void |
restoreToNull()
Restore this object to its (SQL)null value.
|
private void |
setCoreValue(double theValue) |
protected void |
setFrom(DataValueDescriptor dvd)
Set this DECIMAL value from another DataValueDescriptor
|
void |
setValue(boolean theValue)
Set the value from a boolean
|
void |
setValue(double theValue)
Convert from a double, normalize and then convert as a String.
|
void |
setValue(float theValue)
Convert from a float, normalize and then convert as a String.
|
void |
setValue(int theValue)
Set the value from an int, just copy 'byte-by-byte'
from the int to a four byte array.
|
void |
setValue(long theValue)
Set the value from a long.
|
void |
setValue(java.lang.Number theValue)
Called when setting a DECIMAL value internally or from
through a procedure or function.
|
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.
|
NumberDataValue |
times(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
The SQL * operator.
|
abstract NumberDataValue |
timesNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
Multiple two non-nullable values using DECIMAL arithmetic.
|
int |
typePrecedence()
Each built-in type in JSQL has a precedence.
|
int |
typeToBigDecimal()
DECIMAL implementation.
|
void |
writeExternal(java.io.ObjectOutput out)
Distill the Decimal to a byte array and
Write out:
scale (unsigned byte)
length of byte array
the byte array
|
absolute, compare, compare, getDecimalValuePrecision, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setBigDecimal, setObject, setValue, setValue, sqrt, typeComparecheckHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getObject, getStream, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, readExternalFromArray, recycle, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatchclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitsetWidthminuscheckHostVariable, cloneHolder, coalesce, compare, compare, equals, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getNewNull, getObject, getStream, getString, getTime, getTimestamp, getTraceString, 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, setValueprivate static final byte[] ONE_2C
protected byte[] data2c
protected int sqlScale
public final int typeToBigDecimal()
typeToBigDecimal in interface DataValueDescriptortypeToBigDecimal in class NumberDataTypepublic final int typePrecedence()
DataTypetypePrecedence in interface DataValueDescriptortypePrecedence in class DataTypeDataValueDescriptor.typePrecedence()public final java.lang.String getTypeName()
DataValueDescriptorgetTypeName in interface DataValueDescriptorpublic final int getTypeFormatId()
getTypeFormatId in interface TypedFormatTypedFormat.getTypeFormatId()public boolean isNull()
public void restoreToNull()
StorablerestoreToNull in interface Storableprotected boolean isNegative()
NumberDataTypeisNegative in class NumberDataTypepublic void setValue(long theValue)
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor topublic final void setValue(int theValue)
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toNumberDataValue.setValue(java.lang.Number)public void setValue(boolean theValue)
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - Contains the boolean value to set this topublic final void setValue(double theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toStandardException - Thrown on errorpublic final void setValue(float theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor toStandardException - Thrown on errorprivate void setCoreValue(double theValue)
throws StandardException
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)protected void setFrom(DataValueDescriptor dvd) throws StandardException
setFrom in class DataTypedvd - The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.StandardExceptionpublic final int getInt()
throws StandardException
getInt in interface DataValueDescriptorgetInt in class DataTypeStandardException - this value is out of range for an intpublic final byte getByte()
throws StandardException
getByte in interface DataValueDescriptorgetByte in class DataTypeStandardException - this value is out of range for a shortpublic final short getShort()
throws StandardException
getShort in interface DataValueDescriptorgetShort in class DataTypeStandardException - this value is out of range for a shortpublic final 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 final NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
NumberDataValuetimes in interface NumberDataValueleft - The left operandright - The right operandresult - The result of the previous call to this method, null
if not called yet.StandardException - Thrown on error, if result is non-null then its value will be unchanged.public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws StandardException
NumberDataTypedivide 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 final 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 final NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
NumberDataTypeminus 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 minusNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardExceptionpublic abstract NumberDataValue timesNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardExceptionpublic abstract NumberDataValue plusNN(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
StandardExceptionpublic abstract NumberDataValue divideNN(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException
StandardExceptionprivate static byte[] reduceBytes2c(byte[] rd,
int offset,
int dataLength)
dataLength - Valid length of data in data2c.public int getDecimalValueScale()
getDecimalValueScale in interface NumberDataValuegetDecimalValueScale in class NumberDataTypepublic 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 final int getLength()
DataValueDescriptorgetLength in interface DataValueDescriptorpublic 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 void setValueFromResultSet(java.sql.ResultSet resultSet,
int colNumber,
boolean isNullable)
throws StandardException,
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)StandardException - Thrown on errorjava.sql.SQLException - Error accessing the result setpublic int estimateMemoryUsage()
DataValueDescriptorestimateMemoryUsage in interface DataValueDescriptorpublic int hashCode()
hashCode in class java.lang.ObjectApache Derby V10.10 Internals - Copyright © 2004,2014 The Apache Software Foundation. All Rights Reserved.