| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.value; |
| 7 |
|
| 8 |
import java.math.BigDecimal; |
| 9 |
|
| 10 |
import org.h2.api.ErrorCode; |
| 11 |
import org.h2.engine.Constants; |
| 12 |
import org.h2.message.DbException; |
| 13 |
|
| 14 |
/** |
| 15 |
* Base class for BigDecimal-based values. |
| 16 |
*/ |
| 17 |
abstract class ValueBigDecimalBase extends Value { |
| 18 |
|
| 19 |
final BigDecimal value; |
| 20 |
|
| 21 |
TypeInfo type; |
| 22 |
|
| 23 |
ValueBigDecimalBase(BigDecimal value) { |
| 24 |
if (value != null) { |
| 25 |
if (value.getClass() != BigDecimal.class) { |
| 26 |
throw DbException.get(ErrorCode.INVALID_CLASS_2, BigDecimal.class.getName(), |
| 27 |
value.getClass().getName()); |
| 28 |
} |
| 29 |
int length = value.precision(); |
| 30 |
if (length > Constants.MAX_NUMERIC_PRECISION) { |
| 31 |
throw DbException.getValueTooLongException(getTypeName(getValueType()), value.toString(), length); |
| 32 |
} |
| 33 |
} |
| 34 |
this.value = value; |
| 35 |
} |
| 36 |
|
| 37 |
} |