org.apache.derby.iapi.types
Class BigIntegerDecimal

java.lang.Object
  extended by org.apache.derby.iapi.types.DataType
      extended by org.apache.derby.iapi.types.NumberDataType
          extended by org.apache.derby.iapi.types.BinaryDecimal
              extended by org.apache.derby.iapi.types.BigIntegerDecimal
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Comparable, Formatable, Storable, TypedFormat, DataValueDescriptor, NumberDataValue, Orderable, VariableSizeDataValue

public final class BigIntegerDecimal
extends BinaryDecimal

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.

See Also:
Serialized Form

Field Summary
private static java.math.BigInteger MAXLONG_PLUS_ONE
           
private static java.math.BigInteger MINLONG_MINUS_ONE
           
private static java.math.BigInteger TEN
           
 
Fields inherited from class org.apache.derby.iapi.types.BinaryDecimal
data2c, sqlScale
 
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.DataValueDescriptor
UNKNOWN_LOGICAL_LENGTH
 
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 divideNN(NumberDataValue left, NumberDataValue right, NumberDataValue result, int scale)
          Divide two non-null NumberDataValues using DECIMAL arithmetic.
private  BigIntegerDecimal getBID(DataValueDescriptor value)
          Obtain a BinaryDecimal that represents the passed in value.
 boolean getBoolean()
          Gets the value in the data value descriptor as a boolean.
 int getDecimalValuePrecision()
          Return the SQL precision of this value.
 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.
 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.String getString()
          Gets the value in the data value descriptor as a String.
 NumberDataValue minus(NumberDataValue result)
          Negate the number.
 void normalize(DataTypeDescriptor desiredType, DataValueDescriptor source)
          Default normalization method.
 NumberDataValue plusNN(NumberDataValue left, NumberDataValue right, NumberDataValue result)
          Add two non-null NumberDataValues using DECIMAL arithmetic.
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 setValue(java.lang.String theValue)
          Set the value from a String, the format is nnnn Scale always set to zero.
 void setWidth(int desiredPrecision, int desiredScale, boolean errorOnTrunc)
           
 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.
 
Methods inherited from class org.apache.derby.iapi.types.BinaryDecimal
cloneValue, divide, divide, estimateMemoryUsage, getByte, getDecimalValueScale, getInt, getLength, getShort, getTypeFormatId, getTypeName, hashCode, isNegative, isNull, minus, minusNN, plus, readExternal, readExternalFromArray, restoreToNull, setFrom, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, times, typePrecedence, typeToBigDecimal, writeExternal
 
Methods inherited from class org.apache.derby.iapi.types.NumberDataType
absolute, compare, compare, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setBigDecimal, setObject, setValue, setValue, sqrt
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, genericSetObject, getBytes, getDate, getNationalString, getObject, getStream, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, outOfRange, recycle, setInto, setInto, setObjectForCast, setToNull, 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, cloneHolder, coalesce, compare, compare, equals, getBytes, getDate, getObject, getStream, getTime, getTimestamp, getTraceString, greaterOrEquals, greaterThan, hasStream, in, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, recycle, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 

Field Detail

TEN

private static final java.math.BigInteger TEN

MAXLONG_PLUS_ONE

private static final java.math.BigInteger MAXLONG_PLUS_ONE

MINLONG_MINUS_ONE

private static final java.math.BigInteger MINLONG_MINUS_ONE
Constructor Detail

BigIntegerDecimal

public BigIntegerDecimal()
Method Detail

getNewNull

public DataValueDescriptor getNewNull()
Description copied from interface: DataValueDescriptor
Get a new null value of the same type as this data value.


getLong

public long getLong()
             throws StandardException
Description copied from class: DataType
Gets the value in the data value descriptor as a long. Throws an exception if the data value is not receivable as a long.

Specified by:
getLong in interface DataValueDescriptor
Overrides:
getLong in class DataType
Returns:
The data value as a long.
Throws:
StandardException - Thrown on error

getFloat

public float getFloat()
               throws StandardException
Description copied from class: DataType
Gets the value in the data value descriptor as a float. Throws an exception if the data value is not receivable as a float.

