Skip to content

Commit 4723cd8

Browse files
committed
- Refactoring
- Port of EntityEntityModeToTuplizerMapping Note: The EntityMode was ported only in ISessionImplementor to don't have early breaking-change. SVN: trunk@3100
1 parent 119a2fc commit 4723cd8

14 files changed

+175
-145
lines changed

src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using NHibernate.Property;
1010
using NHibernate.Type;
1111
using NHibernate.Util;
12+
using System.Collections.Generic;
1213

1314
namespace NHibernate.Cfg.XmlHbmBinding
1415
{
@@ -843,15 +844,15 @@ private void BindOneToOne(XmlNode node, OneToOne model)
843844
);
844845
}
845846

846-
protected IDictionary GetMetas(XmlNode node)
847+
protected IDictionary<string, MetaAttribute> GetMetas(XmlNode node)
847848
{
848-
IDictionary map = new Hashtable();
849+
Dictionary<string, MetaAttribute> map = new Dictionary<string, MetaAttribute>();
849850

850851
foreach (XmlNode metaNode in node.SelectNodes(HbmConstants.nsMeta, namespaceManager))
851852
{
852853
string name = metaNode.Attributes["attribute"].Value;
853-
MetaAttribute meta = (MetaAttribute) map[name];
854-
if (meta == null)
854+
MetaAttribute meta;
855+
if (!map.TryGetValue(name, out meta))
855856
{
856857
meta = new MetaAttribute();
857858
map[name] = meta;

src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections;
2-
1+
using System.Collections.Generic;
32
using NHibernate.Cfg.MappingSchema;
43
using NHibernate.Engine;
54
using NHibernate.Mapping;
@@ -175,7 +174,7 @@ private void BindProperty(Mapping.Property property, HbmCompositeId idSchema)
175174
property.IsInsertable = true;
176175
property.IsOptimisticLocked = true;
177176
property.Generation = PropertyGeneration.Never;
178-
property.MetaAttributes = new Hashtable();
177+
property.MetaAttributes = new Dictionary<string, MetaAttribute>();
179178

180179
LogMappedProperty(property);
181180
}
@@ -320,7 +319,7 @@ private void BindProperty(HbmKeyManyToOne keyManyToOneSchema, Mapping.Property p
320319
property.IsInsertable = true;
321320
property.IsOptimisticLocked = true;
322321
property.Generation = PropertyGeneration.Never;
323-
property.MetaAttributes = new Hashtable();
322+
property.MetaAttributes = new Dictionary<string, MetaAttribute>();
324323

325324
LogMappedProperty(property);
326325
}
@@ -441,7 +440,7 @@ private void BindProperty(HbmKeyProperty keyPropertySchema, Mapping.Property pro
441440
property.IsInsertable = true;
442441
property.IsOptimisticLocked = true;
443442
property.Generation = PropertyGeneration.Never;
444-
property.MetaAttributes = new Hashtable();
443+
property.MetaAttributes = new Dictionary<string, MetaAttribute>();
445444
LogMappedProperty(property);
446445
}
447446
}

src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Collections.Generic;
23
using System.Xml;
34

45
using NHibernate.Cfg.MappingSchema;
@@ -207,15 +208,14 @@ private void AddDefaultColumn(HbmId idSchema, SimpleValue id)
207208
id.AddColumn(column);
208209
}
209210

