internal 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.Database.Except + "\n"); break; } statement.Append("("); this.second.BuildSql(statement); statement.Append(")"); return(null); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.role.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL"); } else { if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL"); } else { if (this.role.IsMany) { statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IS NOT NULL"); } else { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL"); } } } return this.Include; }
internal void BuildOrder(ExtentStatement statement, string alias) { if (statement.Sorter.Equals(this)) { statement.Append(" ORDER BY " + alias + "." + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType]); } else { statement.Append(" , " + alias + "." + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType]); } 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); } }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.role.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL"); } else { if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL"); } else { if (this.role.IsMany) { statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IS NOT NULL"); } else { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL"); } } } return(this.Include); }
internal void BuildOrder(ExtentStatement statement) { if (statement.Sorter.Equals(this)) { statement.Append(" ORDER BY " + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType]); } else { statement.Append(" , " + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType]); } statement.Append(this.direction == SortDirection.Ascending ? " ASC " : " DESC "); if (this.subSorter != null) { this.subSorter.BuildOrder(statement); } if (this.direction == SortDirection.Ascending) { this.AddAscendingAppendix(statement); } else { this.AddDescendingAppendix(statement); } }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.roleType.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + "=" + statement.AddParameter(this.obj)); } else { var allorsObject = (IObject)this.obj; if (this.roleType.RelationType.ExistExclusiveClasses) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " IS NOT NULL AND "); statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + "=" + allorsObject.Strategy.ObjectId + ")"); } else { statement.Append(" (" + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + "=" + allorsObject.Strategy.ObjectId + ")"); } } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.roleType.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + "=" + statement.AddParameter(this.obj)); } else { var allorsObject = (IObject)this.obj; if (this.roleType.RelationType.ExistExclusiveClasses) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " IS NOT NULL AND "); statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + "=" + allorsObject.Strategy.ObjectId + ")"); } else { statement.Append(" (" + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + "=" + allorsObject.Strategy.ObjectId + ")"); } } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.instanceClasses.Length == 1) { statement.Append(alias + "." + Mapping.ColumnNameForClass + "=" + 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.ColumnNameForClass + "=" + statement.AddParameter(this.instanceClasses[i].Id)); if (i < this.instanceClasses.Length - 1) { statement.Append(" OR "); } } statement.Append(" ) "); } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; var inStatement = statement.CreateChild(this.inExtent, this.association); inStatement.UseRole(this.association.RoleType); if ((this.association.IsMany && this.association.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IS NULL OR"); statement.Append(" NOT " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IN (\n"); statement.Append(" SELECT " + Mapping.ColumnNameForRole + " FROM " + schema.TableNameForRelationByRelationType[this.association.RelationType] + " WHERE " + Mapping.ColumnNameForAssociation + " IN ("); this.inExtent.BuildSql(inStatement); statement.Append(" )))\n"); } else { if (this.association.RoleType.IsMany) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IS NULL OR "); statement.Append(" NOT " + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IN (\n"); this.inExtent.BuildSql(inStatement); statement.Append(" ))\n"); } else { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IS NULL OR "); statement.Append(" NOT " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IN (\n"); this.inExtent.BuildSql(inStatement); statement.Append(" ))\n"); } } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; var inStatement = statement.CreateChild(this.inExtent, this.role); inStatement.UseAssociation(this.role.AssociationType); if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { 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(" ))"); } else { if (this.role.IsMany) { statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IN ("); this.inExtent.BuildSql(inStatement); statement.Append(" ))"); } else { statement.Append(" (" + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL AND "); statement.Append(" " + schema.ColumnNameByRelationType[this.role.RelationType] + " IN ("); this.inExtent.BuildSql(inStatement); statement.Append(" ))"); } } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; 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." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IN (\n"); this.inExtent.BuildSql(inStatement); statement.Append(" ))\n"); } else { if (this.association.RelationType.RoleType.IsMany) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IS NOT NULL AND "); statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IN (\n"); this.inExtent.BuildSql(inStatement); statement.Append(" ))\n"); } else { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IN (\n"); this.inExtent.BuildSql(inStatement); statement.Append(" ))\n"); } } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { if (this.Include) { statement.Append(" NOT ("); this.filter.BuildWhere(statement, alias); statement.Append(")"); } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" (" + alias + "." + Mapping.ColumnNameForObject + "=" + statement.AddParameter(this.obj) + ") "); return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " BETWEEN " + statement.AddParameter(this.first) + " AND " + statement.AddParameter(this.second) + ")"); return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " < " + statement.AddParameter(this.obj)); return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + ">" + alias + "." + schema.ColumnNameByRelationType[this.greaterThanRole.RelationType]); return(this.Include); }
internal void BuildSelect(ExtentStatement statement, string alias) { statement.Append(" , " + alias + "." + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType] + " "); if (this.subSorter != null) { this.subSorter.BuildSelect(statement, alias); } }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; 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 (var 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; }
private void AddDescendingAppendix(ExtentStatement statement) { var sortAppendix = this.session.Database.DescendingSortAppendix; if (sortAppendix != null) { statement.Append(sortAppendix + " "); } }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.role.ObjectType.IsUnit && this.equalsRole.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + "." + schema.ColumnNameByRelationType[this.equalsRole.RelationType]); } else if (((IComposite)this.role.ObjectType).ExistExclusiveClass && ((IComposite)this.equalsRole.ObjectType).ExistExclusiveClass) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + "." + schema.ColumnNameByRelationType[this.equalsRole.RelationType]); } else { throw new NotImplementedException(); } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if (this.role.ObjectType.IsUnit && this.equalsRole.ObjectType.IsUnit) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + "." + schema.ColumnNameByRelationType[this.equalsRole.RelationType]); } else if (((IComposite)this.role.ObjectType).ExistExclusiveClass && ((IComposite)this.equalsRole.ObjectType).ExistExclusiveClass) { statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + "." + schema.ColumnNameByRelationType[this.equalsRole.RelationType]); } else { throw new NotImplementedException(); } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.association.IsMany && this.association.RelationType.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + "=" + this.allorsObject.Strategy.ObjectId + ")"); } else { if (this.association.RelationType.RoleType.IsMany) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IS NOT NULL AND "); statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + "=" + this.allorsObject.Strategy.ObjectId + ")"); } else { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " =" + this.allorsObject.Strategy.ObjectId + ")"); } } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.association.IsMany && this.association.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForRelationByRelationType[this.association.RelationType] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append("AND " + Mapping.ColumnNameForRole + "=" + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append(")"); } else { statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " = " + this.allorsObject.Strategy.ObjectId); } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.association.IsMany && this.association.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForRelationByRelationType[this.association.RelationType] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append("AND " + Mapping.ColumnNameForRole + "=" + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append(")"); } else { statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " = " + this.allorsObject.Strategy.ObjectId); } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; var inStatement = new StringBuilder("0"); foreach (var inObject in this.enumerable) { inStatement.Append(","); inStatement.Append(inObject.Id.ToString()); } if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForAssociation + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } else { if (this.role.IsMany) { statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } else { statement.Append(" (" + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL AND "); statement.Append(" " + schema.ColumnNameByRelationType[this.role.RelationType] + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.association.IsMany && this.association.RelationType.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + "=" + this.allorsObject.Strategy.ObjectId + ")"); } else { if (this.association.RelationType.RoleType.IsMany) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IS NOT NULL AND "); statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + "=" + this.allorsObject.Strategy.ObjectId + ")"); } else { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " =" + this.allorsObject.Strategy.ObjectId + ")"); } } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForRelationByRelationType[this.role.RelationType] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("AND " + Mapping.ColumnNameForRole + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append(")\n"); } else { // 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.SingularFullName + "_R." + schema.O + " = " + allorsObject.ObjectId); statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForObjectByClass[((IComposite)this.role.ObjectType).ExclusiveClass] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForObject + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append("AND " + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + ".O\n"); statement.Append(")\n"); } return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" (" + alias + "." + Mapping.ColumnNameForObject + "=" + statement.AddParameter(this.obj) + ") "); return this.Include; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.role.RelationType] + ">" + alias + "." + schema.ColumnNameByRelationType[this.greaterThanRole.RelationType]); return this.Include; }
private string BuildSqlWithClasses(ExtentStatement statement) { if (statement.IsRoot) { for (var i = 0; i < this.objectType.Classes.Count(); i++) { var alias = statement.CreateAlias(); var rootClass = this.objectType.Classes.ToArray()[i]; statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); if (this.filter != null) { this.filter.BuildWhere(statement, alias); } if (i < this.objectType.Classes.Count() - 1) { statement.Append("\nUNION\n"); } } } else { var inStatement = (ExtentStatementChild)statement; if (inStatement.RoleType != null) { var useUnion = false; foreach (var rootClass in this.objectType.Classes) { var inRole = inStatement.RoleType; var inIRelationType = inRole.RelationType; if (!((IComposite)inRole.ObjectType).Classes.Contains(rootClass)) { continue; } if (useUnion) { statement.Append("\nUNION\n"); } else { useUnion = true; } var alias = statement.CreateAlias(); if (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation); } else { if (inRole.IsMany) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } else { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType]); } } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); var wherePresent = statement.AddWhere(rootClass, 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 (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append(inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL "); } else { if (inRole.IsMany) { statement.Append(alias + "." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } else { statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } } } } else { for (var i = 0; i < this.objectType.Classes.Count(); i++) { var alias = statement.CreateAlias(); var rootClass = this.objectType.Classes.ToArray()[i]; if (statement.IsRoot) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement); } } else { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); if (this.filter != null) { this.filter.BuildWhere(statement, alias); } if (i < this.objectType.Classes.Count() - 1) { statement.Append("\nUNION\n"); } } } } return(null); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; 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) { // TODO: in combination with NOT gives error statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } else { if (this.role.IsMany) { statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IS NOT NULL AND "); statement.Append(" " + this.role.SingularFullName + "_R." + Mapping.ColumnNameForObject + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } else { statement.Append(" (" + schema.ColumnNameByRelationType[this.role.RelationType] + " IS NOT NULL AND "); statement.Append(" " + schema.ColumnNameByRelationType[this.role.RelationType] + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))"); } } return(this.Include); }
private string BuildSqlWithExclusiveClass(ExtentStatement statement) { var alias = statement.CreateAlias(); var rootClass = this.objectType.ExclusiveClass; if (statement.IsRoot) { statement.Append("SELECT DISTINCT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement, alias); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, 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 inIRelationType = inRole.RelationType; if (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation); } else { if (inRole.IsMany) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } else { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType]); } } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); var wherePresent = statement.AddWhere(rootClass, 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 (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append(inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL "); } else { if (inRole.IsMany) { statement.Append(alias + "." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } else { statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } } } else { var inAssociation = inStatement.AssociationType; var inIRelationType = inAssociation.RelationType; if (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append("SELECT " + inAssociation.RoleType.SingularFullName + "_R." + Mapping.ColumnNameForRole); } else { if (inAssociation.RoleType.IsMany) { statement.Append("SELECT " + inAssociation.RoleType.SingularFullName + "_R." + this.Mapping.ColumnNameByRelationType[inAssociation.RelationType]); } else { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); var wherePresent = statement.AddWhere(rootClass, 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 (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append(inAssociation.RoleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL "); } else { if (inAssociation.RoleType.IsMany) { statement.Append(inAssociation.RoleType.SingularFullName + "_R." + this.Mapping.ColumnNameByRelationType[inAssociation.RelationType] + " IS NOT NULL "); } else { statement.Append(alias + "." + inAssociation.RoleType.SingularFullName + " IS NOT NULL "); } } } } return alias; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; var inStatement = new StringBuilder("0"); foreach (var inObject in this.enumerable) { inStatement.Append(","); inStatement.Append(inObject.Id.ToString()); } if ((this.association.IsMany && this.association.RelationType.RoleType.IsMany) || !this.association.RelationType.ExistExclusiveClasses) { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IS NULL OR "); statement.Append(" NOT " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForRole + " IN (\n"); statement.Append(" SELECT " + Mapping.ColumnNameForRole + " FROM " + schema.TableNameForRelationByRelationType[this.association.RelationType] + " WHERE " + Mapping.ColumnNameForAssociation + " IN ("); statement.Append(inStatement.ToString()); statement.Append(" ))\n"); } else { if (this.association.RelationType.RoleType.IsMany) { statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IS NULL OR "); statement.Append(" NOT " + alias + "." + schema.ColumnNameByRelationType[this.association.RelationType] + " IN (\n"); statement.Append(inStatement.ToString()); statement.Append(" ))\n"); } else { statement.Append(" (" + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IS NULL OR "); statement.Append(" NOT " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForObject + " IN (\n"); statement.Append(inStatement.ToString()); statement.Append(" ))\n"); } } return(this.Include); }
internal 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.Database.Except + "\n"); break; } statement.Append("("); this.second.BuildSql(statement); statement.Append(")"); return null; }
private string BuildSqlWithExclusiveClass(ExtentStatement statement) { var alias = statement.CreateAlias(); var rootClass = this.objectType.ExclusiveClass; if (statement.IsRoot) { statement.Append("SELECT DISTINCT " + alias + "." + Mapping.ColumnNameForObject); statement.Sorter?.BuildSelect(statement, alias); statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); this.filter?.BuildWhere(statement, alias); } else { // ContainedIn var inStatement = (ExtentStatementChild)statement; if (inStatement.RoleType != null) { var inRole = inStatement.RoleType; var inIRelationType = inRole.RelationType; if (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation); } else { if (inRole.IsMany) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } else { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType]); } } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); var wherePresent = statement.AddWhere(rootClass, 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 (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append(inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL "); } else { if (inRole.IsMany) { statement.Append(alias + "." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } else { statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } } } else { if (statement.IsRoot) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement); } } else { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); if (this.filter != null) { this.filter.BuildWhere(statement, alias); } } } return(alias); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" (" + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " BETWEEN " + statement.AddParameter(this.first) + " AND " + statement.AddParameter(this.second) + ")"); return this.Include; }
private string BuildSqlWithClasses(ExtentStatement statement) { if (statement.IsRoot) { for (var i = 0; i < this.objectType.Classes.Count(); i++) { var alias = statement.CreateAlias(); var rootClass = this.objectType.Classes.ToArray()[i]; statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); if (this.filter != null) { this.filter.BuildWhere(statement, alias); } if (i < this.objectType.Classes.Count() - 1) { statement.Append("\nUNION\n"); } } } else { var inStatement = (ExtentStatementChild)statement; if (inStatement.RoleType != null) { var useUnion = false; foreach (var rootClass in this.objectType.Classes) { var inRole = inStatement.RoleType; var inIRelationType = inRole.RelationType; if (!((IComposite)inRole.ObjectType).Classes.Contains(rootClass)) { continue; } if (useUnion) { statement.Append("\nUNION\n"); } else { useUnion = true; } var alias = statement.CreateAlias(); if (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation); } else { if (inRole.IsMany) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } else { statement.Append("SELECT " + inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType]); } } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); var wherePresent = statement.AddWhere(rootClass, 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 (inIRelationType.Multiplicity == Multiplicity.ManyToMany || !inIRelationType.ExistExclusiveClasses) { statement.Append(inRole.AssociationType.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL "); } else { if (inRole.IsMany) { statement.Append(alias + "." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } else { statement.Append(inRole.AssociationType.SingularFullName + "_A." + this.Mapping.ColumnNameByRelationType[inRole.RelationType] + " IS NOT NULL "); } } } } else { for (var i = 0; i < this.objectType.Classes.Count(); i++) { var alias = statement.CreateAlias(); var rootClass = this.objectType.Classes.ToArray()[i]; if (statement.IsRoot) { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); if (statement.Sorter != null) { statement.Sorter.BuildSelect(statement); } } else { statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject); } statement.Append(" FROM " + this.Mapping.TableNameForObjectByClass[rootClass] + " " + alias); statement.AddJoins(rootClass, alias); statement.AddWhere(rootClass, alias); if (this.filter != null) { this.filter.BuildWhere(statement, alias); } if (i < this.objectType.Classes.Count() - 1) { statement.Append("\nUNION\n"); } } } } return null; }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; if ((this.role.IsMany && this.role.RelationType.AssociationType.IsMany) || !this.role.RelationType.ExistExclusiveClasses) { statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForRelationByRelationType[this.role.RelationType] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("AND " + Mapping.ColumnNameForRole + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append(")\n"); } else { // 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.SingularFullName + "_R." + schema.O + " = " + allorsObject.ObjectId); statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + schema.TableNameForObjectByClass[((IComposite)this.role.ObjectType).ExclusiveClass] + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForObject + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append("AND " + schema.ColumnNameByRelationType[this.role.RelationType] + "=" + alias + ".O\n"); statement.Append(")\n"); } return(this.Include); }
internal override bool BuildWhere(ExtentStatement statement, string alias) { var schema = statement.Mapping; statement.Append(" " + alias + "." + schema.ColumnNameByRelationType[this.roleType.RelationType] + " < " + statement.AddParameter(this.obj)); return this.Include; }
internal void BuildSelect(ExtentStatement statement, string alias) { statement.Append(" , " + alias + "." + statement.Mapping.ColumnNameByRelationType[this.roleType.RelationType] + " "); if (this.subSorter != null) { this.subSorter.BuildSelect(statement, alias); } }
internal override bool BuildWhere(ExtentStatement statement, string alias) { if (this.Include) { statement.Append(" NOT ("); this.filter.BuildWhere(statement, alias); statement.Append(")"); } return this.Include; }
private void AddDescendingAppendix(ExtentStatement statement) { var sortAppendix = this.session.Database.DescendingSortAppendix; if (sortAppendix != null) { statement.Append(sortAppendix + " "); } }