Top Description Fields Constructors Methods
org.hsqldb.types

public final Class NumberType

extends Type
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, .RoundingMode, org.hsqldb.OpTypes, .Session, .SessionInterface, .Tokens, org.hsqldb.error.Error, .ErrorCode, org.hsqldb.map.ValuePool

Type subclass for all NUMBER types.

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.9.0
Version
2.7.0

Field Summary

Modifier and TypeField and Description
pack-priv static final BigDecimal
public static final int
public static final int
pack-priv static final int
public static final int
public static final int
pack-priv static final int
public static final int
public static final int
public static final int
pack-priv static final int
public static final int
pack-priv static final int
public static final BigDecimal
public static final BigDecimal
public static final BigDecimal
public static final BigInteger
public static final int
pack-priv static final BigDecimal
public static final BigDecimal
public static final BigDecimal
public static final BigInteger
public static final int
pack-priv static final int
public static final Type
public static final int
pack-priv static final int
pack-priv final int
Inherited from org.hsqldb.types.Type:
emptyArrayjdbcConvertTypesOTHERprecisionscaleSQL_ALL_TYPESSQL_ARRAY_ALL_TYPESSQL_BIGINTSQL_BINARYSQL_BINARY_16SQL_BINARY_DEFAULTSQL_BITSQL_BIT_VARYINGSQL_BIT_VARYING_MAX_LENGTHSQL_BLOBSQL_BOOLEANSQL_CHARSQL_CHAR_DEFAULTSQL_CHAR_UUIDSQL_CLOBSQL_DATESQL_DECIMALSQL_DECIMAL_BIGINT_SQRSQL_DECIMAL_DEFAULTSQL_DOUBLESQL_GUIDSQL_INTEGERSQL_INTERVAL_DAYSQL_INTERVAL_DAY_MAX_PRECISIONSQL_INTERVAL_DAY_TO_HOURSQL_INTERVAL_DAY_TO_MINUTESQL_INTERVAL_DAY_TO_SECONDSQL_INTERVAL_DAY_TO_SECOND_MAX_PRECISIONSQL_INTERVAL_HOURSQL_INTERVAL_HOUR_MAX_PRECISIONSQL_INTERVAL_HOUR_TO_MINUTESQL_INTERVAL_HOUR_TO_SECONDSQL_INTERVAL_MINUTESQL_INTERVAL_MINUTE_MAX_PRECISIONSQL_INTERVAL_MINUTE_TO_SECONDSQL_INTERVAL_MONTHSQL_INTERVAL_MONTH_MAX_PRECISIONSQL_INTERVAL_SECONDSQL_INTERVAL_SECOND_MAX_FRACTIONSQL_INTERVAL_SECOND_MAX_FRACTION_MAX_PRECISIONSQL_INTERVAL_SECOND_MAX_PRECISIONSQL_INTERVAL_YEARSQL_INTERVAL_YEAR_MAX_PRECISIONSQL_INTERVAL_YEAR_TO_MONTHSQL_INTERVAL_YEAR_TO_MONTH_MAX_PRECISIONSQL_NUMERICSQL_SMALLINTSQL_TIMESQL_TIME_MAXSQL_TIME_WITH_TIME_ZONESQL_TIME_WITH_TIME_ZONE_MAXSQL_TIMESTAMPSQL_TIMESTAMP_NO_FRACTIONSQL_TIMESTAMP_WITH_TIME_ZONESQL_TIMESTAMP_WITH_TIME_ZONE_MAXSQL_VARBINARYSQL_VARBINARY_DEFAULTSQL_VARCHARSQL_VARCHAR_DEFAULTSQL_VARCHAR_LONGTINYINTtypeAliasestypeCodetypeComparisonGrouptypeDataGrouptypeNamesuserTypeModifier

Constructor Summary

AccessConstructor and Description
public
NumberType(int type, long precision, int scale)

Method Summary

Modifier and TypeMethod and Description
public Object
absolute(Object a)

Overrides org.hsqldb.types.Type.absolute.

All arithmetic ops are called on the pre-determined Type object of the result

public boolean
public boolean
public Object
add(Session session, Object a, Object b, Type otherType)

Overrides org.hsqldb.types.Type.add.

