FileDocCategorySizeDatePackage
WrapVisitor.javaAPI DocHibernate 3.2.54081Fri Jun 17 14:36:08 BST 2005org.hibernate.event.def

WrapVisitor

public class WrapVisitor extends ProxyVisitor
Wrap collections in a Hibernate collection wrapper.
author
Gavin King

Fields Summary
private static final Log
log
boolean
substitute
Constructors Summary
WrapVisitor(org.hibernate.event.EventSource session)

		super(session);
	
Methods Summary
booleanisSubstitutionRequired()


	  
		return substitute;
	
voidprocess(java.lang.Object object, org.hibernate.persister.entity.EntityPersister persister)

		EntityMode entityMode = getSession().getEntityMode();
		Object[] values = persister.getPropertyValues( object, entityMode );
		Type[] types = persister.getPropertyTypes();
		processEntityPropertyValues(values, types);
		if ( isSubstitutionRequired() ) {
			persister.setPropertyValues( object, values, entityMode );
		}
	
final java.lang.ObjectprocessArrayOrNewCollection(java.lang.Object collection, org.hibernate.type.CollectionType collectionType)


		final SessionImplementor session = getSession();

		if (collection==null) {
			//do nothing
			return null;
		}
		else {
			CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() );

			final PersistenceContext persistenceContext = session.getPersistenceContext();
			//TODO: move into collection type, so we can use polymorphism!
			if ( collectionType.hasHolder( session.getEntityMode() ) ) {
				
				if (collection==CollectionType.UNFETCHED_COLLECTION) return null;

				PersistentCollection ah = persistenceContext.getCollectionHolder(collection);
				if (ah==null) {
					ah = collectionType.wrap(session, collection);
					persistenceContext.addNewCollection( persister, ah );
					persistenceContext.addCollectionHolder(ah);
				}
				return null;
			}
			else {

				PersistentCollection persistentCollection = collectionType.wrap(session, collection);
				persistenceContext.addNewCollection( persister, persistentCollection );

				if ( log.isTraceEnabled() ) log.trace( "Wrapped collection in role: " + collectionType.getRole() );

				return persistentCollection; //Force a substitution!

			}

		}

	
java.lang.ObjectprocessCollection(java.lang.Object collection, org.hibernate.type.CollectionType collectionType)


		if ( collection!=null && (collection instanceof PersistentCollection) ) {

			final SessionImplementor session = getSession();
			PersistentCollection coll = (PersistentCollection) collection;
			if ( coll.setCurrentSession(session) ) {
				reattachCollection( coll, collectionType );
			}
			return null;

		}
		else {
			return processArrayOrNewCollection(collection, collectionType);
		}

	
java.lang.ObjectprocessComponent(java.lang.Object component, org.hibernate.type.AbstractComponentType componentType)


		if (component!=null) {
			Object[] values = componentType.getPropertyValues( component, getSession() );
			Type[] types = componentType.getSubtypes();
			boolean substituteComponent = false;
			for ( int i=0; i<types.length; i++ ) {
				Object result = processValue( values[i], types[i] );
				if (result!=null) {
					values[i] = result;
					substituteComponent = true;
				}
			}
			if (substituteComponent) {
				componentType.setPropertyValues( component, values, getSession().getEntityMode() );
			}
		}

		return null;
	
voidprocessValue(int i, java.lang.Object[] values, org.hibernate.type.Type[] types)

		Object result = processValue( values[i], types[i] );
		if (result!=null) {
			substitute = true;
			values[i] = result;
		}