|
|||||||||
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
abstract class BinaryDecimal
SQL DECIMAL using raw data. Provides the basis for the BigIntegerDecimal 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.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 | |
---|---|
BinaryDecimal()
|
Method Summary | |
---|---|
DataValueDescriptor |
cloneValue(boolean forceMaterialization)
Clone this DataValueDescriptor. |
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. |
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()
|
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(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(boolean theValue)
Set the value from a boolean |
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, setObject, setValue, setValue, sqrt, typeCompare |
Methods inherited from class org.apache.derby.iapi.types.DataType |
---|
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getNationalString, getObject, getStream, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, recycle, 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, 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, cloneHolder, coalesce, compare, compare, equals, getBoolean, getBytes, getDate, getDouble, getFloat, getLong, getNewNull, getObject, getStream, getString, getTime, getTimestamp, getTraceString, greaterOrEquals, greaterThan, hasStream, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, recycle, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue |
Field Detail |
---|
private static final byte[] ONE_2C
protected byte[] data2c
protected int sqlScale
Constructor Detail |
---|
BinaryDecimal()
Method Detail |
---|
public final int typeToBigDecimal()
typeToBigDecimal
in interface DataValueDescriptor
typeToBigDecimal
in class NumberDataType
public final int typePrecedence()
DataType
typePrecedence
in interface DataValueDescriptor
typePrecedence
in class DataType
DataValueDescriptor.typePrecedence()
public final java.lang.String getTypeName()
DataValueDescriptor
getTypeName
in interface DataValueDescriptor
public final int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
TypedFormat.getTypeFormatId()
public boolean isNull()
isNull
in interface Storable
public void restoreToNull()
Storable
restoreToNull
in interface Storable
protected boolean isNegative()
NumberDataType
isNegative
in class NumberDataType
public void setValue(long theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor topublic final void setValue(int theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toNumberDataValue.setValue(java.lang.Number)
public void setValue(boolean theValue)
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- Contains the boolean value to set this topublic final void setValue(double theValue) throws StandardException
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor to
StandardException
- Thrown on errorpublic final void setValue(float theValue) throws StandardException
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor to
StandardException
- Thrown on errorprivate void setCoreValue(double theValue) throws StandardException
StandardException
public void setValue(java.lang.Number theValue) throws StandardException
setValue
in interface NumberDataValue
setValue
in class NumberDataType
theValue
- An Number containing the value to set this
NumberDataValue to. Null means set the value
to SQL null.
StandardException
- Thrown on errorNumberDataValue.setValue(java.lang.Number)
protected void setFrom(DataValueDescriptor dvd) throws StandardException
setFrom
in class DataType
dvd
- The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.
StandardException
public final int getInt() throws StandardException
getInt
in interface DataValueDescriptor
getInt
in class DataType
StandardException
- this value is out of range for an intpublic final byte getByte() throws StandardException
getByte
in interface DataValueDescriptor
getByte
in class DataType
StandardException
- this value is out of range for a shortpublic final short getShort() throws StandardException
getShort
in interface DataValueDescriptor
getShort
in class DataType
StandardException
- this value is out of range for a shortpublic final NumberDataValue plus(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
plus
in interface NumberDataValue
plus
in class NumberDataType
addend1
- One of the addendsaddend2
- The other addendresult
- The result of a previous call to this method, null
if not called yet
StandardException
- Thrown on errorpublic final NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
NumberDataValue
times
in interface NumberDataValue
left
- 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 NumberDataValue
divide
in class NumberDataType
dividend
- The numeratordivisor
- The denominatorresult
- The result of a previous call to this method, null
if not called yet
StandardException
- Thrown on errorpublic final NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException
divide
in interface NumberDataValue
divide
in class NumberDataType
dividend
- 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 errorpublic final NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
NumberDataType
minus
in interface NumberDataValue
minus
in class NumberDataType
left
- 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 errorpublic NumberDataValue minusNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue timesNN(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue plusNN(NumberDataValue addend1, NumberDataValue addend2, NumberDataValue result) throws StandardException
StandardException
public abstract NumberDataValue divideNN(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result, int scale) throws StandardException
StandardException
private static byte[] reduceBytes2c(byte[] rd, int offset, int dataLength)
dataLength
- Valid length of data in data2c.public int getDecimalValueScale()
getDecimalValueScale
in interface NumberDataValue
getDecimalValueScale
in class NumberDataType
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
java.io.IOException
Externalizable.readExternal(java.io.ObjectInput)
public void readExternalFromArray(ArrayInputStream in) throws java.io.IOException
DataValueDescriptor
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().
readExternalFromArray
in interface DataValueDescriptor
in
- 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 DataValueDescriptor
public DataValueDescriptor cloneValue(boolean forceMaterialization)
DataValueDescriptor
Even though the objects can be modified independently regardless of the
value of forceMaterialization
, both the clone and the
original may be dependent on the store state if
forceMaterialization
is set to false
. An example is if
you need to access the value you just read using cloneValue
after the current transaction has ended, or after the source result set
has been closed.
cloneValue
in interface DataValueDescriptor
forceMaterialization
- any streams representing the data value will
be materialized if true
, the data value will be kept as a
stream if possible if false
DataValueDescriptor
with the same initial
value as this.DataValueDescriptor.cloneValue(boolean)
public void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable) throws StandardException, java.sql.SQLException
DataValueDescriptor
setValueFromResultSet
in interface DataValueDescriptor
resultSet
- 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 DataValueDescriptor
public int hashCode()
hashCode
in class java.lang.Object
|
Built on Thu 2011-03-10 11:54:14+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |