@@ -343,6 +343,103 @@ protected internal override void AutoDiscoverTypes(IDataReader rs)
343343 transformerAliases = aliases . ToArray ( ) ;
344344 }
345345
346+ public override ISqlCommand CreateSqlCommand ( QueryParameters queryParameters , ISessionImplementor session )
347+ {
348+ // FIX TO NH3079:
349+ if ( queryParameters . NamedParameters . Count == 0 && queryParameters . PositionalParameterTypes . Length > 0 )
350+ {
351+ IType [ ] flattenedPositionalParameterTypes =
352+ this . FlattenComponentParameterTypes (
353+ queryParameters . PositionalParameterTypes ,
354+ session ) ;
355+ object [ ] flattenedPositionalParameterValues =
356+ this . FlattenComponentParameterValues (
357+ queryParameters . PositionalParameterTypes ,
358+ queryParameters . PositionalParameterValues ,
359+ session ) ;
360+ queryParameters . PositionalParameterTypes = flattenedPositionalParameterTypes ;
361+ queryParameters . PositionalParameterValues = flattenedPositionalParameterValues ;
362+ }
363+ return base . CreateSqlCommand ( queryParameters , session ) ;
364+ }
365+
366+ // FIX TO NH3079:
367+ protected internal virtual IType [ ] FlattenComponentParameterTypes ( IType [ ] positionalParameterTypes , ISessionImplementor session )
368+ {
369+ List < IType > typesResult = new List < IType > ( ) ;
370+ for ( int i = 0 ; i < positionalParameterTypes . Length ; i ++ )
371+ {
372+ IType typeItem = positionalParameterTypes [ i ] ;
373+
374+ int loopCount = 0 ;
375+ while ( typeItem . IsEntityType )
376+ {
377+ EntityType entityTypeItem = ( EntityType ) typeItem ;
378+ typeItem = entityTypeItem . GetIdentifierType ( session ) ;
379+
380+ if ( loopCount ++ > 200 )
381+ {
382+ throw new HibernateException ( "unexpected situation here 'loopCount': " + loopCount ) ;
383+ }
384+ }
385+
386+ if ( typeItem . IsComponentType )
387+ {
388+ IAbstractComponentType componentTypeItem = ( IAbstractComponentType ) typeItem ;
389+ IType [ ] subcalues =
390+ this . FlattenComponentParameterTypes (
391+ componentTypeItem . Subtypes ,
392+ session ) ;
393+ typesResult . AddRange ( subcalues ) ;
394+ }
395+ else
396+ {
397+ typesResult . Add ( typeItem ) ;
398+ }
399+ }
400+
401+ return typesResult . ToArray ( ) ;
402+ }
403+
404+ // FIX TO NH3079:
405+ protected internal virtual object [ ] FlattenComponentParameterValues ( IType [ ] positionalParameterTypes , object [ ] positionalParameterValues , ISessionImplementor session )
406+ {
407+ List < Object > valuesResult = new List < Object > ( ) ;
408+ for ( int i = 0 ; i < positionalParameterTypes . Length ; i ++ )
409+ {
410+ IType typeItem = positionalParameterTypes [ i ] ;
411+ object valueItem = positionalParameterValues [ i ] ;
412+
413+ int loopCount = 0 ;
414+ while ( typeItem . IsEntityType )
415+ {
416+ EntityType entityTypeItem = ( EntityType ) typeItem ;
417+ typeItem = entityTypeItem . GetIdentifierType ( session ) ;
418+ valueItem = entityTypeItem . GetIdentifier ( valueItem , session ) ;
419+ if ( loopCount ++ > 200 )
420+ {
421+ throw new HibernateException ( "unexpected situation here 'loopCount': " + loopCount ) ;
422+ }
423+ }
424+
425+ if ( typeItem . IsComponentType )
426+ {
427+ IAbstractComponentType componentTypeItem = ( IAbstractComponentType ) typeItem ;
428+ object [ ] subValues =
429+ this . FlattenComponentParameterValues (
430+ componentTypeItem . Subtypes ,
431+ componentTypeItem . GetPropertyValues ( valueItem , session ) ,
432+ session ) ;
433+ valuesResult . AddRange ( subValues ) ;
434+ }
435+ else
436+ {
437+ valuesResult . Add ( valueItem ) ;
438+ }
439+ }
440+
441+ return valuesResult . ToArray ( ) ;
442+ }
346443 protected override void ResetEffectiveExpectedType ( IEnumerable < IParameterSpecification > parameterSpecs , QueryParameters queryParameters )
347444 {
348445 parameterSpecs . ResetEffectiveExpectedType ( queryParameters ) ;
0 commit comments