Skip to content

Commit 7ba52d2

Browse files
authored
Merge pull request #579 from hazzik/NH-3722
NH-3722 - Remove entity mode switching capability
2 parents ee42371 + ba6576b commit 7ba52d2

File tree

200 files changed

+1007
-3723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+1007
-3723
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ current-test-configuration
1212
# to satisfy later build steps. But it should not be committed.
1313
NHibernate.dll
1414
TestResult.xml
15+
.vscode

doc/reference/modules/persistent_classes.xml

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,11 @@ namespace Eg
256256
(using <literal>Dictionaries</literal> of <literal>Dictionary</literal>s at runtime) . With this approach, you don't
257257
write persistent classes, only mapping files.
258258
</para>
259-
260-
<para>
261-
By default, NHibernate works in normal POCO mode. You may set a default entity
262-
representation mode for a particular <literal>ISessionFactory</literal> using the
263-
<literal>default_entity_mode</literal> configuration option (see
264-
<xref linkend="configuration-optional-properties"/>.
265-
</para>
266-
259+
267260
<para>
268261
The following examples demonstrates the representation using <literal>Map</literal>s (Dictionary).
269262
First, in the mapping file, an <literal>entity-name</literal> has to be declared
270-
instead of (or in addition to) a class name:
263+
instead of a class name:
271264
</para>
272265

273266
<programlisting><![CDATA[<hibernate-mapping>
@@ -305,16 +298,13 @@ namespace Eg
305298
</hibernate-mapping>]]></programlisting>
306299

307300
<para>
308-
309301
Note that even though associations are declared using target class names,
310302
the target type of an associations may also be a dynamic entity instead
311303
of a POCO.
312304
</para>
313305

314306
<para>
315-
After setting the default entity mode to <literal>dynamic-map</literal>
316-
for the <literal>ISessionFactory</literal>, we can at runtime work with
317-
<literal>Dictionaries</literal> of <literal>Dictionaries</literal>:
307+
At runtime we can work with <literal>Dictionaries</literal> of <literal>Dictionaries</literal>:
318308
</para>
319309

320310
<programlisting><![CDATA[using(ISession s = OpenSession())
@@ -345,33 +335,6 @@ using(ITransaction tx = s.BeginTransaction())
345335
to the NHibernate mapping, the database schema can easily be normalized and sound,
346336
allowing to add a proper domain model implementation on top later on.
347337
</para>
348-
349-
<para>
350-
Entity representation modes can also be set on a per <literal>ISession</literal>
351-
basis:
352-
</para>
353-
354-
<programlisting><![CDATA[using (ISession dynamicSession = pocoSession.GetSession(EntityMode.Map))
355-
{
356-
// Create a customer
357-
var frank = new Dictionary<string, object>();
358-
frank["name"] = "Frank";
359-
dynamicSession.Save("Customer", frank);
360-
...
361-
}
362-
// Continue on pocoSession
363-
]]></programlisting>
364-
365-
366-
<para>
367-
Please note that the call to <literal>GetSession()</literal> using an
368-
<literal>EntityMode</literal> is on the <literal>ISession</literal> API, not the
369-
<literal>ISessionFactory</literal>. That way, the new <literal>ISession</literal>
370-
shares the underlying ADO connection, transaction, and other context
371-
information. This means you don't have to call <literal>Flush()</literal>
372-
and <literal>Close()</literal> on the secondary <literal>ISession</literal>, and
373-
also leave the transaction and connection handling to the primary unit of work.
374-
</para>
375338
</sect1>
376339

377340
<sect1 id="persistent-classes-tuplizers" revision="1">

src/NHibernate.DomainModel/CustomPersister.cs

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ public CustomPersister(PersistentClass model, ICacheConcurrencyStrategy cache, I
3434
this.factory = factory;
3535
}
3636

37-
private static void CheckEntityMode(EntityMode entityMode)
38-
{
39-
if (EntityMode.Poco != entityMode)
40-
{
41-
throw new ArgumentOutOfRangeException("entityMode", "Unhandled EntityMode : " + entityMode);
42-
}
43-
}
44-
4537
#region IEntityPersister Members
4638

4739
public ISessionFactoryImplementor Factory
@@ -377,21 +369,11 @@ public object ForceVersionIncrement(object id, object currentVersion, ISessionIm
377369
return null;
378370
}
379371

380-
public EntityMode? GuessEntityMode(object obj)
381-
{
382-
if (!IsInstance(obj, EntityMode.Poco))
383-
{
384-
return null;
385-
}
386-
else
387-
{
388-
return EntityMode.Poco;
389-
}
390-
}
372+
public EntityMode EntityMode => EntityMode.Poco;
391373

392-
public bool IsInstrumented(EntityMode entityMode)
374+
public bool IsInstrumented
393375
{
394-
return false;
376+
get { return false; }
395377
}
396378

397379
public bool HasInsertGeneratedProperties
@@ -424,7 +406,7 @@ public object CreateProxy(object id, ISessionImplementor session)
424406

425407
public object[] GetPropertyValuesToInsert(object obj, IDictionary mergeMap, ISessionImplementor session)
426408
{
427-
return GetPropertyValues(obj, session.EntityMode);
409+
return GetPropertyValues(obj);
428410
}
429411

430412
public void ProcessInsertGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session)
@@ -435,109 +417,91 @@ public void ProcessUpdateGeneratedProperties(object id, object entity, object[]
435417
{
436418
}
437419

438-
public System.Type GetMappedClass(EntityMode entityMode)
420+
public System.Type MappedClass
439421
{
440-
CheckEntityMode(entityMode);
441-
return typeof(Custom);
422+
get { return typeof(Custom); }
442423
}
443424

444-
public bool ImplementsLifecycle(EntityMode entityMode)
425+
public bool ImplementsLifecycle
445426
{
446-
CheckEntityMode(entityMode);
447-
return false;
427+
get { return false; }
448428
}
449429

450-
public bool ImplementsValidatable(EntityMode entityMode)
430+
public bool ImplementsValidatable
451431
{
452-
CheckEntityMode(entityMode);
453-
return false;
432+
get { return false; }
454433
}
455434

456-
public System.Type GetConcreteProxyClass(EntityMode entityMode)
435+
public System.Type ConcreteProxyClass
457436
{
458-
CheckEntityMode(entityMode);
459-
return typeof (Custom);
437+
get { return typeof(Custom); }
460438
}
461439

462-
public void SetPropertyValues(object obj, object[] values, EntityMode entityMode)
440+
public void SetPropertyValues(object obj, object[] values)
463441
{
464-
CheckEntityMode(entityMode);
465-
SetPropertyValue(obj, 0, values[0], entityMode);
442+
SetPropertyValue(obj, 0, values[0]);
466443
}
467444

468-
public void SetPropertyValue(object obj, int i, object value, EntityMode entityMode)
445+
public void SetPropertyValue(object obj, int i, object value)
469446
{
470-
CheckEntityMode(entityMode);
471447
((Custom) obj).Name = (string) value;
472448
}
473449

474-
public object[] GetPropertyValues(object obj, EntityMode entityMode)
450+
public object[] GetPropertyValues(object obj)
475451
{
476-
CheckEntityMode(entityMode);
477452
Custom c = (Custom) obj;
478453
return new Object[] {c.Name};
479454
}
480455

481-
public object GetPropertyValue(object obj, int i, EntityMode entityMode)
456+
public object GetPropertyValue(object obj, int i)
482457
{
483-
CheckEntityMode(entityMode);
484458
return ((Custom)obj).Name;
485459
}
486460

487-
public object GetPropertyValue(object obj, string name, EntityMode entityMode)
461+
public object GetPropertyValue(object obj, string name)
488462
{
489-
CheckEntityMode(entityMode);
490463
return ((Custom)obj).Name;
491464
}
492465

493-
public object GetIdentifier(object obj, EntityMode entityMode)
466+
public object GetIdentifier(object obj)
494467
{
495-
CheckEntityMode(entityMode);
496468
return ((Custom)obj).Id;
497469
}
498470

499-
public void SetIdentifier(object obj, object id, EntityMode entityMode)
471+
public void SetIdentifier(object obj, object id)
500472
{
501-
CheckEntityMode(entityMode);
502473
((Custom) obj).Id = (string) id;
503474
}
504475

505-
public object GetVersion(object obj, EntityMode entityMode)
476+
public object GetVersion(object obj)
506477
{
507-
CheckEntityMode(entityMode);
508478
return null;
509479
}
510480

511-
public object Instantiate(object id, EntityMode entityMode)
481+
public object Instantiate(object id)
512482
{
513-
CheckEntityMode(entityMode);
514483
Custom c = new Custom();
515484
c.Id = (string)id;
516485
return c;
517486
}
518487

519-
public bool IsInstance(object entity, EntityMode entityMode)
488+
public bool IsInstance(object entity)
520489
{
521-
CheckEntityMode(entityMode);
522490
return entity is Custom;
523491
}
524492

525-
public bool HasUninitializedLazyProperties(object obj, EntityMode entityMode)
493+
public bool HasUninitializedLazyProperties(object obj)
526494
{
527-
CheckEntityMode(entityMode);
528495
return false;
529496
}
530497

531-
public void ResetIdentifier(object entity, object currentId, object currentVersion, EntityMode entityMode)
498+
public void ResetIdentifier(object entity, object currentId, object currentVersion)
532499
{
533-
CheckEntityMode(entityMode);
534500
((Custom)entity).Id = (string)currentId;
535501
}
536502

537-
public IEntityPersister GetSubclassEntityPersister(object instance, ISessionFactoryImplementor factory,
538-
EntityMode entityMode)
503+
public IEntityPersister GetSubclassEntityPersister(object instance, ISessionFactoryImplementor factory)
539504
{
540-
CheckEntityMode(entityMode);
541505
return this;
542506
}
543507

@@ -553,6 +517,8 @@ public IComparer VersionComparator
553517
get { return null; }
554518
}
555519

520+
public IEntityTuplizer EntityTuplizer => null;
521+
556522
#endregion
557523
}
558524
}

