forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnLockVisitor.cs
67 lines (64 loc) · 2.35 KB
/
OnLockVisitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using NHibernate.Collection;
using NHibernate.Engine;
using NHibernate.Persister.Collection;
using NHibernate.Type;
namespace NHibernate.Event.Default
{
/// <summary>
/// When a transient entity is passed to lock(), we must inspect all its collections and
/// 1. associate any uninitialized PersistentCollections with this session
/// 2. associate any initialized PersistentCollections with this session, using the existing snapshot
/// 3. throw an exception for each "new" collection
/// </summary>
public partial class OnLockVisitor : ReattachVisitor
{
public OnLockVisitor(IEventSource session, object ownerIdentifier, object owner) : base(session, ownerIdentifier, owner) { }
internal override object ProcessCollection(object collection, CollectionType type)
{
ISessionImplementor session = Session;
ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);
if (collection == null)
{
//do nothing
}
else
{
IPersistentCollection persistentCollection = collection as IPersistentCollection;
if (persistentCollection != null)
{
if (persistentCollection.SetCurrentSession(session))
{
if (IsOwnerUnchanged(persistentCollection, persister, ExtractCollectionKeyFromOwner(persister)))
{
// a "detached" collection that originally belonged to the same entity
if (persistentCollection.IsDirty)
{
throw new HibernateException("reassociated object has dirty collection: " + persistentCollection.Role);
}
ReattachCollection(persistentCollection, type);
}
else
{
// a "detached" collection that belonged to a different entity
throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
}
}
else
{
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
}
}
else
{
// brand new collection
//TODO: or an array!! we can't lock objects with arrays now??
throw new HibernateException("reassociated object has dirty collection reference (or an array)");
}
}
return null;
}
}
}