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_DECIMAL
IGNORE_PRECISION
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALE
UNKNOWN_LOGICAL_LENGTH
ORDER_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, typeCompare
checkHostVariable, 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, throwLangSetMismatch
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
setWidth
minus
checkHostVariable, 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, setValue
private static final byte[] ONE_2C
protected byte[] data2c
protected int sqlScale
public final int typeToBigDecimal()
typeToBigDecimal
in interface DataValueDescriptor
typeToBigDecimal
in class NumberDataType
public final int typePrecedence()
DataType
typePrecedence
in interface DataValueDescriptor
typePrecedence
in class DataType
DataValueDescriptor.typePrecedence()
public final java.lang.String getTypeName()
DataValueDescriptor
getTypeName
in interface DataValueDescriptor
public final int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
TypedFormat.getTypeFormatId()
public boolean isNull()
public void restoreToNull()
Storable
restoreToNull
in interface Storable
protected boolean isNegative()
NumberDataType
isNegative
in class NumberDataType
public void setValue(long theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor topublic final void setValue(int theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toNumberDataValue.setValue(java.lang.Number)
public void setValue(boolean theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- Contains the boolean value to set this topublic final void setValue(double theValue) throws StandardException
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toStandardException
- Thrown on errorpublic final void setValue(float theValue) throws StandardException
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toStandardException
- Thrown on errorprivate void setCoreValue(double theValue) throws StandardException
StandardException
public void setValue(java.lang.Number theValue) throws StandardException
setValue
in interface NumberDataValue
setValue
in class NumberDataType
theValue
- 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 DataType
dvd
- The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.StandardException
public final int getInt() throws StandardException
getInt
in interface DataValueDescriptor
getInt
in class DataType
StandardException
- this value is out of range for an intpublic final byte getByte() throws StandardException
getByte
in interface DataValueDescriptor
getByte
in class DataType
StandardException
- this value is out of range for a shortpublic final short getShort() throws StandardException
getShort
in interface DataValueDescriptor
getShort
in class DataType
StandardException
- this value is out of range for a shortpublic final NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
plus
in interface NumberDataValue
plus
in class NumberDataType
addend1
- 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
NumberDataValue
times
in interface NumberDataValue
left
- 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
NumberDataType
divide
in interface NumberDataValue
divide
in class NumberDataType
dividend
- 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 NumberDataValue
divide
in class NumberDataType
dividend
- 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
NumberDataType
minus
in interface NumberDataValue
minus
in class NumberDataType
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 yetStandardException
- Thrown on errorpublic NumberDataValue minusNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue timesNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue plusNN(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue divideNN(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException
StandardException
private static byte[] reduceBytes2c(byte[] rd, int offset, int dataLength)
dataLength
- Valid length of data in data2c.public int getDecimalValueScale()
getDecimalValueScale
in interface NumberDataValue
getDecimalValueScale
in class NumberDataType
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
java.io.IOException
Externalizable.readExternal(java.io.ObjectInput)
public final int getLength()
DataValueDescriptor
getLength
in interface DataValueDescriptor
public 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 DataValueDescriptor
forceMaterialization
- any streams representing the data value will
be materialized if true
, the data value will be kept as a
stream if possible if false
DataValueDescriptor
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
DataValueDescriptor
setValueFromResultSet
in interface DataValueDescriptor
resultSet
- 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()
DataValueDescriptor
estimateMemoryUsage
in interface DataValueDescriptor
public int hashCode()
hashCode
in class java.lang.Object
Apache Derby V10.10 Internals - Copyright © 2004,2013 The Apache Software Foundation. All Rights Reserved.