//$Id: CustomLoader.java,v 1.6 2005/05/19 22:38:08 oneovthafew Exp $ package org.hibernate.loader.custom; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.QueryException; import org.hibernate.ScrollableResults; import org.hibernate.engine.QueryParameters; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.TypedValue; import org.hibernate.loader.CollectionAliases; import org.hibernate.loader.EntityAliases; import org.hibernate.loader.Loader; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.Loadable; import org.hibernate.type.Type; import org.hibernate.type.TypeFactory; import org.hibernate.util.ArrayHelper; /** * Extension point for loaders which use a SQL * result set with "unexpected" column aliases. * * @author Gavin King */ public class CustomLoader extends Loader { private final Type[] resultTypes; private final Loadable[] persisters; private final CollectionPersister[] collectionPersisters; private final CustomQuery customQuery; /** * hc: Returns true if the query actually returns no result; false otherwise. * A query with no result is indicated by specifying a scaler alias of "null". * An example is a native SQL for bulk insertion. */ public boolean hasNoResult() { String[] a = customQuery.getScalarColumnAliases(); return a.length == 1 && "null".equals(a[0]); } public CustomLoader( CustomQuery customQuery, SessionFactoryImplementor factory ) { super(factory); this.customQuery = customQuery; String[] collectionRoles = customQuery.getCollectionRoles(); if ( collectionRoles==null ) { collectionPersisters = null; } else { int length = collectionRoles.length; collectionPersisters = new CollectionPersister[length]; for ( int i=0; i0 ) { //all scalar results appear first resultRow = new Object[scalarTypes.length + row.length]; for ( int i=0; i