forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPersister.cs
524 lines (425 loc) · 10.1 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
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
{
/// <summary>
/// Summary description for CustomPersister.
/// </summary>
public partial class CustomPersister : IEntityPersister
{
private static readonly Hashtable Instances = new Hashtable();
private static readonly IIdentifierGenerator Generator = new UUIDHexGenerator();
private static readonly IType[] Types = new IType[] { NHibernateUtil.String };
private static readonly string[] Names = new string[] { "name" };
private static readonly bool[] Mutability = new bool[] { true };
private static readonly bool[] Nullability = new bool[] { true };
private readonly ISessionFactoryImplementor factory;
public CustomPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory,
IMapping mapping)
{
this.factory = factory;
}
#region IEntityPersister Members
public ISessionFactoryImplementor Factory
{
get { return factory; }
}
public string RootEntityName
{
get { return "CUSTOMS"; }
}
public string EntityName
{
get { return typeof (Custom).FullName; }
}
public EntityMetamodel EntityMetamodel
{
get { return null; }
}
public string[] PropertySpaces
{
get { return new string[] { "CUSTOMS" }; }
}
public string[] QuerySpaces
{
get { return new string[] { "CUSTOMS" }; }
}
public bool IsMutable
{
get { return true; }
}
public bool IsInherited
{
get { return false; }
}
public bool IsIdentifierAssignedByInsert
{
get { return false; }
}
#region IOptimisticCacheSource Members
public bool IsVersioned
{
get { return false; }
}
bool IEntityPersister.IsVersioned
{
get { return IsVersioned; }
}
public IVersionType VersionType
{
get { return null; }
}
public int VersionProperty
{
get { return 0; }
}
public int[] NaturalIdentifierProperties
{
get { return null; }
}
public IIdentifierGenerator IdentifierGenerator
{
get { return Generator; }
}
public IType[] PropertyTypes
{
get { return Types; }
}
public string[] PropertyNames
{
get { return Names; }
}
public bool[] PropertyInsertability
{
get { return Mutability; }
}
public ValueInclusion[] PropertyInsertGenerationInclusions
{
get { return Array.Empty<ValueInclusion>(); }
}
public ValueInclusion[] PropertyUpdateGenerationInclusions
{
get { return Array.Empty<ValueInclusion>(); }
}
public bool[] PropertyCheckability
{
get { return Mutability; }
}
public bool[] PropertyNullability
{
get { return Nullability; }
}
public bool[] PropertyVersionability
{
get { return Mutability; }
}
public bool[] PropertyLaziness
{
get { return null; }
}
public CascadeStyle[] PropertyCascadeStyles
{
get { return null; }
}
public IType IdentifierType
{
get { return NHibernateUtil.String; }
}
public string IdentifierPropertyName
{
get { return "Id"; }
}
public bool IsCacheInvalidationRequired
{
get { return false; }
}
public bool IsLazyPropertiesCacheable
{
get { return true; }
}
public ICacheConcurrencyStrategy Cache
{
get { return null; }
}
public ICacheEntryStructure CacheEntryStructure
{
get { return new UnstructuredCacheEntry(); }
}
public IClassMetadata ClassMetadata
{
get { return null; }
}
public bool IsBatchLoadable
{
get { return false; }
}
public bool IsSelectBeforeUpdateRequired
{
get { return false; }
}
public bool IsVersionPropertyGenerated
{
get { return false; }
}
public void PostInstantiate()
{
}
public bool IsSubclassEntityName(string entityName)
{
return typeof (Custom).FullName.Equals(entityName);
}
public bool HasProxy
{
get { return false; }
}
public bool HasCollections
{
get { return false; }
}
public bool HasMutableProperties
{
get { return false; }
}
public bool HasSubselectLoadableCollections
{
get { return false; }
}
public bool HasCascades
{
get { return false; }
}
public IType GetPropertyType(string propertyName)
{
throw new NotSupportedException();
}
public int[] FindDirty(object[] currentState, object[] previousState, object entity, ISessionImplementor session)
{
if (!Equals(currentState[0], previousState[0]))
{
return new int[] { 0 };
}
else
{
return null;
}
}
public int[] FindModified(object[] old, object[] current, object entity, ISessionImplementor session)
{
if (!Equals(old[0], current[0]))
{
return new int[] { 0 };
}
else
{
return null;
}
}
public bool HasIdentifierProperty
{
get { return true; }
}
public bool CanExtractIdOutOfEntity
{
get { return true; }
}
public bool HasNaturalIdentifier
{
get { return false; }
}
public object[] GetNaturalIdentifierSnapshot(object id, ISessionImplementor session)
{
return null;
}
public bool HasLazyProperties
{
get { return false; }
}
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, session);
TwoPhaseLoad.PostHydrate(this, id, new String[] {obj.Name}, null, clone, LockMode.None, session);
TwoPhaseLoad.InitializeEntity(clone, false, session, new PreLoadEvent((IEventSource) session),
new PostLoadEvent((IEventSource) session));
}
return clone;
}
public void Lock(object id, object version, object obj, LockMode lockMode, ISessionImplementor session)
{
throw new NotSupportedException();
}
public void Insert(object id, object[] fields, object obj, ISessionImplementor session)
{
Instances[id] = ((Custom)obj).Clone();
}
public object Insert(object[] fields, object obj, ISessionImplementor session)
{
throw new NotSupportedException();
}
public void Delete(object id, object version, object obj, ISessionImplementor session)
{
Instances.Remove(id);
}
public void Update(object id, object[] fields, int[] dirtyFields, bool hasDirtyCollection, object[] oldFields,
object oldVersion, object obj, object rowId, ISessionImplementor session)
{
Instances[id] = ((Custom)obj).Clone();
}
public bool[] PropertyUpdateability
{
get { return Mutability; }
}
public bool HasCache
{
get { return false; }
}
public object[] GetDatabaseSnapshot(object id, ISessionImplementor session)
{
return null;
}
public object GetCurrentVersion(object id, ISessionImplementor session)
{
return Instances[id];
}
public object ForceVersionIncrement(object id, object currentVersion, ISessionImplementor session)
{
return null;
}
public EntityMode EntityMode => EntityMode.Poco;
public bool IsInstrumented
{
get { return false; }
}
public bool HasInsertGeneratedProperties
{
get { return false; }
}
public bool HasUpdateGeneratedProperties
{
get { return false; }
}
public void AfterInitialize(object entity, bool lazyPropertiesAreUnfetched, ISessionImplementor session)
{
}
public void AfterReassociate(object entity, ISessionImplementor session)
{
}
public object CreateProxy(object id, ISessionImplementor session)
{
throw new NotSupportedException("no proxy for this class");
}
public bool? IsTransient(object obj, ISessionImplementor session)
{
return ((Custom) obj).Id == null;
}
public object[] GetPropertyValuesToInsert(object obj, IDictionary mergeMap, ISessionImplementor session)
{
return GetPropertyValues(obj);
}
public void ProcessInsertGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session)
{
}
public void ProcessUpdateGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session)
{
}
public System.Type MappedClass
{
get { return typeof(Custom); }
}
public bool ImplementsLifecycle
{
get { return false; }
}
public bool ImplementsValidatable
{
get { return false; }
}
public System.Type ConcreteProxyClass
{
get { return typeof(Custom); }
}
public void SetPropertyValues(object obj, object[] values)
{
SetPropertyValue(obj, 0, values[0]);
}
public void SetPropertyValue(object obj, int i, object value)
{
((Custom) obj).Name = (string) value;
}
public object[] GetPropertyValues(object obj)
{
Custom c = (Custom) obj;
return new Object[] {c.Name};
}
public object GetPropertyValue(object obj, int i)
{
return ((Custom)obj).Name;
}
public object GetPropertyValue(object obj, string name)
{
return ((Custom)obj).Name;
}
public object GetIdentifier(object obj)
{
return ((Custom)obj).Id;
}
public void SetIdentifier(object obj, object id)
{
((Custom) obj).Id = (string) id;
}
public object GetVersion(object obj)
{
return null;
}
public object Instantiate(object id)
{
Custom c = new Custom();
c.Id = (string)id;
return c;
}
public bool IsInstance(object entity)
{
return entity is Custom;
}
public bool HasUninitializedLazyProperties(object obj)
{
return false;
}
public void ResetIdentifier(object entity, object currentId, object currentVersion)
{
((Custom)entity).Id = (string)currentId;
}
public IEntityPersister GetSubclassEntityPersister(object instance, ISessionFactoryImplementor factory)
{
return this;
}
public bool? IsUnsavedVersion(object version)
{
return false;
}
#endregion
public IComparer VersionComparator
{
get { return null; }
}
public IEntityTuplizer EntityTuplizer => null;
#endregion
}
}