public boolean
public int
canMoveFrom(Type otherType)

Overrides org.hsqldb.types.Type.canMoveFrom.

When canConvertFrom() is true, can convert without changing the object

public Object
public int
compare(Session session, Object a, Object b)

Implements abstract org.hsqldb.types.Type.compare.

public static int
public static int
compareDouble(double value1, double value2)

public static int
public static int
public int
public int
public Object
private static BigDecimal
public Object
convertToDefaultType(SessionInterface session, Object a)

Implements abstract org.hsqldb.types.Type.convertToDefaultType.

Relaxes SQL parameter type enforcement for DECIMAL, allowing long values.

private static Double
convertToDouble(Object a)

Converter from a numeric object to Double.

pack-priv static Integer
convertToInt(SessionInterface session, Object a, int type)

Converter from a numeric object to Integer.

pack-priv static Long
convertToLong(SessionInterface session, Object a)

Converter from a numeric object to Long.

public String
public String
public Object
convertToType(SessionInterface session, Object a, Type otherType)

Implements abstract org.hsqldb.types.Type.convertToType.

Same as castToType except for CHARACTER values.

public Object
convertToTypeJDBC(SessionInterface session, Object a, Type otherType)

Overrides org.hsqldb.types.Type.convertToTypeJDBC.

Convert type for JDBC reads.

public Object
public int
public Object
public Object
public Type
getAggregateType(Type other)

Implements abstract org.hsqldb.types.Type.getAggregateType.

Common type used in comparison operations.

public Type
getCombinedType(Session session, Type other, int operation)

Implements abstract org.hsqldb.types.Type.getCombinedType.

Returns a SQL type "wide" enough to represent the result of the expression.

public int
getDecimalPrecision()

Returns decimal precision.

public String
getDefinition()

Implements abstract org.hsqldb.types.Type.getDefinition.

Returns the full definition of the type, including parameters

public String
getFullNameString()

Overrides org.hsqldb.types.Type.getFullNameString.

Returns the name of the type

public Type
public Class<T>
public String
getJDBCClassName()

Implements abstract org.hsqldb.types.Type.getJDBCClassName.

Returns the JDBC class name of type, if it exists, otherwise the HSQLDB class name.

public int
public int
getJDBCTypeCode()

Implements abstract org.hsqldb.types.Type.getJDBCTypeCode.

Returns the JDBC type number of type, if it exists, otherwise the HSQLDB / SQL type.

public long
public int
public String
getNameString()

Implements abstract org.hsqldb.types.Type.getNameString.

Returns the name of the type

public int
public static NumberType
getNumberType(int type, long precision, int scale)

public static NumberType
public int
public int
getPrecision()

Returns decimal precision for NUMERIC/DECIMAL.

public int
public boolean
public boolean
public boolean
public boolean
public boolean
public static boolean
public Object
modulo(Session session, Object a, Object b, Type otherType)

public Object
public Object
public int
public static int
public Object
round(Object a, int s)

public static long
scaledDecimal(Object a, int scale)

public Object
subtract(Session session, Object a, Object b, Type otherType)

Overrides org.hsqldb.types.Type.subtract.

public static double
public Object
truncate(Object a, int s)

Inherited from org.hsqldb.types.Type:
acceptsFractionalPrecisionarrayLimitCardinalitycanBeAssignedFromcanCompareDirectcardinalitycastToTypecollectionBaseTypecomparecomparecompileconcatconvertSQLToJavaconvertToJSONconvertToJSONduplicateequalsgetAggregateTypegetCatalogNamegetChangeTimestampgetCharacterSetgetCollationgetComponentsgetDefaultArrayTypegetDefaultTypegetDefaultTypeWithSizegetDegreegetHSQLDBTypeCodegetJDBCScalegetJDBCTypeCodegetNamegetOwnergetReferencesgetSchemaNamegetSQLgetSQLGenericTypeCodegetTypegetTypegetTypegetTypeDefinitiongetTypeForJDBCConvertTokengetTypeNrhashCodehashCodeisArrayTypeisBinaryTypeisBitTypeisBooleanTypeisCharacterTypeisDateOrTimestampTypeisDateTimeTypeisDateTimeTypeWithZoneisDistinctTypeisDomainTypeisIntervalDaySecondTypeisIntervalTypeisIntervalYearMonthTypeisLobTypeisMultisetTypeisObjectTypeisRowTypeisStructuredTypeisSupportedSQLTypeisTimestampTypeisTimeTypeisUUIDTypematchesrequiresPrecision