src/NHibernate.Test/CacheTest/CacheFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void TestSimpleCache()
1818

1919
private CacheKey CreateCacheKey(string text)
2020
{
21-
return new CacheKey(text, NHibernateUtil.String, "Foo", EntityMode.Poco, null);
21+
return new CacheKey(text, NHibernateUtil.String, "Foo", null);
2222
}
2323

2424
public void DoTestCache(ICacheProvider cacheProvider)

src/NHibernate.Test/CacheTest/FilterKeyFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public void ToStringIncludeAll()
2424
string filterName = "DescriptionLike";
2525
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
2626
f.SetParameter("pLike", "so%");
27-
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
27+
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
2828
Assert.That(fk.ToString(), Is.EqualTo("FilterKey[DescriptionLike{'pLike'='so%'}]"));
2929

3030
filterName = "DescriptionEqualAndValueGT";
3131
f = new FilterImpl(sessions.GetFilterDefinition(filterName));
3232
f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
33-
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
33+
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
3434
Assert.That(fk.ToString(), Is.EqualTo("FilterKey[DescriptionEqualAndValueGT{'pDesc'='something', 'pValue'='10'}]"));
3535
}
3636

@@ -51,23 +51,23 @@ private void FilterDescLikeToCompare(out FilterKey fk, out FilterKey fk1)
5151
const string filterName = "DescriptionLike";
5252
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
5353
f.SetParameter("pLike", "so%");
54-
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
54+
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
5555

