/// <summary>
        /// 
        /// </summary>
        /// <param name="rootAlias"></param>
        /// <param name="rootType"></param>
        /// <param name="matchMode"></param>
        /// <param name="entityMode"></param>
        /// <param name="instance"></param>
        /// <param name="classInfoProvider"></param>
        public CriteriaCompiled(string rootAlias, System.Type rootType, MatchMode matchMode, EntityMode entityMode,
                                object instance, Func<System.Type, IPersistentClassInfo> classInfoProvider)
        {
            
            if (rootAlias == null || rootAlias.Trim().Equals(string.Empty))
                throw new ArgumentException("The alias for making detached criteria cannot be empty or null", "rootAlias");

            if (rootType == null)
                throw new ArgumentNullException("rootType", "The type which can be used for maikng detached criteria cannot be null.");

            if (instance == null)
                throw new ArgumentNullException("instance", "The instance for building detached criteria cannot be null.");

            if (!rootType.IsInstanceOfType(instance))
                throw new ArgumentTypeException("The given instance for building detached criteria is not suitable for the given criteria type.", "instance", rootType, instance.GetType());

            this.matchMode = matchMode ?? MatchMode.Exact;
            this.entityMode = entityMode;
            this.instance = instance;
            this.classInfoProvider = classInfoProvider;

            this.relationshipTree = new RelationshipTree(rootAlias, rootType);
            this.criteria = DetachedCriteria.For(rootType, rootAlias);
            this.restrictions = new List<ICriterion>();
            this.Init();
        }
        public override object Instantiate(string clazz, EntityMode entityMode, object id)
        {
            if (entityMode == EntityMode.Poco)
            {
                Type type = this.typeResolver.ResolveType(clazz);

                if (type != null)
                {
                    if (type.GetConstructors().Any(constructor => constructor.GetParameters().Any()))
                    {
                        try
                        {
                            object instance = ObjectFactory.GetInstance(type);

                            this.session.SessionFactory
                                    .GetClassMetadata(clazz)
                                    .SetIdentifier(instance, id, entityMode);
                            return instance;
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                        }
                    }
                }
            }

            return base.Instantiate(clazz, entityMode, id);
        }
		/// <summary> 
		/// Locate the contained tuplizer responsible for the given entity-mode.  If
		/// no such tuplizer is defined on this mapping, then return null. 
		/// </summary>
		/// <param name="entityMode">The entity-mode for which the caller wants a tuplizer. </param>
		/// <returns> The tuplizer, or null if not found. </returns>
		public virtual ITuplizer GetTuplizerOrNull(EntityMode entityMode)
		{
			EnsureFullyDeserialized();
			ITuplizer result;
			_tuplizers.TryGetValue(entityMode, out result);
			return result;
		}
		private static void CheckEntityMode(EntityMode entityMode)
		{
			if (EntityMode.Poco != entityMode)
			{
				throw new ArgumentOutOfRangeException("entityMode", "Unhandled EntityMode : " + entityMode);
			}
		}
		private object[] GetValues(object entity, EntityEntry entry, EntityMode entityMode, bool mightBeDirty, ISessionImplementor session)
		{
			object[] loadedState = entry.LoadedState;
			Status status = entry.Status;
			IEntityPersister persister = entry.Persister;

			object[] values;
			if (status == Status.Deleted)
			{
				//grab its state saved at deletion
				values = entry.DeletedState;
			}
			else if (!mightBeDirty && loadedState != null)
			{
				values = loadedState;
			}
			else
			{
				CheckId(entity, persister, entry.Id, entityMode);

				// grab its current state
				values = persister.GetPropertyValues(entity, entityMode);

				CheckNaturalId(persister, entry, values, loadedState, entityMode, session);
			}
			return values;
		}
예제 #6
0
        public static Type FindType(string clazz, ISession session, EntityMode entityMode) {
            if(IsDebugEnabled)
                log.Debug("인스턴싱할 엔티티 형식을 찾습니다... clazz=[{0}], entityMode=[{1}]", clazz, entityMode);

            var result = session.SessionFactory.GetEntityType(clazz, entityMode);

            if(result != null) {
                // lock(_syncLock)
                return _entityTypeCache.GetOrAdd(clazz, result);
            }

            foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
                result = assembly.GetType(clazz, false, true);

                if(result != null) {
                    return _entityTypeCache.GetOrAdd(clazz, result);
                    //lock(_syncLock)
                    //    _entityTypeCache.AddValue(clazz, result);

                    //return result;
                }
            }

            return _entityTypeCache.GetOrAdd(clazz, result);
        }
