FileDocCategorySizeDatePackage
SerializableType.javaAPI DocHibernate 3.2.52925Wed Nov 15 22:12:20 GMT 2006org.hibernate.type

SerializableType

public class SerializableType extends MutableType
serializable: A type that maps an SQL VARBINARY to a serializable Java object.
author
Gavin King

Fields Summary
private final Class
serializableClass
Constructors Summary
public SerializableType(Class serializableClass)

		this.serializableClass = serializableClass;
	
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return (cached==null) ? null : fromBytes( (byte[]) cached );
	
public java.lang.ObjectdeepCopyNotNull(java.lang.Object value)

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

		return (value==null) ? null : toBytes(value);
	
private static java.lang.ObjectfromBytes(byte[] bytes)

		return SerializationHelper.deserialize(bytes);
	
public java.lang.ObjectfromStringValue(java.lang.String xml)

		return fromBytes( (byte[]) Hibernate.BINARY.fromStringValue(xml) );
	
public java.lang.Objectget(java.sql.ResultSet rs, java.lang.String name)

		byte[] bytes = (byte[]) Hibernate.BINARY.get(rs, name);
		// Some JDBC drivers erroneously return an empty array here for a null DB value :/
		if ( bytes == null || bytes.length == 0 ) {
			return null;
		}
		else {
			return fromBytes(bytes);
		}
	
public intgetHashCode(java.lang.Object x, org.hibernate.EntityMode entityMode)

		return Hibernate.BINARY.getHashCode( toBytes(x), entityMode );
	
public java.lang.StringgetName()

		return (serializableClass==Serializable.class) ? "serializable" : serializableClass.getName();
	
public java.lang.ClassgetReturnedClass()

		return serializableClass;
	
public booleanisEqual(java.lang.Object x, java.lang.Object y)

		if ( x == y ) {
			return true;
		}
		if ( x == null || y == null ) {
			return false;
		}
		return x.equals( y ) || Hibernate.BINARY.isEqual( toBytes( x ), toBytes( y ) );
	
public voidset(java.sql.PreparedStatement st, java.lang.Object value, int index)

		Hibernate.BINARY.set(st, toBytes(value), index);
	
public intsqlType()

		return Hibernate.BINARY.sqlType();
	
private static byte[]toBytes(java.lang.Object object)

		return SerializationHelper.serialize( (Serializable) object );
	
public java.lang.StringtoString(java.lang.Object value)

		return Hibernate.BINARY.toString( toBytes(value) );