Use multiple connections when querying the query view.

This reduces the query time.
Don't duplicate class/method definitions when building up the source
of the view query function.
Allow sorting of the database query only for a single column.

This is a low cost on flexibility to pay for a much simpler code.
This commit also changes the model api for the query view collection.
Change the way the sorting of the result of the query is done.

Only sort as long as we need to, stop when we reach desired number of rows.
Merge branch 'master' into release-0.27.x