Skip to content

Commit 4013419

Browse files
committed
NH-3722 - Remove EntityMode.Xml related properties from ICollectionPersister
* Ported HHH-7736 from hibernate/hibernate-orm@1a5bdd9
1 parent 32ed5e0 commit 4013419

File tree

9 files changed

+28
-104
lines changed

9 files changed

+28
-104
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

src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public void BuildingSessionFactoryShouldNotThrows()
4646

4747
public class MyCollectionPersister: OneToManyPersister
4848
{
49-
public MyCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg, ISessionFactoryImplementor factory) : base(collection, cache, cfg, factory) {}
49+
public MyCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) : base(collection, cache, factory) {}
5050
}
5151
}

src/NHibernate.Test/NHSpecificTest/SetFixture.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,6 @@ public bool IsMutable
378378
get { throw new NotImplementedException(); }
379379
}
380380

381-
public string NodeName
382-
{
383-
get { throw new NotImplementedException(); }
384-
}
385-
386-
public string ElementNodeName
387-
{
388-
get { throw new NotImplementedException(); }
389-
}
390-
391-
public string IndexNodeName
392-
{
393-
get { throw new NotImplementedException(); }
394-
}
395-
396381
#endregion
397382
}
398383

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
276276
{
277277
allCacheRegions[cache.RegionName] = cache.Cache;
278278
}
279-
ICollectionPersister persister = PersisterFactory.CreateCollectionPersister(cfg, model, cache, this);
279+
ICollectionPersister persister = PersisterFactory.CreateCollectionPersister(model, cache, this);
280280
collectionPersisters[model.Role] = persister;
281281
IType indexType = persister.IndexType;
282282
if (indexType != null && indexType.IsAssociationType && !indexType.IsAnyType)

src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using NHibernate.AdoNet;
99
using NHibernate.Cache;
1010
using NHibernate.Cache.Entry;
11-
using NHibernate.Cfg;
1211
using NHibernate.Collection;
1312
using NHibernate.Engine;
1413
using NHibernate.Exceptions;
@@ -52,9 +51,6 @@ public abstract class AbstractCollectionPersister : ICollectionMetadata, ISqlLoa
5251
private readonly bool hasOrder;
5352
private readonly bool hasWhere;
5453
private readonly int baseIndex;
55-
private readonly string nodeName;
56-
private readonly string elementNodeName;
57-
private readonly string indexNodeName;
5854

5955
protected internal bool indexContainsFormula;
6056
protected internal bool elementIsPureFormula;
@@ -165,8 +161,7 @@ public abstract class AbstractCollectionPersister : ICollectionMetadata, ISqlLoa
165161

166162
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof (ICollectionPersister));
167163

168-
public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg,
169-
ISessionFactoryImplementor factory)
164+
public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
170165
{
171166
this.factory = factory;
172167
this.cache = cache;
@@ -188,7 +183,6 @@ public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurre
188183
entityName = collection.OwnerEntityName;
189184
ownerPersister = factory.GetEntityPersister(entityName);
190185
queryLoaderName = collection.LoaderName;
191-
nodeName = collection.NodeName;
192186
isMutable = collection.IsMutable;
193187

194188
Table table = collection.CollectionTable;
@@ -277,22 +271,16 @@ public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurre
277271
CheckColumnDuplication(distinctColumns, element.ColumnIterator);
278272
}
279273

280-
string elemNode = collection.ElementNodeName;
281274
if (elementType.IsEntityType)
282275
{
283276
string _entityName = ((EntityType) elementType).GetAssociatedEntityName();
284277
elementPersister = factory.GetEntityPersister(_entityName);
285-
if (elemNode == null)
286-
{
287-
elemNode = cfg.GetClassMapping(_entityName).NodeName;
288-
}
289278
// NativeSQL: collect element column and auto-aliases
290279
}
291280
else
292281
{
293282
elementPersister = null;
294283
}
295-
elementNodeName = elemNode;
296284

297285
int elementSpan = element.ColumnSpan;
298286
elementColumnAliases = new string[elementSpan];
@@ -377,7 +365,6 @@ public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurre
377365
indexContainsFormula = hasFormula;
378366
baseIndex = indexedCollection.IsList ? ((List) indexedCollection).BaseIndex : 0;
379367

