Пример #1
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.Include)
            {
                var root = extent.Filter.Equals(this);
                statement.Append(root ? " AND " : "(");

                var atLeastOneChildIncluded = false;
                foreach (var filter in this.filters)
                {
                    if (atLeastOneChildIncluded)
                    {
                        statement.Append(" AND ");
                    }

                    if (filter.BuildWhere(extent, mapping, statement, type, alias))
                    {
                        atLeastOneChildIncluded = true;
                    }
                }

                if (!root)
                {
                    statement.Append(")");
                }

                return atLeastOneChildIncluded;
            }

            return false;
        }
Пример #2
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.Include)
            {
                statement.Append("(");
                var atLeastOneChildIncluded = false;
                foreach (AllorsPredicateSql filter in this.filters)
                {
                    if (atLeastOneChildIncluded)
                    {
                        statement.Append(" OR ");
                    }

                    if (filter.BuildWhere(extent, mapping, statement, type, alias))
                    {
                        atLeastOneChildIncluded = true;
                    }
                }

                statement.Append(")");
                return atLeastOneChildIncluded;
            }

            return false;
        }
Пример #3
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.instanceClasses.Length == 1)
            {
                statement.Append(" (" + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND ");
                statement.Append(" " + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[0].Id) + ")");
            }
            else if (this.instanceClasses.Length > 1)
            {
                statement.Append(" ( ");
                for (int i = 0; i < this.instanceClasses.Length; i++)
                {
                    statement.Append(" (" + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND ");
                    statement.Append(" " + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[i].Id) + ")");
                    if (i < this.instanceClasses.Length - 1)
                    {
                        statement.Append(" OR ");
                    }
                }

                statement.Append(" ) ");
            }

            return this.Include;
        }
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            AllorsExtentStatementSql inStatement = statement.CreateChild(inExtent, association);
            inStatement.UseRole(association.RoleType);

            statement.Append(" (" + association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IS NOT NULL AND ");
            statement.Append(" " + association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IN (\n");
            inExtent.BuildSql(inStatement);
            statement.Append(" ))\n");
            return Include;
        }
Пример #5
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append("\n");
     statement.Append("EXISTS(\n");
     statement.Append("SELECT " + Mapping.ColumnNameForObject + "\n");
     statement.Append("FROM " + extent.Session.Database.SchemaName + "." + mapping.GetTableName(this.role) + "\n");
     statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + alias + "." + Mapping.ColumnNameForObject + "\n");
     statement.Append("AND " + Mapping.ColumnNameForRole + "=" + this.allorsObject.Strategy.ObjectId + "\n");
     statement.Append(")\n");
     return this.Include;
 }
Пример #6
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            var inStatement = statement.CreateChild(this.inExtent, this.role);

            inStatement.UseAssociation(this.role.AssociationType);

            statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND ");
            statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForAssociation + " IN (");
            this.inExtent.BuildSql(inStatement);
            statement.Append(" ))");

            return this.Include;
        }
Пример #7
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            var inStatement = new StringBuilder("0");
            foreach (var inObject in this.enumerable)
            {
                inStatement.Append(",");
                inStatement.Append(inObject.Id);
            }

            statement.Append(" (" + this.role.SingularPropertyName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND ");
            statement.Append(" " + this.role.SingularPropertyName + "_R." + Mapping.ColumnNameForAssociation + " IN (");
            statement.Append(inStatement.ToString());
            statement.Append(" ))");

            return this.Include;
        }
Пример #8
0
        internal void BuildOrder(AllorsExtentSortSql sorter, Mapping mapping, AllorsExtentStatementSql statement)
        {
            if (sorter.Equals(this))
            {
                statement.Append(" ORDER BY " + this.roleType.SingularFullName + "_R" + ".R");
            }
            else
            {
                statement.Append(" , " + this.roleType.SingularFullName + "_R" + ".R");
            }

            statement.Append(this.sortDirection == SortDirection.Ascending ? " ASC " : " DESC ");

            if (this.subSorter != null)
            {
                this.subSorter.BuildOrder(sorter, mapping, statement);
            }
        }
