Exemple #1
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if (this.roleType.ObjectType is IUnit)
            {
                statement.Append(" " + alias + "." + schema.Column(this.roleType) + "=" + statement.AddParameter(this.obj));
            }
            else
            {
                var allorsObject = (IObject)this.obj;

                if (this.roleType.RelationType.ExistExclusiveClasses)
                {
                    statement.Append(" (" + alias + "." + schema.Column(this.roleType) + " IS NOT NULL AND ");
                    statement.Append(" " + alias + "." + schema.Column(this.roleType) + "=" + allorsObject.Strategy.ObjectId + ")");
                }
                else
                {
                    statement.Append(" (" + this.roleType.SingularPropertyName + "_R." + schema.RoleId + " IS NOT NULL AND ");
                    statement.Append(" " + this.roleType.SingularPropertyName + "_R." + schema.RoleId + "=" + allorsObject.Strategy.ObjectId + ")");
                }
            }

            return(this.Include);
        }
Exemple #2
0
        public override string BuildSql(ExtentStatement statement)
        {
            this.first.BuildSql(statement);

            switch (this.operationType)
            {
            case ExtentOperations.Union:
                statement.Append("\nUNION\n");
                break;

            case ExtentOperations.Intersect:
                statement.Append("\nINTERSECT\n");
                break;

            case ExtentOperations.Except:
                statement.Append("\n" + this.Session.SqlDatabase.Except + "\n");
                break;
            }

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

            return(null);
        }
Exemple #3
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if (this.role.ObjectType is IUnit)
            {
                statement.Append(" " + alias + "." + schema.Column(this.role) + " IS NOT NULL");
            }
            else
            {
                if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses)
                {
                    statement.Append(" " + this.role.SingularPropertyName + "_R." + schema.RoleId + " IS NOT NULL");
                }
                else
                {
                    if (this.role.IsMany)
                    {
                        statement.Append(" " + this.role.SingularPropertyName + "_R." + schema.ObjectId + " IS NOT NULL");
                    }
                    else
                    {
                        statement.Append(" " + alias + "." + schema.Column(this.role) + " IS NOT NULL");
                    }
                }
            }

            return(this.Include);
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if (this.instanceClasses.Length == 1)
            {
                statement.Append(alias + "." + schema.TypeId + "=" + 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 + "." + schema.TypeId + "=" + statement.AddParameter(this.instanceClasses[i].Id));
                    if (i < this.instanceClasses.Length - 1)
                    {
                        statement.Append(" OR ");
                    }
                }

                statement.Append(" ) ");
            }

            return(this.Include);
        }
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema      = statement.Schema;
            var inStatement = statement.CreateChild(this.inExtent, this.association);

            inStatement.UseRole(this.association.RoleType);

            if ((this.association.IsMany && this.association.RelationType.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses)
            {
                statement.Append(" (" + this.association.SingularFullName + "_A." + schema.AssociationId + " IS NOT NULL AND ");
                statement.Append(" " + this.association.SingularFullName + "_A." + schema.AssociationId + " IN (\n");
                this.inExtent.BuildSql(inStatement);
                statement.Append(" ))\n");
            }
            else
            {
                if (this.association.RelationType.RoleType.IsMany)
                {
                    statement.Append(" (" + alias + "." + schema.Column(this.association) + " IS NOT NULL AND ");
                    statement.Append(" " + alias + "." + schema.Column(this.association) + " IN (\n");
                    this.inExtent.BuildSql(inStatement);
                    statement.Append(" ))\n");
                }
                else
                {
                    statement.Append(" (" + this.association.SingularFullName + "_A." + schema.ObjectId + " IS NOT NULL AND ");
                    statement.Append(" " + this.association.SingularFullName + "_A." + schema.ObjectId + " IN (\n");
                    this.inExtent.BuildSql(inStatement);
                    statement.Append(" ))\n");
                }
            }

            return(this.Include);
        }
Exemple #7
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);
        }
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            statement.Append(" " + alias + "." + schema.Column(this.role) + ">" + alias + "." + schema.Column(this.greaterThanRole));
            return(this.Include);
        }
Exemple #9
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            statement.Append(" " + alias + "." + schema.Column(this.role) + " LIKE " + statement.AddParameter(this.like));
            return(this.Include);
        }
Exemple #10
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            statement.Append(" (" + alias + "." + schema.Column(this.role) + " BETWEEN " + alias + "." + schema.Column(this.first) + " AND " + alias + "." + schema.Column(this.second) + ")");
            return(this.Include);
        }
Exemple #11
0
 public void BuildSelect(ExtentStatement statement, string alias)
 {
     statement.Append(" , " + alias + "." + statement.Schema.Column(this.roleType) + " ");
     if (this.subSorter != null)
     {
         this.subSorter.BuildSelect(statement, alias);
     }
 }
Exemple #12
0
        private void AddDescendingAppendix(ExtentStatement statement)
        {
            var sortAppendix = this.session.SqlDatabase.DescendingSortAppendix;

            if (sortAppendix != null)
            {
                statement.Append(sortAppendix + " ");
            }
        }
Exemple #13
0
        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 + " IS NOT NULL AND ");
                statement.Append(" " + this.association.SingularFullName + "_A." + schema.AssociationId + "=" + this.allorsObject.Strategy.ObjectId + ")");
            }
            else
            {
                if (this.association.RelationType.RoleType.IsMany)
                {
                    statement.Append(" (" + alias + "." + schema.Column(this.association) + " IS NOT NULL AND ");
                    statement.Append(" " + alias + "." + schema.Column(this.association) + "=" + this.allorsObject.Strategy.ObjectId + ")");
                }
                else
                {
                    statement.Append(" (" + this.association.SingularFullName + "_A." + schema.ObjectId + " IS NOT NULL AND ");
                    statement.Append(" " + this.association.SingularFullName + "_A." + schema.ObjectId + " =" + this.allorsObject.Strategy.ObjectId + ")");
                }
            }

            return(this.Include);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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);
        }
Exemple #16
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);
        }
Exemple #17
0
        public override bool BuildWhere(ExtentStatement statement, string alias)
        {
            var schema = statement.Schema;

            if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses)
            {
                statement.Append("\n");
                statement.Append("EXISTS(\n");
                statement.Append("SELECT " + alias + "." + schema.ObjectId + "\n");
                statement.Append("FROM " + schema.Table(this.role) + "\n");
                statement.Append("WHERE   " + schema.AssociationId + "=" + alias + "." + schema.ObjectId + "\n");
                statement.Append("AND " + schema.RoleId + "=" + this.allorsObject.Strategy.ObjectId + "\n");
                statement.Append(")\n");
            }
            else
            {
                var compositeType = (IComposite)this.role.ObjectType;

                // This join is not possible because of the 3VL (Three Valued Logic).
                // It should work for normal queries, but it fails when wrapped in a NOT( ... ) predicate.
                // The rows with NULL values should then return TRUE and not UNKNOWN.
                //
                // statement.sql.Append(" " + role.SingularPropertyName + "_R." + schema.O + " = " + allorsObject.ObjectId);

                statement.Append("\n");
                statement.Append("EXISTS(\n");
                statement.Append("SELECT " + schema.ObjectId + "\n");
                statement.Append("FROM " + schema.Table(compositeType.ExclusiveClass) + "\n");
                statement.Append("WHERE " + schema.ObjectId + "=" + this.allorsObject.Strategy.ObjectId + "\n");
                statement.Append("AND " + schema.Column(this.role.AssociationType) + "=" + alias + ".O\n");
                statement.Append(")\n");
            }

            return(Include);
        }
Exemple #18
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);
        }
        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);
        }