Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.iapi.types
Class SQLDecimal  view SQLDecimal download SQLDecimal.java

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataType
      extended byorg.apache.derby.iapi.types.NumberDataType
          extended byorg.apache.derby.iapi.types.SQLDecimal
All Implemented Interfaces:
CloneableObject, DataValueDescriptor, java.io.Externalizable, org.apache.derby.iapi.services.io.Formatable, NumberDataValue, Orderable, java.io.Serializable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.TypedFormat, VariableSizeDataValue

public final class SQLDecimal
extends NumberDataType
implements VariableSizeDataValue

SQLDecimal satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a numeric/decimal column, e.g. for * storing a column value; it can be specified when constructed to not allow nulls. Nullability cannot be changed after construction, as it affects the storage size and mechanism.

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.


Field Summary
private static int BASE_MEMORY_USAGE
           
private static java.lang.reflect.Method bdPrecision
           
private static int BIG_DECIMAL_MEMORY_USAGE
           
(package private) static java.math.BigDecimal MAXLONG_PLUS_ONE
           
(package private) static java.math.BigDecimal MINLONG_MINUS_ONE
           
private static java.math.BigDecimal ONE
           
private  byte[] rawData
          See comments for value
private  int rawScale
          See comments for value
private static java.lang.reflect.Method toPlainString
           
private  java.math.BigDecimal value
          object state.
private static java.math.BigDecimal ZERO
           
 
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
SQLDecimal()
          no-arg constructor, required by Formattable
SQLDecimal(java.math.BigDecimal val)
           
SQLDecimal(java.math.BigDecimal val, int nprecision, int scale)
           
SQLDecimal(java.lang.String val)
           
 
Method Summary
 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.
 DataValueDescriptor getClone()
           WARNING clone is a shallow copy
 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 an 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 Java Object.
 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()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
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 readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in)
          Read the DataValueDescriptor from the stream.
 void restoreToNull()
          Restore this object to its (SQL)null value.
 void setBigDecimal(java.lang.Number theValue)
          Only to be called when the application sets a value using BigDecimal through setBigDecimal calls.
private  void setCoreValue(java.math.BigDecimal theValue)
           
private  void setCoreValue(double theValue)
           
