Esempio n. 1
0
 internal ArangoQuery(AQLQuery aqlQuery, JsonSerializerSettings jsonSettings, bool isDebug)
 {
     this.jsonSettings = jsonSettings;
     this.isDebug      = isDebug;
     query             = aqlQuery;
     CreatePayload();
 }
Esempio n. 2
0
 internal ArangoQuery(string queryStr, ConnectionPool <IConnection> connectionPool, ArangoDatabase database)
 {
     this.connectionPool = connectionPool;
     this.database       = database;
     query = new AQLQuery()
     {
         Query = queryStr
     };
 }
Esempio n. 3
0
 internal ArangoQuery(string queryStr, JsonSerializerSettings jsonSettings, bool isDebug)
 {
     this.jsonSettings = jsonSettings;
     this.isDebug      = isDebug;
     query             = new AQLQuery()
     {
         Query = queryStr
     };
     CreatePayload();
 }
Esempio n. 4
0
 internal ArangoQuery(string queryStr, Dictionary <string, object> parameters, JsonSerializerSettings jsonSettings, bool isDebug)
 {
     this.jsonSettings = jsonSettings;
     this.isDebug      = isDebug;
     query             = new AQLQuery()
     {
         Query      = queryStr,
         Parameters = parameters
     };
     CreatePayload();
 }
Esempio n. 5
0
 internal ArangoQuery(string queryStr, Dictionary <string, object> parameters,
                      ConnectionPool <IConnection> connectionPool, ArangoDatabase database)
 {
     this.connectionPool = connectionPool;
     this.database       = database;
     query = new AQLQuery()
     {
         Query      = queryStr,
         Parameters = parameters
     };
 }
Esempio n. 6
0
        public List <T> AQLQuery <T>(AQLQuery query) where T : new()
        {
            _logger.LogInformation("Posted Query: {Query}", query.Name);
            string restPath = "/query/aql";
            HttpResponseMessage response = _client.Client.PostAsync(OpenehrConfig.openehrEndpoint + restPath, GetHttpContentQuery(query.ToString())).Result;

            //System.Diagnostics.Debug.Print(response.RequestMessage.ToString());
            if (response.IsSuccessStatusCode)
            {
                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    return(null);
                }
                _logger.LogInformation("Received AQL Result From {Query}", query.Name);
                _logger.LogDebug("AQL Result: {Result}", response.Content.ReadAsStringAsync().Result);
                return(openEHRJSONSerializer <T> .ReceiveModelConstructor(response));
            }
            else
            {
                _logger.LogInformation("NO AQL Result Received {Query}", query.Name);
                _logger.LogDebug("No Success Code: {statusCode} \n {responsePhrase}", response.StatusCode, response.ReasonPhrase);
                return(null);
            }
        }
Esempio n. 7
0
        private AQLQuery BuildFKQuery(ForeignKey fk, Type baseType, dynamic parameters = null)
        {
            var q     = new AQLQuery();
            var parms = new Dictionary <string, object>();
            var sb    = new StringBuilder();
            Dictionary <string, object> dParams = null;

            if (parameters != null)
            {
                dParams = DynamicUtil.DynamicToDict(parameters);
            }


            sb.Append("FOR x1 IN " + DynamicUtil.GetTypeName(baseType));
            // parms.Add("@col", baseType.Name);

            if (fk.IsForeignKey)
            {
                for (var i = 0; i < fk.ForeignKeyTypes.Count; i++)
                {
                    sb.AppendFormat(" LET {0} = ( FOR x IN x1.{1} FOR {0} IN {2} FILTER x == {0}._key RETURN {0}) ",
                                    "a" + i,                                      // {0}
                                    fk.ForeignKeyTypes[i].Key.ToLowerInvariant(), // {1}
                                    fk.ForeignKeyTypes[i].Value.Name);            // {2}
                }
            }

            // check for parameters
            if (dParams != null && dParams.Count > 0)
            {
                var dp = dParams.ToArray();
                for (var i = 0; i < dp.Length; i++)
                {
                    sb.AppendFormat(" FILTER x1.{0} == TO_STRING(@{1}) ", dp[i].Key, "pval" + i);
                    parms.Add("pval" + i, dp[i].Value);
                }
            }

            if (fk.IsForeignKey)
            {
                sb.Append(" RETURN MERGE (x1, {");

                for (var i = 0; i < fk.ForeignKeyTypes.Count; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }

                    sb.AppendFormat("{1}: {0}",                                    // Roles: a1
                                    "a" + i,                                       // {0}
                                    fk.ForeignKeyTypes[i].Key.ToLowerInvariant()); // {2}
                }

                sb.Append(" }) ");
            }
            else
            {
                sb.Append(" RETURN x1 ");
            }

            q.Query = sb.ToString();

            if (parms.Count > 0)
            {
                q.Parameters = parms;
            }

            return(q);
        }