Пример #9
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(role);
     statement.UseRole(first);
     statement.UseRole(second);
 }
Пример #10
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " BETWEEN " + statement.AddParameter(this.first) + " AND " + statement.AddParameter(this.second) + " ");
     return this.Include;
 }
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " < " + this.lessThanRole.SingularFullName + "_R." + Mapping.ColumnNameForRole);
     return(this.Include);
 }
Пример #12
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.Include)
            {
                statement.Append("(");
                var atLeastOneChildIncluded = false;
                foreach (AllorsPredicateSql filter in this.filters)
                {
                    if (atLeastOneChildIncluded)
                    {
                        statement.Append(" OR ");
                    }

                    if (filter.BuildWhere(extent, mapping, statement, type, alias))
                    {
                        atLeastOneChildIncluded = true;
                    }
                }

                statement.Append(")");
                return(atLeastOneChildIncluded);
            }

            return(false);
        }
Пример #13
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
 }
Пример #14
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.instanceClasses.Length == 1)
            {
                statement.Append(alias + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[0].Id) + " ");
            }
            else if (this.instanceClasses.Length > 1)
            {
                statement.Append(" ( ");
                for (var i = 0; i < this.instanceClasses.Length; i++)
                {
                    statement.Append(alias + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[i].Id));
                    if (i < this.instanceClasses.Length - 1)
                    {
                        statement.Append(" OR ");
                    }
                }

                statement.Append(" ) ");
            }

            return(this.Include);
        }
Пример #15
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " LIKE " + statement.AddParameter(this.str));
     return this.Include;
 }
Пример #16
0
        internal override string BuildSql(AllorsExtentStatementSql statement)
        {
            this.first.BuildSql(statement);

            switch (this.operationType)
            {
                case AllorsExtentOperationTypeSqlBundled.UNION:
                    statement.Append("\nUNION\n");
                    break;
                case AllorsExtentOperationTypeSqlBundled.INTERSECT:
                    statement.Append("\nINTERSECT\n");
                    break;
                case AllorsExtentOperationTypeSqlBundled.EXCEPT:
                    statement.Append("\nEXCEPT\n");
                    break;
            }

            statement.Append("(");
            this.second.BuildSql(statement);
            statement.Append(")");

            return null;
        }
Пример #17
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" (" + alias + "." + Mapping.ColumnNameForObject + "=" + statement.AddParameter(obj) + ") ");
     return Include;
 }
Пример #18
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL");
     return this.Include;
 }
Пример #19
0
 internal abstract bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias);
Пример #20
0
 internal void BuildSelect(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement)
 {
     statement.Append(" , " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " ");
     if (this.subSorter != null)
     {
         this.subSorter.BuildSelect(extent, mapping, statement);
     }
 }
Пример #21
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.Include)
            {
                var root = extent.Filter.Equals(this);
                statement.Append(root ? " AND " : "(");

                var atLeastOneChildIncluded = false;
                foreach (var filter in this.filters)
                {
                    if (atLeastOneChildIncluded)
                    {
                        statement.Append(" AND ");
                    }

                    if (filter.BuildWhere(extent, mapping, statement, type, alias))
                    {
                        atLeastOneChildIncluded = true;
                    }
                }

                if (!root)
                {
                    statement.Append(")");
                }

                return(atLeastOneChildIncluded);
            }

            return(false);
        }