예제 #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="entity">an actual entity object, not a proxy!</param>
		/// <param name="entityMode"></param>
		/// <returns></returns>
		public string ToString(object entity, EntityMode entityMode)
		{
			IClassMetadata cm = _factory.GetClassMetadata(entity.GetType());
			if (cm == null)
			{
				return entity.GetType().FullName;
			}

			IDictionary<string, string> result = new Dictionary<string, string>();

			if (cm.HasIdentifierProperty)
			{
				result[cm.IdentifierPropertyName] =
					cm.IdentifierType.ToLoggableString(cm.GetIdentifier(entity, entityMode), _factory);
			}

			IType[] types = cm.PropertyTypes;
			string[] names = cm.PropertyNames;
			object[] values = cm.GetPropertyValues(entity, entityMode);

			for (int i = 0; i < types.Length; i++)
			{
				var value = values[i];
				if (Equals(LazyPropertyInitializer.UnfetchedProperty, value) || Equals(BackrefPropertyAccessor.Unknown, value))
				{
					result[names[i]] = value.ToString();
				}
				else
				{
					result[names[i]] = types[i].ToLoggableString(value, _factory);
				}
			}

			return cm.EntityName + CollectionPrinter.ToString(result);
		}
예제 #8
0
		public override bool IsEqual(object x, object y, EntityMode entityMode, ISessionFactoryImplementor factory)
		{
			IEntityPersister persister = factory.GetEntityPersister(associatedEntityName);
			if (!persister.CanExtractIdOutOfEntity)
			{
				return base.IsEqual(x, y, entityMode);
			}

			object xid;
			
			if (x.IsProxy())
			{
				INHibernateProxy proxy = x as INHibernateProxy; 
				xid = proxy.HibernateLazyInitializer.Identifier;
			}
			else
			{
				xid = persister.GetIdentifier(x, entityMode);
			}

			object yid;
			
			if (y.IsProxy())
			{
				INHibernateProxy proxy = y as INHibernateProxy; 
				yid = proxy.HibernateLazyInitializer.Identifier;
			}
			else
			{
				yid = persister.GetIdentifier(y, entityMode);
			}

			return persister.IdentifierType.IsEqual(xid, yid, entityMode, factory);
		}
예제 #9
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="entity">an actual entity object, not a proxy!</param>
		/// <param name="entityMode"></param>
		/// <returns></returns>
		public string ToString(object entity, EntityMode entityMode)
		{
			IClassMetadata cm = _factory.GetClassMetadata(entity.GetType());
			if (cm == null)
			{
				return entity.GetType().FullName;
			}

			IDictionary<string, string> result = new Dictionary<string, string>();

			if (cm.HasIdentifierProperty)
			{
				result[cm.IdentifierPropertyName] =
					cm.IdentifierType.ToLoggableString(cm.GetIdentifier(entity, entityMode), _factory);
			}

			IType[] types = cm.PropertyTypes;
			string[] names = cm.PropertyNames;
			object[] values = cm.GetPropertyValues(entity, entityMode);

			for (int i = 0; i < types.Length; i++)
			{
				result[names[i]] = types[i].ToLoggableString(values[i], _factory);
			}

			return cm.EntityName + CollectionPrinter.ToString(result);
		}
예제 #10
0
		/// <summary> 
		/// Construct a new key for a collection or entity instance.
		/// Note that an entity name should always be the root entity 
		/// name, not a subclass entity name. 
		/// </summary>
		/// <param name="id">The identifier associated with the cached data </param>
		/// <param name="type">The Hibernate type mapping </param>
		/// <param name="entityOrRoleName">The entity or collection-role name. </param>
		/// <param name="entityMode">The entity mode of the originating session </param>
		/// <param name="factory">The session factory for which we are caching </param>
		public CacheKey(object id, IType type, string entityOrRoleName, EntityMode entityMode, ISessionFactoryImplementor factory)
		{
			key = id;
			this.type = type;
			this.entityOrRoleName = entityOrRoleName;
			this.entityMode = entityMode;
			hashCode = type.GetHashCode(key, entityMode, factory);
		}
		public override object DeepCopy(object value, EntityMode entityMode, ISessionFactoryImplementor factory)
		{
			IExternalBlobConnection blobconn;
			byte[] identifier;
			if (this.ExtractLobData(value, out blobconn, out identifier))
				return CreateLobInstance(blobconn, identifier);
			return value;
		}
		public override int GetHashCode(object x, EntityMode entityMode)
		{
			int hashCode = base.GetHashCode(x, entityMode);
			unchecked
			{
				hashCode = 31*hashCode + ((DateTime) x).Kind.GetHashCode();
			}
			return hashCode;
		}
		public FilterKey(string name, IEnumerable<KeyValuePair<string, object>> @params, IDictionary<string, IType> types, EntityMode entityMode)
		{
			filterName = name;
			foreach (KeyValuePair<string, object> me in @params)
			{
				IType type = types[me.Key];
				filterParameters[me.Key] = new TypedValue(type, me.Value, entityMode);
			}
		}
