forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPersister.cs
194 lines (172 loc) · 5.42 KB
/
CustomPersister.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using NHibernate.Cache;
using NHibernate.Cache.Entry;
using NHibernate.Engine;
using NHibernate.Event;
using NHibernate.Id;
using NHibernate.Mapping;
using NHibernate.Metadata;
using NHibernate.Persister.Entity;
using NHibernate.Tuple.Entity;
using NHibernate.Type;
using NHibernate.Util;
using Array = System.Array;
namespace NHibernate.DomainModel
{
using System.Threading.Tasks;
using System.Threading;
public partial class CustomPersister : IEntityPersister
{
#region IEntityPersister Members
#region IOptimisticCacheSource Members
public Task<int[]> FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
if (!Equals(currentState[0], previousState[0]))
{
return Task.FromResult<int[]>(new int[] { 0 });
}
else
{
return Task.FromResult<int[]>(null);
}
}
catch (Exception ex)
{
return Task.FromException<int[]>(ex);
}
}
public Task<int[]> FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
if (!Equals(old[0], current[0]))
{
return Task.FromResult<int[]>(new int[] { 0 });
}
else
{
return Task.FromResult<int[]>(null);
}
}
catch (Exception ex)
{
return Task.FromException<int[]>(ex);
}
}
public Task<object[]> GetNaturalIdentifierSnapshotAsync(object id, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.FromResult<object[]>(null);
}
public async Task<object> LoadAsync(object id, object optionalObject, LockMode lockMode, ISessionImplementor session, CancellationToken cancellationToken)
{
// 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, session);
TwoPhaseLoad.PostHydrate(this, id, new String[] {obj.Name}, null, clone, LockMode.None, session);
await (TwoPhaseLoad.InitializeEntityAsync(clone, false, session, new PreLoadEvent((IEventSource) session),
new PostLoadEvent((IEventSource) session), cancellationToken));
}
return clone;
}
public Task LockAsync(object id, object version, object obj, LockMode lockMode, ISessionImplementor session, CancellationToken cancellationToken)
{
throw new NotSupportedException();
}
public Task InsertAsync(object id, object[] fields, object obj, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
Instances[id] = ((Custom)obj).Clone();
return Task.CompletedTask;
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
public Task<object> InsertAsync(object[] fields, object obj, ISessionImplementor session, CancellationToken cancellationToken)
{
throw new NotSupportedException();
}
public Task DeleteAsync(object id, object version, object obj, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
Instances.Remove(id);
return Task.CompletedTask;
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
public Task UpdateAsync(object id, object[] fields, int[] dirtyFields, bool hasDirtyCollection, object[] oldFields,
object oldVersion, object obj, object rowId, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
Instances[id] = ((Custom)obj).Clone();
return Task.CompletedTask;
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
public Task<object[]> GetDatabaseSnapshotAsync(object id, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.FromResult<object[]>(null);
}
public Task<object> GetCurrentVersionAsync(object id, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
return Task.FromResult<object>(Instances[id]);
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
public Task<object> ForceVersionIncrementAsync(object id, object currentVersion, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.FromResult<object>(null);
}
public Task<bool?> IsTransientAsync(object obj, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
return Task.FromResult<bool?>(((Custom) obj).Id == null);
}
catch (Exception ex)
{
return Task.FromException<bool?>(ex);
}
}
public Task ProcessInsertGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public Task ProcessUpdateGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
#endregion
#endregion
}
}