org.h2.value
Class ValueDecimal

java.lang.Object
  extended by org.h2.value.Value
      extended by org.h2.value.ValueDecimal

public class ValueDecimal
extends Value

Implementation of the DECIMAL data type.


Field Summary
static java.lang.Object ONE
          The value 'one'.
static java.lang.Object ZERO
          The value 'zero'.
 
Fields inherited from class org.h2.value.Value
ARRAY, BLOB, BOOLEAN, BYTE, BYTES, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INT, JAVA_OBJECT, LONG, NULL, RESULT_SET, SHORT, STRING, STRING_FIXED, STRING_IGNORECASE, TIME, TIMESTAMP, TYPE_COUNT, UNKNOWN, UUID
 
Method Summary
 Value add(Value v)
          Add a value and return the result.
 boolean checkPrecision(long precision)
          Check if the precision is smaller or equal than the given precision.
protected  int compareSecure(Value o, CompareMode mode)
          Compare the value with another value of the same type.
 Value convertPrecision(long precision)
          Convert the precision to the requested value.
 Value convertScale(boolean onlyToSmallerScale, int targetScale)
          Convert the scale.
 Value divide(Value v)
          Divide by a value and return the result.
 boolean equals(java.lang.Object other)
          Check if the two values are equal.
static ValueDecimal get(java.math.BigDecimal dec)
          Get or create big decimal value for the given big decimal.
 java.math.BigDecimal getBigDecimal()
           
 int getDisplaySize()
          Get the display size in characters.
 int getMemory()
          Get the memory used by this object.
 java.lang.Object getObject()
          Get the value as an object.
 long getPrecision()
          Get the precision.
 int getScale()
           
 int getSignum()
           
 java.lang.String getSQL()
          Get the SQL expression for this value.
 java.lang.String getString()
          Get the value as a string.
 int getType()
          Get the value type.
 int hashCode()
           
 Value multiply(Value v)
          Multiply with a value and return the result.
 Value negate()
          Return -value if this value support arithmetic operations.
 void set(java.sql.PreparedStatement prep, int parameterIndex)
          Set the value as a parameter in a prepared statement.
 Value subtract(Value v)
          Subtract a value and return the result.
 
Methods inherited from class org.h2.value.Value
close, compareEqual, compareTo, compareTypeSave, convertTo, getBoolean, getByte, getBytes, getBytesNoCopy, getDate, getDateNoCopy, getDouble, getFloat, getHigherOrder, getInputStream, getInt, getLong, getReader, getShort, getTime, getTimeNoCopy, getTimestamp, getTimestampNoCopy, getTraceSQL, isFileBased, isLinked, link, throwUnsupportedExceptionForType, toString, unlink
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final java.lang.Object ZERO
The value 'zero'.


ONE

public static final java.lang.Object ONE
The value 'one'.

Method Detail

add

public Value add(Value v)
Description copied from class: Value
Add a value and return the result.

Overrides:
add in class Value
Parameters:
v - the value to add
Returns:
the result

subtract

public Value subtract(Value v)
Description copied from class: Value
Subtract a value and return the result.

Overrides:
subtract in class Value
Parameters:
v - the value to subtract
Returns:
the result

negate

public Value negate()
Description copied from class: Value
Return -value if this value support arithmetic operations.

Overrides:
negate in class Value
Returns:
the negative

multiply

public Value multiply(Value v)
Description copied from class: Value
Multiply with a value and return the result.

Overrides:
multiply in class Value
Parameters:
v - the value to multiply with
Returns:
the result

divide

public Value divide(Value v)
             throws java.sql.SQLException
Description copied from class: Value
Divide by a value and return the result.

Overrides:
divide in class Value
Parameters:
v - the value to divide by
Returns:
the result
Throws:
java.sql.SQLException

getSQL

public java.lang.String getSQL()
Description copied from class: Value
Get the SQL expression for this value.

Specified by:
getSQL in class Value
Returns:
the SQL expression

getType

public int getType()
Description copied from class: Value
Get the value type.

Specified by:
getType in class Value
Returns:
the type

compareSecure

protected int compareSecure(Value o,
                            CompareMode mode)
Description copied from class: Value
Compare the value with another value of the same type.

Specified by:
compareSecure in class Value
Parameters:
o - the other value
mode - the compare mode
Returns:
0 if both values are equal, -1 if the other value is smaller, and 1 otherwise

getSignum

public int getSignum()
Overrides:
getSignum in class Value

getBigDecimal

public java.math.BigDecimal getBigDecimal()
Overrides:
getBigDecimal in class Value

getString

public java.lang.String getString()
Description copied from class: Value
Get the value as a string.

Specified by:
getString in class Value
Returns:
the string

getPrecision

public long getPrecision()
Description copied from class: Value
Get the precision.

Specified by:
getPrecision in class Value
Returns:
the precision

checkPrecision

public boolean checkPrecision(long precision)
Description copied from class: Value
Check if the precision is smaller or equal than the given precision.

Overrides:
checkPrecision in class Value
Parameters:
precision - the maximum precision
Returns:
true if the precision of this value is smaller or equal to the given precision

getScale

public int getScale()
Overrides:
getScale in class Value

hashCode

public int hashCode()
Specified by:
hashCode in class Value

getObject

public java.lang.Object getObject()
Description copied from class: Value
Get the value as an object.

Specified by:
getObject in class Value
Returns:
the object

set

public void set(java.sql.PreparedStatement prep,
                int parameterIndex)
         throws java.sql.SQLException
Description copied from class: Value
Set the value as a parameter in a prepared statement.

Specified by:
set in class Value
Parameters:
prep - the prepared statement
parameterIndex - the parameter index
Throws:
java.sql.SQLException

convertScale

public Value convertScale(boolean onlyToSmallerScale,
                          int targetScale)
                   throws java.sql.SQLException
Description copied from class: Value
Convert the scale.

Overrides:
convertScale in class Value
Parameters:
onlyToSmallerScale - if the scale should not reduced
targetScale - the requested scale
Returns:
the value
Throws:
java.sql.SQLException

convertPrecision

public Value convertPrecision(long precision)
                       throws java.sql.SQLException
Description copied from class: Value
Convert the precision to the requested value.

Overrides:
convertPrecision in class Value
Parameters:
precision - the new precision
Returns:
the new value
Throws:
java.sql.SQLException

get

public static ValueDecimal get(java.math.BigDecimal dec)
Get or create big decimal value for the given big decimal.

Parameters:
dec - the bit decimal
Returns:
the value

getDisplaySize

public int getDisplaySize()
Description copied from class: Value
Get the display size in characters.

Specified by:
getDisplaySize in class Value
Returns:
the display size

equals

public boolean equals(java.lang.Object other)
Description copied from class: Value
Check if the two values are equal. No data conversion is made; this method returns false if the other object is not of the same class.

Specified by:
equals in class Value
Parameters:
other - the other value
Returns:
true if they are equal

getMemory

public int getMemory()
Description copied from class: Value
Get the memory used by this object.

Overrides:
getMemory in class Value
Returns:
the memory used in bytes