예제 #14
0
 private CollectionKey(string role, object key, IType keyType, EntityMode entityMode, ISessionFactoryImplementor factory)
 {
     this.role = role;
     this.key = key;
     this.keyType = keyType;
     this.entityMode = entityMode;
     this.factory = factory;
     hashCode = GenerateHashCode(); //cache the hashcode
 }
예제 #15
0
		/// <summary> Locate the tuplizer contained within this mapping which is responsible
		/// for the given entity-mode.  If no such tuplizer is defined on this
		/// mapping, then an exception is thrown.
		/// 
		/// </summary>
		/// <param name="entityMode">The entity-mode for which the caller wants a tuplizer.
		/// </param>
		/// <returns> The tuplizer.
		/// </returns>
		/// <throws>  HibernateException Unable to locate the requested tuplizer. </throws>
		public virtual ITuplizer GetTuplizer(EntityMode entityMode)
		{
			ITuplizer tuplizer = GetTuplizerOrNull(entityMode);
			if (tuplizer == null)
			{
				throw new HibernateException("No tuplizer found for entity-mode [" + entityMode + "]");
			}
			return tuplizer;
		}
        public override Object Instantiate(String clazz, EntityMode entityMode, Object id)
        {
            if (entityMode != EntityMode.Poco)
                return base.Instantiate(clazz, entityMode, id);

            var classMetadata = _session.SessionFactory.GetClassMetadata(clazz);
            var entityType = classMetadata.GetMappedClass(entityMode);
            var entity = classMetadata.Instantiate(id, entityMode);
            return AddPropertyChangedInterceptorProxyFactory.Create(entityType, entity);
        }
예제 #17
0
		private Type GetType(string clazz, EntityMode entityMode)
		{
			Type type = SessionFactory.GetClassMetadata(clazz)
										.GetMappedClass(entityMode);
			if (type == null)
			{
				throw new InvalidOperationException(string.Format("Cannot find the type {0}.", clazz));
			}
			return type;
		}
예제 #18
0
		public virtual object[] GetPropertyValues(object component, EntityMode entityMode)
		{
			int len = Subtypes.Length;
			object[] result = new object[len];
			for (int i = 0; i < len; i++)
			{
				result[i] = GetPropertyValue(component, i);
			}
			return result;
		}
예제 #19
0
		public override object Instantiate(string clazz, EntityMode entityMode, object id)
		{
			logger.Debug("Instantiate: " + clazz + " " + entityMode + " " + id);
		    object instance = interceptor.Create(clazz, id);
		    if (instance != null)
		    {
		        Session.SessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode);
		    }
		    return instance;
		}
        protected void Validate(object entity, EntityMode mode)
        {
            if (entity == null || mode != EntityMode.Poco)
                return;

            var validator = validatorFactory.GetValidator(entity.GetType());
            var result = validator != null ? validator.Validate(entity) : emptyValidationResult;
            if (!result.IsValid)
            {
                throw new ValidationException(result.Errors);
            }
        }
		public static ISet CreateFilterKeys(IDictionary<string, IFilter> enabledFilters, EntityMode entityMode)
		{
			if (enabledFilters.Count == 0)
				return null;
			Set result = new HashedSet();
			foreach (FilterImpl filter in enabledFilters.Values)
			{
				FilterKey key = new FilterKey(filter.Name, filter.Parameters, filter.FilterDefinition.ParameterTypes, entityMode);
				result.Add(key);
			}
			return result;
		}
