java.io.Externalizable
, java.io.Serializable
, java.lang.Comparable
, Formatable
, Storable
, TypedFormat
, DataValueDescriptor
, NumberDataValue
, Orderable
public final class SQLDouble extends NumberDataType
Because OrderableDataType is a subtype of DataType, SQLDouble 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.
PERFORMANCE: There are likely alot of performance improvements possible for this implementation -- it new's Double more than it probably wants to.
This is modeled after SQLInteger.
We don't let doubles get constructed with NaN or Infinity values, and check for those values where they can occur on operations, so the set* operations do not check for them coming in.
Modifier and Type | Field | Description |
---|---|---|
private static int |
BASE_MEMORY_USAGE |
|
(package private) static int |
DOUBLE_LENGTH |
|
private boolean |
isnull |
|
private double |
value |
UNKNOWN_LOGICAL_LENGTH
MAXLONG_PLUS_ONE, MINLONG_MINUS_ONE
MAX_DECIMAL_PRECISION_SCALE, MIN_DECIMAL_DIVIDE_SCALE
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
Modifier | Constructor | Description |
---|---|---|
|
SQLDouble() |
no-arg constructor, required by Formattable
|
|
SQLDouble(double val) |
|
private |
SQLDouble(double val,
boolean startsnull) |
|
|
SQLDouble(java.lang.Double obj) |
Modifier and Type | Method | Description |
---|---|---|
DataValueDescriptor |
cloneValue(boolean forceMaterialization) |
Clone this DataValueDescriptor.
|
NumberDataValue |
divide(NumberDataValue dividend,
NumberDataValue divisor,
NumberDataValue result) |
This method implements the / operator for "double / double".
|
BooleanDataValue |
equals(DataValueDescriptor left,
DataValueDescriptor right) |
The = operator as called from the language module, as opposed to
the storage module.
|
int |
estimateMemoryUsage() |
Estimate the memory usage in bytes of the data value and the overhead of the class.
|
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.
|
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.
|
int |
getInt() |
Gets the value in the data value descriptor as a 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 int.
|
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
|
BooleanDataValue |
greaterOrEquals(DataValueDescriptor left,
DataValueDescriptor right) |
The >= operator as called from the language module, as opposed to
the storage module.
|
BooleanDataValue |
greaterThan(DataValueDescriptor left,
DataValueDescriptor right) |
The > operator as called from the language module, as opposed to
the storage module.
|
int |
hashCode() |
|
protected boolean |
isNegative() |
This method implements the isNegative method.
|
boolean |
isNull() |
Return whether the value is null or not.
|
BooleanDataValue |
lessOrEquals(DataValueDescriptor left,
DataValueDescriptor right) |
The <= operator as called from the language module, as opposed to
the storage module.
|
BooleanDataValue |
lessThan(DataValueDescriptor left,
DataValueDescriptor right) |
The < operator as called from the language module, as opposed to
the storage module.
|
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 "double - double".
|
BooleanDataValue |
notEquals(DataValueDescriptor left,
DataValueDescriptor right) |
The <> operator as called from the language module, as opposed to
the storage module.
|
NumberDataValue |
plus(NumberDataValue addend1,
NumberDataValue addend2,
NumberDataValue result) |
This method implements the + operator for "double + double".
|
void |
readExternal(java.io.ObjectInput in) |
|
void |
restoreToNull() |
Restore this object to its (SQL)null value.
|
void |
setBigDecimal(java.math.BigDecimal bigDecimal) |
Called for an application setting this value using a BigDecimal
|
protected void |
setFrom(DataValueDescriptor theValue) |
Set the value of this DataValueDescriptor based on the value
of the specified DataValueDescriptor.
|
void |
setInto(java.sql.PreparedStatement ps,
int position) |
Set the value into a PreparedStatement.
|
void |
setInto(java.sql.ResultSet rs,
int position) |
Set this value into a ResultSet for a subsequent ResultSet.insertRow
or ResultSet.updateRow.
|
(package private) void |
setObject(java.lang.Object theValue) |
Set the value from a correctly typed Double object.
|
void |
setValue(boolean theValue) |
Set the value.
|
void |
setValue(double theValue) |
Set the value of this DataValueDescriptor to the given double value
At DataType level just throws an error lower classes will override
|
void |
setValue(float theValue) |
Set the value of this DataValueDescriptor to the given float value
At DataType level just throws an error lower classes will override
|
void |
setValue(int theValue) |
Set the value of this DataValueDescriptor to the given int value
At DataType level just throws an error lower classes will override
|
void |
setValue(long theValue) |
Set the value of this DataValueDescriptor to the given long value
At DataType level just throws an error lower classes will override
|
void |
setValue(java.lang.Number theValue) |
Common code to handle java.lang.Integer as a Number,
used for TINYINT, SMALLINT, INTEGER
|
void |
setValue(java.lang.String theValue) |
Set the value of this DataValueDescriptor.
|
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) |
This method implements the * operator for "double * double".
|
java.lang.String |
toString() |
|
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() |
DOUBLE implementation.
|
void |
writeExternal(java.io.ObjectOutput out) |
checkHostVariable, cloneHolder, coalesce, compare, compare, compareTo, dataTypeConversion, equals, flip, genericSetObject, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, getTypeName, hasStream, in, invalidFormat, isNotNull, isNullOp, normalize, outOfRange, readExternalFromArray, recycle, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch
checkHostVariable, cloneHolder, coalesce, compare, compare, getBytes, getDate, getStream, getTime, getTimestamp, getTraceString, hasStream, in, isNotNull, isNullOp, normalize, readExternalFromArray, recycle, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
absolute, compare, compare, divide, mod, normalizeDOUBLE, normalizeREAL, normalizeREAL, objectNull, setValue, setValue, sqrt
static final int DOUBLE_LENGTH
private static final int BASE_MEMORY_USAGE
private double value
private boolean isnull
public SQLDouble()
public SQLDouble(double val) throws StandardException
StandardException
public SQLDouble(java.lang.Double obj) throws StandardException
StandardException
private SQLDouble(double val, boolean startsnull) throws StandardException
StandardException
public int getInt() throws StandardException
DataType
getInt
in interface DataValueDescriptor
getInt
in class DataType
StandardException
- thrown on failure to convertpublic byte getByte() throws StandardException
DataType
getByte
in interface DataValueDescriptor
getByte
in class DataType
StandardException
- thrown on failure to convertpublic short getShort() throws StandardException
DataType
getShort
in interface DataValueDescriptor
getShort
in class DataType
StandardException
- thrown on failure to convertpublic long getLong() throws StandardException
DataType
getLong
in interface DataValueDescriptor
getLong
in class DataType
StandardException
- thrown on failure to convertpublic float getFloat() throws StandardException
DataType
getFloat
in interface DataValueDescriptor
getFloat
in class DataType
StandardException
- thrown on failure to convertpublic double getDouble()
DataType
getDouble
in interface DataValueDescriptor
getDouble
in class DataType
public int typeToBigDecimal()
typeToBigDecimal
in interface DataValueDescriptor
typeToBigDecimal
in class NumberDataType
public boolean getBoolean()
DataType
getBoolean
in interface DataValueDescriptor
getBoolean
in class DataType
public java.lang.String getString()
DataValueDescriptor
public java.lang.Object getObject()
DataType
getObject
in interface DataValueDescriptor
getObject
in class DataType
void setObject(java.lang.Object theValue) throws StandardException
setObject
in class NumberDataType
StandardException
protected void setFrom(DataValueDescriptor theValue) throws StandardException
DataType
setFrom
in class DataType
theValue
- The DataValueDescriptor that holds the value to
which we want to set this DataValueDescriptor's value.StandardException
public int getLength()
DataValueDescriptor
public java.lang.String getTypeName()
DataValueDescriptor
public int getTypeFormatId()
TypedFormat.getTypeFormatId()
public boolean isNull()
Storable
Storable.isNull()
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
java.io.IOException
Externalizable.readExternal(java.io.ObjectInput)
public void restoreToNull()
Storable
Storable.restoreToNull()
protected int typeCompare(DataValueDescriptor arg) throws StandardException
NumberDataType
typeCompare
in class NumberDataType
StandardException
- Thrown on errorpublic 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.
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 DataValueDescriptor getNewNull()
DataValueDescriptor
DataValueDescriptor.getNewNull()
public void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable) throws StandardException, java.sql.SQLException
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 errorjava.sql.SQLException
- Thrown on errorDataValueDescriptor.setValueFromResultSet(java.sql.ResultSet, int, boolean)
public final void setInto(java.sql.PreparedStatement ps, int position) throws java.sql.SQLException
setInto
in interface DataValueDescriptor
setInto
in class DataType
java.sql.SQLException
- Error setting value in PreparedStatementpublic final void setInto(java.sql.ResultSet rs, int position) throws java.sql.SQLException, StandardException
setInto
in interface DataValueDescriptor
setInto
in class DataType
java.sql.SQLException
- thrown by the ResultSet objectStandardException
- thrown by me accessing my value.public void setValue(java.lang.String theValue) throws StandardException
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The BigDecimal value to set this DataValueDescriptor toStandardException
- throws NumberFormatException
when the String format is not recognized.public void setValue(double theValue) throws StandardException
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toStandardException
- on NaN or Infinite doublepublic void setValue(float theValue) throws StandardException
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor toStandardException
- on NaN or Infinite floatpublic void setValue(long theValue)
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor topublic void setValue(int theValue)
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- The value to set this DataValueDescriptor topublic void setValue(java.lang.Number theValue) throws StandardException
NumberDataType
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)
public void setBigDecimal(java.math.BigDecimal bigDecimal) throws StandardException
setBigDecimal
in interface DataValueDescriptor
setBigDecimal
in class NumberDataType
bigDecimal
- required to be a BigDecimal or null.StandardException
public void setValue(boolean theValue)
DataType
setValue
in interface DataValueDescriptor
setValue
in class DataType
theValue
- Contains the boolean value to set this toNumberDataValue.setValue(java.lang.Number)
public int typePrecedence()
DataType
typePrecedence
in interface DataValueDescriptor
typePrecedence
in class DataType
DataValueDescriptor.typePrecedence()
public BooleanDataValue equals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
equals
in interface DataValueDescriptor
equals
in class DataType
left
- The value on the left side of the =right
- The value on the right side of the =
is not.StandardException
- Thrown on errorpublic BooleanDataValue notEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
notEquals
in interface DataValueDescriptor
notEquals
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operator
is not.StandardException
- Thrown on errorpublic BooleanDataValue lessThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
lessThan
in interface DataValueDescriptor
lessThan
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic BooleanDataValue greaterThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
greaterThan
in interface DataValueDescriptor
greaterThan
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic BooleanDataValue lessOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
lessOrEquals
in interface DataValueDescriptor
lessOrEquals
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic BooleanDataValue greaterOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException
greaterOrEquals
in interface DataValueDescriptor
greaterOrEquals
in class DataType
left
- The value on the left side of the operatorright
- The value on the right side of the operatorStandardException
- Thrown on errorpublic 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 yetStandardException
- Thrown on errorpublic NumberDataValue minus(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
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 yetStandardException
- Thrown on errorpublic NumberDataValue times(NumberDataValue left, NumberDataValue right, NumberDataValue result) throws StandardException
left
- The first value to be multipliedright
- The second value to be multipliedresult
- The result of a previous call to this method, null
if not called yetStandardException
- Thrown on errorpublic NumberDataValue divide(NumberDataValue dividend, NumberDataValue divisor, NumberDataValue result) 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 yetStandardException
- Thrown on errorpublic NumberDataValue minus(NumberDataValue result) throws StandardException
result
- The result of a previous call to this method, null
if not called yetStandardException
- Thrown on errorprotected boolean isNegative()
isNegative
in class NumberDataType
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int estimateMemoryUsage()
DataValueDescriptor
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.