Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public final Class SQLDecimal

extends NumberDataType
implements VariableSizeDataValue
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.types.VariableSizeDataValue
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.services.io.StoredFormatIds, .Storable, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.cache.ClassSize, java.math.BigDecimal, .BigInteger, .RoundingMode, java.io.ObjectOutput, .ObjectInput, .IOException, java.sql.ResultSet, .PreparedStatement, .SQLException, .Types

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

Modifier and TypeField and Description
private static final int
private static final int
private byte[]
rawData

See comments for value

private int
rawScale

See comments for value

private BigDecimal
value

object state.

Inherited from org.apache.derby.iapi.types.NumberDataType:
MAXLONG_PLUS_ONEMINLONG_MINUS_ONE

Constructor Summary

AccessConstructor and Description
public
SQLDecimal()

no-arg constructor, required by Formattable

public
public
SQLDecimal(BigDecimal val, int nprecision, int scale)

public

Method Summary

Modifier and TypeMethod and Description
public DataValueDescriptor
cloneValue(boolean
any streams representing the data value will be materialized if true, the data value will be kept as a stream if possible if false
forceMaterialization
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.cloneValue.

Clone this DataValueDescriptor.

public NumberDataValue

Returns:

A SQLDecimal containing the result of the division
divide
(NumberDataValue
The numerator
dividend
,
NumberDataValue
The denominator
divisor
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Overrides org.apache.derby.iapi.types.NumberDataType.divide.

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

This method implements the / operator for BigDecimal/BigDecimal

public NumberDataValue

Returns:

A SQLDecimal containing the result of the division
divide
(NumberDataValue
The numerator
dividend
,
NumberDataValue
The denominator
divisor
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
,
int
The result scale, if < 0, calculate the scale according to the actual values' sizes
scale
)

Overrides org.apache.derby.iapi.types.NumberDataType.divide.

Implements org.apache.derby.iapi.types.NumberDataValue.divide.

This method implements the / operator for BigDecimal/BigDecimal

public int
estimateMemoryUsage()

Implements org.apache.derby.iapi.types.DataValueDescriptor.estimateMemoryUsage.

Estimate the memory usage in bytes of the data value and the overhead of the class.

private BigDecimal
public static BigDecimal

Returns:

BigDecimal value
getBigDecimal
(DataValueDescriptor
Non-null value to be converted
value
)

Get a BigDecimal representing the value of a DataValueDescriptor

public boolean
getBoolean()

Overrides org.apache.derby.iapi.types.DataType.getBoolean.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getBoolean.

Gets the value in the data value descriptor as a boolean.

public byte
getByte()

Overrides org.apache.derby.iapi.types.DataType.getByte.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getByte.

Gets the value in the data value descriptor as a byte.

public int
getDecimalValuePrecision()

Return the SQL scale of this value, number of digits after the decimal point, or zero for a whole number.

public int
getDecimalValueScale()

Return the SQL scale of this value, number of digits after the decimal point, or zero for a whole number.

public double
getDouble()

Overrides org.apache.derby.iapi.types.DataType.getDouble.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getDouble.

If we have a value that is greater than the maximum double, exception is thrown.

public float
getFloat()

Overrides org.apache.derby.iapi.types.DataType.getFloat.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getFloat.

Gets the value in the data value descriptor as a float.

public int
getInt()

Overrides org.apache.derby.iapi.types.DataType.getInt.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getInt.

Gets the value in the data value descriptor as an int.

public int
getLength()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getLength.

Gets the length of the data value.

public long
getLong()

Overrides org.apache.derby.iapi.types.DataType.getLong.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getLong.

Gets the value in the data value descriptor as a long.

public DataValueDescriptor
getNewNull()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getNewNull.

Get a new null value of the same type as this data value.

public Object
getObject()

Overrides org.apache.derby.iapi.types.DataType.getObject.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getObject.

Gets the value in the data value descriptor as a Java Object.

public short
getShort()

Overrides org.apache.derby.iapi.types.DataType.getShort.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getShort.

Gets the value in the data value descriptor as a short.

public String
getString()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getString.

Gets the value in the data value descriptor as a String.

public int
public String
getTypeName()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getTypeName.

Get the SQL name of the datatype

private static int

Returns:

number of whole digits.
getWholeDigits
(BigDecimal
Value to get whole digits from, never null.
decimalValue
)

Calculate the number of digits to the left of the decimal point of the passed in value.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

protected boolean

Returns:

A boolean. If this.value is negative, return true. For positive values or null, return false.
isNegative
()

Implements abstract org.apache.derby.iapi.types.NumberDataType.isNegative.

This method implements the isNegative method.

public boolean
isNull()

Implements org.apache.derby.iapi.services.io.Storable.isNull.

Return whether the value is null or not.

public NumberDataValue

Returns:

A SQLDecimal containing the result of the subtraction
minus
(NumberDataValue
The value to be subtracted from
left
,
NumberDataValue
The value to be subtracted
right
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Overrides org.apache.derby.iapi.types.NumberDataType.minus.

Implements org.apache.derby.iapi.types.NumberDataValue.minus.

This method implements the - operator for "decimal - decimal".

public NumberDataValue

Returns:

A SQLDecimal containing the result of the division
minus
(NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.minus.

This method implements the unary minus operator for double.

public void
normalize(DataTypeDescriptor
The type to normalize the source column to
desiredType
,
DataValueDescriptor
The value to normalize
source
)

Overrides org.apache.derby.iapi.types.DataType.normalize.

Implements org.apache.derby.iapi.types.DataValueDescriptor.normalize.

Normalization method - this method may be called when putting a value into a SQLDecimal, for example, when inserting into a SQLDecimal column.

public NumberDataValue

Returns:

A SQLDecimal containing the result of the addition
plus
(NumberDataValue
One of the addends
addend1
,
NumberDataValue
The other addend
addend2
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Overrides org.apache.derby.iapi.types.NumberDataType.plus.

Implements org.apache.derby.iapi.types.NumberDataValue.plus.

This method implements the + operator for DECIMAL.

public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

Note the use of rawData: we reuse the array if the incoming array is the same length or smaller than the array length.

public void
restoreToNull()

Implements org.apache.derby.iapi.services.io.Storable.restoreToNull.

Restore this object to its (SQL)null value.

public void
setBigDecimal(BigDecimal
required to be a BigDecimal or null.
theValue
)

Overrides org.apache.derby.iapi.types.NumberDataType.setBigDecimal.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setBigDecimal.

Only to be called when the application sets a value using BigDecimal through setBigDecimal calls.

private void
private void
setCoreValue(double theValue)

protected void
setFrom(DataValueDescriptor
The DataValueDescriptor that holds the value to which we want to set this DataValueDescriptor's value.
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setFrom.

Set the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.

public final void
setInto(PreparedStatement ps, int position)

Overrides org.apache.derby.iapi.types.DataType.setInto.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setInto.

Set the value into a PreparedStatement.

pack-priv void
setObject(Object theValue)

Overrides org.apache.derby.iapi.types.NumberDataType.setObject.

Set the value from a correctly typed BigDecimal object.

public void
setValue(String
The String value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Warning

there is no checking to make sure that theValue doesn't exceed the precision/scale of the current SQLDecimal.

public void
setValue(double
The value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor to the given double value

public void
setValue(float
A Double containing the value to set this DataValueDescriptor to. Null means set the value to SQL null.
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor to the given double value

public void
setValue(long
The value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor to the given long value

public void
setValue(int
The value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor to the given int value

public void
setValue(Number
An Number containing the value to set this NumberDataValue to. Null means set the value to SQL null.
theValue
)

Overrides org.apache.derby.iapi.types.NumberDataType.setValue.

Implements org.apache.derby.iapi.types.NumberDataValue.setValue.

Called when setting a DECIMAL value internally or from through a procedure or function.

public void
setValue(boolean
Contains the boolean value to set this to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value.

public void
setValueFromResultSet(ResultSet
The specified ResultSet.
resultSet
,
int
The 1-based column # into the resultSet.
colNumber
,
boolean
Whether or not the column is nullable (No need to call wasNull() if not)
isNullable
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValueFromResultSet.

Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.

public void
setWidth(int
the desired precision -- IGNORE_PREICISION if it is to be ignored.
desiredPrecision
,
int
the desired scale
desiredScale
,
boolean
throw error on truncation (ignored -- always thrown if we truncate the non-decimal part of the value)
errorOnTrunc
)

Implements org.apache.derby.iapi.types.VariableSizeDataValue.setWidth.

Set the precision/scale of the to the desired values.

public NumberDataValue

Returns:

A SQLDecimal containing the result of the multiplication
times
(NumberDataValue
The first value to be multiplied
left
,
NumberDataValue
The second value to be multiplied
right
,
NumberDataValue
The result of a previous call to this method, null if not called yet
result
)

Implements org.apache.derby.iapi.types.NumberDataValue.times.

This method implements the * operator for "double * double".

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected int
typeCompare(DataValueDescriptor arg)

Implements abstract org.apache.derby.iapi.types.NumberDataType.typeCompare.

Compare this (not null) to a non-null value.

public int
public int
public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

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
Inherited from org.apache.derby.iapi.types.NumberDataType:
absolutecomparecomparemodnormalizeDOUBLEnormalizeREALnormalizeREALobjectNullsetValuesetValuesqrt