internal void CheckForRoleType(IRoleType roleType) { if (!this.objectType.ExistRoleType(roleType)) { throw new ArgumentException("Extent does not have role " + roleType.SingularName); } }
internal RoleLessThanRole(ExtentFiltered extent, IRoleType role, IRoleType lessThanRole) { extent.CheckRole(role); PredicateAssertions.ValidateRoleLessThan(role, lessThanRole); this.role = role; this.lessThanRole = lessThanRole; }
internal RoleLike(ExtentFiltered extent, IRoleType role, string like) { extent.CheckRole(role); PredicateAssertions.ValidateRoleLikeFilter(role, like); this.role = role; this.like = like; }
internal RoleLessThanValue(ExtentFiltered extent, IRoleType roleType, object obj) { extent.CheckRole(roleType); PredicateAssertions.ValidateRoleLessThan(roleType, obj); this.roleType = roleType; this.obj = roleType.Normalize(obj); }
public RoleContainedInEnumerable(AllorsExtentFilteredSql extent, IRoleType role, IEnumerable<IObject> enumerable) { extent.CheckRole(role); PredicateAssertions.ValidateRoleContainedIn(role, this.enumerable); this.role = role; this.enumerable = enumerable; }
public ICompositePredicate AddBetween(IRoleType role, object firstValue, object secondValue) { this.CheckUnarity(); this.predicate = new RoleBetween(this.extent, role, firstValue, secondValue); this.extent.Invalidate(); return this; }
internal AllorsPredicateRoleInstanceofSql(AllorsExtentFilteredSql extent, IRoleType role, IObjectType instanceType, IClass[] instanceClasses) { extent.CheckRole(role); PredicateAssertions.ValidateRoleInstanceOf(role, instanceType); this.role = role; this.instanceClasses = instanceClasses; }
internal void AddCompositeRole(Reference association, IRoleType roleType, HashSet<ObjectId> added) { if (this.addCompositeRoleRelationsByRoleType == null) { this.addCompositeRoleRelationsByRoleType = new Dictionary<IRoleType, List<CompositeRelation>>(); } List<CompositeRelation> relations; if (!this.addCompositeRoleRelationsByRoleType.TryGetValue(roleType, out relations)) { relations = new List<CompositeRelation>(); this.addCompositeRoleRelationsByRoleType[roleType] = relations; } foreach (var roleObjectId in added) { relations.Add(new CompositeRelation(association.ObjectId, roleObjectId)); } if (relations.Count > BatchSize) { this.session.AddCompositeRole(relations, roleType); relations.Clear(); } }
internal AllorsPredicateRoleGreaterThanValueSql(AllorsExtentFilteredSql extent, IRoleType roleType, Object obj) { extent.CheckRole(roleType); PredicateAssertions.ValidateRoleGreaterThan(roleType, obj); this.roleType = roleType; this.obj = roleType.ObjectType is IUnit ? roleType.Normalize(obj) : obj; }
internal AllorsPredicateRoleLikeSql(AllorsExtentFilteredSql extent, IRoleType role, String str) { extent.CheckRole(role); PredicateAssertions.ValidateRoleLikeFilter(role, str); this.role = role; this.str = str; }
internal AllorsPredicateRoleUnitEqualsRoleSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType equalsRole) { extent.CheckRole(role); PredicateAssertions.ValidateRoleEquals(role, equalsRole); this.role = role; this.equalsRole = equalsRole; }
public AllorsPredicateRoleInExtentSql(AllorsExtentFilteredSql extent, IRoleType role, Allors.Extent inExtent) { extent.CheckRole(role); PredicateAssertions.ValidateRoleContainedIn(role, inExtent); this.role = role; this.inExtent = (AllorsExtentSql)inExtent; }
internal RoleContains(ExtentFiltered extent, IRoleType role, IObject allorsObject) { extent.CheckRole(role); PredicateAssertions.ValidateRoleContains(role, allorsObject); this.role = role; this.allorsObject = allorsObject; }
internal AllorsPredicateRoleCompositeEqualsSql(AllorsExtentFilteredSql extent, IRoleType role, Object obj) { extent.CheckRole(role); PredicateAssertions.ValidateRoleEquals(role, obj); this.role = role; this.obj = obj; }
internal AllorsPredicateRoleGreaterThanSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType greaterThanRole) { extent.CheckRole(role); PredicateAssertions.ValidateRoleGreaterThan(role, greaterThanRole); this.role = role; this.greaterThanRole = greaterThanRole; }
internal RoleContainedInExtent(ExtentFiltered extent, IRoleType role, Allors.Extent inExtent) { extent.CheckRole(role); PredicateAssertions.ValidateRoleContainedIn(role, inExtent); this.role = role; this.inExtent = ((Extent)inExtent).ContainedInExtent; }
internal RoleEqualsRole(ExtentFiltered extent, IRoleType role, IRoleType equalsRole) { extent.CheckRole(role); PredicateAssertions.ValidateRoleEquals(role, equalsRole); this.role = role; this.equalsRole = equalsRole; }
internal RoleExists(ExtentFiltered extent, IRoleType roleType) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleExists(roleType); this.roleType = roleType; }
internal AllorsPredicateRoleBetweenValueSql(AllorsExtentFilteredSql extent, IRoleType roleType, Object first, Object second) { extent.CheckRole(roleType); PredicateAssertions.ValidateRoleBetween(roleType, first, second); this.roleType = roleType; this.first = roleType.ObjectType is IUnit ? roleType.Normalize(first) : first; this.second = roleType.ObjectType is IUnit ? roleType.Normalize(second) : second; }
internal RoleContains(ExtentFiltered extent, IRoleType roleType, IObject containedObject) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleContains(roleType, containedObject); this.roleType = roleType; this.containedObject = containedObject; }
internal RoleInstanceof(ExtentFiltered extent, IRoleType roleType, IComposite objectType) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleInstanceOf(roleType, objectType); this.roleType = roleType; this.objectType = objectType; }
internal RoleOneContainedInExtent(ExtentFiltered extent, IRoleType roleType, Allors.Extent containingExtent) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleContainedIn(roleType, containingExtent); this.roleType = roleType; this.containingExtent = containingExtent; }
internal RoleBetweenValue(ExtentFiltered extent, IRoleType roleType, object first, object second) { extent.CheckRole(roleType); PredicateAssertions.ValidateRoleBetween(roleType, first, second); this.roleType = roleType; this.first = roleType.Normalize(first); this.second = roleType.Normalize(second); }
internal AllorsPredicateRoleBetweenRoleSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType first, IRoleType second) { extent.CheckRole(role); PredicateAssertions.ValidateRoleBetween(role, first, second); this.role = role; this.first = first; this.second = second; }
internal RoleCompositeEqualsValue(ExtentFiltered extent, IRoleType roleType, object equals) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleEquals(roleType, equals); this.roleType = roleType; this.equals = equals; }
internal RoleManyContainedInEnumerable(ExtentFiltered extent, IRoleType roleType, IEnumerable<IObject> containingEnumerable) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleContainedIn(roleType, containingEnumerable); this.roleType = roleType; this.containingEnumerable = containingEnumerable; }
internal RoleLike(ExtentFiltered extent, IRoleType roleType, string like) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleLikeFilter(roleType, like); this.roleType = roleType; this.isEmpty = like.Length == 0; this.regex = new Regex("^" + like.Replace("%", ".*") + "$"); }
internal RoleLessThan(ExtentFiltered extent, IRoleType roleType, object compare) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleLessThan(roleType, compare); this.extent = extent; this.roleType = roleType; this.compare = compare; }
internal void AddSort(IRoleType sortRoleType, SortDirection sortDirection) { if (this.subSorter == null) { this.subSorter = new AllorsExtentSortSql(this.session, sortRoleType, sortDirection); } else { this.subSorter.AddSort(sortRoleType, sortDirection); } }
internal void AddSort(IRoleType subSortIRoleType, SortDirection subSortDirection) { if (this.subSorter == null) { this.subSorter = new ExtentSort(this.session, subSortIRoleType, subSortDirection); } else { this.subSorter.AddSort(subSortIRoleType, subSortDirection); } }
internal IObject ExtentGetItem(IRoleType roleType, int index) { var i = 0; foreach (var oid in this.Roles.GetCompositesRole(roleType)) { if (i == index) { return(this.Session.State.GetOrCreateReferenceForExistingObject(oid, this.Session).Strategy.GetObject()); } ++i; } return(null); }
internal void OnChangingCompositeRole(Roles association, IRoleType roleType, long? previousRole, long? newRole) { this.associations.Add(association.Reference.ObjectId); if (previousRole != null) { this.roles.Add(previousRole.Value); } if (newRole != null) { this.roles.Add(newRole.Value); } this.RoleTypes(association.Reference.ObjectId).Add(roleType); }
public bool ExistCompositeRoles(IRoleType roleType) { this.AssertNotDeleted(); switch (roleType.RelationType.Multiplicity) { case Multiplicity.OneToMany: return(this.session.ExistCompositeRoleOneToMany(this.objectId, roleType)); case Multiplicity.ManyToMany: return(this.session.ExistCompositeRoleManyToMany(this.objectId, roleType)); default: throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity); } }
internal int ExtentIndexOf(IRoleType roleType, IObject value) { var i = 0; foreach (var oid in this.Roles.GetCompositesRole(roleType)) { if (oid.Equals(value.Id)) { return(i); } ++i; } return(-1); }
private void AddCompositeRoleOne2Many(IRoleType roleType, Strategy newRoleStrategy) { this.compositesRoleByRoleType.TryGetValue(roleType, out var previousRoleStrategies); if (previousRoleStrategies != null && previousRoleStrategies.Contains(newRoleStrategy)) { return; } this.ChangeSet.OnChangingCompositesRole(this.ObjectId, roleType, newRoleStrategy); // 1-... newRoleStrategy.compositeAssociationByAssociationType.TryGetValue(roleType.AssociationType, out var newRolePreviousAssociationStrategy); if (newRolePreviousAssociationStrategy != null) { this.ChangeSet.OnChangingCompositesRole(newRolePreviousAssociationStrategy.ObjectId, roleType, null); // Remove obsolete role newRolePreviousAssociationStrategy.Backup(roleType); newRolePreviousAssociationStrategy.compositesRoleByRoleType.TryGetValue(roleType, out var newRolePreviousAssociationStrategyRoleStrategies); if (newRolePreviousAssociationStrategyRoleStrategies == null) { newRolePreviousAssociationStrategyRoleStrategies = new HashSet <Strategy>(); newRolePreviousAssociationStrategy.compositesRoleByRoleType[roleType] = newRolePreviousAssociationStrategyRoleStrategies; } newRolePreviousAssociationStrategyRoleStrategies.Remove(newRoleStrategy); if (newRolePreviousAssociationStrategyRoleStrategies.Count == 0) { newRolePreviousAssociationStrategy.compositesRoleByRoleType.Remove(roleType); } } // Add the new role this.Backup(roleType); this.compositesRoleByRoleType.TryGetValue(roleType, out var roleStrategies); if (roleStrategies == null) { roleStrategies = new HashSet <Strategy>(); this.compositesRoleByRoleType[roleType] = roleStrategies; } roleStrategies.Add(newRoleStrategy); // Set new association newRoleStrategy.Backup(roleType.AssociationType); newRoleStrategy.compositeAssociationByAssociationType[roleType.AssociationType] = this; }
/// <summary> /// Asserts that the <see cref="RoleType"/> and the unit are compatible with /// <see cref="ICompositePredicate#AddLessThan"/>. /// </summary> /// <param name="role">The role .</param> /// <param name="unit">The unit .</param> public static void ValidateRoleLessThan(IRoleType role, object unit) { if (role.ObjectType is IComposite) { throw new ArgumentException("AddLessThan() can only be used with unit types."); } if (unit == null) { throw new ArgumentException("AddLessThan() requires a value."); } if (unit is IRoleType compareRole && compareRole.ObjectType is IComposite) { throw new ArgumentException("AddLessThan() can only be used with roles having unit types."); } }
internal void SetCompositeRoleMany2One(IRoleType roleType, IObject newRole) { this.AssertNotDeleted(); this.session.MemoryDatabase.CompositeRoleChecks(this, roleType, newRole); var previousRole = this.GetCompositeRole(roleType.RelationType); this.ChangeSet.OnChangingCompositeRole(this.ObjectId, roleType, previousRole?.Id, newRole?.Id); if (!newRole.Equals(previousRole)) { var associationType = roleType.AssociationType; // Update association of previous role if (previousRole != null) { var previousRoleStrategy = this.session.GetStrategy(previousRole); HashSet <Strategy> previousRoleStrategies; previousRoleStrategy.compositesAssociationByAssociationType.TryGetValue(associationType, out previousRoleStrategies); previousRoleStrategy.Backup(associationType); previousRoleStrategies.Remove(this); if (previousRoleStrategies.Count == 0) { previousRoleStrategy.compositesAssociationByAssociationType.Remove(associationType); } } var newRoleStrategy = this.session.GetStrategy(newRole); this.Backup(roleType); this.compositeRoleByRoleType[roleType] = newRoleStrategy; HashSet <Strategy> strategies; newRoleStrategy.compositesAssociationByAssociationType.TryGetValue(associationType, out strategies); newRoleStrategy.Backup(associationType); if (strategies == null) { strategies = new HashSet <Strategy>(); newRoleStrategy.compositesAssociationByAssociationType[associationType] = strategies; } strategies.Add(this); } }
internal void SetCompositeRolesMany2Many(IRoleType roleType, HashSet <Strategy> roles) { this.AssertNotDeleted(); var originalRoles = this.GetStrategies(roleType); if (!roles.SetEquals(originalRoles)) { this.RemoveCompositeRolesMany2Many(roleType); // TODO: Optimize this foreach (var strategy in roles) { this.AddCompositeRoleMany2Many(roleType, strategy); } } }
internal void SetCompositeRoleOne2One(IRoleType roleType, IObject newRole) { this.AssertNotDeleted(); this.MemorySession.MemoryDatabase.CompositeRoleChecks(this, roleType, newRole); var previousRole = this.GetCompositeRole(roleType.RelationType); if (!newRole.Equals(previousRole)) { this.ChangeSet.OnChangingCompositeRole(this.ObjectId, roleType, previousRole?.Id, newRole?.Id); var newRoleStrategy = this.MemorySession.GetStrategy(newRole); if (previousRole != null) { // previous role var previousRoleStrategy = this.MemorySession.GetStrategy(previousRole); var associationType = roleType.AssociationType; previousRoleStrategy.Backup(associationType); previousRoleStrategy.compositeAssociationByAssociationType.Remove(associationType); } // previous association of newRole var newRolePreviousAssociation = newRoleStrategy.GetCompositeAssociation(roleType.RelationType); if (newRolePreviousAssociation != null) { var newRolePreviousAssociationStrategy = this.MemorySession.GetStrategy(newRolePreviousAssociation); if (!this.Equals(newRolePreviousAssociationStrategy)) { this.ChangeSet.OnChangingCompositeRole(newRolePreviousAssociationStrategy.ObjectId, roleType, previousRole?.Id, null); newRolePreviousAssociationStrategy.Backup(roleType); newRolePreviousAssociationStrategy.compositeRoleByRoleType.Remove(roleType); } } // Set new role this.Backup(roleType); this.compositeRoleByRoleType[roleType] = newRoleStrategy; // Set new role's association var associationType1 = roleType.AssociationType; newRoleStrategy.Backup(associationType1); newRoleStrategy.compositeAssociationByAssociationType[associationType1] = this; } }
public bool TryGetComposites(long association, object cacheId, IRoleType roleType, out long[] role) { if (this.cachedCompositesRoleByAssociationByRoleType.TryGetValue(roleType, out var entryByAssociation)) { if (entryByAssociation.TryGetValue(association, out var cachedCompositesRole)) { if (cachedCompositesRole.CacheId.Equals(cacheId)) { role = cachedCompositesRole.Role; return(true); } } } role = null; return(false); }
private long[] GetNonModifiedCompositeRoles(IRoleType roleType) { if (!this.Reference.IsNew) { if (this.CachedObject != null && this.CachedObject.TryGetValue(roleType, out var roleOut)) { return((long[])roleOut); } this.Reference.Session.Commands.GetCompositesRole(this, roleType); this.cachedObject.TryGetValue(roleType, out roleOut); var role = (long[])roleOut; return(role); } return(Database.EmptyObjectIds); }
internal IObject ExtentFirst(Session session, IRoleType roleType) { if (this.ModifiedRolesByRoleType != null && this.ModifiedRolesByRoleType.TryGetValue(roleType, out var compositesRole)) { var objectId = compositesRole.First; return(objectId == null ? null : session.State.GetOrCreateReferenceForExistingObject(objectId.Value, session).Strategy.GetObject()); } var nonModifiedCompositeRoles = this.GetNonModifiedCompositeRoles(roleType); if (nonModifiedCompositeRoles.Length > 0) { return(session.State.GetOrCreateReferenceForExistingObject(nonModifiedCompositeRoles[0], session).Strategy.GetObject()); } return(null); }
public static void RoleExistHasException(IObject allorsObject, IRoleType roleType) { var exceptionOccured = false; try { object o = allorsObject.Strategy.ExistRole(roleType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.True(false, "Exist didn't threw an Exception for role " + roleType); } }
public static void RoleGetHasException(IObject allorsObject, IRoleType roleType) { var exceptionOccured = false; try { var o = allorsObject.Strategy.GetRole(roleType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.True(false); // Fail } }
public virtual void RemoveRole(IRoleType roleType) { if (roleType.ObjectType is IUnit) { this.RemoveUnitRole(roleType); } else { if (roleType.IsMany) { this.RemoveCompositeRoles(roleType); } else { this.RemoveCompositeRole(roleType); } } }
internal RoleUnitEquals(ExtentFiltered extent, IRoleType roleType, object equals) { extent.CheckForRoleType(roleType); PredicateAssertions.ValidateRoleEquals(roleType, equals); this.extent = extent; this.roleType = roleType; if (equals is Enum) { if (roleType.ObjectType is IUnit unitType && unitType.IsInteger) { this.equals = (int)equals; } else { throw new Exception("Role Object Type " + roleType.ObjectType.SingularName + " doesn't support enumerations."); } }
internal void OnChangingCompositeRole(long association, IRoleType roleType, long?previousRole, long?newRole) { this.associations.Add(association); if (previousRole != null) { this.roles.Add(previousRole.Value); this.AssociationTypes(previousRole.Value).Add(roleType.AssociationType); } if (newRole != null) { this.roles.Add(newRole.Value); this.AssociationTypes(newRole.Value).Add(roleType.AssociationType); } this.RoleTypes(association).Add(roleType); }
public string GetSql(IObjectType objectType, IRoleType roleType) { Dictionary <IRoleType, string> sqlByRoleType; if (!this.sqlByRoleTypeByObjectType.TryGetValue(objectType, out sqlByRoleType)) { sqlByRoleType = new Dictionary <IRoleType, string>(); this.sqlByRoleTypeByObjectType.Add(objectType, sqlByRoleType); } if (!sqlByRoleType.ContainsKey(roleType)) { var sql = Schema.AllorsPrefix + "SR_" + objectType.SingularName + "_" + roleType.SingularPropertyName; sqlByRoleType[roleType] = sql; } return(sqlByRoleType[roleType]); }
internal void RemoveCompositeRole(List <CompositeRelation> relations, IRoleType roleType) { if (!this.RemoveCompositeRoleByRoleType.TryGetValue(roleType, out var command)) { var sql = this.Database.Mapping.ProcedureNameForRemoveRoleByRelationType[roleType.RelationType]; command = this.connection.CreateCommand(); command.CommandText = sql; command.CommandType = CommandType.StoredProcedure; command.AddCompositeRoleTableParameter(relations); this.removeCompositeRoleByRoleType[roleType] = command; } else { command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateCompositeRelationTable(relations); } command.ExecuteNonQuery(); }
public static void RoleGetHasException(IObject allorsObject, IRoleType roleType) { bool exceptionOccured = false; try { object o = allorsObject.Strategy.GetRole(roleType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail(); } }
/// <summary> /// Asserts that the <see cref="RoleType"/> and the object are compatible with /// <see cref="ICompositePredicate#AddEquals"/>. /// </summary> /// <param name="role">The role .</param> /// <param name="compareObject">The compare object.</param> public static void ValidateRoleEquals(IRoleType role, object compareObject) { if (role.IsMany) { throw new ArgumentException("AddRoleEqual() can only be used when the role has multiplicity one."); } if (compareObject == null) { throw new ArgumentException( "AddEquals() requires a non-null value or object, use AddNot().AddExists() instead."); } if (compareObject is IRoleType compareRole && compareRole.ObjectType is IComposite) { throw new ArgumentException("AddRoleEqual() for composites can only be used with objects (not other roles)."); } }
public object GetUnitRole(IRoleType roleType) { object role = null; if (this.modifiedRoleByRoleType == null || !this.modifiedRoleByRoleType.TryGetValue(roleType, out role)) { if (this.CachedObject == null || !this.CachedObject.TryGetValue(roleType, out role)) { if (!this.Reference.IsNew) { this.Reference.Session.SessionCommands.GetUnitRolesCommand.Execute(this); this.cachedObject.TryGetValue(roleType, out role); } } } return(role); }
public virtual long?GetCompositeRole(IRoleType roleType) { object role = null; if (this.modifiedRoleByRoleType == null || !this.modifiedRoleByRoleType.TryGetValue(roleType, out role)) { if (this.CachedObject == null || !this.CachedObject.TryGetValue(roleType, out role)) { if (!this.Reference.IsNew) { this.Reference.Session.SessionCommands.GetCompositeRoleCommand.Execute(this, roleType); this.cachedObject.TryGetValue(roleType, out role); } } } return((long?)role); }
// TODO: inline internal SqlMetaData GetSqlMetaData(string name, IRoleType roleType) { var unit = (IUnit)roleType.ObjectType; switch (unit.UnitTag) { case UnitTags.String: if (roleType.Size == -1 || roleType.Size > 4000) { return(new SqlMetaData(name, SqlDbType.NVarChar, -1)); } return(new SqlMetaData(name, SqlDbType.NVarChar, roleType.Size.Value)); case UnitTags.Integer: return(new SqlMetaData(name, SqlDbType.Int)); case UnitTags.Decimal: return(new SqlMetaData(name, SqlDbType.Decimal, (byte)roleType.Precision.Value, (byte)roleType.Scale.Value)); case UnitTags.Float: return(new SqlMetaData(name, SqlDbType.Float)); case UnitTags.Boolean: return(new SqlMetaData(name, SqlDbType.Bit)); case UnitTags.DateTime: return(new SqlMetaData(name, SqlDbType.DateTime2)); case UnitTags.Unique: return(new SqlMetaData(name, SqlDbType.UniqueIdentifier)); case UnitTags.Binary: if (roleType.Size == -1 || roleType.Size > 8000) { return(new SqlMetaData(name, SqlDbType.VarBinary, -1)); } return(new SqlMetaData(name, SqlDbType.VarBinary, (long)roleType.Size)); default: throw new Exception("!UNKNOWN VALUE TYPE!"); } }
internal void GetCompositesRole(Roles roles, IRoleType roleType) { var reference = roles.Reference; Command command; if (!this.GetCompositesRoleByRoleType.TryGetValue(roleType, out command)) { var associationType = roleType.AssociationType; string sql; if (associationType.IsMany || !roleType.RelationType.ExistExclusiveClasses) { sql = this.Database.Mapping.ProcedureNameForGetRoleByRelationType[roleType.RelationType]; } else { sql = this.Database.Mapping.ProcedureNameForGetRoleByRelationType[roleType.RelationType]; } command = this.connection.CreateCommand(); command.CommandText = sql; command.CommandType = CommandType.StoredProcedure; command.AddAssociationParameter(reference.ObjectId); this.getCompositesRoleByRoleType[roleType] = command; } else { command.Parameters[Mapping.ParamNameForAssociation].Value = reference.ObjectId; } var objectIds = new List <long>(); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var id = this.Session.State.GetObjectIdForExistingObject(reader[0].ToString()); objectIds.Add(id); } } roles.CachedObject.SetValue(roleType, objectIds.ToArray()); }
/// <summary> /// Asserts that the <see cref="RoleType"/> and the unit are compatible with /// <see cref="ICompositePredicate#AddGreaterThan"/>. /// </summary> /// <param name="role">The role .</param> /// <param name="unit">The unit .</param> public static void ValidateRoleGreaterThan(IRoleType role, object unit) { if (role.ObjectType is IComposite) { throw new ArgumentException("AddGreaterThan() can only be used with unit types."); } if (unit == null) { throw new ArgumentException("AddGreaterThan() requires a non-null value."); } var compareRole = unit as IRoleType; if (compareRole != null && compareRole.ObjectType is IComposite) { throw new ArgumentException("AAddGreaterThan() can only be used with roles having unit types."); } }
public void RemoveCompositeRoles(IRoleType roleType) { this.AssertNotDeleted(); RoleAssertions.CompositeRolesChecks(this, roleType); switch (roleType.RelationType.Multiplicity) { case Multiplicity.OneToMany: this.session.RemoveCompositeRolesOneToMany(this.objectId, roleType); return; case Multiplicity.ManyToMany: this.session.RemoveCompositeRolesManyToMany(this.objectId, roleType); return; default: throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity); } }
public ObjectId[] ExtentGetCompositeRoles(IRoleType roleType) { ObjectId[] roles; switch (roleType.RelationType.Multiplicity) { case Multiplicity.OneToMany: roles = this.session.GetCompositeRolesOneToMany(this.objectId, roleType); break; case Multiplicity.ManyToMany: roles = this.session.GetCompositeRolesManyToMany(this.objectId, roleType); break; default: throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity); } return(roles); }
public IObject ExtentFirst(DatabaseSession session, IRoleType roleType) { CompositeRoles compositeRoles; if (this.ModifiedRolesByRoleType != null && this.ModifiedRolesByRoleType.TryGetValue(roleType, out compositeRoles)) { var objectId = compositeRoles.First; return(objectId == null ? null : session.GetOrCreateAssociationForExistingObject(objectId.Value).Strategy.GetObject()); } var nonModifiedCompositeRoles = this.GetNonModifiedCompositeRoles(roleType); if (nonModifiedCompositeRoles.Length > 0) { return(session.GetOrCreateAssociationForExistingObject(nonModifiedCompositeRoles[0]).Strategy.GetObject()); } return(null); }
internal void ClearCompositeAndCompositesRole(IList <long> associations, IRoleType roleType) { var sql = this.Database.Mapping.ProcedureNameForClearRoleByRelationType[roleType.RelationType]; if (!this.ClearCompositeAndCompositesRoleByRoleType.TryGetValue(roleType, out var command)) { command = this.connection.CreateCommand(); command.CommandText = sql; command.CommandType = CommandType.StoredProcedure; command.AddObjectTableParameter(associations); this.clearCompositeAndCompositesRoleByRoleType[roleType] = command; } else { command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(associations); } command.ExecuteNonQuery(); }