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

AnyType

public class AnyType extends AbstractType implements AbstractComponentType, AssociationType
Handles "any" mappings and the old deprecated "object" type
author
Gavin King

Fields Summary
private final Type
identifierType
private final Type
metaType
private static final String[]
PROPERTY_NAMES
Constructors Summary
public AnyType(Type metaType, Type identifierType)

		this.identifierType = identifierType;
		this.metaType = metaType;
	
public AnyType()

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


		ObjectTypeCacheEntry e = (ObjectTypeCacheEntry) cached;
		return e==null ? null : session.internalLoad(e.entityName, e.id, false, false);
	
public intcompare(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode)

		return 0; //TODO: entities CAN be compared, by PK and entity name, fix this!
	
public java.lang.ObjectdeepCopy(java.lang.Object value, org.hibernate.EntityMode entityMode, org.hibernate.engine.SessionFactoryImplementor factory)

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

		return value==null ?
			null :
			new ObjectTypeCacheEntry(
						session.bestGuessEntityName(value),
						ForeignKeys.getEntityIdentifierIfNotUnsaved( 
								session.bestGuessEntityName(value), value, session 
							)
					);
	
public java.lang.ObjectfromXMLNode(org.dom4j.Node xml, org.hibernate.engine.Mapping factory)

		throw new UnsupportedOperationException(); //TODO: is this right??
	
public java.lang.StringgetAssociatedEntityName(org.hibernate.engine.SessionFactoryImplementor factory)

		throw new UnsupportedOperationException("any types do not have a unique referenced persister");
	
public org.hibernate.persister.entity.JoinablegetAssociatedJoinable(org.hibernate.engine.SessionFactoryImplementor factory)

		throw new UnsupportedOperationException("any types do not have a unique referenced persister");
	
public org.hibernate.engine.CascadeStylegetCascadeStyle(int i)

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

		return 2;
	
public org.hibernate.FetchModegetFetchMode(int i)

		return FetchMode.SELECT;
	
public ForeignKeyDirectiongetForeignKeyDirection()

		//return AssociationType.FOREIGN_KEY_TO_PARENT; //this is better but causes a transient object exception...
		return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
	
private java.io.SerializablegetIdentifier(java.lang.Object value, org.hibernate.engine.SessionImplementor session)

		try {
			return ForeignKeys.getEntityIdentifierIfNotUnsaved( session.bestGuessEntityName(value), value, session );
		}
		catch (TransientObjectException toe) {
			return null;
		}
	
public java.lang.StringgetLHSPropertyName()

		return null;
	
public java.lang.StringgetName()

		return "object";
	
public java.lang.StringgetOnCondition(java.lang.String alias, org.hibernate.engine.SessionFactoryImplementor factory, java.util.Map enabledFilters)

		throw new UnsupportedOperationException();
	
public java.lang.String[]getPropertyNames()


	   
		return PROPERTY_NAMES;
	
public boolean[]getPropertyNullability()

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


		return i==0 ?
				session.bestGuessEntityName(component) :
				getIdentifier(component, session);
	
public java.lang.Object[]getPropertyValues(java.lang.Object component, org.hibernate.engine.SessionImplementor session)


		return new Object[] { session.bestGuessEntityName(component), getIdentifier(component, session) };
	
public java.lang.Object[]getPropertyValues(java.lang.Object component, org.hibernate.EntityMode entityMode)

		throw new UnsupportedOperationException();
	
public java.lang.StringgetRHSUniqueKeyPropertyName()

		return null;
	
public java.lang.ClassgetReturnedClass()

		return Object.class;
	
public Type[]getSubtypes()

		return new Type[] { metaType, identifierType };
	
public java.lang.Objecthydrate(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		String entityName = (String) metaType.nullSafeGet(rs, names[0], session, owner);
		Serializable id = (Serializable) identifierType.nullSafeGet(rs, names[1], session, owner);
		return new ObjectTypeCacheEntry(entityName, id);
	
public booleanisAlwaysDirtyChecked()

		return false;
	
public booleanisAnyType()

		return true;
	
public booleanisAssociationType()

		return true;
	
public booleanisComponentType()

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

		//TODO!!!
		return isDirty(old, current, session);
	
public booleanisEmbedded()

		return false;
	
public booleanisEmbeddedInXML()

		return false;
	
public booleanisMethodOf(java.lang.reflect.Method method)

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

		if (current==null) return old!=null;
		if (old==null) return current!=null;
		ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) old;
		boolean[] idcheckable = new boolean[checkable.length-1];
		System.arraycopy(checkable, 1, idcheckable, 0, idcheckable.length);
		return ( checkable[0] && !holder.entityName.equals( session.bestGuessEntityName(current) ) ) ||
				identifierType.isModified(holder.id, getIdentifier(current, session), idcheckable, session);
	
public booleanisMutable()

		return false;
	
public booleanisReferenceToPrimaryKey()

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

		return x==y;
	
public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String name, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)


		throw new UnsupportedOperationException("object is a multicolumn type");
	
public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		return resolveAny(
				(String) metaType.nullSafeGet(rs, names[0], session, owner),
				(Serializable) identifierType.nullSafeGet(rs, names[1], session, owner),
				session
			);
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.SessionImplementor session)

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


		Serializable id;
		String entityName;
		if (value==null) {
			id=null;
			entityName=null;
		}
		else {
			entityName = session.bestGuessEntityName(value);
			id = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, value, session);
		}
		
		// metaType is assumed to be single-column type
		if ( settable==null || settable[0] ) {
			metaType.nullSafeSet(st, entityName, index, session);
		}
		if (settable==null) {
			identifierType.nullSafeSet(st, id, index+1, session);
		}
		else {
			boolean[] idsettable = new boolean[ settable.length-1 ];
			System.arraycopy(settable, 1, idsettable, 0, idsettable.length);
			identifierType.nullSafeSet(st, id, index+1, idsettable, 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)

		if (original==null) {
			return null;
		}
		else {
			String entityName = session.bestGuessEntityName(original);
			Serializable id = ForeignKeys.getEntityIdentifierIfNotUnsaved( 
					entityName, 
					original, 
					session 
				);
			return session.internalLoad( 
					entityName, 
					id, 
					false, 
					false
				);
		}
	
public java.lang.Objectresolve(java.lang.Object value, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) value;
		return resolveAny(holder.entityName, holder.id, session);
	
private java.lang.ObjectresolveAny(java.lang.String entityName, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)

		return entityName==null || id==null ?
				null : session.internalLoad( entityName, id, false, false );
	
public java.lang.ObjectsemiResolve(java.lang.Object value, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		throw new UnsupportedOperationException("any mappings may not form part of a property-ref");
	
public voidsetPropertyValues(java.lang.Object component, java.lang.Object[] values, org.hibernate.EntityMode entityMode)


		throw new UnsupportedOperationException();

	
public voidsetToXMLNode(org.dom4j.Node xml, java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)

		throw new UnsupportedOperationException("any types cannot be stringified");
	
public int[]sqlTypes(org.hibernate.engine.Mapping mapping)

		return ArrayHelper.join(
				metaType.sqlTypes(mapping),
				identifierType.sqlTypes(mapping)
			);
	
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)

		//TODO: terrible implementation!
		return value==null ?
				"null" :
				Hibernate.entity( HibernateProxyHelper.getClassWithoutInitializingProxy(value) )
						.toLoggableString(value, factory);
	
public booleanuseLHSPrimaryKey()

		return false;