コード例 #1
0
ファイル: ExtentSort.cs プロジェクト: lulzzz/allors2
        public void BuildOrder(ExtentStatement statement, string alias)
        {
            if (statement.Sorter.Equals(this))
            {
                statement.Append(" ORDER BY " + alias + "." + statement.Schema.Column(this.roleType));
            }
            else
            {
                statement.Append(" , " + alias + "." + statement.Schema.Column(this.roleType));
            }

            if (this.direction == SortDirection.Ascending)
            {
                statement.Append(" ASC ");
                this.AddAscendingAppendix(statement);
            }
            else
            {
                statement.Append(" DESC ");
                this.AddDescendingAppendix(statement);
            }

            if (this.subSorter != null)
            {
                this.subSorter.BuildOrder(statement, alias);
            }
        }
コード例 #2
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            statement.Append(" " + alias + "." + schema.Column(this.role) + " < " + alias + "." + schema.Column(this.lessThanRole));
            return(this.Include);
        }
コード例 #3
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            statement.Append(" " + alias + "." + schema.Column(this.roleType) + ">" + statement.AddParameter(this.obj));
            return(this.Include);
        }
コード例 #4
0
ファイル: ExtentSort.cs プロジェクト: lulzzz/allors2
 public void BuildSelect(ExtentStatement statement, string alias)
 {
     statement.Append(" , " + alias + "." + statement.Schema.Column(this.roleType) + " ");
     if (this.subSorter != null)
     {
         this.subSorter.BuildSelect(statement, alias);
     }
 }
コード例 #5
0
ファイル: ExtentSort.cs プロジェクト: lulzzz/allors2
        private void AddDescendingAppendix(ExtentStatement statement)
        {
            var sortAppendix = this.session.SqlDatabase.DescendingSortAppendix;

            if (sortAppendix != null)
            {
                statement.Append(sortAppendix + " ");
            }
        }
コード例 #6
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            if (this.Include)
            {
                statement.Append(" NOT (");
                this.filter.BuildWhere(statement, alias);
                statement.Append(")");
            }

            return(this.Include);
        }
コード例 #7
0
        public override string BuildSql(ExtentStatement statement)
        {
            this.LazyLoadFilter();
            this.filter.Setup(statement);

            if (this.objectType.ExistClass)
            {
                if (this.objectType.ExistExclusiveClass)
                {
                    return(this.BuildSqlWithExclusiveLeafClass(statement));
                }

                return(this.BuildSqlWithExclusiveLeafClasses(statement));
            }

            return(null);
        }
コード例 #8
0
ファイル: AssociationContains.cs プロジェクト: lulzzz/allors2
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if ((this.association.IsMany && this.association.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses)
            {
                statement.Append("\n");
                statement.Append("EXISTS(\n");
                statement.Append("SELECT " + alias + "." + schema.ObjectId + "\n");
                statement.Append("FROM " + schema.Table(this.association) + "\n");
                statement.Append("WHERE " + schema.AssociationId + "=" + this.allorsObject.Strategy.ObjectId + "\n");
                statement.Append("AND " + schema.RoleId + "=" + alias + "." + schema.ObjectId + "\n");
                statement.Append(")");
            }
            else
            {
                statement.Append(" " + this.association.SingularFullName + "_A." + schema.ObjectId + " = " + this.allorsObject.Strategy.ObjectId);
            }

            return(this.Include);
        }
コード例 #9
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            var inStatement = new StringBuilder("0");

            foreach (var inObject in this.enumerable)
            {
                inStatement.Append(",");
                inStatement.Append(inObject.Id);
            }

            if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses)
            {
                statement.Append(" (" + this.role.SingularPropertyName + "_R." + schema.RoleId + " IS NOT NULL AND ");
                statement.Append(" " + this.role.SingularPropertyName + "_R." + schema.AssociationId + " IN (");
                statement.Append(inStatement.ToString());
                statement.Append(" ))");
            }
            else
            {
                if (this.role.IsMany)
                {
                    statement.Append(" (" + this.role.SingularPropertyName + "_R." + schema.ObjectId + " IS NOT NULL AND ");
                    statement.Append(" " + this.role.SingularPropertyName + "_R." + schema.ObjectId + " IN (");
                    statement.Append(inStatement.ToString());
                    statement.Append(" ))");
                }
                else
                {
                    statement.Append(" (" + schema.Column(this.role) + " IS NOT NULL AND ");
                    statement.Append(" " + schema.Column(this.role) + " IN (");
                    statement.Append(inStatement.ToString());
                    statement.Append(" ))");
                }
            }

            return(this.Include);
        }
