internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { if (this.instanceClasses.Length == 1) { statement.Append(" (" + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND "); statement.Append(" " + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[0].Id) + ")"); } else if (this.instanceClasses.Length > 1) { statement.Append(" ( "); for (int i = 0; i < this.instanceClasses.Length; i++) { statement.Append(" (" + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + " IS NOT NULL AND "); statement.Append(" " + statement.GetJoinName(this.role) + "." + Mapping.ColumnNameForType + "=" + statement.AddParameter(this.instanceClasses[i].Id) + ")"); if (i < this.instanceClasses.Length - 1) { statement.Append(" OR "); } } statement.Append(" ) "); } return this.Include; }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { 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.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; }
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) { statement.Append("\n"); statement.Append("EXISTS(\n"); statement.Append("SELECT " + Mapping.ColumnNameForObject + "\n"); statement.Append("FROM " + extent.Session.Database.SchemaName + "." + mapping.GetTableName(this.role) + "\n"); statement.Append("WHERE " + Mapping.ColumnNameForAssociation + "=" + alias + "." + Mapping.ColumnNameForObject + "\n"); statement.Append("AND " + Mapping.ColumnNameForRole + "=" + this.allorsObject.Strategy.ObjectId + "\n"); statement.Append(")\n"); return this.Include; }
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; }
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); } }
public ObjectDataRecords(Mapping mapping, IEnumerable <long> objectIds) { this.mapping = mapping; this.objectIds = objectIds; }
internal Initialization(Mapping mapping, Schema schema, bool useViews) { this.mapping = mapping; this.schema = schema; this.useViews = useViews; }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" " + this.roleType.SingularFullName + "_R." + Mapping.ColumnNameForRole + " BETWEEN " + statement.AddParameter(this.first) + " AND " + statement.AddParameter(this.second) + " "); return this.Include; }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " LIKE " + statement.AddParameter(this.str)); return this.Include; }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" (" + this.role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL AND "); statement.Append(" " + this.role.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(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL"); return this.Include; }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" " + role.SingularFullName + "_R." + Mapping.ColumnNameForRole + " IS NOT NULL"); return Include; }
internal abstract bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias);
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" (" + alias + "." + Mapping.ColumnNameForObject + "=" + statement.AddParameter(obj) + ") "); return Include; }
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); } }
public Database(Configuration configuration) { this.connectionString = configuration.ConnectionString; if (this.connectionString == null) { throw new Exception("Configuration.ConnectionString is missing"); } var connectionStringBuilder = new SqlConnectionStringBuilder(this.connectionString); var applicationName = connectionStringBuilder.ApplicationName.Trim(); if (!string.IsNullOrWhiteSpace(applicationName)) { this.id = applicationName; } else { if (!string.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog)) { this.id = connectionStringBuilder.InitialCatalog.ToLowerInvariant(); } else { using (this.connection = new SqlConnection(this.connectionString)) { this.connection.Open(); this.id = this.connection.Database.ToLowerInvariant(); } } } this.objectFactory = configuration.ObjectFactory; if (this.objectFactory == null) { throw new Exception("Configuration.ObjectFactory is missing"); } if (!this.objectFactory.MetaPopulation.IsValid) { throw new ArgumentException("Domain is invalid"); } this.objectIds = configuration.ObjectIds ?? new ObjectIdsInteger(); this.roleCache = configuration.RoleCache ?? new RoleCache(); this.classCache = configuration.ClassCache ?? new ClassCache(); this.commandTimeout = configuration.CommandTimeout ?? 30; this.isolationLevel = configuration.IsolationLevel ?? IsolationLevel.Snapshot; this.schemaName = configuration.SchemaName ?? "allors"; this.useViews = configuration.UseViews ?? true; if (this.ObjectIds is ObjectIdsInteger) { this.mapping = new MappingInteger(this); } else if (this.ObjectIds is ObjectIdsLong) { this.mapping = new MappingLong(this); } else { throw new NotSupportedException("ObjectIds of type " + this.ObjectIds.GetType() + " are not supported."); } }
internal override bool BuildWhere(AllorsExtentFilteredSql extent, Mapping mapping, AllorsExtentStatementSql statement, IObjectType type, string alias) { statement.Append(" " + this.association.SingularFullName + "_A." + Mapping.ColumnNameForAssociation + " IS NOT NULL"); return(this.Include); }
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; }