|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ types overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.types
Class BinaryDecimal

java.lang.Objectorg.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.NumberDataType
org.apache.derby.iapi.types.BinaryDecimal
- 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
- Direct Known Subclasses:
- BigIntegerDecimal
- abstract class BinaryDecimal
- extends NumberDataType
- implements VariableSizeDataValue
- extends NumberDataType
SQL DECIMAL using raw data. Provides the basis for the CDCDecimal implementation.
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.
| Field Summary | |
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 |
| Fields inherited from class org.apache.derby.iapi.types.NumberDataType |
MAXLONG_PLUS_ONE, MINLONG_MINUS_ONE, 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 | |
(package private) |
BinaryDecimal()
|
| 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 |
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. |
DataValueDescriptor |
getClone()
Clone this DataValueDescriptor. |
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()
Get a value that represents this Object, as uniquely as possible within the confines of an int. |
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. |
void |
readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in)
Read the DataValueDescriptor from the stream. |
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(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 |
| Methods inherited from class org.apache.derby.iapi.types.NumberDataType |
absolute, compare, compare, getDecimalValuePrecision, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setBigDecimal, setValue, setValue, sqrt, typeCompare |
| Methods inherited from class org.apache.derby.iapi.types.DataType |
checkHostVariable, cloneObject, coalesce, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getNationalString, getObject, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, setInto, setInto, setObjectForCast, setToNull, setValue, 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, toString, wait, wait, wait |
| Methods inherited from interface org.apache.derby.iapi.types.VariableSizeDataValue |
setWidth |
| Methods inherited from interface org.apache.derby.iapi.types.NumberDataValue |
minus |
| Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor |
checkHostVariable, coalesce, equals, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getNewNull, getObject, getStream, getString, getTime, getTimestamp, greaterOrEquals, greaterThan, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue |
| Field Detail |
ONE_2C
private static final byte[] ONE_2C
- An unscaled value of 1 in two's complement
data2c
protected byte[] data2c
- The unscaled value as a binary two's complement array.
sqlScale
protected int sqlScale
- The SQL scale, zero or positive, of the value
| Constructor Detail |
BinaryDecimal
BinaryDecimal()
| Method Detail |
typeToBigDecimal
public final int typeToBigDecimal()
- DECIMAL implementation.
Use DECIMAL to indicate to self that another
passed in value is an instance of this type.
- Specified by:
typeToBigDecimalin interfaceDataValueDescriptor- Overrides:
typeToBigDecimalin classNumberDataType
typePrecedence
public final 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:
typePrecedencein interfaceDataValueDescriptor- Overrides:
typePrecedencein classDataType
getTypeName
public final java.lang.String getTypeName()
- Description copied from interface:
DataValueDescriptor - Get the SQL name of the datatype
- Specified by:
getTypeNamein interfaceDataValueDescriptor
getTypeFormatId
public final int getTypeFormatId()
- Return my format identifier.
- Specified by:
getTypeFormatIdin interfaceorg.apache.derby.iapi.services.io.TypedFormat
isNull
public boolean isNull()
- see if the decimal value is null.
- Specified by:
isNullin interfaceorg.apache.derby.iapi.services.io.Storable
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:
restoreToNullin interfaceorg.apache.derby.iapi.services.io.Storable
isNegative
protected boolean isNegative()
- Description copied from class:
NumberDataType - The isNegative abstract method. Checks to see if this.value is negative.
To be implemented by each NumberDataType.
- Specified by:
isNegativein classNumberDataType
setValue
public void setValue(long theValue)
- Set the value from a long.
- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType
setValue
public final void setValue(int theValue)
- Set the value from an int, just copy 'byte-by-byte'
from the int to a four byte array. Then reduce.
- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType
setValue
public final void setValue(double theValue)
throws org.apache.derby.iapi.error.StandardException
- Convert from a double, normalize and then convert as a String.
- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType
setValue
public final void setValue(float theValue)
throws org.apache.derby.iapi.error.StandardException
- Convert from a float, normalize and then convert as a String.
- Specified by:
setValuein interfaceDataValueDescriptor- Overrides:
setValuein classDataType
setCoreValue
private void setCoreValue(double theValue)
throws org.apache.derby.iapi.error.StandardException
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:
setValuein interfaceNumberDataValue- Overrides:
setValuein classNumberDataType
setFrom
protected void setFrom(DataValueDescriptor dvd) throws org.apache.derby.iapi.error.StandardException
getInt
public final int getInt()
throws org.apache.derby.iapi.error.StandardException
- Return a int from this value.
- Specified by:
getIntin interfaceDataValueDescriptor- Overrides:
getIntin classDataType
getByte
public final byte getByte()
throws org.apache.derby.iapi.error.StandardException
- Return a byte from this value.
- Specified by:
getBytein interfaceDataValueDescriptor- Overrides:
getBytein classDataType
getShort
public final short getShort()
throws org.apache.derby.iapi.error.StandardException
- Return a short from this value.
- Specified by:
getShortin interfaceDataValueDescriptor- Overrides:
getShortin classDataType
plus
public final NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- This method implements the + operator for DECIMAL.
- Specified by:
plusin interfaceNumberDataValue- Overrides:
plusin classNumberDataType
times
public final NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
NumberDataValue - The SQL * operator.
- Specified by:
timesin interfaceNumberDataValue
divide
public NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Description copied from class:
NumberDataType - This method implements the / operator for TINYINT, SMALLINT and INTEGER.
Specialized methods are not required for TINYINT and SMALLINT as the Java
virtual machine always executes byte and int division as integer.
- Specified by:
dividein interfaceNumberDataValue- Overrides:
dividein classNumberDataType
divide
public final 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:
dividein interfaceNumberDataValue- Overrides:
dividein classNumberDataType
minus
public final NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Description copied from class:
NumberDataType - This method implements the - operator for TINYINT, SMALLINT and INTEGER.
- Specified by:
minusin interfaceNumberDataValue- Overrides:
minusin classNumberDataType
minusNN
public NumberDataValue minusNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Implement subtraction using addition and negation of the right value.
timesNN
public abstract NumberDataValue timesNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Multiple two non-nullable values using DECIMAL arithmetic.
plusNN
public abstract NumberDataValue plusNN(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws org.apache.derby.iapi.error.StandardException
- Add two non-nullable values using DECIMAL arithmetic.
For subclasses of BinaryDecimal, any implementation
must handle the result and addend2 (right) being references
to the same object.
divideNN
public abstract NumberDataValue divideNN(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws org.apache.derby.iapi.error.StandardException
- Divide two non-nullable values using DECIMAL arithmetic.
reduceBytes2c
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.
E.g.
0x00000453 ->>> 0x0453
0xfffffff2 ->>> 0xf2
0xff192312 ->>> 0xff192312 (unchanged)
0xffff8039 ->>> 0x8039
data2c is set to the compressed value.
getDecimalValueScale
public int getDecimalValueScale()
- Return the SQL scale of this value, number of digits after the
decimal point, or zero for a whole number.
- Specified by:
getDecimalValueScalein interfaceNumberDataValue- Overrides:
getDecimalValueScalein classNumberDataType
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Distill the Decimal to a byte array and
Write out:
- scale (unsigned byte)
- length of byte array
- the byte array
- Specified by:
writeExternalin interfacejava.io.Externalizable
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- Note the use of data2c: we reuse the array if the
incoming array is the same length or smaller than
the array length.
- Specified by:
readExternalin interfacejava.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:
readExternalFromArrayin interfaceDataValueDescriptor
getLength
public final 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:
getLengthin interfaceDataValueDescriptor
getClone
public DataValueDescriptor getClone()
- Description copied from interface:
DataValueDescriptor - Clone this DataValueDescriptor. Results in a new object
that has the same value as this but can be modified independently.
- Specified by:
getClonein interfaceDataValueDescriptor
setValueFromResultSet
public void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable) throws org.apache.derby.iapi.error.StandardException, 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:
setValueFromResultSetin interfaceDataValueDescriptor
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:
estimateMemoryUsagein interfaceDataValueDescriptor
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, thena.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
hashCodeis 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) - Semantic equality implies identical hashcodes. In other
words, if
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ types overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC