本文整理汇总了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));
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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));
}
示例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);
}
示例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;
}
示例14: IsNullifiable
public bool IsNullifiable(bool earlyInsert, ISessionImplementor session)
{
return Status == Status.Saving || (earlyInsert ? !ExistsInDatabase : session.PersistenceContext.NullifiableEntityKeys.Contains(session.GenerateEntityKey(Id, Persister)));
}
示例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;
}