forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatefulInterceptor.cs
54 lines (48 loc) · 1.16 KB
/
StatefulInterceptor.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
using System.Collections;
using System.Collections.Generic;
using NHibernate.Type;
namespace NHibernate.Test.Interceptor
{
public class StatefulInterceptor : EmptyInterceptor
{
private ISession session;
private readonly IList<Log> list = new List<Log>();
public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
if (!(entity is Log))
{
list.Add(new Log("insert", (string) id, entity.GetType().FullName));
}
return false;
}
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState,
string[] propertyNames, IType[] types)
{
if (!(entity is Log))
{
list.Add(new Log("update", (string) id, entity.GetType().FullName));
}
return false;
}
public override void PostFlush(ICollection entities)
{
if (list.Count > 0)
{
foreach (Log iter in list)
{
session.Persist(iter);
}
list.Clear();
session.Flush();
}
}
public override void SetSession(ISession sessionLocal)
{
session = sessionLocal;
}
public ISession Session
{
get { return session; }
}
}
}