5656
var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
5757
f1.SetParameter("pLike", "%ing");
58-
fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
58+
fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
5959
}
6060

6161
private void FilterDescValueToCompare(out FilterKey fk, out FilterKey fk1)
6262
{
6363
const string filterName = "DescriptionEqualAndValueGT";
6464
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
6565
f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
66-
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
66+
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
6767

6868
var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
6969
f1.SetParameter("pDesc", "something").SetParameter("pValue", 11);
70-
fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
70+
fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
7171
}
7272

7373
[Test]

src/NHibernate.Test/CacheTest/QueryKeyFixture.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ private void QueryKeyFilterDescLikeToCompare(out QueryKey qk, out QueryKey qk1)
4040
const string filterName = "DescriptionLike";
4141
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
4242
f.SetParameter("pLike", "so%");
43-
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
43+
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
4444
ISet<FilterKey> fks = new HashSet<FilterKey> { fk };
4545
qk = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
4646

4747
var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
4848
f1.SetParameter("pLike", "%ing");
49-
var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
49+
var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
5050
fks = new HashSet<FilterKey> { fk1 };
5151
qk1 = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
5252
}
@@ -57,13 +57,13 @@ private void QueryKeyFilterDescValueToCompare(out QueryKey qk, out QueryKey qk1)
5757

