FileDocCategorySizeDatePackage
CustomType.javaAPI DocHibernate 3.2.56379Wed Jul 05 10:03:52 BST 2006org.hibernate.type

CustomType

public class CustomType extends AbstractType implements DiscriminatorType, IdentifierType, VersionType
Adapts {@link UserType} to the generic {@link Type} interface, in order to isolate user code from changes in the internal Type contracts.
see
org.hibernate.usertype.UserType
author
Gavin King

Fields Summary
private final org.hibernate.usertype.UserType
userType
private final String
name
private final int[]
types
private final boolean
customLogging
Constructors Summary
public CustomType(Class userTypeClass, Properties parameters)


		if ( !UserType.class.isAssignableFrom( userTypeClass ) ) {
			throw new MappingException(
					"Custom type does not implement UserType: " +
					userTypeClass.getName()
				);
		}

		name = userTypeClass.getName();

		try {
			userType = ( UserType ) userTypeClass.newInstance();
		}
		catch ( InstantiationException ie ) {
			throw new MappingException(
					"Cannot instantiate custom type: " +
					userTypeClass.getName()
				);
		}
		catch ( IllegalAccessException iae ) {
			throw new MappingException(
					"IllegalAccessException trying to instantiate custom type: " +
					userTypeClass.getName()
				);
		}

        TypeFactory.injectParameters( userType, parameters );
		types = userType.sqlTypes();

		customLogging = LoggableUserType.class.isAssignableFrom( userTypeClass );
	
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return userType.assemble(cached, owner);
	
public java.lang.ObjectdeepCopy(java.lang.Object value, org.hibernate.EntityMode entityMode, org.hibernate.engine.SessionFactoryImplementor factory)

		return userType.deepCopy(value);
	
public java.io.Serializabledisassemble(java.lang.Object value, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return userType.disassemble(value);
	
public java.lang.ObjectfromXMLNode(org.dom4j.Node xml, org.hibernate.engine.Mapping factory)

		return fromXMLString( xml.getText(), factory );
	
public java.lang.ObjectfromXMLString(java.lang.String xml, org.hibernate.engine.Mapping factory)

		return ( (EnhancedUserType) userType ).fromXMLString(xml);
	
public intgetColumnSpan(org.hibernate.engine.Mapping session)

		return types.length;
	
public java.util.ComparatorgetComparator()

		return (Comparator) userType;
	
public intgetHashCode(java.lang.Object x, org.hibernate.EntityMode entityMode)

		return userType.hashCode(x);
	
public java.lang.StringgetName()

		return name;
	
public java.lang.ClassgetReturnedClass()

		return userType.returnedClass();
	
public booleanisDirty(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.SessionImplementor session)

		return checkable[0] && isDirty(old, current, session);
	
public booleanisEqual(java.lang.Object x, java.lang.Object y)

		return userType.equals(x, y);
	
public booleanisEqual(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode)

		return isEqual(x, y);
	
public booleanisMutable()

		return userType.isMutable();
	
public java.lang.Objectnext(java.lang.Object current, org.hibernate.engine.SessionImplementor session)

		return ( (UserVersionType) userType ).next( current, session );
	
public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)


		return userType.nullSafeGet(rs, names, owner);
	
public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String columnName, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return nullSafeGet(rs, new String[] { columnName }, session, owner);
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.SessionImplementor session)


		if ( settable[0] ) userType.nullSafeSet(st, value, index);
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.SessionImplementor session)


		userType.nullSafeSet(st, value, index);
	
public java.lang.StringobjectToSQLString(java.lang.Object value, org.hibernate.dialect.Dialect dialect)

		return ( (EnhancedUserType) userType ).objectToSQLString(value);
	
public java.lang.Objectreplace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.SessionImplementor session, java.lang.Object owner, java.util.Map copyCache)

		return userType.replace(original, target, owner);
	
public java.lang.Objectseed(org.hibernate.engine.SessionImplementor session)

		return ( (UserVersionType) userType ).seed( session );
	
public voidsetToXMLNode(org.dom4j.Node node, java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		node.setText( toXMLString(value, factory) );
	
public int[]sqlTypes(org.hibernate.engine.Mapping pi)

		return types;
	
public java.lang.ObjectstringToObject(java.lang.String xml)

		return ( (EnhancedUserType) userType ).fromXMLString(xml);
	
public boolean[]toColumnNullness(java.lang.Object value, org.hibernate.engine.Mapping mapping)

		boolean[] result = new boolean[ getColumnSpan(mapping) ];
		if (value!=null) Arrays.fill(result, true);
		return result;
	
public java.lang.StringtoLoggableString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		if ( value == null ) {
			return "null";
		}
		else if ( customLogging ) {
			return ( ( LoggableUserType ) userType ).toLoggableString( value, factory );
		}
		else {
			return toXMLString( value, factory );
		}
	
public java.lang.StringtoXMLString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		if (value==null) return null;
		if (userType instanceof EnhancedUserType) {
			return ( (EnhancedUserType) userType ).toXMLString(value);
		}
		else {
			return value.toString();
		}