210-
private static IDictionary GetMetas(HbmId idSchema)
211+
private static IDictionary<string, MetaAttribute> GetMetas(HbmId idSchema)
211212
{
212-
IDictionary map = new Hashtable();
213+
Dictionary<string, MetaAttribute> map = new Dictionary<string, MetaAttribute>();
213214

214215
foreach (HbmMeta metaSchema in idSchema.meta ?? new HbmMeta[0])
215216
{
216-
MetaAttribute meta = (MetaAttribute) map[metaSchema.attribute];
217-
218-
if (meta == null)
217+
MetaAttribute meta;
218+
if (!map.TryGetValue(metaSchema.attribute, out meta))
219219
{
220220
meta = new MetaAttribute();
221221
map[metaSchema.attribute] = meta;

src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
2-
using System.Collections;
2+
using System.Collections.Generic;
33
using System.Xml;
4-
54
using NHibernate.Cfg.MappingSchema;
65
using NHibernate.Mapping;
76
using NHibernate.Type;
@@ -152,7 +151,7 @@ private void BindProperty(HbmTimestamp timestampSchema, Mapping.Property propert
152151
property.IsUpdateable = false;
153152
}
154153

155-
property.MetaAttributes = new Hashtable();
154+
property.MetaAttributes = new Dictionary<string, MetaAttribute>();
156155

157156
LogMappedProperty(property);
158157
}
@@ -272,7 +271,7 @@ private void BindProperty(HbmVersion versionSchema, Mapping.Property property)
272271
property.IsUpdateable = false;
273272
}
274273

275-
property.MetaAttributes = new Hashtable();
274+
property.MetaAttributes = new Dictionary<string, MetaAttribute>();
276275

277276
LogMappedProperty(property);
278277
}

src/NHibernate/Engine/ISessionImplementor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,8 @@ public interface ISessionImplementor
285285
/// </summary>
286286
/// <returns></returns>
287287
ISession GetSession();
288+
289+
/// <summary> Retrieve the entity mode in effect for this session. </summary>
290+
EntityMode EntityMode { get;}
288291
}
289292
}

src/NHibernate/Impl/AbstractSessionImpl.cs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public ISessionFactoryImplementor Factory
4242
{
4343
get { return factory; }
4444
}
45+
public abstract EntityMode EntityMode { get;}
4546

4647
public abstract IBatcher Batcher { get; }
4748

src/NHibernate/Impl/SessionImpl.cs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public sealed class SessionImpl : AbstractSessionImpl, IEventSource, ISerializab
4747

4848
private readonly IInterceptor interceptor;
4949

50+
[NonSerialized]
51+
private EntityMode entityMode;
52+
5053
[NonSerialized]
5154
private readonly EventListeners listeners;
5255

@@ -1858,6 +1861,11 @@ public override CacheMode CacheMode
18581861
}
18591862
}
18601863

1864+
public override EntityMode EntityMode
1865+
{
1866+
get { return entityMode; }
1867+
}
1868+
18611869
public void SetReadOnly(object entity, bool readOnly)
18621870
{
18631871
ErrorIfClosed();

src/NHibernate/Impl/StatelessSessionImpl.cs

+5
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ public override CacheMode CacheMode
458458
set { throw new NotSupportedException(); }
459459
}
460460

461+
public override EntityMode EntityMode
462+
{
463+
get { return NHibernate.EntityMode.Poco; }
464+
}
465+
461466
/// <summary> Close the stateless session and release the ADO.NET connection.</summary>
462467
public void Close()
463468
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Mapping
4+
{
5+
/// <summary> Common interface for things that can handle meta attributes. </summary>
6+
public interface IMetaAttributable
7+
{
8+
/// <summary>
9+
/// Meta-Attribute collection.
10+
/// </summary>
11+
IDictionary<string, MetaAttribute> MetaAttributes { get;set;}
12+
13+
/// <summary>
14+
/// Retrive the <see cref="MetaAttribute"/>
15+
/// </summary>
16+
/// <param name="name">The attribute name</param>
17+
/// <returns>The <see cref="MetaAttribute"/> if exists; null otherwise</returns>
18+
MetaAttribute GetMetaAttribute(string name);
19+
}
20+
}

src/NHibernate/Mapping/PersistentClass.cs

