@ SuppressWarnings ( { "unchecked" } ) private static SelectResults < Object > formatSelectResults ( List < List < Object > > queryResults , int limit ) { List < Object > list = new ArrayList < Object > ( ) ; ObjectType baseElementType = null ; for ( List < Object > queryResult : queryResults ) { ObjectType elementType = ( ObjectType ) queryResult . remove ( queryResult . size ( ) - 1 ) ; if ( baseElementType == null ) { baseElementType = elementType ; } else if ( ! baseElementType . equals ( elementType ) ) { throw new IllegalStateException ( "Collection types for query result are different." ) ; } list . addAll ( queryResult ) ; if ( limit != - 1 && list . size ( ) >= limit ) { break ; } } return limit == - 1 ? new ResultsCollectionWrapper ( baseElementType , list ) : new ResultsCollectionWrapper ( baseElementType , list , limit ) ; }
Collects and formats query results into SelectResults . Limits query results based on limit value .