FileDocCategorySizeDatePackage
NamedQueryCollectionInitializer.javaAPI DocHibernate 3.2.51709Thu Jun 15 02:50:12 BST 2006org.hibernate.persister.collection

NamedQueryCollectionInitializer

public final class NamedQueryCollectionInitializer extends Object implements org.hibernate.loader.collection.CollectionInitializer
A wrapper around a named query.
author
Gavin King

Fields Summary
private final String
queryName
private final CollectionPersister
persister
private static final Log
log
Constructors Summary
public NamedQueryCollectionInitializer(String queryName, CollectionPersister persister)


	     
		super();
		this.queryName = queryName;
		this.persister = persister;
	
Methods Summary
public voidinitialize(java.io.Serializable key, org.hibernate.engine.SessionImplementor session)

		
		if ( log.isDebugEnabled() ) {
			log.debug(
					"initializing collection: " + 
					persister.getRole() + 
					" using named query: " + 
					queryName 
				);
		}
		
		//TODO: is there a more elegant way than downcasting?
		AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery(queryName); 
		if ( query.getNamedParameters().length>0 ) {
			query.setParameter( 
					query.getNamedParameters()[0], 
					key, 
					persister.getKeyType() 
				);
		}
		else {
			query.setParameter( 0, key, persister.getKeyType() );
		}
		query.setCollectionKey( key )
				.setFlushMode( FlushMode.MANUAL )
				.list();