380-
indexNodeName = indexedCollection.IndexNodeName;
381368
CheckColumnDuplication(distinctColumns, indexedCollection.Index.ColumnIterator);
382369
}
383370
else
@@ -390,7 +377,6 @@ public AbstractCollectionPersister(Mapping.Collection collection, ICacheConcurre
390377
indexColumnNames = null;
391378
indexColumnAliases = null;
392379
baseIndex = 0;
393-
indexNodeName = null;
394380
}
395381

396382
hasIdentifier = collection.IsIdentified;
@@ -1937,21 +1923,6 @@ public bool IsVersioned
19371923
get { return isVersioned && OwnerEntityPersister.IsVersioned; }
19381924
}
19391925

1940-
public string NodeName
1941-
{
1942-
get { return nodeName; }
1943-
}
1944-
1945-
public string ElementNodeName
1946-
{
1947-
get { return elementNodeName; }
1948-
}
1949-
1950-
public string IndexNodeName
1951-
{
1952-
get { return indexNodeName; }
1953-
}
1954-
19551926
protected virtual ISQLExceptionConverter SQLExceptionConverter
19561927
{
19571928
get { return sqlExceptionConverter; }

src/NHibernate/Persister/Collection/BasicCollectionPersister.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Data.Common;
44
using NHibernate.AdoNet;
55
using NHibernate.Cache;
6-
using NHibernate.Cfg;
76
using NHibernate.Collection;
87
using NHibernate.Engine;
98
using NHibernate.Exceptions;
@@ -23,8 +22,8 @@ namespace NHibernate.Persister.Collection
2322
/// </summary>
2423
public class BasicCollectionPersister : AbstractCollectionPersister
2524
{
26-
public BasicCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg, ISessionFactoryImplementor factory)
27-
: base(collection, cache, cfg, factory) { }
25+
public BasicCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
26+
: base(collection, cache, factory) { }
2827

2928
public override bool CascadeDeleteEnabled
3029
{

src/NHibernate/Persister/Collection/ICollectionPersister.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ public interface ICollectionPersister
130130
/// <summary> Can the elements of this collection change?</summary>
131131
bool IsMutable { get;}
132132

133-
string NodeName { get;}
134-
135-
string ElementNodeName { get;}
136-
137-
string IndexNodeName { get;}
138-
139133
ISessionFactoryImplementor Factory { get; }
140134
bool IsExtraLazy { get;}
141135

src/NHibernate/Persister/Collection/OneToManyPersister.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Text;
66
using NHibernate.AdoNet;
77
using NHibernate.Cache;
8-
using NHibernate.Cfg;
98
using NHibernate.Collection;
109
using NHibernate.Engine;
1110
using NHibernate.Exceptions;
@@ -24,8 +23,8 @@ public class OneToManyPersister : AbstractCollectionPersister
2423
private readonly bool _keyIsNullable;
2524
private readonly bool _keyIsUpdateable;
2625

27-
public OneToManyPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg, ISessionFactoryImplementor factory)
28-
: base(collection, cache, cfg, factory)
26+
public OneToManyPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
27+
: base(collection, cache, factory)
2928
{
3029
_cascadeDeleteEnabled = collection.Key.IsCascadeDeleteEnabled && factory.Dialect.SupportsCascadeDelete;
3130
_keyIsNullable = collection.Key.IsNullable;

src/NHibernate/Persister/PersisterFactory.cs

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Reflection;
33
using System.Text;
44
using NHibernate.Cache;
5-
using NHibernate.Cfg;
65
using NHibernate.Engine;
76
using NHibernate.Mapping;
87
using NHibernate.Persister.Collection;
@@ -18,30 +17,19 @@ public static class PersisterFactory
1817
//TODO: make ClassPersisters *not* depend on ISessionFactoryImplementor
1918
// interface, if possible
2019

21-
private static readonly System.Type[] PersisterConstructorArgs = new System.Type[]
22-
{
23-
typeof(PersistentClass),
24-
typeof(ICacheConcurrencyStrategy),
25-
typeof(ISessionFactoryImplementor),
26-
typeof(IMapping)
27-
};
28-
29-
// TODO: is it really necessary to provide Configuration to CollectionPersisters ? Should it not be enough with associated class ?
30-
// or why does ClassPersister's not get access to configuration ?
31-
private static readonly System.Type[] CollectionPersisterConstructorArgs = new System.Type[]
32-
{
33-
typeof(Mapping.Collection),
34-
typeof(ICacheConcurrencyStrategy),
35-
typeof(ISessionFactoryImplementor)
36-
};
20+
static readonly System.Type[] PersisterConstructorArgs = {
21+
typeof(PersistentClass),
22+
typeof(ICacheConcurrencyStrategy),
23+
typeof(ISessionFactoryImplementor),
24+
typeof(IMapping)
25+
};
3726

38-
private static readonly System.Type[] CollectionPersisterConstructor2Args = new System.Type[]
39-
{
40-
typeof(Mapping.Collection),
41-
typeof(ICacheConcurrencyStrategy),
42-
typeof(Configuration),
43-
typeof(ISessionFactoryImplementor)
44-
};
27+
static readonly System.Type[] CollectionPersisterConstructorArgs =
28+
{
29+
typeof(Mapping.Collection),
30+
typeof(ICacheConcurrencyStrategy),
31+
typeof(ISessionFactoryImplementor)
32+
};
4533

4634
/// <summary>
4735
/// Creates a built in Entity Persister or a custom Persister.
@@ -69,7 +57,7 @@ public static IEntityPersister CreateClassPersister(PersistentClass model, ICach
6957
}
7058
}
7159

72-
public static ICollectionPersister CreateCollectionPersister(Configuration cfg, Mapping.Collection model, ICacheConcurrencyStrategy cache,
60+
public static ICollectionPersister CreateCollectionPersister(Mapping.Collection model, ICacheConcurrencyStrategy cache,
7361
ISessionFactoryImplementor factory)
7462
{
7563
System.Type persisterClass = model.CollectionPersisterClass;
@@ -78,12 +66,12 @@ public static ICollectionPersister CreateCollectionPersister(Configuration cfg,
7866
// default behaviour
7967
return
8068
model.IsOneToMany
81-
? (ICollectionPersister) new OneToManyPersister(model, cache, cfg, factory)
82-
: (ICollectionPersister) new BasicCollectionPersister(model, cache, cfg, factory);
69+
? (ICollectionPersister) new OneToManyPersister(model, cache, factory)
70+
: (ICollectionPersister) new BasicCollectionPersister(model, cache, factory);
8371
}
8472
else
8573
{
86-
return Create(persisterClass, model, cache, factory, cfg);
74+
return Create(persisterClass, model, cache, factory);
8775
}
8876
}
8977

@@ -127,18 +115,12 @@ public static IEntityPersister Create(System.Type persisterClass, PersistentClas
127115
}
128116

129117
public static ICollectionPersister Create(System.Type persisterClass, Mapping.Collection model,
130-
ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, Configuration cfg)
118+
ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
131119
{
132120
ConstructorInfo pc;
133-
var use4Parameters = false;
134121
try
135122
{
136123
pc = persisterClass.GetConstructor(CollectionPersisterConstructorArgs);
137-
if (pc == null)
138-
{
139-
use4Parameters = true;
140-
pc = persisterClass.GetConstructor(CollectionPersisterConstructor2Args);
141-
}
142124
}
143125
catch (Exception e)
144126
{
@@ -147,21 +129,14 @@ public static ICollectionPersister Create(System.Type persisterClass, Mapping.Co
147129
if(pc == null)
148130
{
149131
var messageBuilder = new StringBuilder();
150-
messageBuilder.AppendLine("Could not find a public constructor for " + persisterClass.Name +";");
151-
messageBuilder.AppendLine("- The ctor may have " + CollectionPersisterConstructorArgs.Length + " parameters of types (in order):");
132+
messageBuilder.Append("Could not find a public constructor for ").Append(persisterClass.Name).AppendLine(";");
133+
messageBuilder.Append("- The ctor may have ").Append(CollectionPersisterConstructorArgs.Length).AppendLine(" parameters of types (in order):");
152134
System.Array.ForEach(CollectionPersisterConstructorArgs, t=> messageBuilder.AppendLine(t.FullName));
153-
messageBuilder.AppendLine();
154-
messageBuilder.AppendLine("- The ctor may have " + CollectionPersisterConstructor2Args.Length + " parameters of types (in order):");
155-
System.Array.ForEach(CollectionPersisterConstructor2Args, t => messageBuilder.AppendLine(t.FullName));
156135
throw new MappingException(messageBuilder.ToString());
157136
}
158137
try
159138
{
160-
if (!use4Parameters)
161-
{
162-
return (ICollectionPersister) pc.Invoke(new object[] {model, cache, factory});
163-
}
164-
return (ICollectionPersister)pc.Invoke(new object[] { model, cache, cfg, factory });
139+
return (ICollectionPersister) pc.Invoke(new object[] {model, cache, factory});
165140
}
166141
catch (TargetInvocationException tie)
167142
{

0 commit comments

Comments
 (0)