Пример #22
0
        internal override string BuildSql(AllorsExtentStatementSql statement)
        {
            if (this.role != null || this.association != null)
            {
                // We're being used in another Extent so we need to
                // migrate from role/associatin to filter
                this.LazyLoadFilter();
            }

            if (this.filter != null)
            {
                this.filter.Setup(this, statement);
            }

            string alias = statement.CreateAlias();

            if (statement.IsRoot)
            {
                //TODO: DISTINCT isn't always necessary
                statement.Append("SELECT DISTINCT " + alias + "." + Mapping.ColumnNameForObject);

                if (statement.Sorter != null)
                {
                    statement.Sorter.Setup(this, statement);
                    statement.Sorter.BuildSelect(this, this.Mapping, statement);
                }

                statement.Append(" FROM " + this.Session.Database.SchemaName + "." + Mapping.TableNameForObjects + " " + alias);

                statement.AddJoins(alias);
                statement.AddWhere(alias);

                if (this.filter != null)
                {
                    this.filter.BuildWhere(this, this.Mapping, statement, this.type, alias);
                }
            }
            else
            {
                var inStatement = (AllorsExtentStatementChildSql)statement;
                if (inStatement.Role != null)
                {
                    var inRole = inStatement.Role;
                    var inAssociation = inRole.AssociationType;
                    statement.Append("SELECT " + inAssociation.SingularFullName + "_A." + Mapping.ColumnNameForAssociation);
                }
                else
                {
                    var inAssociation = inStatement.Association;
                    var inRole = inAssociation.RoleType;
                    statement.Append("SELECT " + inRole.SingularFullName + "_R." + Mapping.ColumnNameForRole);
                }

                statement.Append(" FROM " + this.Session.Database.SchemaName + "." + Mapping.TableNameForObjects + " " + alias);

                statement.AddJoins(alias);
                statement.AddWhere(alias);

                if (this.filter != null)
                {
                    this.filter.BuildWhere(this, this.Mapping, statement, this.type, alias);
                }

                statement.Append(" AND ");

                if (inStatement.Role != null)
                {
                    var inRole = inStatement.Role;
                    var inAssociation = inRole.AssociationType;
                    statement.Append(inAssociation.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL ");
                }
                else
                {
                    var inAssociation = inStatement.Association;
                    var inRole = inAssociation.RoleType;
                    statement.Append(inRole.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL ");
                }
            }

            return alias;
        }
Пример #23
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append("\n");
     statement.Append("EXISTS(\n");
     statement.Append("SELECT " + Mapping.ColumnNameForObject + "\n");
     statement.Append("FROM " + extent.Session.Database.SchemaName + "." + mapping.GetTableName(this.role) + "\n");
     statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + alias + "." + Mapping.ColumnNameForObject + "\n");
     statement.Append("AND " + Mapping.ColumnNameForRole + "=" + this.allorsObject.Strategy.ObjectId + "\n");
     statement.Append(")\n");
     return(this.Include);
 }
Пример #24
0
 internal void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(this.roleType);
     if (this.subSorter != null)
     {
         this.subSorter.Setup(extent, statement);
     }
 }
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND ");
     statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + "=" + statement.AddParameter(this.obj) + ")");
     return(this.Include);
 }
Пример #26
0
 internal abstract void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement);
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(this.role);
 }
Пример #28
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
 }
Пример #29
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL AND ");
     statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + "=" + this.allorsObject.Strategy.ObjectId + ")");
     return(this.Include);
 }
Пример #30
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL");
     return Include;
 }
Пример #31
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseAssociation(this.association);
 }
Пример #32
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     foreach (AllorsPredicateSql filter in this.filters)
     {
         filter.Setup(extent, statement);
     }
 }
Пример #33
0
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.Include)
            {
                statement.Append(" NOT (");
                this.filter.BuildWhere(extent, mapping, statement, type, alias);
                statement.Append(")");
            }

            return this.Include;
        }
Пример #34
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseAssociation(association);
 }
Пример #35
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     if (this.filter != null)
     {
         this.filter.Setup(extent, statement);
     }
 }
Пример #36
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(this.role);
 }
Пример #37
0
 internal abstract string BuildSql(AllorsExtentStatementSql statement);