public class BigDecimalLongTranslatorFactory extends ValueTranslatorFactory<BigDecimal,Long>
This a simple strategy for storing BigDecimal in the datastore. BigDecimalLongConverter multiplies by a fixed factor and stores the result as a Long. This is appropriate for monetary and other (relatively) small values with fixed decimal precision.
This is one possible strategy and not appropriate for all uses of BigDecimal - especially very large values which cannot fit in a Long. For this reason, the converter is not installed by default. You can Install this converter at the same time you perform registration:
ObjectifyService.factory().getTranslators().add(new BigDecimalLongTranslatorFactory());
The default factor of 1,000 is good for currency, which usually has 0-3 digits of precision past the decimal point. But you can pick any other factor appropriate to your application.
All custom translators must be registered *before* entity classes are registered.
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_FACTOR
Default factor is 1000, which gives you three digits of precision past the decimal point
|
Constructor and Description |
---|
BigDecimalLongTranslatorFactory()
Construct this converter with the default factor (1000), which can store three points of
precision past the decimal point.
|
BigDecimalLongTranslatorFactory(long factor)
Construct this with an arbitrary factor.
|
Modifier and Type | Method and Description |
---|---|
protected ValueTranslator<BigDecimal,Long> |
createValueTranslator(TypeKey<BigDecimal> tk,
CreateContext ctx,
Path path)
Create a translator, knowing that we have the appropriate type.
|
create
public static final long DEFAULT_FACTOR
public BigDecimalLongTranslatorFactory()
public BigDecimalLongTranslatorFactory(long factor)
factor
- number multiplied by before storage and divided by on retrieval.protected ValueTranslator<BigDecimal,Long> createValueTranslator(TypeKey<BigDecimal> tk, CreateContext ctx, Path path)
ValueTranslatorFactory
createValueTranslator
in class ValueTranslatorFactory<BigDecimal,Long>
tk
- type is guaranteed to erase to something assignable to ClassCopyright © 2016. All rights reserved.