|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.googlecode.objectify.impl.conv.BigDecimalLongConverter
public class BigDecimalLongConverter
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().getConversions().add(new BigDecimalLongConverter());
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.
Field Summary | |
---|---|
static long |
DEFAULT_FACTOR
Default factor is 1000, which gives you three digits of precision past the decimal point |
Constructor Summary | |
---|---|
BigDecimalLongConverter()
Construct this converter with the default factor (1000), which can store three points of precision past the decimal point. |
|
BigDecimalLongConverter(long factor)
Construct this with an arbitrary factor. |
Method Summary | |
---|---|
java.lang.Object |
forDatastore(java.lang.Object value,
ConverterSaveContext ctx)
Convert the value into an object suitable for storage in the datastore. |
java.lang.Object |
forPojo(java.lang.Object value,
java.lang.Class<?> fieldType,
ConverterLoadContext ctx,
java.lang.Object onPojo)
Convert the value into an object suitable for setting on a field with the specified type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long DEFAULT_FACTOR
Constructor Detail |
---|
public BigDecimalLongConverter()
public BigDecimalLongConverter(long factor)
factor
- number multiplied by before storage and divided by on retrieval.Method Detail |
---|
public java.lang.Object forDatastore(java.lang.Object value, ConverterSaveContext ctx)
Converter
forDatastore
in interface Converter
value
- will never be null
public java.lang.Object forPojo(java.lang.Object value, java.lang.Class<?> fieldType, ConverterLoadContext ctx, java.lang.Object onPojo)
Converter
forPojo
in interface Converter
value
- will never be nullfieldType
- is the type that the value should be converted toonPojo
- is the actual pojo object that this value will eventually be set upon
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |