Ejemplo n.º 1
0
        private string GetInnerQuery()
        {
            string ret             = string.Empty;
            var    originalColumns = InnerQuery.GetSelectColumns();

            InnerQuery.SetSelectColumns(uniqueRegister);
            ret = InnerQuery.BuildSelect();
            InnerQuery.SetSelectColumns(originalColumns);

            return(ret);
        }
Ejemplo n.º 2
0
        private TranslatedQuery VisitInner(IExpression expression)
        {
            InnerQuery query = new InnerQuery();

            StringVisitor visitor = new StringVisitor(query);

            visitor.Visite(expression);
            //combine the order expressions.
            this.OrderFields.AddRange(visitor.OrderFields);

            return(query);
        }
Ejemplo n.º 3
0
        // no statement building
#else
        //
        // SQL Statement
        //

        #region public override bool BuildStatement(DBStatementBuilder builder)

        public override bool BuildStatement(DBStatementBuilder builder, bool isInorNot = false)
        {
            InnerQuery.BuildStatement(builder);

            if (string.IsNullOrEmpty(this.Alias) == false)
            {
                builder.WriteSubQueryAlias(this.Alias);
            }

            if (this.HasJoins)
            {
                this.Joins.BuildStatement(builder);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private static void WriteSourcedVariable(StringBuilder sb, InnerQuery query, InnerSource innerSource, Variable variable)
        {
            if (query.NamingProvider.TryGetSourceName(innerSource, out var innerSourceName))
            {
                sb.Append(innerSourceName);
                sb.Append(".");

                if (innerSource.NamingProvider.TryGetVariableName(variable, out var variableName))
                {
                    sb.Append(variableName);
                }
                else
                {
                    throw new InvalidOperationException("Cannot find name for a variable from source");
                }
            }
            else
            {
                throw new InvalidOperationException("Cannot find name for an existing variable source");
            }
        }
Ejemplo n.º 5
0
 private static void WriteVariable(StringBuilder sb, InnerQuery query, Variable variable)
 {
     if (query.NamingProvider.TryGetSource(variable, out var innerSource))
     {
         WriteSourcedVariable(sb, query, innerSource, variable);
     }
     else
     {
         if (variable.IsAssigned)
         {
             var assignedVariable = ((Variable.Assigned)variable).Item;
             var assignment       = query.Assignments.Single(x => x.Variable == assignedVariable);
             WriteExpression(sb, query, assignment.Expression);
         }
         else
         {
             throw new InvalidOperationException(
                       $"Variable {variable} has not been found in any source and still, it is not assigned.");
         }
     }
 }
Ejemplo n.º 6
0
        private TranslatedQuery VisitInner(IExpression expression)
        {
            InnerQuery query = new InnerQuery();

            StringVisitor visitor = new StringVisitor(query);
            visitor.Visite(expression);
            //combine the order expressions.
            this.OrderFields.AddRange(visitor.OrderFields);

            return query;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  Return a set of queries to find relations between two objects.
        /// </summary>
        /// <param name="object1">First object</param>
        /// <param name="object2">Second object</param>
        /// <param name="maxDistance"> maxDistance The maximum distance up to which we want to search</param>
        /// <param name="limit">limit The maximum number of results per SPARQL query (=LIMIT).</param>
        /// <param name="ignoredObjects">Objects which should not be part of the returned connections between the first and second object</param>
        /// <param name="ignoredProperties">Properties which should not be part of the returned connections between the first and second object</param>
        /// <param name="avoidCycles">Integer value which indicates whether we want to suppress cycles , 0 = no cycle avoidance ,  1 = no intermediate object can be object1 or object2 ,   2 = like 1 + an object can not occur more than once in a connection </param>
        /// <returns>A two dimensional array of the form $array[$distance][$queries]</returns>
        private Dictionary<int, List<InnerQuery>> getQueries(string object1, string object2, int maxDistance, int limit, List<string> ignoredObjects = null, List<string> ignoredProperties = null, int avoidCycles = 0)
        {
            Dictionary<int, List<InnerQuery>> queries = new Dictionary<int, List<InnerQuery>>();
            Dictionary<string, List<string>> options = new Dictionary<string, List<string>>();

            //May generate null
            options["object1"] = stringToLoist(object1);
            options["object2"] = stringToLoist(object2);
            options["limit"] = stringToLoist(limit.ToString());
            options["ignoredObjects"] = ignoredObjects;
            options["ignoredProperties"] = ignoredProperties;
            options["avoidCycles"] = stringToLoist(avoidCycles.ToString());

            for (int distance = 1; distance <= maxDistance; distance++)
            {
                // get direct connection in both directions
                //queries[distance] = new ArrayCollection();
                //(queries[distance] as ArrayCollection).addItem(new Array(direct(object1, object2, distance, options), connectedDirectly));
                //(queries[distance] as ArrayCollection).addItem(new Array(direct(object2, object1, distance, options), connectedDirectlyInverted));
                //we substitiued ArrayCollection with a list and passed the list to the dictionary
                var tempList = new List<InnerQuery>();
                var tempInnerQuery = new InnerQuery();
                tempInnerQuery.queryText = direct(object1, object2, distance, options);
                tempInnerQuery.connectState = connectedDirectly;
                tempList.Add(tempInnerQuery);

                tempInnerQuery = new InnerQuery();
                tempInnerQuery.queryText = direct(object2, object1, distance, options);
                tempInnerQuery.connectState = connectedDirectlyInverted;
                tempList.Add(tempInnerQuery);

                //queries.Add(distance, tempList);
                //ended substitution

                for (int a = 1; a <= distance; a++)
                {
                    for (int b = 1; b <= distance; b++)
                    {
                        if ((a + b) == distance)
                        {

                            //(queries[distance] as ArrayCollection).addItem(new Array(connectedViaAMiddleObject(object1, object2, a, b, true,  options), connectedViaMiddle));
                            //tempList = new List<InnerQuery>();
                            tempInnerQuery = new InnerQuery();
                            tempInnerQuery.queryText = connectedViaAMiddleObject(object1, object2, a, b, true, options);
                            tempInnerQuery.connectState = connectedViaMiddle;
                            tempList.Add(tempInnerQuery);

                            tempInnerQuery = new InnerQuery();
                            tempInnerQuery.queryText = connectedViaAMiddleObject(object1, object2, a, b, false, options);
                            tempInnerQuery.connectState = connectedViaMiddleInverted;
                            tempList.Add(tempInnerQuery);

                            //(queries[distance] as ArrayCollection).addItem(new Array(connectedViaAMiddleObject(object1, object2, a, b, false, options), connectedViaMiddleInverted));
                        }
                    }
                }
                queries.Add(distance, tempList);
                //substitution of the above code:

            }
            return queries;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// IQueryable string presentation.
 /// </summary>
 public override string ToString() => InnerQuery.ToString();
Ejemplo n.º 9
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(InnerQuery.GetEnumerator());
 }
Ejemplo n.º 10
0
 public IEnumerator <T> GetEnumerator()
 {
     return(InnerQuery.GetEnumerator());
 }
Ejemplo n.º 11
0
 public override string ToString()
 {
     return(InnerQuery.ToString());
 }
Ejemplo n.º 12
0
 public IQueryable <T> Include(string path)
 {
     return(InnerQuery.Include(path).AsExpandable());
 }
Ejemplo n.º 13
0
 public IQueryable <T> Include <TProperty>(Expression <Func <T, TProperty> > navigationPropertyPath)
 {
     return(((IQueryable <T>)InnerQuery.Include(navigationPropertyPath)).AsExpandable());
 }
 public IQueryable <T> Include <TProperty>(Expression <Func <T, TProperty> > navigationPropertyPath)
 {
     return(InnerQuery.Include(navigationPropertyPath).AsVisitable(Visitors));
 }
Ejemplo n.º 15
0
 public IQueryable <T> Include(string path)
 {
     return(InnerQuery.Include(path).AsCustomMappingCompatible());
 }
Ejemplo n.º 16
0
        private static void WriteCondition(StringBuilder sb, InnerQuery query, TypedCondition condition)
        {
            var writer = new MsSqlExpressionWriter(sb, (x, variable) => WriteVariable(x, query, variable));

            SqlDatabaseWriterHelper.ProcessCondition(writer, condition);
        }
Ejemplo n.º 17
0
        private void WriteInnerSelectQueryContent(StringBuilder sb, InnerQuery query, List <string> variables, Dictionary <string, List <Variable> > variablesMappings)
        {
            var isFirstVariable = true;

            foreach (var variableName in variables)
            {
                if (isFirstVariable)
                {
                    sb.Append(" ");
                    isFirstVariable = false;
                }
                else
                {
                    sb.Append(", ");
                }

                var providedVariables = variablesMappings.GetOrDefault(variableName, new List <Variable>())
                                        .Where(var => query.ProvidedVariables.Contains(var))
                                        .ToList();

                if (providedVariables.Count > 1)
                {
                    throw new InvalidOperationException($"There are more provided variables for name {variableName}");
                }
                else if (providedVariables.Count == 1)
                {
                    var variable = providedVariables[0];
                    WriteVariable(sb, query, variable);
                }
                else
                {
                    WriteExpression(sb, query, new TypedExpression(_databaseSchema.NullType, _databaseSchema.NullType, TypedExpressionContent.Null));
                }

                sb.Append(" AS ");
                sb.Append(variableName);
            }

            sb.Append(" FROM");

            var isFirstSource = true;

            foreach (var innerSource in query.Sources)
            {
                sb.Append(!isFirstSource ? " INNER JOIN " : " ");

                WriteInnerSource(sb, innerSource);

                sb.Append(" AS ");

                if (query.NamingProvider.TryGetSourceName(innerSource, out var sourceName))
                {
                    sb.Append(sourceName);
                }
                else
                {
                    throw new InvalidOperationException($"Name for source has not been found. Source: {innerSource}");
                }

                if (!isFirstSource)
                {
                    sb.Append(" ON 1=1");
                }
                else
                {
                    isFirstSource = false;
                }
            }

            foreach (var leftJoined in query.LeftJoinedSources)
            {
                sb.Append(" LEFT JOIN ");
                WriteInnerSource(sb, leftJoined.Item1);
                sb.Append(" AS ");
                if (query.NamingProvider.TryGetSourceName(leftJoined.Item1, out var sourceName))
                {
                    sb.Append(sourceName);
                }
                else
                {
                    throw new InvalidOperationException($"Name for source has not been found. Source: {leftJoined}");
                }
                sb.Append(" ON ");
                WriteCondition(sb, query, leftJoined.Item2);
            }

            var isFirstCondition = true;

            foreach (var condition in query.Filters)
            {
                if (!isFirstCondition)
                {
                    sb.Append(" AND ");
                }
                else
                {
                    sb.Append(" WHERE ");
                    isFirstCondition = false;
                }

                WriteCondition(sb, query, condition);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        ///  Return a set of queries to find relations between two objects.
        /// </summary>
        /// <param name="object1">First object</param>
        /// <param name="object2">Second object</param>
        /// <param name="distance"> maxDistance The maximum distance up to which we want to search</param>
        /// <param name="limit">limit The maximum number of results per SPARQL query (=LIMIT).</param>
        /// <param name="ignoredObjects">Objects which should not be part of the returned connections between the first and second object</param>
        /// <param name="ignoredProperties">Properties which should not be part of the returned connections between the first and second object</param>
        /// <param name="avoidCycles">Integer value which indicates whether we want to suppress cycles , 0 = no cycle avoidance ,  1 = no intermediate object can be object1 or object2 ,   2 = like 1 + an object can not occur more than once in a connection </param>
        /// <returns>A two dimensional array of the form $array[$distance][$queries]</returns>
        private Dictionary <int, List <InnerQuery> > getQueries(string object1, string object2, int distance, int limit, List <string> ignoredObjects = null, List <string> ignoredProperties = null, int avoidCycles = 0)
        {
            Dictionary <int, List <InnerQuery> > queries = new Dictionary <int, List <InnerQuery> >();
            Dictionary <string, List <string> >  options = new Dictionary <string, List <string> >();


            //May generate null
            options["object1"]           = stringToLoist(object1);
            options["object2"]           = stringToLoist(object2);
            options["limit"]             = stringToLoist(limit.ToString());
            options["ignoredObjects"]    = ignoredObjects;
            options["ignoredProperties"] = ignoredProperties;
            options["avoidCycles"]       = stringToLoist(avoidCycles.ToString());

            // get direct connection in both directions
            //queries[distance] = new ArrayCollection();
            //(queries[distance] as ArrayCollection).addItem(new Array(direct(object1, object2, distance, options), connectedDirectly));
            //(queries[distance] as ArrayCollection).addItem(new Array(direct(object2, object1, distance, options), connectedDirectlyInverted));
            //we substitiued ArrayCollection with a list and passed the list to the dictionary
            var tempList       = new List <InnerQuery>();
            var tempInnerQuery = new InnerQuery();

            tempInnerQuery.queryText    = direct(object1, object2, distance, options);
            tempInnerQuery.connectState = connectionType.connectedDirectly;
            tempInnerQuery.object1      = object1;
            tempInnerQuery.object2      = object2;
            tempList.Add(tempInnerQuery);

            tempInnerQuery              = new InnerQuery();
            tempInnerQuery.queryText    = direct(object2, object1, distance, options);
            tempInnerQuery.connectState = connectionType.connectedDirectlyInverted;
            tempInnerQuery.object1      = object2;
            tempInnerQuery.object2      = object1;
            tempList.Add(tempInnerQuery);

            //queries.Add(distance, tempList);
            //ended substitution

            for (int a = 1; a <= distance; a++)
            {
                for (int b = 1; b <= distance; b++)
                {
                    if ((a + b) == distance)
                    {
                        //(queries[distance] as ArrayCollection).addItem(new Array(connectedViaAMiddleObject(object1, object2, a, b, true,  options), connectedViaMiddle));
                        //tempList = new List<InnerQuery>();
                        tempInnerQuery              = new InnerQuery();
                        tempInnerQuery.queryText    = connectedViaAMiddleObject(object1, object2, a, b, true, options);
                        tempInnerQuery.connectState = connectionType.connectedViaMiddle;
                        tempInnerQuery.object1      = object1;
                        tempInnerQuery.object2      = object2;
                        tempList.Add(tempInnerQuery);

                        tempInnerQuery              = new InnerQuery();
                        tempInnerQuery.queryText    = connectedViaAMiddleObject(object1, object2, a, b, false, options);
                        tempInnerQuery.connectState = connectionType.connectedViaMiddleInverted;
                        tempInnerQuery.object1      = object1;
                        tempInnerQuery.object2      = object2;
                        tempList.Add(tempInnerQuery);


                        //(queries[distance] as ArrayCollection).addItem(new Array(connectedViaAMiddleObject(object1, object2, a, b, false, options), connectedViaMiddleInverted));
                    }
                }
            }
            queries.Add(distance, tempList);
            //substitution of the above code:



            return(queries);
        }
 public IQueryable <T> Include(string path)
 {
     return(InnerQuery.Include(path).AsVisitable(Visitors));
 }