forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIEntityTuplizer.cs
148 lines (129 loc) · 7.3 KB
/
IEntityTuplizer.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
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Engine;
using NHibernate.Util;
namespace NHibernate.Tuple.Entity
{
/// <summary>
/// Defines further responsibilities regarding tuplization based on a mapped entity.
/// </summary>
/// <remarks>
/// EntityTuplizer implementations should have the following constructor signature:
/// (<see cref="EntityMetamodel"/>, <see cref="Mapping.PersistentClass"/>)
/// </remarks>
public interface IEntityTuplizer : ITuplizer
{
/// <summary>
/// Does the <see cref="ITuplizer.MappedClass">class</see> managed by this tuplizer implement
/// the <see cref="NHibernate.Classic.ILifecycle"/> interface.
/// </summary>
/// <returns> True if the ILifecycle interface is implemented; false otherwise. </returns>
bool IsLifecycleImplementor { get; }
/// <summary>
/// Does the <see cref="ITuplizer.MappedClass">class</see> managed by this tuplizer implement
/// the <see cref="NHibernate.Classic.IValidatable"/> interface.
/// </summary>
/// <returns> True if the IValidatable interface is implemented; false otherwise. </returns>
bool IsValidatableImplementor { get; }
// TODO: getConcreteProxyClass() is solely used (externally) to perform narrowProxy()
// would be great to fully encapsulate that narrowProxy() functionality within the
// Tuplizer, itself, with a Tuplizer.narrowProxy(..., PersistentContext) method
/// <summary> Returns the java class to which generated proxies will be typed. </summary>
/// <returns> The .NET class to which generated proxies will be typed </returns>
System.Type ConcreteProxyClass { get; }
/// <summary> Is it an instrumented POCO?</summary>
// Since 5.3
[Obsolete("This property is not used and will be removed in a future version.")]
bool IsInstrumented { get; }
/// <summary> Create an entity instance initialized with the given identifier. </summary>
/// <param name="id">The identifier value for the entity to be instantiated. </param>
/// <returns> The instantiated entity. </returns>
object Instantiate(object id);
/// <summary> Extract the identifier value from the given entity. </summary>
/// <param name="entity">The entity from which to extract the identifier value. </param>
/// <returns> The identifier value. </returns>
object GetIdentifier(object entity);
/// <summary>
/// Inject the identifier value into the given entity.
/// </summary>
/// <param name="entity">The entity to inject with the identifier value.</param>
/// <param name="id">The value to be injected as the identifier. </param>
/// <remarks>Has no effect if the entity does not define an identifier property</remarks>
void SetIdentifier(object entity, object id);
/// <summary>
/// Inject the given identifier and version into the entity, in order to
/// "roll back" to their original values.
/// </summary>
/// <param name="entity"></param>
/// <param name="currentId">The identifier value to inject into the entity. </param>
/// <param name="currentVersion">The version value to inject into the entity. </param>
void ResetIdentifier(object entity, object currentId, object currentVersion);
/// <summary> Extract the value of the version property from the given entity. </summary>
/// <param name="entity">The entity from which to extract the version value. </param>
/// <returns> The value of the version property, or null if not versioned. </returns>
object GetVersion(object entity);
/// <summary> Inject the value of a particular property. </summary>
/// <param name="entity">The entity into which to inject the value. </param>
/// <param name="i">The property's index. </param>
/// <param name="value">The property value to inject. </param>
void SetPropertyValue(object entity, int i, object value);
/// <summary> Inject the value of a particular property. </summary>
/// <param name="entity">The entity into which to inject the value. </param>
/// <param name="propertyName">The name of the property. </param>
/// <param name="value">The property value to inject. </param>
void SetPropertyValue(object entity, string propertyName, object value);
/// <summary> Extract the values of the insertable properties of the entity (including backrefs) </summary>
/// <param name="entity">The entity from which to extract. </param>
/// <param name="mergeMap">a map of instances being merged to merged instances </param>
/// <param name="session">The session in which the request is being made. </param>
/// <returns> The insertable property values. </returns>
object[] GetPropertyValuesToInsert(object entity, IDictionary mergeMap, ISessionImplementor session);
/// <summary> Extract the value of a particular property from the given entity. </summary>
/// <param name="entity">The entity from which to extract the property value. </param>
/// <param name="propertyName">The name of the property for which to extract the value. </param>
/// <returns> The current value of the given property on the given entity. </returns>
object GetPropertyValue(object entity, string propertyName);
/// <summary> Called just after the entities properties have been initialized. </summary>
/// <param name="entity">The entity being initialized. </param>
/// <param name="lazyPropertiesAreUnfetched">Are defined lazy properties currently unfecthed </param>
/// <param name="session">The session initializing this entity. </param>
// Since 5.3
[Obsolete("Use the extension method instead")]
void AfterInitialize(object entity, bool lazyPropertiesAreUnfetched, ISessionImplementor session);
/// <summary> Does this entity, for this mode, present a possibility for proxying? </summary>
/// <value> True if this tuplizer can generate proxies for this entity. </value>
bool HasProxy { get; }
/// <summary>
/// Generates an appropriate proxy representation of this entity for this entity-mode.
/// </summary>
/// <param name="id">The id of the instance for which to generate a proxy. </param>
/// <param name="session">The session to which the proxy should be bound. </param>
/// <returns> The generate proxies. </returns>
object CreateProxy(object id, ISessionImplementor session);
/// <summary> Does the given entity instance have any currently uninitialized lazy properties? </summary>
/// <param name="entity">The entity to be check for uninitialized lazy properties. </param>
/// <returns> True if uninitialized lazy properties were found; false otherwise. </returns>
// Since 5.3
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
bool HasUninitializedLazyProperties(object entity);
}
public static class EntityTuplizerExtensions
{
/// <summary> Called just after the entities properties have been initialized. </summary>
/// <param name="entityTuplizer">The entity tupilizer.</param>
/// <param name="entity">The entity being initialized. </param>
/// <param name="session">The session initializing this entity. </param>
public static void AfterInitialize(this IEntityTuplizer entityTuplizer, object entity, ISessionImplementor session)
{
if (entityTuplizer is AbstractEntityTuplizer abstractEntityTuplizer)
{
abstractEntityTuplizer.AfterInitialize(entity, session);
return;
}
#pragma warning disable 618
entityTuplizer.AfterInitialize(entity, true, session);
#pragma warning restore 618
}
}
}