Added query optimization to GraphSailConnection

I ran into some performance problems when using the Sesame ouplementation and figured out that there was no query optimization.
I added basic query optimization that should speed up query execution in most cases.