예제 #22
0
파일: TimeType.cs 프로젝트: ray2006/WCell
		public override int GetHashCode(object x, EntityMode entityMode)
		{
			DateTime date = (DateTime)x;
			int hashCode = 1;
			unchecked
			{
				hashCode = 31 * hashCode + date.Second;
				hashCode = 31 * hashCode + date.Minute;
				hashCode = 31 * hashCode + date.Hour;
			}
			return hashCode;
		}
		/// <summary> 
		/// If the user specified an id, assign it to the instance and use that, 
		/// otherwise use the id already assigned to the instance
		/// </summary>
		protected override object GetUpdateId(object entity, IEntityPersister persister, object requestedId, EntityMode entityMode)
		{
			if (requestedId == null)
			{
				return base.GetUpdateId(entity, persister, requestedId, entityMode);
			}
			else
			{
				persister.SetIdentifier(entity, requestedId, entityMode);
				return requestedId;
			}
		}
예제 #24
0
		public override int GetHashCode(object x, EntityMode entityMode)
		{
			DateTime date = (DateTime)x;
			int hashCode = 1;
			unchecked
			{
				hashCode = 31 * hashCode + date.Day;
				hashCode = 31 * hashCode + date.Month;
				hashCode = 31 * hashCode + date.Year;
			}
			return hashCode;
		}
        protected static void Validate(object entity, EntityMode mode)
        {
            if (entity == null || mode != EntityMode.Poco)
            {
                return;
            }

            InvalidValue[] consolidatedInvalidValues = Engine.Validate(entity);
            if (consolidatedInvalidValues.Length > 0)
            {
                throw new InvalidStateException(consolidatedInvalidValues, entity.GetType().Name);
            }
        }
예제 #26
0
		public static string ToString(EntityMode entityMode)
		{
			switch (entityMode)
			{
				case EntityMode.Poco:
					return "poco";
				case EntityMode.Map:
					return "dynamic-map";
				case EntityMode.Xml:
					return "xml";
			}
			return null;
		}
		public static NHibernateEntityMode Convert(EntityMode @enum)
		{
			switch(@enum)
			{
				case EntityMode.Poco:
					return NHibernateEntityMode.Poco;

				case EntityMode.DynamicEntity:
					return NHibernateEntityMode.Map;

				default:
					return default(NHibernateEntityMode);
			}
		}
예제 #28
0
 public override object Instantiate(string clazz, EntityMode entityMode, object id)
 {
     if (entityMode == EntityMode.Poco)
     {
         Type type = Type.GetType(clazz);
         if (type != null)
         {
             var instance = DataBindingFactory.Create(type);
             UnitOfWork.GetSessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode);
             return instance;
         }
     }
     return base.Instantiate(clazz, entityMode, id);
 }
예제 #29
0
		/// <summary> Used to reconstruct an EntityKey during deserialization. </summary>
		/// <param name="identifier">The identifier value </param>
		/// <param name="rootEntityName">The root entity name </param>
		/// <param name="entityName">The specific entity name </param>
		/// <param name="identifierType">The type of the identifier value </param>
		/// <param name="batchLoadable">Whether represented entity is eligible for batch loading </param>
		/// <param name="factory">The session factory </param>
		/// <param name="entityMode">The entity's entity mode </param>
		private EntityKey(object identifier, string rootEntityName, string entityName, IType identifierType, bool batchLoadable, ISessionFactoryImplementor factory, EntityMode entityMode)
		{
			if (identifier == null)
				throw new AssertionFailure("null identifier");

			this.identifier = identifier;
			this.rootEntityName = rootEntityName;
			this.entityName = entityName;
			this.identifierType = identifierType;
			isBatchLoadable = batchLoadable;
			this.factory = factory;
			this.entityMode = entityMode;
			hashCode = GenerateHashCode();
		}
		public override object Instantiate(string entityName, EntityMode entityMode, object id)
		{
			if (entityMode == EntityMode.Poco)
			{
				if (typeof(Customer).FullName.Equals(entityName))
				{
					return ProxyHelper.NewCustomerProxy(id);
				}
				else if (typeof(Company).FullName.Equals(entityName))
				{
					return ProxyHelper.NewCompanyProxy(id);
				}
			}
			return base.Instantiate(entityName, entityMode, id);
		}
예제 #31
0
 public virtual void SetPropertyValues(object component, object[] values, EntityMode entityMode)
 {
     tuplizerMapping.GetTuplizer(entityMode).SetPropertyValues(component, values);
 }