protected  void setFrom(DataValueDescriptor theValue)
           
 void setInto(java.sql.PreparedStatement ps, int position)
          Set the value into a PreparedStatement.
 void setValue(boolean theValue)
          Set the value.
 void setValue(double theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(float theValue)
          Set the value of this DataValueDescriptor to the given double value
 void setValue(int theValue)
          Set the value of this DataValueDescriptor to the given int value
 void setValue(long theValue)
          Set the value of this DataValueDescriptor to the given long value
 void setValue(java.lang.Number theValue)
          Called when setting a DECIMAL value internally or from through a procedure or function.
 void setValue(java.lang.Object theValue)
          Set the value of this DataValueDescriptor to the given value
 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.
 DataValueDescriptor 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()
          Convert this Object to a human-readable String.
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
 
Methods inherited from class org.apache.derby.iapi.types.NumberDataType
absolute, compare, compare, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setValue, setValue, sqrt
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, cloneObject, coalesce, dataTypeConversion, equals, equals, flip, genericSetObject, getBytes, getDate, getNationalString, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, outOfRange, setInto, setObjectForCast, setToNull, 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, getBytes, getDate, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, isNotNull, isNullOp, lessOrEquals, lessThan, notEquals, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 

Field Detail

ZERO

private static final java.math.BigDecimal ZERO

ONE

private static final java.math.BigDecimal ONE

MAXLONG_PLUS_ONE

static final java.math.BigDecimal MAXLONG_PLUS_ONE

MINLONG_MINUS_ONE

static final java.math.BigDecimal MINLONG_MINUS_ONE

value

private java.math.BigDecimal value
object state. Note that scale and precision are always determined dynamically from value when it is not null. The field value can be null without the data value being null. In this case the value is stored in rawData and rawScale. This is to allow the minimal amount of work to read a SQLDecimal from disk. Creating the BigDecimal is expensive as it requires allocating three objects, the last two are a waste in the case the row does not qualify or the row will be written out by the sorter before being returned to the application.

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.


rawData

private byte[] rawData
See comments for value


rawScale

private int rawScale
See comments for value


BASE_MEMORY_USAGE

private static final int BASE_MEMORY_USAGE

BIG_DECIMAL_MEMORY_USAGE

private static final int BIG_DECIMAL_MEMORY_USAGE

toPlainString

private static final java.lang.reflect.Method toPlainString

bdPrecision

private static final java.lang.reflect.Method bdPrecision
Constructor Detail

SQLDecimal

public SQLDecimal()
no-arg constructor, required by Formattable


SQLDecimal

public SQLDecimal(java.math.BigDecimal val)

SQLDecimal

public SQLDecimal(java.math.BigDecimal val,
                  int nprecision,
                  int scale)
           throws org.apache.derby.iapi.error.StandardException

SQLDecimal

public SQLDecimal(java.lang.String val)
Method Detail

estimateMemoryUsage

public int estimateMemoryUsage()
Description copied from interface: DataValueDescriptor
Estimate the memory usage in bytes of the data value and the overhead of the class.

Specified by:
estimateMemoryUsage in interface DataValueDescriptor

getInt

public int getInt()
           throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as an int. Throws an exception if the data value is not an int.

Specified by:
getInt in interface DataValueDescriptor
Overrides:
getInt in class DataType

getByte

public byte getByte()
             throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a byte. Throws an exception if the data value is not a byte.

Specified by:
getByte in interface DataValueDescriptor
Overrides:
getByte in class DataType

getShort

public short getShort()
               throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a short. Throws an exception if the data value is not a short.

Specified by:
getShort in interface DataValueDescriptor
Overrides:
getShort in class DataType

getLong

public long getLong()
             throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a long. Throws an exception if the data value is not a long.

Specified by:
getLong in interface DataValueDescriptor
Overrides:
getLong in class DataType

getFloat

public float getFloat()
               throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a float. Throws an exception if the data value is not a float.

Specified by:
getFloat in interface DataValueDescriptor
Overrides:
getFloat in class DataType

getDouble

public double getDouble()
                 throws org.apache.derby.iapi.error.StandardException
If we have a value that is greater than the maximum double, exception is thrown. Otherwise, ok. If the value is less than can be represented by a double, ti will get set to the smallest double value.

Specified by:
getDouble in interface DataValueDescriptor
Overrides:
getDouble in class DataType

getBigDecimal

private java.math.BigDecimal getBigDecimal()

typeToBigDecimal

public int typeToBigDecimal()
DECIMAL implementation. Convert to a BigDecimal using getObject which will return a BigDecimal

Specified by:
typeToBigDecimal in interface DataValueDescriptor
Overrides:
typeToBigDecimal in class NumberDataType

getBoolean

public boolean getBoolean()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a boolean. Throws an exception if the data value is not a boolean. For DataValueDescriptor, this is the preferred interface for BIT, but for this no-casting interface, it isn't, because BIT is stored internally as a Bit, not as a Boolean.

Specified by:
getBoolean in interface DataValueDescriptor
Overrides:
getBoolean in class DataType

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.

Specified by:
getString in interface DataValueDescriptor

getObject

public java.lang.Object getObject()
Description copied from interface: DataValueDescriptor
Gets the value in the data value descriptor as a Java Object. The type of the Object will be the Java object type corresponding to the data value's SQL type. JDBC defines a mapping between Java object types and SQL types - we will allow that to be extended through user type definitions. Throws an exception if the data value is not an object (yeah, right).

Specified by:
getObject in interface DataValueDescriptor
Overrides:
getObject in class DataType

setValue

public void setValue(java.lang.Object theValue)
              throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setFrom

protected void setFrom(DataValueDescriptor theValue)
                throws org.apache.derby.iapi.error.StandardException
Overrides:
setFrom in class DataType

getLength

public int getLength()
Description copied from interface: DataValueDescriptor
Gets the length of the data value. The meaning of this is implementation-dependent. For string types, it is the number of characters in the string. For numeric types, it is the number of bytes used to store the number. This is the actual length of this value, not the length of the type it was defined as. For example, a VARCHAR value may be shorter than the declared VARCHAR (maximum) length.

Specified by:
getLength in interface DataValueDescriptor

getTypeName

public java.lang.String getTypeName()
Description copied from interface: DataValueDescriptor
Get the SQL name of the datatype

Specified by:
getTypeName in interface DataValueDescriptor

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Specified by:
getTypeFormatId in interface org.apache.derby.iapi.services.io.TypedFormat

isNull

public boolean isNull()
Description copied from interface: org.apache.derby.iapi.services.io.Storable
Return whether the value is null or not.

Specified by:
isNull in interface org.apache.derby.iapi.services.io.Storable

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
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

Specified by:
writeExternal in interface java.io.Externalizable

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Note the use of rawData: we reuse the array if the incoming array is the same length or smaller than the array length.

Specified by:
readExternal in interface java.io.Externalizable

readExternalFromArray

public void readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in)
                           throws java.io.IOException
