11using System . Collections . Generic ;
2- using System . Linq ;
32using NHibernate . Engine ;
43using NHibernate . Hql . Ast . ANTLR . Tree ;
4+ using NHibernate . Util ;
55
66namespace NHibernate . Hql . Ast . ANTLR
77{
88 public class AstPolymorphicProcessor
99 {
1010 private readonly IASTNode _ast ;
1111 private readonly ISessionFactoryImplementor _factory ;
12- private IEnumerable < KeyValuePair < IASTNode , IASTNode [ ] > > _nodeMapping ;
12+ private Dictionary < IASTNode , IASTNode [ ] > _nodeMapping ;
1313
1414 private AstPolymorphicProcessor ( IASTNode ast , ISessionFactoryImplementor factory )
1515 {
@@ -29,28 +29,27 @@ private IASTNode[] Process()
2929 // Find all the polymorphic query sources
3030 _nodeMapping = new PolymorphicQuerySourceDetector ( _factory ) . Process ( _ast ) ;
3131
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 )
3738 {
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" ) ;
3944 }
45+
46+ return parsers ;
4047 }
4148
42- private IEnumerable < IASTNode > DuplicateTree ( )
49+ private IASTNode [ ] DuplicateTree ( )
4350 {
4451 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 ) ) ;
5453 }
5554
5655 private static IASTNode DuplicateTree ( IASTNode ast , IDictionary < IASTNode , IASTNode > nodeMapping )
@@ -72,4 +71,4 @@ private static IASTNode DuplicateTree(IASTNode ast, IDictionary<IASTNode, IASTNo
7271 return dup ;
7372 }
7473 }
75- }
74+ }
0 commit comments