コード例 #10
0
ファイル: AssociationExists.cs プロジェクト: lulzzz/allors2
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if ((this.association.IsMany && this.association.RelationType.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses)
            {
                statement.Append(" " + this.association.SingularFullName + "_A." + schema.AssociationId.StatementName + " IS NOT NULL");
            }
            else
            {
                if (this.association.RelationType.RoleType.IsMany)
                {
                    statement.Append(" " + alias + "." + schema.Column(this.association) + " IS NOT NULL");
                }
                else
                {
                    statement.Append(" " + this.association.SingularFullName + "_A." + schema.ObjectId + " IS NOT NULL");
                }
            }

            return(this.Include);
        }
コード例 #11
0
ファイル: RoleEqualsRole.cs プロジェクト: lulzzz/allors2
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if (this.role.ObjectType is IUnit && this.equalsRole.ObjectType is IUnit)
            {
                statement.Append(" " + alias + "." + schema.Column(this.role) + "=" + alias + "." + schema.Column(this.equalsRole));
            }
            else
            {
                var roleCompositeType       = this.role.ObjectType as IComposite;
                var equalsRoleCompositeType = this.equalsRole.ObjectType as IComposite;

                if (roleCompositeType != null && roleCompositeType.ExclusiveClass != null &&
                    equalsRoleCompositeType != null && equalsRoleCompositeType.ExclusiveClass != null)
                {
                    statement.Append(" " + alias + "." + schema.Column(this.role) + "=" + alias + "." + schema.Column(this.equalsRole));
                }

                throw new NotImplementedException();
            }

            return(this.Include);
        }
コード例 #12
0
 public override void Setup(ExtentStatement statement)
 {
 }
コード例 #13
0
ファイル: RoleLike.cs プロジェクト: lulzzz/allors2
 public override void Setup(ExtentStatement statement)
 {
     statement.UseRole(this.role);
 }
コード例 #14
0
ファイル: RoleContains.cs プロジェクト: lulzzz/allors2
 public override void Setup(ExtentStatement statement)
 {
     //extent.UseRole(role);
 }
コード例 #15
0
        private string BuildSqlWithExclusiveLeafClass(ExtentStatement statement)
        {
            var alias = statement.CreateAlias();
            var exclusiveLeafClass = this.objectType.ExclusiveClass;

            if (statement.IsRoot)
            {
                statement.Append("SELECT DISTINCT " + alias + "." + this.Schema.ObjectId);
                if (statement.Sorter != null)
                {
                    statement.Sorter.BuildSelect(statement, alias);
                }

                statement.Append(" FROM " + this.Schema.Table(exclusiveLeafClass) + " " + alias);
                statement.AddJoins(exclusiveLeafClass, alias);
                statement.AddWhere(exclusiveLeafClass, alias);
                if (this.filter != null)
                {
                    this.filter.BuildWhere(statement, alias);
                }
            }
            else
            {
                // ContainedIn
                var inStatement = (ExtentStatementChild)statement;

                if (inStatement.RoleType != null)
                {
                    var inRole         = inStatement.RoleType;
                    var inRelationType = inRole.RelationType;
                    if (inRelationType.Multiplicity == Multiplicity.ManyToMany || !inRelationType.ExistExclusiveClasses)
                    {
                        statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Schema.AssociationId);
                    }
                    else
                    {
                        if (inRole.IsMany)
                        {
                            statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                        }
                        else
                        {
                            statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Schema.Column(inRole.AssociationType));
                        }
                    }

                    statement.Append(" FROM " + this.Schema.Table(exclusiveLeafClass) + " " + alias);
                    statement.AddJoins(exclusiveLeafClass, alias);

                    var wherePresent = statement.AddWhere(exclusiveLeafClass, alias);
                    var filterUsed   = false;
                    if (this.filter != null)
                    {
                        filterUsed = this.filter.BuildWhere(statement, alias);
                    }

                    if (wherePresent || filterUsed)
                    {
                        statement.Append(" AND ");
                    }
                    else
                    {
                        statement.Append(" WHERE ");
                    }

                    if (inRelationType.Multiplicity == Multiplicity.ManyToMany || !inRelationType.ExistExclusiveClasses)
                    {
                        statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Schema.AssociationId + " IS NOT NULL ");
                    }
                    else
                    {
                        if (inRole.IsMany)
                        {
                            statement.Append(alias + "." + this.Schema.Column(inRole.AssociationType) + " IS NOT NULL ");
                        }
                        else
                        {
                            statement.Append(inRole.AssociationType.SingularFullName + "_A." +
                                             this.Schema.Column(inRole.AssociationType) + " IS NOT NULL ");
                        }
                    }
                }
                else
                {
                    if (statement.IsRoot)
                    {
                        statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                        if (statement.Sorter != null)
                        {
                            statement.Sorter.BuildSelect(statement);
                        }
                    }
                    else
                    {
                        statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                    }

                    statement.Append(" FROM " + this.Schema.Table(exclusiveLeafClass) + " " + alias);

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

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

            return(alias);
        }
