internal override sealed void SystemSetValue(FieldInfo field, object oldValue, object newValue) { Session.SystemEvents.NotifyFieldValueSet(this, field, oldValue, newValue); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueSet(this, field, oldValue, newValue); if (Session.IsSystemLogicOnly) { return; } if (CanBeValidated) { Session.ValidationContext.RegisterForValidation(this, field); } var subscriptionInfo = GetSubscription(EntityEventBroker.SetFieldEventKey); if (subscriptionInfo.Second != null) { ((Action <Key, FieldInfo, object, object>)subscriptionInfo.Second) .Invoke(subscriptionInfo.First, field, oldValue, newValue); } NotifyFieldChanged(field); OnSetFieldValue(field, oldValue, newValue); } }
private static FieldAccessor CreateFieldAccessor(FieldInfo field) { if (field.IsEntity) { return(CreateFieldAccessor(EntityFieldAccessorType, field)); } if (field.IsEntitySet) { return(CreateFieldAccessor(EntitySetFieldAccessorType, field)); } if (field.IsStructure) { return(CreateFieldAccessor(StructureFieldAccessorType, field)); } if (field.IsEnum) { return(CreateFieldAccessor(EnumFieldAccessorType, field)); } if (field.ValueType == WellKnownOrmTypes.Key) { return(CreateFieldAccessor(KeyFieldAccessorType, field)); } return(CreateFieldAccessor(DefaultFieldAccessorType, field)); }
internal override sealed void SystemBeforeGetValue(FieldInfo field) { if (!Session.Configuration.Supports(SessionOptions.ReadRemovedObjects)) { EnsureNotRemoved(); } if (Session.IsDebugEventLoggingEnabled) { OrmLog.Debug(Strings.LogSessionXGettingValueKeyYFieldZ, Session, Key, field); } EnsureIsFetched(field); Session.CheckForSwitching(); Session.SystemEvents.NotifyFieldValueGetting(this, field); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueGetting(this, field); if (Session.IsSystemLogicOnly) { return; } var subscriptionInfo = GetSubscription(EntityEventBroker.GettingFieldEventKey); if (subscriptionInfo.Second != null) { ((Action <Key, FieldInfo>)subscriptionInfo.Second) .Invoke(subscriptionInfo.First, field); } OnGettingFieldValue(field); } }
internal override sealed void EnsureIsFetched(FieldInfo field) { var state = State; if (state.PersistenceState == PersistenceState.New) { return; } var tuple = state.Tuple; // tuple is already cleared if (tuple == null && (Session.Configuration.Options & SessionOptions.ReadRemovedObjects) == SessionOptions.ReadRemovedObjects) { return; } if (tuple.GetFieldState(field.MappingInfo.Offset).IsAvailable()) { return; } EnsureNotRemoved(); Session.Handler.FetchField(Key, field); }
/// <summary> /// Invoked to update <see cref="VersionInfo"/>. /// </summary> /// <param name="changedEntity">The changed entity.</param> /// <param name="changedField">The changed field.</param> /// <returns> /// <see langword="True"/>, if <see cref="VersionInfo"/> was changed; /// otherwise, <see langword="false"/>. /// </returns> /// <exception cref="NotSupportedException">Version root can't implement /// <see cref="IHasVersionRoots"/>.</exception> protected internal bool UpdateVersionInfo(Entity changedEntity, FieldInfo changedField) { if (State.IsVersionInfoUpdated || IsRemoved || changedEntity.TypeInfo.IsSystem) { return(true); } bool changed = false; try { State.IsVersionInfoUpdated = true; // Prevents recursion if (!TypeInfo.HasVersionRoots) { changed = SystemUpdateVersionInfo(changedEntity, changedField); } else { foreach (var root in ((IHasVersionRoots)this).GetVersionRoots()) { if (root.TypeInfo.HasVersionRoots) { throw new NotSupportedException(Strings.ExVersionRootObjectCantImplementIHasVersionRoots); } changed |= root.UpdateVersionInfo(changedEntity, changedField); } } return(changed); } finally { State.IsVersionInfoUpdated = changed; } }
internal override sealed void SystemBeforeSetValue(FieldInfo field, object value) { EnsureNotRemoved(); if (!changeVersionOnSetAttempt) { UpdateVersionInfo(this, field); } Session.SystemEvents.NotifyFieldValueSetting(this, field, value); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueSetting(this, field, value); if (Session.IsSystemLogicOnly) { return; } var subscriptionInfo = GetSubscription(EntityEventBroker.SettingFieldEventKey); if (subscriptionInfo.Second != null) { ((Action <Key, FieldInfo, object>)subscriptionInfo.Second).Invoke(subscriptionInfo.First, field, value); } OnSettingFieldValue(field, value); } }
internal override sealed void SystemSetValueCompleted(FieldInfo field, object oldValue, object newValue, Exception exception) { Session.SystemEvents.NotifyFieldValueSetCompleted(this, field, oldValue, newValue, exception); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueSetCompleted(this, field, oldValue, newValue, exception); } }
/// <summary> /// Called to update the fields describing <see cref="Entity"/>'s version. /// </summary> /// <param name="changedEntity">The changed entity.</param> /// <param name="changedField">The changed field.</param> /// <returns> /// <see langword="True"/>, if <see cref="VersionInfo"/> was changed; /// otherwise, <see langword="false"/>. /// </returns> protected virtual bool UpdateVersion(Entity changedEntity, FieldInfo changedField) { foreach (var field in TypeInfo.GetVersionFields().Where(f => f.AutoVersion)) { SetFieldValue(field, VersionGenerator.GenerateNextVersion(GetFieldValue(field))); } return(true); }
public static Structure CreateStructure(Type type, Persistent owner, FieldInfo field) { var activator = StructureActivators.GetOrAdd(type, GetActivator <Persistent, FieldInfo, Structure>); var result = activator.Invoke(owner, field); result.SystemInitialize(true); return(result); }
private static IQueryable <TItem> GetItemsQuery(QueryEndpoint qe, FieldInfo field) { var owner = Expression.Property(Expression.Constant(ownerParameter), ownerParameter.GetType() .GetProperty("Value", typeof(Entity))); var queryExpression = QueryHelper.CreateEntitySetQuery(owner, field); return(qe.Provider.CreateQuery <TItem>(queryExpression)); }
// Constructors protected FieldExpression( ExtendedExpressionType expressionType, FieldInfo field, Segment <int> mapping, ParameterExpression parameterExpression, bool defaultIfEmpty) : base(expressionType, field.Name, field.ValueType, mapping, field.UnderlyingProperty, parameterExpression, defaultIfEmpty) { Field = field; }
public static FieldExpression CreateField(FieldInfo field, int offset) { if (!field.IsPrimitive) { throw new ArgumentException(string.Format(Strings.ExFieldXIsNotPrimitive, field.Name), "field"); } var mapping = new Segment <int>(field.MappingInfo.Offset + offset, field.MappingInfo.Length); return(new FieldExpression(ExtendedExpressionType.Field, field, mapping, null, false)); }
private static FieldAccessor CreateFieldAccessor(Type accessorType, FieldInfo field) { var accessor = (FieldAccessor) System.Activator.CreateInstance( accessorType.MakeGenericType(field.ValueType), BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, ArrayUtils <object> .EmptyArray, null); accessor.Field = field; return(accessor); }
private bool SystemUpdateVersionInfo(Entity changedEntity, FieldInfo changedField) { Session.SystemEvents.NotifyEntityVersionInfoChanging(changedEntity, changedField, false); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyEntityVersionInfoChanging(changedEntity, changedField, false); } var changed = TypeInfo.HasExplicitVersionFields ? UpdateVersion(changedEntity, changedField) : !changedField.IsEntitySet; Session.SystemEvents.NotifyEntityVersionInfoChanged(changedEntity, changedField, changed); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyEntityVersionInfoChanged(changedEntity, changedField, changed); } return(changed); }
internal override sealed void SystemGetValue(FieldInfo field, object value) { Session.SystemEvents.NotifyFieldValueGet(this, field, value); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueGet(this, field, value); if (Session.IsSystemLogicOnly) { return; } var subscriptionInfo = GetSubscription(EntityEventBroker.GetFieldEventKey); if (subscriptionInfo.Second != null) { ((Action <Key, FieldInfo, object>)subscriptionInfo.Second) .Invoke(subscriptionInfo.First, field, value); } OnGetFieldValue(field, value); } }
internal override sealed void SystemSetValueAttempt(FieldInfo field, object value) { EnsureNotRemoved(); if (Session.IsDebugEventLoggingEnabled) { OrmLog.Debug(Strings.LogSessionXSettingValueKeyYFieldZ, Session, Key, field); } if (field.IsPrimaryKey) { throw new NotSupportedException(string.Format(Strings.ExUnableToSetKeyFieldXExplicitly, field.Name)); } if (changeVersionOnSetAttempt) { UpdateVersionInfo(this, field); } Session.SystemEvents.NotifyFieldValueSettingAttempt(this, field, value); using (Session.Operations.EnableSystemOperationRegistration()) { Session.Events.NotifyFieldValueSettingAttempt(this, field, value); if (Session.IsSystemLogicOnly) { return; } var subscriptionInfo = GetSubscription(EntityEventBroker.SettingFieldAttemptEventKey); if (subscriptionInfo.Second != null) { ((Action <Key, FieldInfo, object>)subscriptionInfo.Second).Invoke(subscriptionInfo.First, field, value); } OnSettingFieldValueAttempt(field, value); Session.ValidationContext.ValidateSetAttempt(this, field, value); } }
protected override void OnSetFieldValue(FieldInfo field, object oldValue, object newValue) { base.OnSetFieldValue(field, oldValue, newValue); throw new InvalidOperationException(); }
protected override void OnSettingFieldValue(FieldInfo field, object value) { base.OnSettingFieldValue(field, value); throw new InvalidOperationException(); }
public MyEntitySet(Entity owner, FieldInfo field) : base(owner, field) { }
public static EntitySetBase CreateEntitySet(Entity owner, FieldInfo field) { var activator = EntitySetActivators.GetOrAdd(field.ValueType, GetActivator <Entity, FieldInfo, EntitySetBase>); return(activator.Invoke(owner, field)); }
// Constructors /// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="owner">Persistent this entity set belongs to.</param> /// <param name="field">Field corresponds to this entity set.</param> protected EntitySet(Entity owner, FieldInfo field) : base(owner, field) { }
protected ContentDirectoryCollection(Entity owner, FieldInfo field) : base(owner, field) { }
/// <inheritdoc/> protected sealed override Func <QueryEndpoint, Int64> GetItemCountQueryDelegate(FieldInfo field) { return(qe => GetItemsQuery(qe, field).LongCount()); }
protected override void OnSettingFieldValue(FieldInfo field, object value) { TestLog.Debug("Entity field setting. Field: {0}; Value: {1}", field.Name, value); }
private static EntitySet <TItem> CreateObject(Entity owner, FieldInfo field) { return(new EntitySet <TItem>(owner, field)); }
protected override void OnSetFieldValue(FieldInfo field, object oldValue, object newValue) { TestLog.Debug("Entity field set. Field: {0}; Value: {1}", field.Name, newValue); }
protected HistoryEntitySet(Xtensive.Orm.Entity owner, Xtensive.Orm.Model.FieldInfo field) : base(owner, field) { }
public FieldAccessor GetFieldAccessor(FieldInfo field) => fieldAccessors[field.FieldId];