本文整理汇总了C#中IEventSource.GenerateEntityKey方法的典型用法代码示例。如果您正苦于以下问题:C# IEventSource.GenerateEntityKey方法的具体用法?C# IEventSource.GenerateEntityKey怎么用?C# IEventSource.GenerateEntityKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEventSource
的用法示例。
在下文中一共展示了IEventSource.GenerateEntityKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformSaveOrReplicate
/// <summary>
/// Performs all the actual work needed to save an entity (well to get the save moved to
/// the execution queue).
/// </summary>
/// <param name="entity">The entity to be saved </param>
/// <param name="key">The id to be used for saving the entity (or null, in the case of identity columns) </param>
/// <param name="persister">The entity's persister instance. </param>
/// <param name="useIdentityColumn">Should an identity column be used for id generation? </param>
/// <param name="anything">Generally cascade-specific information. </param>
/// <param name="source">The session which is the source of the current event. </param>
/// <param name="requiresImmediateIdAccess">
/// Is access to the identifier required immediately
/// after the completion of the save? persist(), for example, does not require this...
/// </param>
/// <returns>
/// The id used to save the entity; may be null depending on the
/// type of id generator used and the requiresImmediateIdAccess value
/// </returns>
protected virtual object PerformSaveOrReplicate(object entity, EntityKey key, IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess)
{
Validate(entity, persister, source);
object id = key == null ? null : key.Identifier;
// NH Different behavior (shouldDelayIdentityInserts=false anyway)
//bool inTxn = source.ConnectionManager.IsInActiveTransaction;
//bool shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;
bool shouldDelayIdentityInserts = false;
// Put a placeholder in entries, so we don't recurse back and try to save() the
// same object again. QUESTION: should this be done before onSave() is called?
// likewise, should it be done before onUpdate()?
source.PersistenceContext.AddEntry(entity, Status.Saving, null, null, id, null, LockMode.Write, useIdentityColumn, persister, false, false);
CascadeBeforeSave(source, persister, entity, anything);
// NH-962: This was originally done before many-to-one cascades.
if (useIdentityColumn && !shouldDelayIdentityInserts)
{
log.Debug("executing insertions");
source.ActionQueue.ExecuteInserts();
}
object[] values = persister.GetPropertyValuesToInsert(entity, GetMergeMap(anything), source);
IType[] types = persister.PropertyTypes;
bool substitute = SubstituteValuesIfNecessary(entity, id, values, persister, source);
if (persister.HasCollections)
{
substitute = substitute || VisitCollectionsBeforeSave(entity, id, values, types, source);
}
if (substitute)
{
persister.SetPropertyValues(entity, values, source.EntityMode);
}
TypeHelper.DeepCopy(values, types, persister.PropertyUpdateability, values, source);
new ForeignKeys.Nullifier(entity, false, useIdentityColumn, source).NullifyTransientReferences(values, types);
new Nullability(source).CheckNullability(values, persister, false);
if (useIdentityColumn)
{
EntityIdentityInsertAction insert = new EntityIdentityInsertAction(values, entity, persister, source, shouldDelayIdentityInserts);
if (!shouldDelayIdentityInserts)
{
log.Debug("executing identity-insert immediately");
source.ActionQueue.Execute(insert);
id = insert.GeneratedId;
//now done in EntityIdentityInsertAction
//persister.setIdentifier( entity, id, source.getEntityMode() );
key = source.GenerateEntityKey(id, persister);
source.PersistenceContext.CheckUniqueness(key, entity);
//source.getBatcher().executeBatch(); //found another way to ensure that all batched joined inserts have been executed
}
else
{
log.Debug("delaying identity-insert due to no transaction in progress");
source.ActionQueue.AddAction(insert);
key = insert.DelayedEntityKey;
}
}
object version = Versioning.GetVersion(values, persister);
source.PersistenceContext.AddEntity(
entity,
persister.IsMutable ? Status.Loaded : Status.ReadOnly,
values, key,
version,
LockMode.Write,
useIdentityColumn,
persister,
VersionIncrementDisabled,
false);
//source.getPersistenceContext().removeNonExist( new EntityKey( id, persister, source.getEntityMode() ) );
if (!useIdentityColumn)
{
//.........这里部分代码省略.........
示例2: PerformSave
/// <summary>
/// Prepares the save call by checking the session caches for a pre-existing
/// entity and performing any lifecycle callbacks.
/// </summary>
/// <param name="entity">The entity to be saved. </param>
/// <param name="id">The id by which to save the entity. </param>
/// <param name="persister">The entity's persister instance. </param>
/// <param name="useIdentityColumn">Is an identity column being used? </param>
/// <param name="anything">Generally cascade-specific information. </param>
/// <param name="source">The session from which the event originated. </param>
/// <param name="requiresImmediateIdAccess">
/// does the event context require
/// access to the identifier immediately after execution of this method (if
/// not, post-insert style id generators may be postponed if we are outside
/// a transaction).
/// </param>
/// <returns>
/// The id used to save the entity; may be null depending on the
/// type of id generator used and the requiresImmediateIdAccess value
/// </returns>
protected virtual object PerformSave(object entity, object id, IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess)
{
if (log.IsDebugEnabled)
{
log.Debug("saving " + MessageHelper.InfoString(persister, id, source.Factory));
}
EntityKey key;
if (!useIdentityColumn)
{
key = source.GenerateEntityKey(id, persister);
object old = source.PersistenceContext.GetEntity(key);
if (old != null)
{
if (source.PersistenceContext.GetEntry(old).Status == Status.Deleted)
{
source.ForceFlush(source.PersistenceContext.GetEntry(old));
}
else
{
throw new NonUniqueObjectException(id, persister.EntityName);
}
}
persister.SetIdentifier(entity, id, source.EntityMode);
}
else
{
key = null;
}
if (InvokeSaveLifecycle(entity, persister, source))
{
return id; //EARLY EXIT
}
return PerformSaveOrReplicate(entity, key, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess);
}
示例3: ExistsInDatabase
private static bool ExistsInDatabase(object entity, IEventSource source, IEntityPersister persister)
{
EntityEntry entry = source.PersistenceContext.GetEntry(entity);
if (entry == null)
{
object id = persister.GetIdentifier(entity, source.EntityMode);
if (id != null)
{
EntityKey key = source.GenerateEntityKey(id, persister);
object managedEntity = source.PersistenceContext.GetEntity(key);
entry = source.PersistenceContext.GetEntry(managedEntity);
}
}
if (entry == null)
{
// perhaps this should be an exception since it is only ever used
// in the above method?
return false;
}
else
{
return entry.ExistsInDatabase;
}
}
示例4: PerformReplication
private void PerformReplication(object entity, object id, object version, IEntityPersister persister, ReplicationMode replicationMode, IEventSource source)
{
if (log.IsDebugEnabled)
{
log.Debug("replicating changes to " + MessageHelper.InfoString(persister, id, source.Factory));
}
new OnReplicateVisitor(source, id, entity, true).Process(entity, persister);
source.PersistenceContext.AddEntity(
entity,
persister.IsMutable ? Status.Loaded : Status.ReadOnly,
null,
source.GenerateEntityKey(id, persister),
version,
LockMode.None,
true,
persister,
true,
false);
CascadeAfterReplicate(entity, persister, replicationMode, source);
}
示例5: DeleteEntity
/// <summary>
/// Perform the entity deletion. Well, as with most operations, does not
/// really perform it; just schedules an action/execution with the
/// <see cref="ActionQueue"/> for execution during flush.
/// </summary>
/// <param name="session">The originating session </param>
/// <param name="entity">The entity to delete </param>
/// <param name="entityEntry">The entity's entry in the <see cref="ISession"/> </param>
/// <param name="isCascadeDeleteEnabled">Is delete cascading enabled? </param>
/// <param name="persister">The entity persister. </param>
/// <param name="transientEntities">A cache of already deleted entities. </param>
protected virtual void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, IEntityPersister persister, ISet<object> transientEntities)
{
if (log.IsDebugEnabled)
{
log.Debug("deleting " + MessageHelper.InfoString(persister, entityEntry.Id, session.Factory));
}
IPersistenceContext persistenceContext = session.PersistenceContext;
IType[] propTypes = persister.PropertyTypes;
object version = entityEntry.Version;
object[] currentState;
if (entityEntry.LoadedState == null)
{
//ie. the entity came in from update()
currentState = persister.GetPropertyValues(entity, session.EntityMode);
}
else
{
currentState = entityEntry.LoadedState;
}
object[] deletedState = CreateDeletedState(persister, currentState, session);
entityEntry.DeletedState = deletedState;
session.Interceptor.OnDelete(entity, entityEntry.Id, deletedState, persister.PropertyNames, propTypes);
// before any callbacks, etc, so subdeletions see that this deletion happened first
persistenceContext.SetEntryStatus(entityEntry, Status.Deleted);
EntityKey key = session.GenerateEntityKey(entityEntry.Id, persister);
CascadeBeforeDelete(session, persister, entity, entityEntry, transientEntities);
new ForeignKeys.Nullifier(entity, true, false, session).NullifyTransientReferences(entityEntry.DeletedState, propTypes);
new Nullability(session).CheckNullability(entityEntry.DeletedState, persister, true);
persistenceContext.NullifiableEntityKeys.Add(key);
// Ensures that containing deletions happen before sub-deletions
session.ActionQueue.AddAction(new EntityDeleteAction(entityEntry.Id, deletedState, version, entity, persister, isCascadeDeleteEnabled, session));
CascadeAfterDelete(session, persister, entity, transientEntities);
// the entry will be removed after the flush, and will no longer
// override the stale snapshot
// This is now handled by removeEntity() in EntityDeleteAction
//persistenceContext.removeDatabaseSnapshot(key);
}