java.lang.Object
org.postgresql.pljava.adt.Numeric.AsBigDecimal
- All Implemented Interfaces:
Adapter.Contract<BigDecimal>
,Adapter.Contract.Scalar<BigDecimal>
,Numeric<BigDecimal>
A reference implementation that maps to
BigDecimal
(but cannot represent all possible values).
A Java BigDecimal
cannot represent the not-a-number or positive
or negative infinity values possible for a PostgreSQL NUMERIC
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.postgresql.pljava.Adapter.Contract
Adapter.Contract.Array<T,
E, A extends Adapter<E, ?>>, Adapter.Contract.Scalar<T> Nested classes/interfaces inherited from interface org.postgresql.pljava.adt.Numeric
Numeric.AsBigDecimal, Numeric.Kind, Numeric.Modifier<T>
-
Field Summary
Fields inherited from interface org.postgresql.pljava.adt.Numeric
DEC_DIGITS, NBASE, NUMERIC_MAX_PRECISION, NUMERIC_MAX_SCALE, NUMERIC_MIN_SCALE
-
Method Summary
Modifier and TypeMethodDescriptionconstruct
(Numeric.Kind kind, int displayScale, int weight, short[] base10000Digits) Produces aBigDecimal
representation of theNUMERIC
value, or throws an exception if the value is not-a-number or positive or negative infinity.<T> T
store
(BigDecimal bd, Numeric<T> f)
-
Field Details
-
INSTANCE
-
-
Method Details
-
construct
public BigDecimal construct(Numeric.Kind kind, int displayScale, int weight, short[] base10000Digits) throws SQLException Produces aBigDecimal
representation of theNUMERIC
value, or throws an exception if the value is not-a-number or positive or negative infinity.In resolving the ambiguity when displayScale is zero, this implementation constructs a
BigDecimal
with significant figures inferred from the base10000Digits array's length, where decimal digits are grouped in fours, and therefore theBigDecimal
'sscale
method will always return a multiple of four in such cases. Therefore, from the querySELECT 6.62607015e-34 AS planck, 6.02214076e23 AS avogadro;
this conversion will produce theBigDecimal
6.62607015E-34 for planck (scale
will return 42, as expected), but will produce 6.02214076000E+23 for avogadro, showing three unexpected trailing zeros;scale()
will not return -15 as expected, but the next larger multiple of four, -12.- Specified by:
construct
in interfaceNumeric<BigDecimal>
- Parameters:
kind
- POSITIVE, NEGATIVE, POSINFINITY, NEGINFINITY, or NANdisplayScale
- nominal precision, nonnegative; the number of base ten digits right of the decimal point. If this exceeds the number of right-of-decimal digits determined by the stored value, the excess represents a number of trailing decimal zeroes that are significant but trimmed from storage.weight
- indicates the power of ten thousand which the first base ten-thousand digit is taken is taken to represent. If the array base10000Digits has length one, and that one digit has the value 3, and weight is zero, the value is 3. If weight is 1, the value is 30000, and if weight is -1, the value is 0.0003.base10000Digits
- each array element is a nonnegative value not above 9999, representing a single digit of a base-ten-thousand number. The element at index zero is the most significant. The caller may pass a zero-length array, but may not pass null. The array is unshared and may be used as desired.- Throws:
SQLException
- 22000 if the value is NaN or +/- infinity.
-
store
- Throws:
SQLException
-