5858
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
5959
f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
60-
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
60+
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
6161
ISet<FilterKey> fks = new HashSet<FilterKey> { fk };
6262
qk = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
6363

6464
var f1 = new FilterImpl(sessions.GetFilterDefinition(filterName));
6565
f1.SetParameter("pDesc", "something").SetParameter("pValue", 11);
66-
var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
66+
var fk1 = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
6767
fks = new HashSet<FilterKey> { fk1 };
6868
qk1 = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
6969
}
@@ -111,15 +111,15 @@ public void ToStringWithFilters()
111111
string filterName = "DescriptionLike";
112112
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
113113
f.SetParameter("pLike", "so%");
114-
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
114+
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
115115
ISet<FilterKey> fks = new HashSet<FilterKey> { fk };
116116
var qk = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
117117
Assert.That(qk.ToString(), Does.Contain(string.Format("filters: ['{0}']",fk)));
118118

119119
filterName = "DescriptionEqualAndValueGT";
120120
f = new FilterImpl(sessions.GetFilterDefinition(filterName));
121121
f.SetParameter("pDesc", "something").SetParameter("pValue", 10);
122-
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
122+
fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
123123
fks = new HashSet<FilterKey> { fk };
124124
qk = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);
125125
Assert.That(qk.ToString(), Does.Contain(string.Format("filters: ['{0}']", fk)));
@@ -131,12 +131,12 @@ public void ToStringWithMoreFilters()
131131
string filterName = "DescriptionLike";
132132
var f = new FilterImpl(sessions.GetFilterDefinition(filterName));
133133
f.SetParameter("pLike", "so%");
134-
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
134+
var fk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
135135

136136
filterName = "DescriptionEqualAndValueGT";
137137
var fv = new FilterImpl(sessions.GetFilterDefinition(filterName));
138138
fv.SetParameter("pDesc", "something").SetParameter("pValue", 10);
139-
var fvk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes, EntityMode.Poco);
139+
var fvk = new FilterKey(filterName, f.Parameters, f.FilterDefinition.ParameterTypes);
140140

141141
ISet<FilterKey> fks = new HashSet<FilterKey> { fk, fvk };
142142
var qk = new QueryKey(sessions, SqlAll, new QueryParameters(), fks, null);

src/NHibernate.Test/Criteria/AddNumberProjection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AddNumberProjection(string propertyName, int numberToAdd)
1818
{
1919
this.propertyName = propertyName;
2020
this.numberToAdd = numberToAdd;
21-
typedValue = new TypedValue(NHibernateUtil.Int32, this.numberToAdd, EntityMode.Poco);
21+
typedValue = new TypedValue(NHibernateUtil.Int32, this.numberToAdd);
2222
}
2323

2424
public override bool IsAggregate

0 commit comments

Comments
 (0)