コード例 #16
0
 public override void Setup(ExtentStatement statement)
 {
     statement.UseAssociation(this.association);
     statement.UseAssociationInstance(this.association);
 }
コード例 #17
0
        private string BuildSqlWithExclusiveLeafClasses(ExtentStatement statement)
        {
            if (statement.IsRoot)
            {
                var leafClasses = this.objectType.Classes.ToArray();
                for (var i = 0; i < leafClasses.Length; i++)
                {
                    var alias     = statement.CreateAlias();
                    var leafClass = leafClasses[i];

                    statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                    if (statement.Sorter != null)
                    {
                        statement.Sorter.BuildSelect(statement);
                    }

                    statement.Append(" FROM " + this.Schema.Table(leafClass) + " " + alias);

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

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

                    if (i < leafClasses.Length - 1)
                    {
                        statement.Append("\nUNION\n");
                    }
                }
            }
            else
            {
                var inStatement = (ExtentStatementChild)statement;

                if (inStatement.RoleType != null)
                {
                    var useUnion = false;
                    foreach (var leafClass in this.objectType.Classes)
                    {
                        var inRole         = inStatement.RoleType;
                        var inRelationType = inRole.RelationType;

                        if (!((IComposite)inRole.ObjectType).Classes.Contains(leafClass))
                        {
                            continue;
                        }

                        if (useUnion)
                        {
                            statement.Append("\nUNION\n");
                        }
                        else
                        {
                            useUnion = true;
                        }

                        var alias = statement.CreateAlias();

                        if (inRelationType.Multiplicity == Multiplicity.ManyToMany || !inRelationType.ExistExclusiveClasses)
                        {
                            statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Schema.AssociationId);
                        }
                        else
                        {
                            if (inRole.IsMany)
                            {
                                statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                            }
                            else
                            {
                                statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Schema.Column(inRole.AssociationType));
                            }
                        }

                        statement.Append(" FROM " + this.Schema.Table(leafClass) + " " + alias);

                        statement.AddJoins(leafClass, alias);

                        var wherePresent = statement.AddWhere(leafClass, alias);
                        var filterUsed   = false;
                        if (this.filter != null)
                        {
                            filterUsed = this.filter.BuildWhere(statement, alias);
                        }

                        if (wherePresent || filterUsed)
                        {
                            statement.Append(" AND ");
                        }
                        else
                        {
                            statement.Append(" WHERE ");
                        }

                        if (inRelationType.Multiplicity == Multiplicity.ManyToMany || !inRelationType.ExistExclusiveClasses)
                        {
                            statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Schema.AssociationId + " IS NOT NULL ");
                        }
                        else
                        {
                            if (inRole.IsMany)
                            {
                                statement.Append(alias + "." + this.Schema.Column(inRole.AssociationType) + " IS NOT NULL ");
                            }
                            else
                            {
                                statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Schema.Column(inRole.AssociationType) + " IS NOT NULL ");
                            }
                        }
                    }
                }
                else
                {
                    var leafClasses = this.objectType.Classes.ToArray();
                    for (var i = 0; i < leafClasses.Length; i++)
                    {
                        var alias     = statement.CreateAlias();
                        var leafClass = leafClasses[i];

                        if (statement.IsRoot)
                        {
                            statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                            if (statement.Sorter != null)
                            {
                                statement.Sorter.BuildSelect(statement);
                            }
                        }
                        else
                        {
                            statement.Append("SELECT " + alias + "." + this.Schema.ObjectId);
                        }

                        statement.Append(" FROM " + this.Schema.Table(leafClass) + " " + alias);

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

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

                        if (i < leafClasses.Length - 1)
                        {
                            statement.Append("\nUNION\n");
                        }
                    }
                }
            }

            return(null);
        }
コード例 #18
0
 public override void Setup(ExtentStatement statement)
 {
     statement.UseRole(this.role);
     statement.UseRole(this.first);
     statement.UseRole(this.second);
 }
コード例 #19
0
ファイル: SqlExtent.cs プロジェクト: lulzzz/allors2
 public abstract string BuildSql(ExtentStatement statement);