FileDocCategorySizeDatePackage
MonetaryAmountUserType.javaAPI DocHibernate 3.2.52343Tue May 08 16:56:00 BST 2007org.hibernate.test.sql.hand

MonetaryAmountUserType

public class MonetaryAmountUserType extends Object implements org.hibernate.usertype.UserType
This is a simple Hibernate custom mapping type for MonetaryAmount value types.

author
Max & Christian

Fields Summary
private static final int[]
SQL_TYPES
Constructors Summary
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, java.lang.Object owner)

		return cached;
	
public java.lang.ObjectdeepCopy(java.lang.Object value)

		return value; // MonetaryAmount is immutable
	
public java.io.Serializabledisassemble(java.lang.Object value)

		return (Serializable) value;
	
public booleanequals(java.lang.Object x, java.lang.Object y)

		if (x == y) return true;
		if (x == null || y == null) return false;
		return x.equals(y);
	
public inthashCode(java.lang.Object x)

		return x.hashCode();
	
public booleanisMutable()

 return false; 
public java.lang.ObjectnullSafeGet(java.sql.ResultSet resultSet, java.lang.String[] names, java.lang.Object owner)


		BigDecimal value = resultSet.getBigDecimal(names[0]);
		if (resultSet.wasNull()) return null;
		String cur = resultSet.getString(names[1]);
		Currency userCurrency = Currency.getInstance(cur);
						
		return new MonetaryAmount(value, userCurrency);
	
public voidnullSafeSet(java.sql.PreparedStatement statement, java.lang.Object value, int index)


		if (value == null) {
			statement.setNull(index, Types.NUMERIC);			
			statement.setNull(index+1, Types.VARCHAR);
		} else {
			MonetaryAmount currency = (MonetaryAmount)value;
			statement.setBigDecimal(index, currency.getValue());
			statement.setString(index+1, currency.getCurrency().getCurrencyCode());
		}
	
public java.lang.Objectreplace(java.lang.Object original, java.lang.Object target, java.lang.Object owner)

		return original;
	
public java.lang.ClassreturnedClass()

 return MonetaryAmount.class; 
public int[]sqlTypes()


	    return SQL_TYPES;