|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.NumberDataType
org.apache.derby.iapi.types.BinaryDecimal
org.apache.derby.iapi.types.BigIntegerDecimal
DECIMAL support using the immutable java.math.BigInteger to perform arithmetic and conversions. Extends BinaryDecimal to use the base support of that class. J2ME/CDC/Foundation includes BigInteger. A BigInteger is used in calculations etc. to represent the integral unscaled value. It is simply created from new BigInteger(data2c). No additional instance fields are used by this class, a possible enhancement would be to keep the BigInteger around but would require calls from the parent class to reset state etc.
| Field Summary | |
protected byte[] |
data2c
The unscaled value as a binary two's complement array. |
private static java.math.BigInteger |
MAXLONG_PLUS_ONE
|
private static java.math.BigInteger |
MINLONG_MINUS_ONE
|
protected int |
sqlScale
The SQL scale, zero or positive, of the value |
private static java.math.BigInteger |
TEN
|
| Fields inherited from class org.apache.derby.iapi.types.NumberDataType |
ZERO_DECIMAL |
| Fields inherited from interface org.apache.derby.iapi.types.VariableSizeDataValue |
IGNORE_PRECISION |
| Fields inherited from interface org.apache.derby.iapi.types.NumberDataValue |
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALE |
| Fields inherited from interface org.apache.derby.iapi.types.Orderable |
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN |
| Constructor Summary | |
BigIntegerDecimal()
|
|
| Method Summary | |
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 |
NumberDataValue |
divideNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result,
int scale)
Divide two non-null NumberDataValues using DECIMAL arithmetic. |
int |
estimateMemoryUsage()
Estimate the memory usage in bytes of the data value and the overhead of the class. |
private BigIntegerDecimal |
getBID(DataValueDescriptor value)
Obtain a BinaryDecimal that represents the passed in value. |
byte |
getByte()
Return a byte from this value. |
DataValueDescriptor |
getClone()
Clone this DataValueDescriptor. |
int |
getDecimalValuePrecision()
Return the SQL precision of this value. |
int |
getDecimalValueScale()
Return the SQL scale of this value, number of digits after the decimal point, or zero for a whole number. |
double |
getDouble()
Gets the value in the data value descriptor as a double. |
float |
getFloat()
Gets the value in the data value descriptor as a float. |
int |
getInt()
Return a int from this value. |
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. |
short |
getShort()
Return a short from this value. |
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 |
int |
hashCode()
|
protected boolean |
isNegative()
The isNegative abstract method. |
boolean |
isNull()
see if the decimal value is null. |
NumberDataValue |
minus(NumberDataValue result)
Negate the number. |
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. |
void |
normalize(DataTypeDescriptor desiredType,
DataValueDescriptor source)
Normalize the source value to this type described by this class and the passed in DataTypeDescriptor. |
NumberDataValue |
plus(NumberDataValue addend1,
NumberDataValue addend2,
NumberDataValue result)
This method implements the + operator for DECIMAL. |
NumberDataValue |
plusNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
Add two non-null NumberDataValues 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. |
void |
readExternalFromArray(ArrayInputStream in)
Read the DataValueDescriptor from the stream. |
private static java.math.BigInteger |
rescale(java.math.BigInteger bi,
int deltaScale)
Rescale a BigInteger, a positive delta means the scale is increased, zero no change and negative decrease of scale. |
void |
restoreToNull()
Restore this object to its (SQL)null value. |
protected void |
setFrom(DataValueDescriptor dvd)
Set this DECIMAL value from another DataValueDescriptor |
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 |
setValue(java.lang.String theValue)
Set the value from a String, the format is nnnn Scale always set to zero. |
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. |
DataValueDescriptor |
setWidth(int desiredPrecision,
int desiredScale,
boolean errorOnTrunc)
|
NumberDataValue |
times(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
The SQL * operator. |
NumberDataValue |
timesNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
Multiple two non-null NumberDataValues using DECIMAL arithmetic. |
java.lang.String |
toString()
|
protected int |
typeCompare(DataValueDescriptor arg)
Compare two non-null NumberDataValues 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 |
| Methods inherited from class org.apache.derby.iapi.types.NumberDataType |
absolute, compare, compare, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setBigDecimal, setValue, setValue, sqrt |
| Methods inherited from class org.apache.derby.iapi.types.DataType |
checkHostVariable, cloneObject, coalesce, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getBytes, getDate, getNationalString, getObject, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, outOfRange, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor |
checkHostVariable, coalesce, equals, getBoolean, getBytes, getDate, getObject, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue |
| Field Detail |
private static final java.math.BigInteger TEN
private static final java.math.BigInteger MAXLONG_PLUS_ONE
private static final java.math.BigInteger MINLONG_MINUS_ONE
protected byte[] data2c
protected int sqlScale
| Constructor Detail |
public BigIntegerDecimal()
| Method Detail |
public DataValueDescriptor getNewNull()
DataValueDescriptor
public long getLong()
throws StandardException
DataValueDescriptor
getLong in interface DataValueDescriptorgetLong in class DataTypeStandardException - Thrown on error
public float getFloat()
throws StandardException
DataValueDescriptor
getFloat in interface DataValueDescriptorgetFloat in class DataTypeStandardException - Thrown on error
public double getDouble()
throws StandardException
DataValueDescriptor
getDouble in interface DataValueDescriptorgetDouble in class DataTypeStandardException - Thrown on error
public void setValue(java.lang.String theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The BigDecimal value to set this DataValueDescriptor to
StandardExceptionpublic java.lang.String getString()
DataValueDescriptor
public int getDecimalValuePrecision()
getDecimalValuePrecision in interface NumberDataValuegetDecimalValuePrecision in class NumberDataType
protected int typeCompare(DataValueDescriptor arg)
throws StandardException
typeCompare in class NumberDataTypeStandardException - Thrown on error
public NumberDataValue plusNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
throws StandardException
plusNN in class BinaryDecimalStandardException
public NumberDataValue minus(NumberDataValue result)
throws StandardException
result - 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.NumberDataValue.minus(org.apache.derby.iapi.types.NumberDataValue)
public NumberDataValue timesNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
throws StandardException
left * right
= (left_unscaled * 10^-left_scale) * (right_unscaled * 10^-right_scale)
= (left_unscaled * 10^-left_scale) * (right_unscaled * 10^-right_scale)
= (left_unscaled * right_unscaled) * 10^-(left_scale + right_scale)
timesNN in class BinaryDecimalStandardException
public NumberDataValue divideNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result,
int scale)
throws StandardException
left / right
= (left_unscaled * 10^-left_scale) / (right_unscaled * 10^-right_scale)
= (left_unscaled / right_unscaled) * (10^-left_scale / 10^-right_scale)
= (left_unscaled / right_unscaled) * (10^-(left_scale-right_scale))
divideNN in class BinaryDecimalStandardException
public void normalize(DataTypeDescriptor desiredType,
DataValueDescriptor source)
throws StandardException
DataValueDescriptor
normalize in interface DataValueDescriptornormalize in class DataTypedesiredType - The type to normalize the source column tosource - The value to normalize
StandardException - Thrown normalization error.
public DataValueDescriptor setWidth(int desiredPrecision,
int desiredScale,
boolean errorOnTrunc)
throws StandardException
StandardException
private BigIntegerDecimal getBID(DataValueDescriptor value)
throws StandardException
StandardException
private static java.math.BigInteger rescale(java.math.BigInteger bi,
int deltaScale)
bi - value to be rescaleddeltaScale - change of scale
public java.lang.String toString()
public final int typeToBigDecimal()
typeToBigDecimal in interface DataValueDescriptortypeToBigDecimal in class NumberDataTypepublic final int typePrecedence()
DataValueDescriptor
typePrecedence in interface DataValueDescriptortypePrecedence in class DataTypeDataValueDescriptor.typePrecedence()public final java.lang.String getTypeName()
DataValueDescriptor
getTypeName in interface DataValueDescriptorpublic final int getTypeFormatId()
getTypeFormatId in interface TypedFormatTypedFormat.getTypeFormatId()public boolean isNull()
isNull in interface Storablepublic void restoreToNull()
Storable
restoreToNull in interface Storableprotected boolean isNegative()
NumberDataType
isNegative in class NumberDataTypepublic void setValue(long theValue)
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor to
public final void setValue(int theValue)
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor to
NumberDataValue.setValue(java.lang.Number)
public final void setValue(double theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor to
StandardException - Thrown on error
public final void setValue(float theValue)
throws StandardException
setValue in interface DataValueDescriptorsetValue in class DataTypetheValue - The value to set this DataValueDescriptor to
StandardException - Thrown on error
public void setValue(java.lang.Number theValue)
throws StandardException
setValue in interface NumberDataValuesetValue in class NumberDataTypeStandardException - Thrown on errorNumberDataValue.setValue(java.lang.Number)
protected void setFrom(DataValueDescriptor dvd)
throws StandardException
setFrom in class DataTypeStandardException
public final int getInt()
throws StandardException
getInt in interface DataValueDescriptorgetInt in class DataTypeStandardException - this value is out of range for an int
public final byte getByte()
throws StandardException
getByte in interface DataValueDescriptorgetByte in class DataTypeStandardException - this value is out of range for a short
public final short getShort()
throws StandardException
getShort in interface DataValueDescriptorgetShort in class DataTypeStandardException - this value is out of range for a short
public 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 yet
StandardException - Thrown on error
public final NumberDataValue times(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
throws StandardException
NumberDataValue
times 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
NumberDataType
divide in interface NumberDataValuedivide in class NumberDataTypedividend - The numeratordivisor - The denominatorresult - The result of a previous call to this method, null
if not called yet
StandardException - Thrown on error
public 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' sizes
StandardException - Thrown on error
public final NumberDataValue minus(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
throws StandardException
NumberDataType
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 yet
StandardException - Thrown on error
public NumberDataValue minusNN(NumberDataValue left,
NumberDataValue right,
NumberDataValue result)
throws StandardException
StandardExceptionpublic int getDecimalValueScale()
getDecimalValueScale in interface NumberDataValuegetDecimalValueScale in class NumberDataType
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal in interface java.io.Externalizablejava.io.IOException
public void readExternal(java.io.ObjectInput in)
throws java.io.IOException
readExternal in interface java.io.Externalizablejava.io.IOExceptionExternalizable.readExternal(java.io.ObjectInput)
public void readExternalFromArray(ArrayInputStream in)
throws java.io.IOException
DataValueDescriptorInitialize the data value by reading it's values from the ArrayInputStream. This interface is provided as a way to achieve possible performance enhancement when reading an array can be optimized over reading from a generic stream from readExternal().
readExternalFromArray in interface DataValueDescriptorin - The array stream positioned at the beginning of the
byte stream to read from.
java.io.IOException - Usual error is if you try to read
past limit on the stream.public final int getLength()
DataValueDescriptor
getLength in interface DataValueDescriptorpublic DataValueDescriptor getClone()
DataValueDescriptor
getClone in interface DataValueDescriptor
public void setValueFromResultSet(java.sql.ResultSet resultSet,
int colNumber,
boolean isNullable)
throws StandardException,
java.sql.SQLException
DataValueDescriptor
setValueFromResultSet 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 error
java.sql.SQLException - Error accessing the result setpublic int estimateMemoryUsage()
DataValueDescriptor
estimateMemoryUsage in interface DataValueDescriptorpublic int hashCode()
|
Built on Tue 2006-10-10 19:23:47+0200, from revision exported | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||