예제 #32
0
 public object Instantiate(object id, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #33
0
 public object GetVersion(object obj, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #34
0
 public void SetPropertyValue(object obj, int i, object value, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #35
0
 public override bool IsEqual(object x, object y, EntityMode entityMode)
 {
     return(x == y ||
            (x is IPersistentCollection && ((IPersistentCollection)x).IsWrapper(y)) ||
            (y is IPersistentCollection && ((IPersistentCollection)y).IsWrapper(x)));
 }
예제 #36
0
 public object GetPropertyValue(object obj, string name, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #37
0
 /// <summary>
 /// Starts a new Session with the given entity mode in effect. This secondary
 ///             Session inherits the connection, transaction, and other context
 ///             information from the primary Session. It doesn't need to be flushed
 ///             or closed by the developer.
 /// </summary>
 /// <param name="entityMode">The entity mode to use for the new session.</param>
 /// <returns>
 /// The new session
 /// </returns>
 public ISession GetSession(EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #38
0
 public void SetIdentifier(object obj, object id, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #39
0
 public object GetIdentifier(object obj, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #40
0
 public void ResetIdentifier(object entity, object currentId, object currentVersion, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #41
0
 public virtual bool HasHolder(EntityMode entityMode)
 {
     return(false);           // entityMode == EntityMode.DOM4J;
 }
예제 #42
0
 public IEntityPersister GetSubclassEntityPersister(object instance, ISessionFactoryImplementor factory,
                                                    EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #43
0
 public override int GetHashCode(object x, EntityMode entityMode)
 {
     throw new InvalidOperationException("cannot perform lookups on collections");
 }
예제 #44
0
 public bool ImplementsLifecycle(EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #45
0
 public object[] GetPropertyValues(object component, EntityMode entityMode)
 {
     return(tuplizerMapping.GetTuplizer(entityMode).GetPropertyValues(component));
 }
예제 #46
0
 /// <summary> This method does not populate the component parent</summary>
 public object Instantiate(EntityMode entityMode)
 {
     return(tuplizerMapping.GetTuplizer(entityMode).Instantiate());
 }
예제 #47
0
 public object GetPropertyValue(object component, int i, EntityMode entityMode)
 {
     return(tuplizerMapping.GetTuplizer(entityMode).GetPropertyValue(component, i));
 }
예제 #48
0
        /// <summary>
        /// Retrieve the collection that is being loaded as part of processing this result set.
        /// </summary>
        /// <param name="persister">The persister for the collection being requested. </param>
        /// <param name="key">The key of the collection being requested. </param>
        /// <returns> The loading collection (see discussion above). </returns>
        /// <remarks>
        /// Basically, there are two valid return values from this method:<ul>
        /// <li>an instance of {@link PersistentCollection} which indicates to
        /// continue loading the result set row data into that returned collection
        /// instance; this may be either an instance already associated and in the
        /// midst of being loaded, or a newly instantiated instance as a matching
        /// associated collection was not found.</li>
        /// <li><i>null</i> indicates to ignore the corresponding result set row
        /// data relating to the requested collection; this indicates that either
        /// the collection was found to already be associated with the persistence
        /// context in a fully loaded state, or it was found in a loading state
        /// associated with another result set processing context.</li>
        /// </ul>
        /// </remarks>
        public IPersistentCollection GetLoadingCollection(ICollectionPersister persister, object key)
        {
            EntityMode em = loadContexts.PersistenceContext.Session.EntityMode;

            CollectionKey collectionKey = new CollectionKey(persister, key, em);

            if (log.IsDebugEnabled)
            {
                log.Debug("starting attempt to find loading collection [" + MessageHelper.InfoString(persister.Role, key) + "]");
            }
            LoadingCollectionEntry loadingCollectionEntry = loadContexts.LocateLoadingCollectionEntry(collectionKey);

            if (loadingCollectionEntry == null)
            {
                // look for existing collection as part of the persistence context
                IPersistentCollection collection = loadContexts.PersistenceContext.GetCollection(collectionKey);
                if (collection != null)
                {
                    if (collection.WasInitialized)
                    {
                        log.Debug("collection already initialized; ignoring");
                        return(null);                        // ignore this row of results! Note the early exit
                    }
                    else
                    {
                        // initialize this collection
                        log.Debug("collection not yet initialized; initializing");
                    }
                }
                else
                {
                    object owner            = loadContexts.PersistenceContext.GetCollectionOwner(key, persister);
                    bool   newlySavedEntity = owner != null && loadContexts.PersistenceContext.GetEntry(owner).Status != Status.Loading && em != EntityMode.Xml;
                    if (newlySavedEntity)
                    {
                        // important, to account for newly saved entities in query
                        // todo : some kind of check for new status...
                        log.Debug("owning entity already loaded; ignoring");
                        return(null);
                    }
                    else
                    {
                        // create one
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("instantiating new collection [key=" + key + ", rs=" + resultSet + "]");
                        }
                        collection = persister.CollectionType.Instantiate(loadContexts.PersistenceContext.Session, persister, key);
                    }
                }
                collection.BeforeInitialize(persister, -1);
                collection.BeginRead();
                localLoadingCollectionKeys.Add(collectionKey);
                loadContexts.RegisterLoadingCollectionXRef(collectionKey, new LoadingCollectionEntry(resultSet, persister, key, collection));
                return(collection);
            }
            else
            {
                if (loadingCollectionEntry.ResultSet == resultSet)
                {
                    log.Debug("found loading collection bound to current result set processing; reading row");
                    return(loadingCollectionEntry.Collection);
                }
                else
                {
                    // ignore this row, the collection is in process of
                    // being loaded somewhere further "up" the stack
                    log.Debug("collection is already being initialized; ignoring row");
                    return(null);
                }
            }
        }
예제 #49
0
 public virtual ISession GetSession(EntityMode entityMode)
 {
     throw new NotSupportedException();
 }
예제 #50
0
 public Type GetConcreteProxyClass(EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #51
0
 public object[] GetPropertyValues(object obj, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #52
0
 public ISession GetSession(EntityMode entityMode)
 {
     return(session.GetSession(entityMode));
 }
예제 #53
0
 public void SetPropertyValues(object obj, object[] values, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #54
0
 public override object DeepCopy(object value, EntityMode entityMode, ISessionFactoryImplementor factory)
 {
     return(value);
 }
예제 #55
0
 public bool ImplementsValidatable(EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #56
0
        private static void PrepareCollectionForUpdate(IPersistentCollection collection, CollectionEntry entry, EntityMode entityMode, ISessionFactoryImplementor factory)
        {
            //1. record the collection role that this collection is referenced by
            //2. decide if the collection needs deleting/creating/updating (but don't actually schedule the action yet)

            if (entry.IsProcessed)
            {
                throw new AssertionFailure("collection was processed twice by flush()");
            }

            entry.IsProcessed = true;

            ICollectionPersister loadedPersister  = entry.LoadedPersister;
            ICollectionPersister currentPersister = entry.CurrentPersister;

            if (loadedPersister != null || currentPersister != null)
            {
                // it is or was referenced _somewhere_
                bool ownerChanged = loadedPersister != currentPersister ||
                                    !currentPersister.KeyType.IsEqual(entry.LoadedKey, entry.CurrentKey, entityMode, factory);

                if (ownerChanged)
                {
                    // do a check
                    bool orphanDeleteAndRoleChanged = loadedPersister != null &&
                                                      currentPersister != null && loadedPersister.HasOrphanDelete;

                    if (orphanDeleteAndRoleChanged)
                    {
                        throw new HibernateException("Don't change the reference to a collection with cascade=\"all-delete-orphan\": " + loadedPersister.Role);
                    }

                    // do the work
                    if (currentPersister != null)
                    {
                        entry.IsDorecreate = true;                         // we will need to create new entries
                    }

                    if (loadedPersister != null)
                    {
                        entry.IsDoremove = true;                         // we will need to remove ye olde entries
                        if (entry.IsDorecreate)
                        {
                            log.Debug("Forcing collection initialization");
                            collection.ForceInitialization();                             // force initialize!
                        }
                    }
                }
                else if (collection.IsDirty)
                {
                    // else if it's elements changed
                    entry.IsDoupdate = true;
                }
            }
        }
예제 #57
0
 public bool HasUninitializedLazyProperties(object obj, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #58
0
 public bool IsInstance(object entity, EntityMode entityMode)
 {
     throw new NotImplementedException();
 }
예제 #59
0
 protected internal virtual bool InitializeImmediately(EntityMode entityMode)
 {
     return(false);           // entityMode == EntityMode.DOM4J;
 }
예제 #60
0
 /// <summary>
 /// If the user specified an id, assign it to the instance and use that,
 /// otherwise use the id already assigned to the instance
 /// </summary>
 protected override object GetUpdateId(object entity, IEntityPersister persister, object requestedId, EntityMode entityMode)
 {
     if (requestedId == null)
     {
         return(base.GetUpdateId(entity, persister, requestedId, entityMode));
     }
     else
     {
         persister.SetIdentifier(entity, requestedId, entityMode);
         return(requestedId);
     }
 }