Field Detail

BD_1back to summary
pack-priv static final BigDecimal BD_1
BIGINT_WIDTHback to summary
public static final int BIGINT_WIDTH
bigintPrecisionback to summary
public static final int bigintPrecision
bigintSquareNumericPrecisionback to summary
pack-priv static final int bigintSquareNumericPrecision
BIT_WIDTHback to summary
public static final int BIT_WIDTH
DECIMAL_WIDTHback to summary
public static final int DECIMAL_WIDTH
decimalLiteralPrecisionback to summary
pack-priv static final int decimalLiteralPrecision
defaultNumericPrecisionback to summary
public static final int defaultNumericPrecision
defaultNumericScaleback to summary
public static final int defaultNumericScale
DOUBLE_WIDTHback to summary
public static final int DOUBLE_WIDTH
doublePrecisionback to summary
pack-priv static final int doublePrecision
INTEGER_WIDTHback to summary
public static final int INTEGER_WIDTH
integerPrecisionback to summary
pack-priv static final int integerPrecision
MAX_DOUBLEback to summary
public static final BigDecimal MAX_DOUBLE
MAX_INTback to summary
public static final BigDecimal MAX_INT
MAX_LONGback to summary
public static final BigDecimal MAX_LONG
MAX_LONG_BIback to summary
public static final BigInteger MAX_LONG_BI
maxNumericPrecisionback to summary
public static final int maxNumericPrecision
MBD_1back to summary
pack-priv static final BigDecimal MBD_1
MIN_INTback to summary
public static final BigDecimal MIN_INT
MIN_LONGback to summary
public static final BigDecimal MIN_LONG
MIN_LONG_BIback to summary
public static final BigInteger MIN_LONG_BI
SMALLINT_WIDTHback to summary
public static final int SMALLINT_WIDTH
smallintPrecisionback to summary
pack-priv static final int smallintPrecision
SQL_NUMERIC_DEFAULT_INTback to summary
public static final Type SQL_NUMERIC_DEFAULT_INT
TINYINT_WIDTHback to summary
public static final int TINYINT_WIDTH
tinyintPrecisionback to summary
pack-priv static final int tinyintPrecision
typeWidthback to summary
pack-priv final int typeWidth

Constructor Detail

NumberTypeback to summary
public NumberType(int type, long precision, int scale)

Method Detail

absoluteback to summary
public Object absolute(Object a)

Overrides org.hsqldb.types.Type.absolute.

Doc from org.hsqldb.types.Type.absolute.

All arithmetic ops are called on the pre-determined Type object of the result

acceptsPrecisionback to summary
public boolean acceptsPrecision()

Overrides org.hsqldb.types.Type.acceptsPrecision.

acceptsScaleback to summary
public boolean acceptsScale()

Overrides org.hsqldb.types.Type.acceptsScale.

addback to summary
public Object add(Session session, Object a, Object b, Type otherType)

Overrides org.hsqldb.types.Type.add.

canConvertFromback to summary
public boolean canConvertFrom(Type otherType)

Implements abstract org.hsqldb.types.Type.canConvertFrom.

canMoveFromback to summary
public int canMoveFrom(Type otherType)

Overrides org.hsqldb.types.Type.canMoveFrom.

Doc from org.hsqldb.types.Type.canMoveFrom.

When canConvertFrom() is true, can convert without changing the object

ceilingback to summary
public Object ceiling(Object a)
compareback to summary
public int compare(Session session, Object a, Object b)

Implements abstract org.hsqldb.types.Type.compare.

compareBigDecimalToLongLimitsback to summary
public static int compareBigDecimalToLongLimits(Object value)
compareDoubleback to summary
public static int compareDouble(double value1, double value2)
compareToLongLimitsback to summary
public static int compareToLongLimits(BigDecimal value)
compareToLongLimitsback to summary
public static int compareToLongLimits(BigInteger value)
compareToTypeRangeback to summary
public int compareToTypeRange(Object o)

