当前位置: 首页>>代码示例>>C#>>正文


C# ISessionImplementor.GenerateEntityKey方法代码示例

本文整理汇总了C#中ISessionImplementor.GenerateEntityKey方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionImplementor.GenerateEntityKey方法的具体用法?C# ISessionImplementor.GenerateEntityKey怎么用?C# ISessionImplementor.GenerateEntityKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISessionImplementor的用法示例。


在下文中一共展示了ISessionImplementor.GenerateEntityKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

		public object Load(object id, object optionalObject, ISessionImplementor session)
		{
			if (log.IsDebugEnabled)
			{
				log.Debug(string.Format("loading entity: {0} using named query: {1}", persister.EntityName, queryName));
			}

			AbstractQueryImpl query = (AbstractQueryImpl) session.GetNamedQuery(queryName);
			if (query.HasNamedParameters)
			{
				query.SetParameter(query.NamedParameters[0], id, persister.IdentifierType);
			}
			else
			{
				query.SetParameter(0, id, persister.IdentifierType);
			}
			query.SetOptionalId(id);
			query.SetOptionalEntityName(persister.EntityName);
			query.SetOptionalObject(optionalObject);
			query.SetFlushMode(FlushMode.Never);
			query.List();

			// now look up the object we are really interested in!
			// (this lets us correctly handle proxies and multi-row
			// or multi-column queries)
			return session.PersistenceContext.GetEntity(session.GenerateEntityKey(id, persister));
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:27,代码来源:NamedQueryLoader.cs

示例2: ProcessDereferencedCollection

		private static void ProcessDereferencedCollection(IPersistentCollection coll, ISessionImplementor session)
		{
			IPersistenceContext persistenceContext = session.PersistenceContext;
			CollectionEntry entry = persistenceContext.GetCollectionEntry(coll);
			ICollectionPersister loadedPersister = entry.LoadedPersister;

			if (log.IsDebugEnabled && loadedPersister != null)
				log.Debug("Collection dereferenced: " + MessageHelper.InfoString(loadedPersister, entry.LoadedKey, session.Factory));

			// do a check
			bool hasOrphanDelete = loadedPersister != null && loadedPersister.HasOrphanDelete;
			if (hasOrphanDelete)
			{
				object ownerId = loadedPersister.OwnerEntityPersister.GetIdentifier(coll.Owner, session.EntityMode);
				// TODO NH Different behavior
				//if (ownerId == null)
				//{
				//  // the owning entity may have been deleted and its identifier unset due to
				//  // identifier-rollback; in which case, try to look up its identifier from
				//  // the persistence context
				//  if (session.Factory.Settings.IsIdentifierRollbackEnabled)
				//  {
				//    EntityEntry ownerEntry = persistenceContext.GetEntry(coll.Owner);
				//    if (ownerEntry != null)
				//    {
				//      ownerId = ownerEntry.Id;
				//    }
				//  }
				//  if (ownerId == null)
				//  {
				//    throw new AssertionFailure("Unable to determine collection owner identifier for orphan-delete processing");
				//  }
				//}
				EntityKey key = session.GenerateEntityKey(ownerId, loadedPersister.OwnerEntityPersister);
				object owner = persistenceContext.GetEntity(key);
				if (owner == null)
				{
					throw new AssertionFailure("collection owner not associated with session: " + loadedPersister.Role);
				}
				EntityEntry e = persistenceContext.GetEntry(owner);
				//only collections belonging to deleted entities are allowed to be dereferenced in the case of orphan delete
				if (e != null && e.Status != Status.Deleted && e.Status != Status.Gone)
				{
					throw new HibernateException("A collection with cascade=\"all-delete-orphan\" was no longer referenced by the owning entity instance: " + loadedPersister.Role);
				}
			}

			// do the work
			entry.CurrentPersister = null;
			entry.CurrentKey = null;
			PrepareCollectionForUpdate(coll, entry, session.EntityMode, session.Factory);
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:52,代码来源:Collections.cs

示例3: IsNull

		public override bool IsNull(object owner, ISessionImplementor session)
		{
			if (propertyName != null)
			{
				IEntityPersister ownerPersister = session.Factory.GetEntityPersister(entityName);
				object id = session.GetContextEntityIdentifier(owner);

				EntityKey entityKey = session.GenerateEntityKey(id, ownerPersister);

				return session.PersistenceContext.IsPropertyNull(entityKey, PropertyName);
			}
			else
			{
				return false;
			}
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:16,代码来源:OneToOneType.cs

示例4: Delete

		public void Delete(object id, object version, object obj, ISessionImplementor session)
		{
			int span = TableSpan;
			bool isImpliedOptimisticLocking = !entityMetamodel.IsVersioned &&
																				entityMetamodel.OptimisticLockMode > Versioning.OptimisticLock.Version;
			object[] loadedState = null;
			if (isImpliedOptimisticLocking)
			{
				// need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense);
				// first we need to locate the "loaded" state
				//
				// Note, it potentially could be a proxy, so perform the location the safe way...
				EntityKey key = session.GenerateEntityKey(id, this);
				object entity = session.PersistenceContext.GetEntity(key);
				if (entity != null)
				{
					EntityEntry entry = session.PersistenceContext.GetEntry(entity);
					loadedState = entry.LoadedState;
				}
			}

			SqlCommandInfo[] deleteStrings;
			if (isImpliedOptimisticLocking && loadedState != null)
			{
				// we need to utilize dynamic delete statements
				deleteStrings = GenerateSQLDeleteStrings(loadedState);
			}
			else
			{
				// otherwise, utilize the static delete statements
				deleteStrings = SqlDeleteStrings;
			}

			for (int j = span - 1; j >= 0; j--)
			{
				Delete(id, version, j, obj, deleteStrings[j], session, loadedState);
			}
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:38,代码来源:AbstractEntityPersister.cs

示例5: ProcessUpdateGeneratedProperties

		public void ProcessUpdateGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session)
		{
			if (!HasUpdateGeneratedProperties)
			{
				throw new AssertionFailure("no update-generated properties");
			}

			session.Batcher.ExecuteBatch(); //force immediate execution of the update

			if (loaderName == null)
			{
				ProcessGeneratedPropertiesWithGeneratedSql(id, entity, state, session, sqlUpdateGeneratedValuesSelectString, PropertyUpdateGenerationInclusions);
			}
			else
			{
				// Remove entity from first-level cache to ensure that loader fetches fresh data from database.
				// The loader will ensure that the same entity is added back to the first-level cache.
				session.PersistenceContext.RemoveEntity(session.GenerateEntityKey(id, this));
				ProcessGeneratedPropertiesWithLoader(id, entity, session);
			}
		}
开发者ID:JKeyser,项目名称:nhibernate-core,代码行数:21,代码来源:AbstractEntityPersister.cs

示例6: ProcessInsertGeneratedProperties

		public void ProcessInsertGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session)
		{
			if (!HasInsertGeneratedProperties)
			{
				throw new AssertionFailure("no insert-generated properties");
			}

			session.Batcher.ExecuteBatch(); //force immediate execution of the insert

			if (loaderName == null)
			{
				ProcessGeneratedPropertiesWithGeneratedSql(id, entity, state, session, sqlInsertGeneratedValuesSelectString, PropertyInsertGenerationInclusions);
		}
			else
			{
				ProcessGeneratedPropertiesWithLoader(id, entity, session);

				// The loader has added the entity to the first-level cache. We must remove
				// the entity from the first-level cache to avoid problems in the Save or SaveOrUpdate
				// event listeners, which don't expect the entity to already be present in the 
				// first-level cache.
				session.PersistenceContext.RemoveEntity(session.GenerateEntityKey(id, this));
			}
		}
开发者ID:JKeyser,项目名称:nhibernate-core,代码行数:24,代码来源:AbstractEntityPersister.cs

示例7: ScheduleBatchLoadIfNeeded

		private void ScheduleBatchLoadIfNeeded(object id, ISessionImplementor session)
		{
			//cannot batch fetch by unique key (property-ref associations)
			if (uniqueKeyPropertyName == null && id != null)
			{
				IEntityPersister persister = session.Factory.GetEntityPersister(GetAssociatedEntityName());
				EntityKey entityKey = session.GenerateEntityKey(id, persister);
				if (!session.PersistenceContext.ContainsEntity(entityKey))
				{
					session.PersistenceContext.BatchFetchQueue.AddBatchLoadableEntityKey(entityKey);
				}
			}
		}
开发者ID:KaraokeStu,项目名称:nhibernate-core,代码行数:13,代码来源:ManyToOneType.cs

示例8: GetKeyFromResultSet

		/// <summary>
		/// Read a row of <c>EntityKey</c>s from the <c>IDataReader</c> into the given array.
		/// </summary>
		/// <remarks>
		/// Warning: this method is side-effecty. If an <c>id</c> is given, don't bother going
		/// to the <c>IDataReader</c>
		/// </remarks>
		private EntityKey GetKeyFromResultSet(int i, IEntityPersister persister, object id, IDataReader rs, ISessionImplementor session)
		{
			object resultId;

			// if we know there is exactly 1 row, we can skip.
			// it would be great if we could _always_ skip this;
			// it is a problem for <key-many-to-one>

			if (IsSingleRowLoader && id != null)
			{
				resultId = id;
			}
			else
			{
				IType idType = persister.IdentifierType;
				resultId = idType.NullSafeGet(rs, EntityAliases[i].SuffixedKeyAliases, session, null);

				bool idIsResultId = id != null && resultId != null && idType.IsEqual(id, resultId, session.EntityMode, _factory);

				if (idIsResultId)
				{
					resultId = id; //use the id passed in
				}
			}

			return resultId == null ? null : session.GenerateEntityKey(resultId, persister);
		}
开发者ID:DavidS,项目名称:nhibernate-core,代码行数:34,代码来源:Loader.cs

示例9: GetOptionalObjectKey

		// Not ported: sequentialLoad, loadSequentialRowsForward, loadSequentialRowsReverse

		internal static EntityKey GetOptionalObjectKey(QueryParameters queryParameters, ISessionImplementor session)
		{
			object optionalObject = queryParameters.OptionalObject;
			object optionalId = queryParameters.OptionalId;
			string optionalEntityName = queryParameters.OptionalEntityName;

			if (optionalObject != null && !string.IsNullOrEmpty(optionalEntityName))
			{
				return session.GenerateEntityKey(optionalId, session.GetEntityPersister(optionalEntityName, optionalObject));
			}
			else
			{
				return null;
			}
		}
开发者ID:DavidS,项目名称:nhibernate-core,代码行数:17,代码来源:Loader.cs

示例10: GetSubselectInitializer

		private ICollectionInitializer GetSubselectInitializer(object key, ISessionImplementor session)
		{
			if (!IsSubselectLoadable)
			{
				return null;
			}

			IPersistenceContext persistenceContext = session.PersistenceContext;

			SubselectFetch subselect =
				persistenceContext.BatchFetchQueue.GetSubselect(session.GenerateEntityKey(key, OwnerEntityPersister));

			if (subselect == null)
			{
				return null;
			}
			else
			{
				// Take care of any entities that might have
				// been evicted!
				List<EntityKey> keysToRemove = subselect.Result
					.Where(entityKey => !persistenceContext.ContainsEntity(entityKey)).ToList();

				foreach (var entityKey in keysToRemove)
					subselect.Result.Remove(entityKey);

				// Run a subquery loader
				return CreateSubselectInitializer(subselect, session);
			}
		}
开发者ID:snbbgyth,项目名称:WorkFlowEngine,代码行数:30,代码来源:AbstractCollectionPersister.cs

示例11: GenerateEntityKeyOrNull

		private static EntityKey GenerateEntityKeyOrNull(object id, ISessionImplementor s, string entityName)
		{
			if (id == null || s == null || entityName == null)
				return null;

			return s.GenerateEntityKey(id, s.Factory.GetEntityPersister(entityName));
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:7,代码来源:AbstractLazyInitializer.cs

示例12: GetImplementation

		/// <summary>
		/// Return the Underlying Persistent Object in a given <see cref="ISession"/>, or null.
		/// </summary>
		/// <param name="s">The Session to get the object from.</param>
		/// <returns>The Persistent Object this proxy is Proxying, or <see langword="null" />.</returns>
		public object GetImplementation(ISessionImplementor s)
		{
			EntityKey key = s.GenerateEntityKey(Identifier, s.Factory.GetEntityPersister(EntityName));
			return s.PersistenceContext.GetEntity(key);
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:10,代码来源:AbstractLazyInitializer.cs

示例13: Load

		public object Load(object id, object optionalObject, LockMode lockMode, ISessionImplementor session)
		{
			// fails when optional object is supplied
			Custom clone = null;
			Custom obj = (Custom)Instances[id];
			if (obj != null)
			{
				clone = (Custom)obj.Clone();
				TwoPhaseLoad.AddUninitializedEntity(session.GenerateEntityKey(id, this), clone, this, LockMode.None, false,
				                                    session);
				TwoPhaseLoad.PostHydrate(this, id, new String[] {obj.Name}, null, clone, LockMode.None, false, session);
				TwoPhaseLoad.InitializeEntity(clone, false, session, new PreLoadEvent((IEventSource) session),
				                              new PostLoadEvent((IEventSource) session));
			}
			return clone;
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:16,代码来源:CustomPersister.cs

示例14: IsNullifiable

		public bool IsNullifiable(bool earlyInsert, ISessionImplementor session)
		{
			return Status == Status.Saving || (earlyInsert ? !ExistsInDatabase : session.PersistenceContext.NullifiableEntityKeys.Contains(session.GenerateEntityKey(Id, Persister)));
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:4,代码来源:EntityEntry.cs

示例15: Hydrate

		public override object Hydrate(IDataReader rs, string[] names, ISessionImplementor session, object owner)
		{
			IType type = GetIdentifierOrUniqueKeyType(session.Factory);
			object identifier = session.GetContextEntityIdentifier(owner);

			//This ugly mess is only used when mapping one-to-one entities with component ID types
			EmbeddedComponentType componentType = type as EmbeddedComponentType;
			if (componentType != null)
			{
				EmbeddedComponentType ownerIdType = session.GetEntityPersister(null, owner).IdentifierType as EmbeddedComponentType;
				if (ownerIdType != null)
				{
					object[] values = ownerIdType.GetPropertyValues(identifier, session);
					object id = componentType.ResolveIdentifier(values, session, null);
					IEntityPersister persister = session.Factory.GetEntityPersister(type.ReturnedClass.FullName);
					var key = session.GenerateEntityKey(id, persister);
					return session.PersistenceContext.GetEntity(key);
				}
			}
			return identifier;
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:21,代码来源:OneToOneType.cs


注:本文中的ISessionImplementor.GenerateEntityKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。