Beispiel #1
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;
        }
        internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
        {
            if (this.instanceClasses.Length == 1)
            {
                statement.Append(" (" + statement.GetJoinName(this.association) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND ");
                statement.Append(" " + statement.GetJoinName(this.association) + "." + 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(" (" + statement.GetJoinName(this.association) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND ");
                    statement.Append(" " + statement.GetJoinName(this.association) + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[i].Id) + ")");
                    if (i < this.instanceClasses.Length - 1)
                    {
                        statement.Append(" OR ");
                    }
                }

                statement.Append(" ) ");
            }

            return this.Include;
        }
Beispiel #3
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;
        }
Beispiel #4
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 " + 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;
 }
        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;
        }
        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;
        }
        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;
        }
Beispiel #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);
            }
        }
Beispiel #9
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " > " + statement.AddParameter(this.obj));
     return this.Include;
 }
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " BETWEEN " + first.SingularFullName + "_R." + Mapping.ColumnNameForRole + " AND " + second.SingularFullName + "_R." + Mapping.ColumnNameForRole + " ");
     return(Include);
 }
Beispiel #11
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;
 }
Beispiel #12
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.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " > " + statement.AddParameter(this.obj));
     return(this.Include);
 }
Beispiel #14
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 " + 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 " + 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;
        }
Beispiel #15
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;
 }
Beispiel #16
0
 internal abstract void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement);
Beispiel #17
0
 internal abstract bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias);
Beispiel #18
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);
        }
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(role);
     statement.UseRole(first);
     statement.UseRole(second);
 }
Beispiel #20
0
 internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias)
 {
     statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " BETWEEN " + first.SingularFullName + "_R." + Mapping.ColumnNameForRole + " AND " + second.SingularFullName + "_R." + Mapping.ColumnNameForRole + " ");
     return Include;
 }
Beispiel #21
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(role);
     statement.UseRole(first);
     statement.UseRole(second);
 }
Beispiel #22
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;
            }

            this.second.BuildSql(statement);

            return null;
        }
Beispiel #23
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseAssociation(this.association);
     statement.UseAssociationInstance(this.association);
 }
Beispiel #24
0
 internal abstract string BuildSql(AllorsExtentStatementSql statement);
Beispiel #25
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);
     }
 }
        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);
        }
Beispiel #27
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     foreach (AllorsPredicateSql filter in this.filters)
     {
         filter.Setup(extent, statement);
     }
 }
Beispiel #28
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     if (this.filter != null)
     {
         this.filter.Setup(extent, statement);
     }
 }
Beispiel #29
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
 }
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(this.roleType);
 }
Beispiel #31
0
 internal override void Setup(AllorsExtentFilteredSql extent, AllorsExtentStatementSql statement)
 {
     statement.UseRole(this.role);
 }
Beispiel #32
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;
        }