Class JodaMoneyType
java.lang.Object
google.registry.persistence.converter.JodaMoneyType
- All Implemented Interfaces:
org.hibernate.metamodel.spi.EmbeddableInstantiator
,org.hibernate.metamodel.spi.Instantiator
,org.hibernate.usertype.CompositeUserType<org.joda.money.Money>
public class JodaMoneyType
extends Object
implements org.hibernate.usertype.CompositeUserType<org.joda.money.Money>
Defines JPA mapping for
Joda Money type
.
Money
is mapped to two table columns, a text currency
column that stores the
currency code, and a numeric amount
column that stores the amount.
The main purpose of this class is to normalize the amount loaded from the database. To support
all currency types, the scale of the numeric column is set to 2. As a result, the BigDecimal
instances obtained from query ResultSets all have their scale at 2. However, some
currency types, e.g., JPY requires that the scale be zero. This class strips trailing zeros from
each loaded BigDecimal, then calls the appropriate factory method for Money, which will adjust
the scale appropriately.
Conversion of Money
is automatic. See NomulusPostgreSQLDialect
for more information.
Usage:
@AttributeOverride(
name = "amount",
// Override default (numeric(38,2)) to match real schema definition (numeric(19,2)).
column = @Column(name = "cost_currency", precision = 19, scale = 2))
@AttributeOverride(name = "currency", column = @Column(name = "cost_currency"))
Money cost;
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
MapsMoney
fields to database columns. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.joda.money.Money
assemble
(Serializable cached, Object owner) org.joda.money.Money
deepCopy
(org.joda.money.Money value) disassemble
(org.joda.money.Money value) Class
<?> boolean
equals
(org.joda.money.Money x, org.joda.money.Money y) getPropertyValue
(org.joda.money.Money money, int property) int
hashCode
(org.joda.money.Money x) org.joda.money.Money
instantiate
(org.hibernate.metamodel.spi.ValueAccess values, org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory) boolean
org.joda.money.Money
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hibernate.usertype.CompositeUserType
isInstance, isSameClass
-
Constructor Details
-
JodaMoneyType
public JodaMoneyType()
-
-
Method Details
-
getPropertyValue
public Object getPropertyValue(org.joda.money.Money money, int property) throws org.hibernate.HibernateException - Specified by:
getPropertyValue
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-
returnedClass
- Specified by:
returnedClass
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
-
equals
public boolean equals(org.joda.money.Money x, org.joda.money.Money y) - Specified by:
equals
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
-
hashCode
public int hashCode(org.joda.money.Money x) throws org.hibernate.HibernateException - Specified by:
hashCode
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-
deepCopy
public org.joda.money.Money deepCopy(org.joda.money.Money value) throws org.hibernate.HibernateException - Specified by:
deepCopy
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-
isMutable
public boolean isMutable()- Specified by:
isMutable
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
-
embeddable
- Specified by:
embeddable
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
-
instantiate
public org.joda.money.Money instantiate(org.hibernate.metamodel.spi.ValueAccess values, org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory) - Specified by:
instantiate
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Specified by:
instantiate
in interfaceorg.hibernate.metamodel.spi.EmbeddableInstantiator
-
disassemble
- Specified by:
disassemble
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-
assemble
public org.joda.money.Money assemble(Serializable cached, Object owner) throws org.hibernate.HibernateException - Specified by:
assemble
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-
replace
public org.joda.money.Money replace(org.joda.money.Money original, org.joda.money.Money target, Object owner) throws org.hibernate.HibernateException - Specified by:
replace
in interfaceorg.hibernate.usertype.CompositeUserType<org.joda.money.Money>
- Throws:
org.hibernate.HibernateException
-