Ejemplo n.º 1
0
 protected virtual void NotifyBefore()
 {
     if (Notification == Notification.Disabled)
     {
         return;
     }
     if (MuteNotify)
     {
         return;
     }
     if (Interceptable != null)
     {
         if (PropertyName.Length > 0)
         {
             bool   cancel  = false;
             object newList = List;
             Interceptable.GetInterceptor().NotifyPropertySet(Interceptable, PropertyName, ref newList, OldList, ref cancel);
             if (cancel)
             {
                 RollBack();
             }
         }
         else
         {
             throw new NPersistException("Managed list has not been associated with a property of the holder object!");                     // do not localize
         }
     }
     else
     {
         throw new NPersistException("Managed list has not been associated with a holder object!");                 // do not localize
     }
 }
Ejemplo n.º 2
0
 protected virtual void NotifyAfter()
 {
     if (Notification != Notification.Full)
     {
         return;
     }
     if (MuteNotify)
     {
         return;
     }
     if (Interceptable != null)
     {
         if (PropertyName.Length > 0)
         {
             Interceptable.GetInterceptor().NotifyWroteProperty(Interceptable, PropertyName, List, OldList);
         }
         else
         {
             throw new NPersistException("Managed list has not been associated with a property of the holder object!");                     // do not localize
         }
     }
     else
     {
         throw new NPersistException("Managed list has not been associated with a holder object!");                 // do not localize
     }
 }
        private void EnsureWriteConsistency(object value)
        {
            IContext ctx = this.Context;

            if (ctx.WriteConsistency.Equals(ConsistencyMode.Pessimistic))
            {
                IIdentityHelper identityHelper = Interceptable as IIdentityHelper;
                if (identityHelper == null)
                {
                    throw new NPersistException(string.Format("Object of type {0} does not implement IIdentityHelper", Interceptable.GetType()));
                }

                IClassMap  classMap  = ClassMap;
                ISourceMap sourceMap = classMap.GetSourceMap();
                if (sourceMap != null)
                {
                    if (sourceMap.PersistenceType.Equals(PersistenceType.ObjectRelational) || sourceMap.PersistenceType.Equals(PersistenceType.Default))
                    {
                        ITransaction tx = ctx.GetTransaction(ctx.GetDataSource(sourceMap).GetConnection());
                        if (tx == null)
                        {
                            throw new WriteConsistencyException(
                                      string.Format("A write consistency exception has occurred. The property {0} for the object of type {1} and with identity {2} was updated with a value outside of a transaction. This is not permitted in a context using Pessimistic WriteConsistency.",
                                                    PropertyName,
                                                    Interceptable.GetType(),
                                                    ctx.ObjectManager.GetObjectIdentity(Interceptable)),
                                      Interceptable);
                        }

                        Guid txGuid = identityHelper.GetTransactionGuid();
                        if (!(tx.Guid.Equals(txGuid)))
                        {
                            throw new WriteConsistencyException(
                                      string.Format("A write consistency exception has occurred. The property {0} for the object of type {1} and with identity {2} was loaded or initialized inside a transactions with Guid {3} and was now updated with a value under another transaction with Guid {4}. This is not permitted in a context using Pessimistic WriteConsistency.",
                                                    PropertyName,
                                                    Interceptable.GetType(),
                                                    ctx.ObjectManager.GetObjectIdentity(Interceptable),
                                                    txGuid,
                                                    tx.Guid),
                                      txGuid,
                                      tx.Guid,
                                      Interceptable);
                        }

                        if (value != null)
                        {
                            IPropertyMap propertyMap = PropertyMap;
                            if (propertyMap.ReferenceType != ReferenceType.None)
                            {
                                IIdentityHelper valueIdentityHelper = value as IIdentityHelper;
                                if (valueIdentityHelper == null)
                                {
                                    throw new NPersistException(string.Format("Object of type {0} does not implement IIdentityHelper", value.GetType()));
                                }

                                Guid valueTxGuid = valueIdentityHelper.GetTransactionGuid();
                                if (!(tx.Guid.Equals(valueTxGuid)))
                                {
                                    throw new WriteConsistencyException(
                                              string.Format("A write consistency exception has occurred. The property {0} for the object of type {1} and with identity {2} was loaded or initialized inside a transactions with Guid {3} and was now updated with a reference to an object that was loaded under another transaction with Guid {4}. This is not permitted in a context using Pessimistic WriteConsistency.",
                                                            PropertyName,
                                                            Interceptable.GetType(),
                                                            ctx.ObjectManager.GetObjectIdentity(Interceptable),
                                                            tx.Guid,
                                                            valueTxGuid),
                                              tx.Guid,
                                              valueTxGuid,
                                              Interceptable);
                                }
                            }
                        }
                    }
                }
            }
        }