Specified by:
getFloat in interface DataValueDescriptor
Overrides:
getFloat in class DataType
Returns:
The data value as a float.
Throws:
StandardException - Thrown on error

getDouble

public double getDouble()
                 throws StandardException
Description copied from class: DataType
Gets the value in the data value descriptor as a double. Throws an exception if the data value is not receivable as a double.

Specified by:
getDouble in interface DataValueDescriptor
Overrides:
getDouble in class DataType
Returns:
The data value as a double.
Throws:
StandardException - Thrown on error

getBoolean

public boolean getBoolean()
Description copied from class: DataType
Gets the value in the data value descriptor as a boolean. Throws an exception if the data value is not receivable as a boolean.

Specified by:
getBoolean in interface DataValueDescriptor
Overrides:
getBoolean in class DataType
Returns:
The data value as a boolean.

setValue

public void setValue(java.lang.String theValue)
              throws StandardException
Set the value from a String, the format is nnnn Scale always set to zero.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType
Parameters:
theValue - The BigDecimal value to set this DataValueDescriptor to
Throws:
StandardException

getString

public java.lang.String getString()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a String. Throws an exception if the data value is not a string.

Returns:
The data value as a String.

getDecimalValuePrecision

public int getDecimalValuePrecision()
Return the SQL precision of this value.

Specified by:
getDecimalValuePrecision in interface NumberDataValue
Overrides:
getDecimalValuePrecision in class NumberDataType

typeCompare

protected int typeCompare(DataValueDescriptor arg)
                   throws StandardException
Compare two non-null NumberDataValues using DECIMAL arithmetic.

Specified by:
typeCompare in class NumberDataType
Throws:
StandardException - Thrown on error

plusNN

public NumberDataValue plusNN(NumberDataValue left,
                              NumberDataValue right,
                              NumberDataValue result)
                       throws StandardException
Add two non-null NumberDataValues using DECIMAL arithmetic. Uses add() to perform the calculation.

Specified by:
plusNN in class BinaryDecimal
Throws:
StandardException

minus

public NumberDataValue minus(NumberDataValue result)
                      throws StandardException
Negate the number.

Parameters:
result - The result of the previous call to this method, null if not called yet.
Returns:
- operand
Throws:
StandardException - Thrown on error, if result is non-null then its value will be unchanged.
See Also:
NumberDataValue.minus(org.apache.derby.iapi.types.NumberDataValue)

timesNN

public NumberDataValue timesNN(NumberDataValue left,
                               NumberDataValue right,
                               NumberDataValue result)
                        throws StandardException
Multiple two non-null NumberDataValues using DECIMAL arithmetic. Uses BigInteger.multipy() to perform the calculation. Simply multiply the unscaled values and add the scales, proof: 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)

Specified by:
timesNN in class BinaryDecimal
Throws:
StandardException

divideNN

public NumberDataValue divideNN(NumberDataValue left,
                                NumberDataValue right,
                                NumberDataValue result,
                                int scale)
                         throws StandardException
Divide two non-null NumberDataValues using DECIMAL arithmetic. Uses divide() to perform the calculation. Simply multiply the unscaled values and subtract the scales, proof: 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))

Specified by:
divideNN in class BinaryDecimal
Throws:
StandardException

normalize

public void normalize(DataTypeDescriptor desiredType,
                      DataValueDescriptor source)
               throws StandardException
Description copied from class: DataType
Default normalization method. No information needed from DataTypeDescriptor.

Specified by:
normalize in interface DataValueDescriptor
Overrides:
normalize in class DataType
Parameters:
desiredType - The type to normalize the source column to
source - The value to normalize
Throws:
StandardException - Thrown normalization error.

setWidth

public void setWidth(int desiredPrecision,
                     int desiredScale,
                     boolean errorOnTrunc)
              throws StandardException
Throws:
StandardException

getBID

private BigIntegerDecimal getBID(DataValueDescriptor value)
                          throws StandardException
Obtain a BinaryDecimal that represents the passed in value.

Throws:
StandardException

rescale

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. It is up to the caller to manage the actual scale of the value, e.g. don't allow the scale to go negative.

Parameters:
bi - value to be rescaled
deltaScale - change of scale
Returns:
rescaled value

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.