Ejemplo n.º 1
0
        /// <summary>
        /// Search table of the path and facet
        /// </summary>
        /// <param name="facet">Facet name</param>
        /// <param name="onPath">Path to solve</param>
        /// <returns>Table name</returns>
        public string GetTable(string facet, ONPath onPath)
        {
            ONSqlPath  lOnSqlPath  = new ONSqlPath(onPath, facet);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            // Path no exist
            if (lOnSqlAlias == null)
            {
                return("");
            }

            return(lOnSqlAlias.Table);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search alias
        /// </summary>
        /// <param name="facet">Facet name</param>
        /// <param name="onPath">Path to solve</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        /// <returns>Alias string</returns>
        public string GetAlias(string facet, ONPath onPath, bool isLinkedTo)
        {
            ONSqlPath  lOnSqlPath  = new ONSqlPath(onPath, facet, isLinkedTo);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            // Path no exist
            if (lOnSqlAlias == null)
            {
                return("");
            }

            return(lOnSqlAlias.Alias);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find or create an alias for this table with left/right join
        /// </summary>
        /// <param name="joinType">Type of join</param>
        /// <param name="fatherAlias">Father alias</param>
        /// <param name="table">Table</param>
        /// <param name="onPath">Path to solve</param>
        /// <param name="facet">Facet of the path to solve</param>
        /// <param name="force">Add the almost the last alias to the select</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        /// <returns></returns>
        public string CreateAlias(JoinType joinType, string fatherAlias, string table, ONPath onPath, string facet, bool force, bool isLinkedTo)
        {
            ONSqlPath  lOnSqlPath  = new ONSqlPath(onPath, facet, isLinkedTo);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            if ((lOnSqlAlias == null) || (force && !mFrom.ContainsKey(lOnSqlPath)))
            {
                // Search father alias
                ONSqlAlias lOnSqlAliasFather = null;
                if (fatherAlias != "")
                {
                    lOnSqlAliasFather = GetOnSqlAlias(fatherAlias);
                    lOnSqlAlias       = new ONSqlAlias(joinType, lOnSqlAliasFather, GenerateAlias(table), table, onPath, facet);
                }
                else
                {
                    lOnSqlAlias = new ONSqlAlias(joinType, null, GenerateAlias(table), table, onPath, facet);
                }

                // Path no exist
                mFrom.Add(lOnSqlPath, lOnSqlAlias);
                mFromAlias.Add(lOnSqlAlias.Alias, lOnSqlAlias);
            }

            // Change the left join to inner join if it is needed
            if ((joinType == JoinType.InnerJoin) && (onPath != null))
            {
                ONSqlAlias lTemp = lOnSqlAlias;
                do
                {
                    if (mFrom.ContainsKey(lOnSqlPath))
                    {
                        lTemp.JoiningType = JoinType.InnerJoin;
                        lTemp             = lTemp.FatherAlias;

                        if (lTemp != null)
                        {
                            lOnSqlPath = new ONSqlPath(lTemp.OnPath, lTemp.Facet, isLinkedTo);
                        }
                    }
                    else
                    {
                        lTemp = null;
                    }
                }while (lTemp != null);
            }

            return(lOnSqlAlias.Alias);
        }
Ejemplo n.º 4
0
        public override bool Equals(object onSqlPath)
        {
            ONSqlPath lOnSqlPath = onSqlPath as ONSqlPath;

            // Not exists path
            if (lOnSqlPath == null)
            {
                return(false);
            }

            // Solve void or null paths
            if ((OnPath == null || OnPath.Path == "") && (lOnSqlPath.OnPath == null || lOnSqlPath.OnPath.Path == ""))
            {
                return(string.Compare(Facet, lOnSqlPath.Facet, true) == 0);
            }

            return((OnPath == lOnSqlPath.OnPath) && (string.Compare(Facet, lOnSqlPath.Facet, true) == 0) && (IslinkedTo = lOnSqlPath.IslinkedTo));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Search Sql alias
        /// </summary>
        /// <param name="lOnSqlPath">Sql paht</param>
        /// <returns></returns>
        public ONSqlAlias GetOnSqlAlias(ONSqlPath lOnSqlPath)
        {
            ONSqlAlias lOnSqlAlias = null;

            foreach (KeyValuePair <ONSqlPath, ONSqlAlias> lFrom in mFrom)
            {
                if ((lFrom.Key.OnPath == lOnSqlPath.OnPath) && (lFrom.Key.Facet == lOnSqlPath.Facet) && ((lFrom.Key.IslinkedTo == lOnSqlPath.IslinkedTo) || (lOnSqlPath.IslinkedTo)))
                {
                    return(lFrom.Value);
                }
            }

            if ((lOnSqlAlias == null) && (SuperQuery != null))
            {
                return(SuperQuery.GetOnSqlAlias(lOnSqlPath));
            }

            return(lOnSqlAlias);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Search table of the path and facet
        /// </summary>
        /// <param name="facet">Facet name</param>
        /// <param name="onPath">Path to solve</param>
        /// <returns>Table name</returns>
        public string GetTable(string facet, ONPath onPath)
        {
            ONSqlPath lOnSqlPath = new ONSqlPath(onPath, facet);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            // Path no exist
            if (lOnSqlAlias == null)
                return "";

            return lOnSqlAlias.Table;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Search Sql alias
        /// </summary>
        /// <param name="lOnSqlPath">Sql paht</param>
        /// <returns></returns>
        public ONSqlAlias GetOnSqlAlias(ONSqlPath lOnSqlPath)
        {
            ONSqlAlias lOnSqlAlias = null;
            foreach(KeyValuePair<ONSqlPath, ONSqlAlias>lFrom in mFrom)
            {
                if ((lFrom.Key.OnPath == lOnSqlPath.OnPath) && (lFrom.Key.Facet == lOnSqlPath.Facet) && ((lFrom.Key.IslinkedTo == lOnSqlPath.IslinkedTo) || (lOnSqlPath.IslinkedTo)))
                    return lFrom.Value;
            }

            if ((lOnSqlAlias == null) && (SuperQuery != null))
                return (SuperQuery.GetOnSqlAlias(lOnSqlPath));

            return lOnSqlAlias;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Search alias
        /// </summary>
        /// <param name="facet">Facet name</param>
        /// <param name="onPath">Path to solve</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        /// <returns>Alias string</returns>
        public string GetAlias(string facet, ONPath onPath, bool isLinkedTo)
        {
            ONSqlPath lOnSqlPath = new ONSqlPath(onPath, facet, isLinkedTo);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            // Path no exist
            if (lOnSqlAlias == null)
                return "";

            return lOnSqlAlias.Alias;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Find or create an alias for this table with left/right join
        /// </summary>
        /// <param name="joinType">Type of join</param>
        /// <param name="fatherAlias">Father alias</param>
        /// <param name="table">Table</param>
        /// <param name="onPath">Path to solve</param>
        /// <param name="facet">Facet of the path to solve</param>
        /// <param name="force">Add the almost the last alias to the select</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        /// <returns></returns>
        public string CreateAlias(JoinType joinType, string fatherAlias, string table, ONPath onPath, string facet, bool force, bool isLinkedTo)
        {
            ONSqlPath lOnSqlPath = new ONSqlPath(onPath, facet, isLinkedTo);
            ONSqlAlias lOnSqlAlias = GetOnSqlAlias(lOnSqlPath);

            if ((lOnSqlAlias == null) || (force && !mFrom.ContainsKey(lOnSqlPath)))
            {
                // Search father alias
                ONSqlAlias lOnSqlAliasFather = null;
                if (fatherAlias != "")
                {
                    lOnSqlAliasFather = GetOnSqlAlias(fatherAlias);
                    lOnSqlAlias = new ONSqlAlias(joinType, lOnSqlAliasFather, GenerateAlias(table), table, onPath, facet);
                }
                else
                    lOnSqlAlias = new ONSqlAlias(joinType, null, GenerateAlias(table), table, onPath, facet);

                // Path no exist
                mFrom.Add(lOnSqlPath, lOnSqlAlias);
                mFromAlias.Add(lOnSqlAlias.Alias, lOnSqlAlias);
            }

            // Change the left join to inner join if it is needed
            if ((joinType == JoinType.InnerJoin) && (onPath != null))
            {
                ONSqlAlias lTemp = lOnSqlAlias;
                do
                {
                    if (mFrom.ContainsKey(lOnSqlPath))
                    {
                        lTemp.JoiningType = JoinType.InnerJoin;
                        lTemp = lTemp.FatherAlias;

                        if(lTemp != null)
                            lOnSqlPath = new ONSqlPath(lTemp.OnPath, lTemp.Facet, isLinkedTo);
                    }
                    else
                        lTemp = null;
                }
                while (lTemp != null);
            }

            return lOnSqlAlias.Alias;
        }