public QueryResult execute ( Query query ) throws QueryEngineException { if ( ! ( query instanceof QueryImpl ) ) { throw new QueryEngineException ( "Couldn't cast Query to QueryImpl." ) ; } QueryImpl q = ( QueryImpl ) query ; // search for unbound results vars resvarsLoop : for ( QueryArgument arg : q . getResultVars ( ) ) { for ( QueryAtomGroup g : q . getAtomGroups ( ) ) { for ( QueryAtom a : g . getAtoms ( ) ) { if ( a . getArguments ( ) . contains ( arg ) ) { continue resvarsLoop ; } } } // throw new QueryEngineException("Query contains an unbound result argument " + arg + "."); } Queue < QueryResultImpl > results = new LinkedList <> ( ) ; for ( QueryAtomGroup g : q . getAtomGroups ( ) ) { QueryAtomGroupImpl group = ( QueryAtomGroupImpl ) g ; List < QueryAtomGroupImpl > components = findComponents ( group ) ; Queue < QueryResultImpl > componentResults = new LinkedList <> ( ) ; boolean groupAsk = true ; for ( QueryAtomGroupImpl component : components ) { QueryAtomGroupImpl preorderedGroup = preorder ( component ) ; QueryResultImpl result = new QueryResultImpl ( query ) ; if ( eval ( q , preorderedGroup , result , new QueryBindingImpl ( ) , BoundChecking . CHECK_BOUND ) ) { if ( query . isSelectDistinct ( ) ) { result = eliminateDuplicates ( result ) ; } componentResults . add ( result ) ; } else { groupAsk = false ; break ; } } if ( groupAsk ) { results . add ( combineResults ( componentResults , query . getType ( ) == SELECT_DISTINCT ) ) ; } else { // return only empty result with no solution for this group QueryResultImpl ret = new QueryResultImpl ( query ) ; ret . setAsk ( false ) ; results . add ( ret ) ; } } return unionResults ( q , results , query . getType ( ) == SELECT_DISTINCT ) ; }
Execute a sparql - dl query and generate the result set .