本文整理汇总了C#中ISessionImplementor.GetContextEntityIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionImplementor.GetContextEntityIdentifier方法的具体用法?C# ISessionImplementor.GetContextEntityIdentifier怎么用?C# ISessionImplementor.GetContextEntityIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionImplementor
的用法示例。
在下文中一共展示了ISessionImplementor.GetContextEntityIdentifier方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Assemble
public override object Assemble(object cached, ISessionImplementor session, object owner)
{
//this should be a call to resolve(), not resolveIdentifier(),
//'cos it might be a property-ref, and we did not cache the
//referenced value
return ResolveIdentifier(session.GetContextEntityIdentifier(owner), session, owner);
}
示例2: GetObjectFromList
private object GetObjectFromList(IList results, object id, ISessionImplementor session)
{
// get the right object from the list ... would it be easier to just call getEntity() ??
foreach (object obj in results)
{
bool equal = idType.IsEqual(id, session.GetContextEntityIdentifier(obj), session.EntityMode, session.Factory);
if (equal)
{
return obj;
}
}
return null;
}
示例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 = new EntityKey(id, ownerPersister, session.EntityMode);
return session.PersistenceContext.IsPropertyNull(entityKey, PropertyName);
}
else
{
return false;
}
}
示例4: Generate
public object Generate(ISessionImplementor session, object obj)
{
var existingId = session.GetContextEntityIdentifier(obj);
Guid existingGuid = Guid.Empty;
if (existingId != null)
existingGuid = (Guid)existingId;
else
{
var castAsRef = obj as IReferenceByGuid;
if (castAsRef != null)
existingGuid = castAsRef.Id;
}
if (existingGuid != Guid.Empty)
return existingGuid;
var newGuid = (Guid)new GuidCombGenerator().Generate(session, obj);
return newGuid;
}
示例5: GetEntityIdentifierIfNotUnsaved
/// <summary>
/// Return the identifier of the persistent or transient object, or throw
/// an exception if the instance is "unsaved"
/// </summary>
/// <remarks>
/// Used by OneToOneType and ManyToOneType to determine what id value should
/// be used for an object that may or may not be associated with the session.
/// This does a "best guess" using any/all info available to use (not just the
/// EntityEntry).
/// </remarks>
public static object GetEntityIdentifierIfNotUnsaved(string entityName, object entity, ISessionImplementor session)
{
if (entity == null)
{
return null;
}
else
{
object id = session.GetContextEntityIdentifier(entity);
if (id == null)
{
// context-entity-identifier returns null explicitly if the entity
// is not associated with the persistence context; so make some deeper checks...
/***********************************************/
// NH-479 (very dirty patch)
if (entity.GetType().IsPrimitive)
return entity;
/**********************************************/
if (IsTransient(entityName, entity, false, session))
{
/***********************************************/
// TODO NH verify the behavior of NH607 test
// these lines are only to pass test NH607 during PersistenceContext porting
// i'm not secure that NH607 is a test for a right behavior
EntityEntry entry = session.PersistenceContext.GetEntry(entity);
if (entry != null)
return entry.Id;
// the check was put here to have les possible impact
/**********************************************/
throw new TransientObjectException(
"object references an unsaved transient instance - save the transient instance before flushing: "
+ (entityName ?? session.GuessEntityName(entity)));
}
id = session.GetEntityPersister(entityName, entity).GetIdentifier(entity, session.EntityMode);
}
return id;
}
}
示例6: InitializeLazyProperty
public virtual object InitializeLazyProperty(string fieldName, object entity, ISessionImplementor session)
{
object id = session.GetContextEntityIdentifier(entity);
EntityEntry entry = session.PersistenceContext.GetEntry(entity);
if (entry == null)
throw new HibernateException("entity is not associated with the session: " + id);
if (log.IsDebugEnabled)
{
log.Debug(
string.Format("initializing lazy properties of: {0}, field access: {1}",
MessageHelper.InfoString(this, id, Factory), fieldName));
}
if (HasCache)
{
CacheKey cacheKey = session.GenerateCacheKey(id, IdentifierType, EntityName);
object ce = Cache.Get(cacheKey, session.Timestamp);
if (ce != null)
{
CacheEntry cacheEntry = (CacheEntry)CacheEntryStructure.Destructure(ce, factory);
if (!cacheEntry.AreLazyPropertiesUnfetched)
{
//note early exit here:
return InitializeLazyPropertiesFromCache(fieldName, entity, session, entry, cacheEntry);
}
}
}
return InitializeLazyPropertiesFromDatastore(fieldName, entity, session, id, entry);
}
示例7: Replace
public override object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache)
{
if (original == null)
{
return null;
}
object cached = copyCache[original];
if (cached != null)
{
return cached;
}
else
{
if (original == target)
{
return target;
}
if (session.GetContextEntityIdentifier(original) == null && ForeignKeys.IsTransient(associatedEntityName, original, false, session))
{
object copy = session.Factory.GetEntityPersister(associatedEntityName).Instantiate(null, session.EntityMode);
//TODO: should this be Session.instantiate(Persister, ...)?
copyCache.Add(original, copy);
return copy;
}
else
{
object id = GetIdentifier(original, session);
if (id == null)
{
throw new AssertionFailure("non-transient entity has a null id");
}
id = GetIdentifierOrUniqueKeyType(session.Factory).Replace(id, null, session, owner, copyCache);
return ResolveIdentifier(id, session, owner);
}
}
}
示例8: 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 = new EntityKey(id, persister, session.EntityMode);
return session.PersistenceContext.GetEntity(key);
}
}
return identifier;
}
示例9: Hydrate
public override object Hydrate(IDataReader rs, string[] names, ISessionImplementor session, object owner)
{
return session.GetContextEntityIdentifier(owner);
}