Overrides org.hsqldb.types.Type.compareToTypeRange.

compareToZeroback to summary
public int compareToZero(Object a)
convertJavaToSQLback to summary
public Object convertJavaToSQL(SessionInterface session, Object a)

Overrides org.hsqldb.types.Type.convertJavaToSQL.

convertToDecimalback to summary
private static BigDecimal convertToDecimal(Object a)
convertToDefaultTypeback to summary
public Object convertToDefaultType(SessionInterface session, Object a)

Implements abstract org.hsqldb.types.Type.convertToDefaultType.

Relaxes SQL parameter type enforcement for DECIMAL, allowing long values.

convertToDoubleback to summary
private static Double convertToDouble(Object a)

Converter from a numeric object to Double. Input is checked to be within range represented by Double

convertToIntback to summary
pack-priv static Integer convertToInt(SessionInterface session, Object a, int type)

Converter from a numeric object to Integer. Input is checked to be within range represented by the given number type.

convertToLongback to summary
pack-priv static Long convertToLong(SessionInterface session, Object a)

Converter from a numeric object to Long. Input is checked to be within range represented by Long.

convertToSQLStringback to summary
public String convertToSQLString(Object a)

Implements abstract org.hsqldb.types.Type.convertToSQLString.

convertToStringback to summary
public String convertToString(Object a)

Implements abstract org.hsqldb.types.Type.convertToString.

convertToTypeback to summary
public Object convertToType(SessionInterface session, Object a, Type otherType)

Implements abstract org.hsqldb.types.Type.convertToType.

Doc from org.hsqldb.types.Type.convertToType.

Same as castToType except for CHARACTER values. Perform string truncation of trailing spaces only. For other long strings, it raises an exception.

convertToTypeJDBCback to summary
public Object convertToTypeJDBC(SessionInterface session, Object a, Type otherType)

Overrides org.hsqldb.types.Type.convertToTypeJDBC.

Doc from org.hsqldb.types.Type.convertToTypeJDBC.

Convert type for JDBC reads. Same as convertToType, but supports non-standard SQL conversions supported by JDBC

convertToTypeLimitsback to summary
public Object convertToTypeLimits(SessionInterface session, Object a)

Implements abstract org.hsqldb.types.Type.convertToTypeLimits.

displaySizeback to summary
public int displaySize()

Implements abstract org.hsqldb.types.Type.displaySize.

divideback to summary
public Object divide(Session session, Object a, Object b)

Overrides org.hsqldb.types.Type.divide.

floorback to summary
public Object floor(Object a)
getAggregateTypeback to summary
public Type getAggregateType(Type other)

Implements abstract org.hsqldb.types.Type.getAggregateType.

Doc from org.hsqldb.types.Type.getAggregateType.

Common type used in comparison operations. other must be comparable with this.

getCombinedTypeback to summary
public Type getCombinedType(Session session, Type other, int operation)

Implements abstract org.hsqldb.types.Type.getCombinedType.

Returns a SQL type "wide" enough to represent the result of the expression.
A type is "wider" than the other if it can represent all its numeric values.
Arithmetic operation terms are promoted to a type that can represent the resulting values and avoid incorrect results.

FLOAT/REAL/DOUBLE used in an operation results in the same type, regardless of the type of the other operand. When the result or the expression is converted to the type of the target column for storage, an exception is thrown if the resulting value cannot be stored in the column

Types narrower than INTEGER (int) are promoted to INTEGER. The order of promotion is as follows

INTEGER, BIGINT, NUMERIC/DECIMAL

TINYINT and SMALLINT in any combination return INTEGER
TINYINT/SMALLINT/INTEGER and INTEGER return BIGINT
TINYINT/SMALLINT/INTEGER and BIGINT return NUMERIC/DECIMAL
BIGINT and BIGINT return NUMERIC/DECIMAL
REAL/FLOAT/DOUBLE and any type return REAL/FLOAT/DOUBLE
NUMERIC/DECIMAL any type other than REAL/FLOAT/DOUBLE returns NUMERIC/DECIMAL
In the case of NUMERIC/DECIMAL returned, the result precision is always large enough to express any value result, while the scale depends on the operation:
For ADD/SUBTRACT/DIVIDE, the scale is the larger of the two
For MULTIPLY, the scale is the sum of the two scales

