internal static IRacoonResponse CreateResponse(ParameterTypeEnum returnWanted) { if (returnWanted.HasFlag(ParameterTypeEnum.Multivalue)) { return(new MultiVariableResponse()); //it matters not what the sub type is here } //it;s a single parameter type switch (returnWanted) { case ParameterTypeEnum.String: return(new ExecuteQueryResponse()); case ParameterTypeEnum.ByteArray: return(new ExecuteQueryBytesResponse()); case ParameterTypeEnum.NoExtraData: return(new SimpleRacoonResponse()); } return(null); }
/// <summary> /// This executes the saved SPARQL against the passed server and with the passed parameters /// </summary> /// <param name="parameters">Parameters to pass on to the SPARQL query. Can be any of the types that extend MiddlewareParameter</param> /// <param name="session">This holds server details, including username and password</param> /// <returns></returns> public IEnumerable <MiddlewareParameter> ExecuteSelect(IEnumerable <MiddlewareParameter> parameters, Session session, ParameterTypeEnum returnTypeWanted) { StardogConnector theConnector = getConnector(session); SparqlParameterizedString query = getQuery(parameters, sparql); try { IEnumerable <SparqlResult> queryResult = theConnector.Query(query.ToString()) as SparqlResultSet;//actually fire the query if (queryResult.Count <SparqlResult>() == 0) { return(Enumerable.Empty <MiddlewareParameter>());//Don't do unnecessary processing, but returning null causes crashes further up } List <MiddlewareParameter> Result = new List <MiddlewareParameter>(); bool linkParams = returnTypeWanted.HasFlag(ParameterTypeEnum.Multivalue); //I stay null if not doing multivalue requests MiddlewareParameter <List <MiddlewareParameter> > multiValue = null; int lineNumber = 1; foreach (SparqlResult res in queryResult)//for each line { if (linkParams) { multiValue = new MiddlewareParameter <List <MiddlewareParameter> >(MiddlewareParameterDirection.Out); multiValue.ParamName = lineNumber++.ToString(); multiValue.ParamValue = new List <MiddlewareParameter>(); returnTypeWanted &= ~ParameterTypeEnum.Multivalue; //The effect of this is allowing us to switch on the return type wanted } foreach (KeyValuePair <string, INode> parameterValue in res) //each parameter { if (linkParams) { handleLanguageTags(multiValue, parameterValue); } MiddlewareParameter toAdd = null; switch (returnTypeWanted) { case ParameterTypeEnum.AsSource: toAdd = createAsPerSourceType(parameterValue); break; case ParameterTypeEnum.String: toAdd = createStringParameter(parameterValue); break; case ParameterTypeEnum.ByteArray: toAdd = createByteParameter(parameterValue); break; case ParameterTypeEnum.Uri: toAdd = createUriParameter(parameterValue); break; default: throw new ArgumentException("Invalid return parameter type specified"); } if ((toAdd != null) && (!linkParams)) { Result.Add(toAdd); } else if (linkParams) { multiValue.ParamValue.Add(toAdd); } } if (linkParams) { Result.Add(multiValue); } } return(Result); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(query.CommandText); throw ex; } }