+33-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace NHibernate.Mapping
1313
/// <see cref="Subclass"/> that is mapped by <c>&lt;subclass&gt;</c> or
1414
/// <c>&lt;joined-subclass&gt;</c>.
1515
/// </summary>
16-
public abstract class PersistentClass : IFilterable
16+
public abstract class PersistentClass : IFilterable, IMetaAttributable
1717
{
1818
private static readonly Alias PKAlias = new Alias(15, "PK");
1919

@@ -36,7 +36,7 @@ public abstract class PersistentClass : IFilterable
3636
private int batchSize = 1;
3737
private bool selectBeforeUpdate;
3838
private OptimisticLockMode optimisticLockMode;
39-
private IDictionary metaAttributes;
39+
private IDictionary<string, MetaAttribute> metaAttributes;
4040
private readonly List<Join> joins = new List<Join>();
4141
private readonly List<Join> subclassJoins = new List<Join>();
4242
private readonly IDictionary<string, string> filters = new Dictionary<string, string>();
@@ -63,6 +63,8 @@ public abstract class PersistentClass : IFilterable
6363
private bool hasSubselectLoadableCollections;
6464
private string entityName;
6565

66+
private IDictionary<EntityMode, System.Type> tuplizerImpls;
67+
6668
/// <summary>
6769
/// Gets or Sets if the Insert Sql is built dynamically.
6870
/// </summary>
@@ -525,15 +527,15 @@ public bool IsDiscriminatorValueNull
525527
get { return NullDiscriminatorMapping.Equals(DiscriminatorValue); }
526528
}
527529

528-
public IDictionary MetaAttributes
530+
public IDictionary<string, MetaAttribute> MetaAttributes
529531
{
530532
get { return metaAttributes; }
531533
set { metaAttributes = value; }
532534
}
533535

534536
public MetaAttribute GetMetaAttribute(string name)
535537
{
536-
return (MetaAttribute) metaAttributes[name];
538+
return metaAttributes[name];
537539
}
538540

539541
public virtual IEnumerable<Join> JoinIterator
@@ -945,5 +947,32 @@ public virtual bool HasIdentifierMapper
945947
get { return identifierMapper != null; }
946948
}
947949

950+
public void AddTuplizer(EntityMode entityMode, System.Type implClass)
951+
{
952+
if (tuplizerImpls == null)
953+
{
954+
tuplizerImpls = new Dictionary<EntityMode, System.Type>();
955+
}
956+
tuplizerImpls[entityMode] = implClass;
957+
}
958+
959+
public virtual System.Type GetTuplizerImplClassName(EntityMode mode)
960+
{
961+
if (tuplizerImpls == null)
962+
return null;
963+
return tuplizerImpls[mode];
964+
}
965+
966+
public virtual IDictionary<EntityMode, System.Type> TuplizerMap
967+
{
968+
get
969+
{
970+
if (tuplizerImpls == null)
971+
return null;
972+
973+
return new Dictionary<EntityMode, System.Type>(tuplizerImpls);
974+
}
975+
976+
}
948977
}
949978
}

src/NHibernate/Mapping/Property.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
21
using System.Collections;
2+
using System.Collections.Generic;
33
using NHibernate.Engine;
44
using NHibernate.Property;
55
using NHibernate.Type;
@@ -11,7 +11,7 @@ namespace NHibernate.Mapping
1111
/// Mapping for a property of a .NET class (entity
1212
/// or component).
1313
/// </summary>
14-
public class Property
14+
public class Property: IMetaAttributable
1515
{
1616
private string name;
1717
private IValue propertyValue;
@@ -21,7 +21,7 @@ public class Property
2121
private bool selectable = true;
2222
private string propertyAccessorName;
2323
private bool optional;
24-
private IDictionary metaAttributes;
24+
private IDictionary<string, MetaAttribute> metaAttributes;
2525
private PersistentClass persistentClass;
2626
private bool isOptimisticLocked;
2727
private PropertyGeneration generation = PropertyGeneration.Never;
@@ -202,7 +202,7 @@ public bool IsBasicPropertyAccessor
202202
get { return propertyAccessorName == null || propertyAccessorName.Equals("property"); }
203203
}
204204

205-
public IDictionary MetaAttributes
205+
public IDictionary<string, MetaAttribute> MetaAttributes
206206
{
207207
get { return metaAttributes; }
208208
set { metaAttributes = value; }

src/NHibernate/NHibernate-2.0.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@
723723
<Compile Include="IMultiCriteria.cs" />
724724
<Compile Include="IStatelessSession.cs" />
725725
<Compile Include="Mapping\DenormalizedTable.cs" />
726+
<Compile Include="Mapping\IMetaAttributable.cs" />
726727
<Compile Include="Mapping\PropertyGeneration.cs" />
727728
<Compile Include="Mapping\UnionSubclass.cs" />
728729
<Compile Include="Persister\Entity\ILockable.cs" />

0 commit comments

Comments
 (0)