getDecimalPrecisionback to summary
public int getDecimalPrecision()

Returns decimal precision.

getDefinitionback to summary
public String getDefinition()

Implements abstract org.hsqldb.types.Type.getDefinition.

Doc from org.hsqldb.types.Type.getDefinition.

Returns the full definition of the type, including parameters

getFullNameStringback to summary
public String getFullNameString()

Overrides org.hsqldb.types.Type.getFullNameString.

Doc from org.hsqldb.types.Type.getFullNameString.

Returns the name of the type

getIntegralTypeback to summary
public Type getIntegralType()
getJDBCClassback to summary
public Class<T> getJDBCClass()

Implements abstract org.hsqldb.types.Type.getJDBCClass.

getJDBCClassNameback to summary
public String getJDBCClassName()

Implements abstract org.hsqldb.types.Type.getJDBCClassName.

Doc from org.hsqldb.types.Type.getJDBCClassName.

Returns the JDBC class name of type, if it exists, otherwise the HSQLDB class name.

getJDBCPrecisionback to summary
public int getJDBCPrecision()

Overrides org.hsqldb.types.Type.getJDBCPrecision.

getJDBCTypeCodeback to summary
public int getJDBCTypeCode()

Implements abstract org.hsqldb.types.Type.getJDBCTypeCode.

Doc from org.hsqldb.types.Type.getJDBCTypeCode.

Returns the JDBC type number of type, if it exists, otherwise the HSQLDB / SQL type.

getMaxPrecisionback to summary
public long getMaxPrecision()

Overrides org.hsqldb.types.Type.getMaxPrecision.

getMaxScaleback to summary
public int getMaxScale()

Overrides org.hsqldb.types.Type.getMaxScale.

getNameStringback to summary
public String getNameString()

Implements abstract org.hsqldb.types.Type.getNameString.

Doc from org.hsqldb.types.Type.getNameString.

Returns the name of the type

getNominalWidthback to summary
public int getNominalWidth()
getNumberTypeback to summary
public static NumberType getNumberType(int type, long precision, int scale)
getNumberTypeForLiteralback to summary
public static NumberType getNumberTypeForLiteral(BigDecimal value)
getNumericPrecisionInRadixback to summary
public int getNumericPrecisionInRadix()
getPrecisionback to summary
public int getPrecision()

Returns decimal precision for NUMERIC/DECIMAL. Returns binary precision for other parts.

getPrecisionRadixback to summary
public int getPrecisionRadix()

Overrides org.hsqldb.types.Type.getPrecisionRadix.

isDecimalTypeback to summary
public boolean isDecimalType()

Overrides org.hsqldb.types.Type.isDecimalType.

isExactNumberTypeback to summary
public boolean isExactNumberType()

Overrides org.hsqldb.types.Type.isExactNumberType.

isIntegralTypeback to summary
public boolean isIntegralType()

Overrides org.hsqldb.types.Type.isIntegralType.

isNegativeback to summary
public boolean isNegative(Object a)

Overrides org.hsqldb.types.Type.isNegative.

isNumberTypeback to summary
public boolean isNumberType()

Overrides org.hsqldb.types.Type.isNumberType.

isZeroback to summary
public static boolean isZero(Object a)
moduloback to summary
public Object modulo(Session session, Object a, Object b, Type otherType)
multiplyback to summary
public Object multiply(Object a, Object b)

Overrides org.hsqldb.types.Type.multiply.

negateback to summary
public Object negate(Object a)

Overrides org.hsqldb.types.Type.negate.

precedenceDegreeback to summary
public int precedenceDegree(Type other)

Overrides org.hsqldb.types.Type.precedenceDegree.

precisionback to summary
public static int precision(BigDecimal o)
roundback to summary
public Object round(Object a, int s)
scaledDecimalback to summary
public static long scaledDecimal(Object a, int scale)
subtractback to summary
public Object subtract(Session session, Object a, Object b, Type otherType)

Overrides org.hsqldb.types.Type.subtract.

toDoubleback to summary
public static double toDouble(Object a)
truncateback to summary
public Object truncate(Object a, int s)