2
2
using System . Reflection ;
3
3
using System . Text ;
4
4
using NHibernate . Cache ;
5
- using NHibernate . Cfg ;
6
5
using NHibernate . Engine ;
7
6
using NHibernate . Mapping ;
8
7
using NHibernate . Persister . Collection ;
@@ -18,30 +17,19 @@ public static class PersisterFactory
18
17
//TODO: make ClassPersisters *not* depend on ISessionFactoryImplementor
19
18
// interface, if possible
20
19
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
+ } ;
37
26
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
+ } ;
45
33
46
34
/// <summary>
47
35
/// Creates a built in Entity Persister or a custom Persister.
@@ -69,7 +57,7 @@ public static IEntityPersister CreateClassPersister(PersistentClass model, ICach
69
57
}
70
58
}
71
59
72
- public static ICollectionPersister CreateCollectionPersister ( Configuration cfg , Mapping . Collection model , ICacheConcurrencyStrategy cache ,
60
+ public static ICollectionPersister CreateCollectionPersister ( Mapping . Collection model , ICacheConcurrencyStrategy cache ,
73
61
ISessionFactoryImplementor factory )
74
62
{
75
63
System . Type persisterClass = model . CollectionPersisterClass ;
@@ -78,12 +66,12 @@ public static ICollectionPersister CreateCollectionPersister(Configuration cfg,
78
66
// default behaviour
79
67
return
80
68
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 ) ;
83
71
}
84
72
else
85
73
{
86
- return Create ( persisterClass , model , cache , factory , cfg ) ;
74
+ return Create ( persisterClass , model , cache , factory ) ;
87
75
}
88
76
}
89
77
@@ -127,18 +115,12 @@ public static IEntityPersister Create(System.Type persisterClass, PersistentClas
127
115
}
128
116
129
117
public static ICollectionPersister Create ( System . Type persisterClass , Mapping . Collection model ,
130
- ICacheConcurrencyStrategy cache , ISessionFactoryImplementor factory , Configuration cfg )
118
+ ICacheConcurrencyStrategy cache , ISessionFactoryImplementor factory )
131
119
{
132
120
ConstructorInfo pc ;
133
- var use4Parameters = false ;
134
121
try
135
122
{
136
123
pc = persisterClass . GetConstructor ( CollectionPersisterConstructorArgs ) ;
137
- if ( pc == null )
138
- {
139
- use4Parameters = true ;
140
- pc = persisterClass . GetConstructor ( CollectionPersisterConstructor2Args ) ;
141
- }
142
124
}
143
125
catch ( Exception e )
144
126
{
@@ -147,21 +129,14 @@ public static ICollectionPersister Create(System.Type persisterClass, Mapping.Co
147
129
if ( pc == null )
148
130
{
149
131
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):" ) ;
152
134
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 ) ) ;
156
135
throw new MappingException ( messageBuilder . ToString ( ) ) ;
157
136
}
158
137
try
159
138
{
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 } ) ;
165
140
}
166
141
catch ( TargetInvocationException tie )
167
142
{
0 commit comments