Esempio n. 8
0
 private ArangoQuery <T> Query <T>(AQLQuery query)
 {
     return(new ArangoQuery <T>(query, connectionPool, this));
 }
Esempio n. 9
0
        private AQLQuery BuildFKQuery(ForeignKey fk, string collection, dynamic parameters = null)
        {
            if (fk == null)
            {
                throw new ArgumentNullException(nameof(fk));
            }
            if (string.IsNullOrWhiteSpace(collection))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(collection));
            }

            var q     = new AQLQuery();
            var parms = new Dictionary <string, object>();
            var sb    = new StringBuilder();
            Dictionary <string, object> dParams = null;

            if (parameters != null)
            {
                dParams = DynamicUtil.DynamicToDict(parameters);
            }


            sb.Append($"FOR x1 IN {collection}");

            if (fk.IsForeignKey)
            {
                for (var i = 0; i < fk.ForeignKeyTypes.Count; i++)
                {
                    sb.AppendFormat(" LET {0} = ( FOR x IN x1.{1} FOR {0} IN {2} FILTER x == {0}._key RETURN {0}) ",
                                    "a" + i,                                      // {0}
                                    fk.ForeignKeyTypes[i].Key.ToLowerInvariant(), // {1}
                                    fk.ForeignKeyTypes[i].Value.Name);            // {2}
                }
            }

            // check for parameters
            if (dParams != null && dParams.Count > 0)
            {
                var dp = dParams.ToArray();
                for (var i = 0; i < dp.Length; i++)
                {
                    sb.AppendFormat(" FILTER x1.{0} == TO_STRING(@{1}) ", dp[i].Key, "pval" + i);
                    parms.Add("pval" + i, dp[i].Value);
                }
            }

            if (fk.IsForeignKey)
            {
                sb.Append(" RETURN MERGE (x1, {");

                for (var i = 0; i < fk.ForeignKeyTypes.Count; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }

                    sb.AppendFormat("{1}: {0}",                                    // Roles: a1
                                    "a" + i,                                       // {0}
                                    fk.ForeignKeyTypes[i].Key.ToLowerInvariant()); // {2}
                }

                sb.Append(" }) ");
            }
            else
            {
                sb.Append(" RETURN x1 ");
            }

            q.Query = sb.ToString();

            if (parms.Count > 0)
            {
                q.Parameters = parms;
            }

            return(q);
        }
Esempio n. 10
0
        private async Task <List <T> > Query <T>(AQLQuery query)
        {
            var arangoQuery = new ArangoQuery <T>(query, DatabaseSettings.JsonSettings, DatabaseSettings.IsDebug);

            return(await ExecuteQuery(arangoQuery));
        }
Esempio n. 11
0
 public async Task Execute(AQLQuery query, HttpContext http)
 {
     await http.Response.WriteAsync($"Executing!");
 }
Esempio n. 12
0
 internal ArangoQuery(AQLQuery aqlQuery, ConnectionPool <IConnection> connectionPool, ArangoDatabase database)
 {
     this.connectionPool = connectionPool;
     this.database       = database;
     query = aqlQuery;
 }