FileDocCategorySizeDatePackage
CompositeCustomType.javaAPI DocHibernate 3.2.57132Fri Jul 29 00:36:14 BST 2005org.hibernate.type

CompositeCustomType

public class CompositeCustomType extends AbstractType implements AbstractComponentType
Adapts CompositeUserType to Type interface
author
Gavin King

Fields Summary
private final org.hibernate.usertype.CompositeUserType
userType
private final String
name
Constructors Summary
public CompositeCustomType(Class userTypeClass, Properties parameters)

		name = userTypeClass.getName();

		if ( !CompositeUserType.class.isAssignableFrom(userTypeClass) ) {
			throw new MappingException( 
					"Custom type does not implement CompositeUserType: " + 
					userTypeClass.getName() 
				);
		}
		
		try {
			userType = (CompositeUserType) 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);
	
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)


		return userType.assemble(cached, session, 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, session);
	
public java.lang.ObjectfromXMLNode(org.dom4j.Node xml, org.hibernate.engine.Mapping factory)

		return xml;
	
public org.hibernate.engine.CascadeStylegetCascadeStyle(int i)

		return CascadeStyle.NONE;
	
public intgetColumnSpan(org.hibernate.engine.Mapping mapping)

		Type[] types = userType.getPropertyTypes();
		int n=0;
		for (int i=0; i<types.length; i++) {
			n+=types[i].getColumnSpan(mapping);
		}
		return n;
	
public org.hibernate.FetchModegetFetchMode(int i)

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

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

		return name;
	
public java.lang.String[]getPropertyNames()

		return userType.getPropertyNames();
	
public boolean[]getPropertyNullability()

		return null;
	
public java.lang.ObjectgetPropertyValue(java.lang.Object component, int i, org.hibernate.engine.SessionImplementor session)

		return getPropertyValue(component, i);
	
public java.lang.ObjectgetPropertyValue(java.lang.Object component, int i)

		return userType.getPropertyValue(component, i);
	
public java.lang.Object[]getPropertyValues(java.lang.Object component, org.hibernate.engine.SessionImplementor session)

		return getPropertyValues( component, session.getEntityMode() );
	
public java.lang.Object[]getPropertyValues(java.lang.Object component, org.hibernate.EntityMode entityMode)


		int len = getSubtypes().length;
		Object[] result = new Object[len];
		for ( int i=0; i<len; i++ ) {
			result[i] = getPropertyValue(component, i);
		}
		return result;
	
public java.lang.ClassgetReturnedClass()

		return userType.returnedClass();
	
public Type[]getSubtypes()

		return userType.getPropertyTypes();
	
public booleanisComponentType()

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

		return isDirty(old, current, session);
	
public booleanisEmbedded()

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

		return userType.equals(x, y);
	
public booleanisMethodOf(java.lang.reflect.Method method)

		return false;
	
public booleanisMutable()

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


		return userType.nullSafeGet(rs, new String[] {columnName}, session, owner);
	
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, session, owner);
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.SessionImplementor session)


		userType.nullSafeSet(st, value, index, session);

	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.SessionImplementor session)


		userType.nullSafeSet(st, value, index, session);

	
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, session, owner);
	
public voidsetPropertyValues(java.lang.Object component, java.lang.Object[] values, org.hibernate.EntityMode entityMode)


		for (int i=0; i<values.length; i++) {
			userType.setPropertyValue( component, i, values[i] );
		}
	
public voidsetToXMLNode(org.dom4j.Node node, java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		replaceNode( node, (Element) value );
	
public int[]sqlTypes(org.hibernate.engine.Mapping mapping)

		Type[] types = userType.getPropertyTypes();
		int[] result = new int[ getColumnSpan(mapping) ];
		int n=0;
		for (int i=0; i<types.length; i++) {
			int[] sqlTypes = types[i].sqlTypes(mapping);
			for ( int k=0; k<sqlTypes.length; k++ ) result[n++] = sqlTypes[k];
		}
		return result;
	
public boolean[]toColumnNullness(java.lang.Object value, org.hibernate.engine.Mapping mapping)

		boolean[] result = new boolean[ getColumnSpan(mapping) ];
		if (value==null) return result;
		Object[] values = getPropertyValues(value, EntityMode.POJO); //TODO!!!!!!!
		int loc = 0;
		Type[] propertyTypes = getSubtypes();
		for ( int i=0; i<propertyTypes.length; i++ ) {
			boolean[] propertyNullness = propertyTypes[i].toColumnNullness( values[i], mapping );
			System.arraycopy(propertyNullness, 0, result, loc, propertyNullness.length);
			loc += propertyNullness.length;
		}
		return result;
	
public java.lang.StringtoLoggableString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)


		return value==null ? "null" : value.toString();