private List doQuery()

in core/src/main/java/org/hibernate/ogm/loader/impl/OgmLoader.java [314:397]


	private List<Object> doQuery(
			SharedSessionContractImplementor session,
			QueryParameters qp,
			OgmLoadingContext ogmLoadingContext,
			boolean returnProxies) {
		//TODO support lock timeout

		int entitySpan = entityPersisters.length;
		final List<Object> hydratedObjects = entitySpan == 0 ? null : new ArrayList<Object>( entitySpan * 10 );
		//TODO yuk! Is there a cleaner way to access the id?
		final Serializable id;
		// see if we use batching first
		// then look for direct id
		// then for a tuple based result set we could extract the id
		// otherwise that's a collection so we use the collection key
		boolean loadSeveralIds = loadSeveralIds( qp );
		boolean isCollectionLoader;
		if ( loadSeveralIds ) {
			// need to be set to null otherwise the optionalId has precedence
			// and is used for all tuples regardless of their actual ids
			id = null;
			isCollectionLoader = false;
		}
		else if ( qp.getOptionalId() != null ) {
			id = qp.getOptionalId();
			isCollectionLoader = false;
		}
		else if ( ogmLoadingContext.hasResultSet() ) {
			// extract the ids from the tuples directly
			id = null;
			isCollectionLoader = false;
		}
		else {
			id = qp.getCollectionKeys()[0];
			isCollectionLoader = true;
		}
		TupleAsMapResultSet resultset = getResultSet( id, qp, ogmLoadingContext, session );

		//Todo implement lockmode
		//final LockMode[] lockModesArray = getLockModes( queryParameters.getLockOptions() );
		//FIXME should we use subselects as it's closer to this process??

		//TODO is resultset a good marker, or should it be an ad-hoc marker??
		//It likely all depends on what resultset ends up being
		handleEmptyCollections( qp.getCollectionKeys(), resultset, session );

		final org.hibernate.engine.spi.EntityKey[] keys = new org.hibernate.engine.spi.EntityKey[entitySpan];

		//for each element in resultset
		//TODO should we collect List<Object> as result? Not necessary today
		Object result = null;
		List<Object> results = new ArrayList<Object>();

		if ( isCollectionLoader ) {
			preLoadBatchFetchingQueue( session, resultset );

		}

		try {
			while ( resultset.next() ) {
				result = getRowFromResultSet(
						resultset,
						session,
						qp,
						ogmLoadingContext,
						//lockmodeArray,
						id,
						hydratedObjects,
						keys,
						returnProxies );
				results.add( result );
			}
			//TODO collect subselect result key
		}
		catch ( SQLException e ) {
			//never happens this is not a regular ResultSet
		}

		//end of for each element in resultset

		initializeEntitiesAndCollections( hydratedObjects, resultset, session, qp.isReadOnly( session ) );
		//TODO create subselects
		return results;
	}