Description copied from interface: DataValueDescriptor
Read the DataValueDescriptor from the stream.

Initialize 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().

Specified by:
readExternalFromArray in interface DataValueDescriptor

restoreToNull

public void restoreToNull()
Description copied from interface: org.apache.derby.iapi.services.io.Storable
Restore this object to its (SQL)null value.

Specified by:
restoreToNull in interface org.apache.derby.iapi.services.io.Storable

typeCompare

protected int typeCompare(DataValueDescriptor arg)
                   throws org.apache.derby.iapi.error.StandardException
Description copied from class: NumberDataType
Compare this (not null) to a non-null value.

Specified by:
typeCompare in class NumberDataType

getClone

public DataValueDescriptor getClone()
WARNING clone is a shallow copy

Specified by:
getClone in interface DataValueDescriptor

getNewNull

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

Specified by:
getNewNull in interface DataValueDescriptor

setValueFromResultSet

public void setValueFromResultSet(java.sql.ResultSet resultSet,
                                  int colNumber,
                                  boolean isNullable)
                           throws java.sql.SQLException
Description copied from interface: DataValueDescriptor
Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.

Specified by:
setValueFromResultSet in interface DataValueDescriptor

setInto

public final void setInto(java.sql.PreparedStatement ps,
                          int position)
                   throws java.sql.SQLException
Set the value into a PreparedStatement.

Specified by:
setInto in interface DataValueDescriptor
Overrides:
setInto in class DataType

setValue

public void setValue(java.lang.String theValue)
              throws org.apache.derby.iapi.error.StandardException
WARNING there is no checking to make sure that theValue doesn't exceed the precision/scale of the current SQLDecimal. It is just assumed that the SQLDecimal is supposed to take the precision/scale of the BigDecimalized String.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setValue

public void setValue(double theValue)
              throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setValue

public void setValue(float theValue)
              throws org.apache.derby.iapi.error.StandardException
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given double value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setValue

public void setValue(long theValue)
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given long value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setValue

public void setValue(int theValue)
Description copied from interface: DataValueDescriptor
Set the value of this DataValueDescriptor to the given int value

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

setBigDecimal

public void setBigDecimal(java.lang.Number theValue)
                   throws org.apache.derby.iapi.error.StandardException
Only to be called when the application sets a value using BigDecimal through setBigDecimal calls.

Specified by:
setBigDecimal in interface DataValueDescriptor
Overrides:
setBigDecimal in class NumberDataType

setValue

public void setValue(java.lang.Number theValue)
              throws org.apache.derby.iapi.error.StandardException
Called when setting a DECIMAL value internally or from through a procedure or function. Handles long in addition to BigDecimal to handle identity being stored as a long but returned as a DECIMAL.

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

setValue

public void setValue(boolean theValue)
Description copied from interface: DataValueDescriptor
Set the value.

