1
1
using System . Collections . Generic ;
2
- using System . Linq ;
3
2
using NHibernate . Engine ;
4
3
using NHibernate . Hql . Ast . ANTLR . Tree ;
4
+ using NHibernate . Util ;
5
5
6
6
namespace NHibernate . Hql . Ast . ANTLR
7
7
{
8
8
public class AstPolymorphicProcessor
9
9
{
10
10
private readonly IASTNode _ast ;
11
11
private readonly ISessionFactoryImplementor _factory ;
12
- private IEnumerable < KeyValuePair < IASTNode , IASTNode [ ] > > _nodeMapping ;
12
+ private Dictionary < IASTNode , IASTNode [ ] > _nodeMapping ;
13
13
14
14
private AstPolymorphicProcessor ( IASTNode ast , ISessionFactoryImplementor factory )
15
15
{
@@ -29,28 +29,27 @@ private IASTNode[] Process()
29
29
// Find all the polymorphic query sources
30
30
_nodeMapping = new PolymorphicQuerySourceDetector ( _factory ) . Process ( _ast ) ;
31
31
32
- if ( _nodeMapping . Count ( ) > 0 )
33
- {
34
- return DuplicateTree ( ) . ToArray ( ) ;
35
- }
36
- else
32
+ if ( _nodeMapping . Count == 0 )
33
+ return new [ ] { _ast } ;
34
+
35
+ var parsers = DuplicateTree ( ) ;
36
+
37
+ if ( parsers . Length == 0 )
37
38
{
38
- return new [ ] { _ast } ;
39
+ var entityNames = _nodeMapping . Keys . ToArray ( x => PolymorphicQuerySourceDetector . GetClassName ( x ) ) ;
40
+ throw new QuerySyntaxException (
41
+ entityNames . Length == 1
42
+ ? entityNames [ 0 ] + " is not mapped"
43
+ : string . Join ( ", " , entityNames ) + " are not mapped" ) ;
39
44
}
45
+
46
+ return parsers ;
40
47
}
41
48
42
- private IEnumerable < IASTNode > DuplicateTree ( )
49
+ private IASTNode [ ] DuplicateTree ( )
43
50
{
44
51
var replacements = CrossJoinDictionaryArrays . PerformCrossJoin ( _nodeMapping ) ;
45
-
46
- var dups = new IASTNode [ replacements . Count ( ) ] ;
47
-
48
- for ( var i = 0 ; i < replacements . Count ( ) ; i ++ )
49
- {
50
- dups [ i ] = DuplicateTree ( _ast , replacements [ i ] ) ;
51
- }
52
-
53
- return dups ;
52
+ return replacements . ToArray ( x => DuplicateTree ( _ast , x ) ) ;
54
53
}
55
54
56
55
private static IASTNode DuplicateTree ( IASTNode ast , IDictionary < IASTNode , IASTNode > nodeMapping )
@@ -72,4 +71,4 @@ private static IASTNode DuplicateTree(IASTNode ast, IDictionary<IASTNode, IASTNo
72
71
return dup ;
73
72
}
74
73
}
75
- }
74
+ }
0 commit comments