Specified by:
setValue in interface DataValueDescriptor
Overrides:
setValue in class DataType

typePrecedence

public int typePrecedence()
Description copied from interface: DataValueDescriptor
Each built-in type in JSQL has a precedence. This precedence determines how to do type promotion when using binary operators. For example, float has a higher precedence than int, so when adding an int to a float, the result type is float. The precedence for some types is arbitrary. For example, it doesn't matter what the precedence of the boolean type is, since it can't be mixed with other types. But the precedence for the number types is critical. The SQL standard requires that exact numeric types be promoted to approximate numeric when one operator uses both. Also, the precedence is arranged so that one will not lose precision when promoting a type.

Specified by:
typePrecedence in interface DataValueDescriptor
Overrides:
typePrecedence in class DataType

setCoreValue

private void setCoreValue(java.math.BigDecimal theValue)

setCoreValue

private void setCoreValue(double theValue)

normalize

public void normalize(DataTypeDescriptor desiredType,
                      DataValueDescriptor source)
               throws org.apache.derby.iapi.error.StandardException
Normalization method - this method may be called when putting a value into a SQLDecimal, for example, when inserting into a SQLDecimal column. See NormalizeResultSet in execution.

Note that truncation is allowed on the decimal portion of a numeric only.

Specified by:
normalize in interface DataValueDescriptor
Overrides:
normalize in class DataType

plus

public NumberDataValue plus(NumberDataValue addend1,
                            NumberDataValue addend2,
                            NumberDataValue result)
                     throws org.apache.derby.iapi.error.StandardException
This method implements the + operator for DECIMAL.

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

minus

public NumberDataValue minus(NumberDataValue left,
                             NumberDataValue right,
                             NumberDataValue result)
                      throws org.apache.derby.iapi.error.StandardException
This method implements the - operator for "decimal - decimal".

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

times

public NumberDataValue times(NumberDataValue left,
                             NumberDataValue right,
                             NumberDataValue result)
                      throws org.apache.derby.iapi.error.StandardException
This method implements the * operator for "double * double".

Specified by:
times in interface NumberDataValue

divide

public NumberDataValue divide(NumberDataValue dividend,
                              NumberDataValue divisor,
                              NumberDataValue result)
                       throws org.apache.derby.iapi.error.StandardException
This method implements the / operator for BigDecimal/BigDecimal

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

divide

public NumberDataValue divide(NumberDataValue dividend,
                              NumberDataValue divisor,
                              NumberDataValue result,
                              int scale)
                       throws org.apache.derby.iapi.error.StandardException
This method implements the / operator for BigDecimal/BigDecimal

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

minus

public NumberDataValue minus(NumberDataValue result)
                      throws org.apache.derby.iapi.error.StandardException
This method implements the unary minus operator for double.

Specified by:
minus in interface NumberDataValue

isNegative

protected boolean isNegative()
This method implements the isNegative method.

Specified by:
isNegative in class NumberDataType

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


setWidth

public DataValueDescriptor setWidth(int desiredPrecision,
                                    int desiredScale,
                                    boolean errorOnTrunc)
                             throws org.apache.derby.iapi.error.StandardException
Set the precision/scale of the to the desired values. Used when CASTing. Ideally we'd recycle normalize(), but the use is different.

Specified by:
setWidth in interface VariableSizeDataValue

getDecimalValuePrecision

public int getDecimalValuePrecision()
Return the SQL scale of this value, number of digits after the decimal point, or zero for a whole number. This does not match the return from BigDecimal.scale() since in J2SE 5.0 onwards that can return negative scales.

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

getDecimalValueScale

public int getDecimalValueScale()
Return the SQL scale of this value, number of digits after the decimal point, or zero for a whole number. This does not match the return from BigDecimal.scale() since in J2SE 5.0 onwards that can return negative scales.

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

getBigDecimal

public static java.math.BigDecimal getBigDecimal(DataValueDescriptor value)
                                          throws org.apache.derby.iapi.error.StandardException
Get a BigDecimal representing the value of a DataValueDescriptor


getWholeDigits

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.