@@ -54,7 +54,7 @@ public class GeneralTestAsync : TestCase
5454
5555 protected override IList Mappings
5656 {
57- get { return new [ ] { "SqlTest.Query.NativeSQLQueries.hbm.xml" } ; }
57+ get { return new [ ] { "SqlTest.Query.NativeSQLQueries.hbm.xml" } ; }
5858 }
5959
6060 protected override string MappingsAssembly
@@ -103,17 +103,17 @@ public async Task SQLQueryInterfaceAsync()
103103 await ( s . SaveAsync ( emp ) ) ;
104104
105105 IList l = await ( s . CreateSQLQuery ( OrgEmpRegionSQL )
106- . AddEntity ( "org" , typeof ( Organization ) )
107- . AddJoin ( "emp" , "org.employments" )
108- . AddScalar ( "regionCode" , NHibernateUtil . String )
109- . ListAsync ( ) ) ;
106+ . AddEntity ( "org" , typeof ( Organization ) )
107+ . AddJoin ( "emp" , "org.employments" )
108+ . AddScalar ( "regionCode" , NHibernateUtil . String )
109+ . ListAsync ( ) ) ;
110110 Assert . AreEqual ( 2 , l . Count ) ;
111111
112112 l = await ( s . CreateSQLQuery ( OrgEmpPersonSQL )
113- . AddEntity ( "org" , typeof ( Organization ) )
114- . AddJoin ( "emp" , "org.employments" )
115- . AddJoin ( "pers" , "emp.employee" )
116- . ListAsync ( ) ) ;
113+ . AddEntity ( "org" , typeof ( Organization ) )
114+ . AddJoin ( "emp" , "org.employments" )
115+ . AddJoin ( "pers" , "emp.employee" )
116+ . ListAsync ( ) ) ;
117117 Assert . AreEqual ( l . Count , 1 ) ;
118118
119119 await ( t . CommitAsync ( ) ) ;
@@ -122,13 +122,14 @@ public async Task SQLQueryInterfaceAsync()
122122 s = OpenSession ( ) ;
123123 t = s . BeginTransaction ( ) ;
124124
125- l = await ( s . CreateSQLQuery ( "select {org.*}, {emp.*} " +
126- "from ORGANIZATION org " +
127- " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
128- . AddEntity ( "org" , typeof ( Organization ) )
129- . AddJoin ( "emp" , "org.employments" )
130- . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) )
131- . ListAsync ( ) ) ;
125+ l = await ( s . CreateSQLQuery (
126+ "select {org.*}, {emp.*} " +
127+ "from ORGANIZATION org " +
128+ " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
129+ . AddEntity ( "org" , typeof ( Organization ) )
130+ . AddJoin ( "emp" , "org.employments" )
131+ . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) )
132+ . ListAsync ( ) ) ;
132133 Assert . AreEqual ( l . Count , 2 ) ;
133134
134135 await ( t . CommitAsync ( ) ) ;
@@ -162,13 +163,13 @@ public async Task ResultSetMappingDefinitionAsync()
162163 await ( s . SaveAsync ( emp ) ) ;
163164
164165 IList l = await ( s . CreateSQLQuery ( OrgEmpRegionSQL )
165- . SetResultSetMapping ( "org-emp-regionCode" )
166- . ListAsync ( ) ) ;
166+ . SetResultSetMapping ( "org-emp-regionCode" )
167+ . ListAsync ( ) ) ;
167168 Assert . AreEqual ( l . Count , 2 ) ;
168169
169170 l = await ( s . CreateSQLQuery ( OrgEmpPersonSQL )
170- . SetResultSetMapping ( "org-emp-person" )
171- . ListAsync ( ) ) ;
171+ . SetResultSetMapping ( "org-emp-person" )
172+ . ListAsync ( ) ) ;
172173 Assert . AreEqual ( l . Count , 1 ) ;
173174
174175 await ( s . DeleteAsync ( emp ) ) ;
@@ -313,7 +314,7 @@ public async Task MappedAliasStrategyAsync()
313314 sqlQuery . SetResultTransformer ( CriteriaSpecification . AliasToEntityMap ) ;
314315 list = await ( sqlQuery . ListAsync ( ) ) ;
315316 Assert . AreEqual ( 2 , list . Count ) ;
316- m = ( IDictionary ) list [ 0 ] ;
317+ m = ( IDictionary ) list [ 0 ] ;
317318 Assert . IsTrue ( m . Contains ( "org" ) ) ;
318319 AssertClassAssignability ( m [ "org" ] . GetType ( ) , typeof ( Organization ) ) ;
319320 Assert . IsTrue ( m . Contains ( "emp" ) ) ;
@@ -381,28 +382,29 @@ public async Task CompositeIdJoinsFailureExpectedAsync()
381382
382383 s = OpenSession ( ) ;
383384 t = s . BeginTransaction ( ) ;
384- object [ ] o = ( object [ ] ) ( await ( s . CreateSQLQuery ( "select\r \n " +
385- " product.orgid as {product.id.orgid}," +
386- " product.productnumber as {product.id.productnumber}," +
387- " {prod_orders}.orgid as orgid3_1_,\r \n " +
388- " {prod_orders}.ordernumber as ordernum2_3_1_,\r \n " +
389- " product.name as {product.name}," +
390- " {prod_orders.element.*}," +
391- /*" orders.PROD_NO as PROD4_3_1_,\r\n" +
392- " orders.person as person3_1_,\r\n" +
393- " orders.PROD_ORGID as PROD3_0__,\r\n" +
394- " orders.PROD_NO as PROD4_0__,\r\n" +
395- " orders.orgid as orgid0__,\r\n" +
396- " orders.ordernumber as ordernum2_0__ \r\n" +*/
397- " from\r \n " +
398- " Product product \r \n " +
399- " inner join\r \n " +
400- " TBL_ORDER {prod_orders} \r \n " +
401- " on product.orgid={prod_orders}.PROD_ORGID \r \n " +
402- " and product.productnumber={prod_orders}.PROD_NO" )
403- . AddEntity ( "product" , typeof ( Product ) )
404- . AddJoin ( "prod_orders" , "product.orders" )
405- . ListAsync ( ) ) ) [ 0 ] ;
385+ object [ ] o = ( object [ ] ) ( await ( s . CreateSQLQuery (
386+ "select\r \n " +
387+ " product.orgid as {product.id.orgid}," +
388+ " product.productnumber as {product.id.productnumber}," +
389+ " {prod_orders}.orgid as orgid3_1_,\r \n " +
390+ " {prod_orders}.ordernumber as ordernum2_3_1_,\r \n " +
391+ " product.name as {product.name}," +
392+ " {prod_orders.element.*}," +
393+ /*" orders.PROD_NO as PROD4_3_1_,\r\n" +
394+ " orders.person as person3_1_,\r\n" +
395+ " orders.PROD_ORGID as PROD3_0__,\r\n" +
396+ " orders.PROD_NO as PROD4_0__,\r\n" +
397+ " orders.orgid as orgid0__,\r\n" +
398+ " orders.ordernumber as ordernum2_0__ \r\n" +*/
399+ " from\r \n " +
400+ " Product product \r \n " +
401+ " inner join\r \n " +
402+ " TBL_ORDER {prod_orders} \r \n " +
403+ " on product.orgid={prod_orders}.PROD_ORGID \r \n " +
404+ " and product.productnumber={prod_orders}.PROD_NO" )
405+ . AddEntity ( "product" , typeof ( Product ) )
406+ . AddJoin ( "prod_orders" , "product.orders" )
407+ . ListAsync ( ) ) ) [ 0 ] ;
406408
407409 p = ( Product ) o [ 0 ] ;
408410 Assert . IsTrue ( NHibernateUtil . IsInitialized ( p . Orders ) ) ;
@@ -432,8 +434,8 @@ public async Task AutoDetectAliasingAsync()
432434 s = OpenSession ( ) ;
433435 t = s . BeginTransaction ( ) ;
434436 IList list = await ( s . CreateSQLQuery ( EmploymentSQL )
435- . AddEntity ( typeof ( Employment ) . FullName )
436- . ListAsync ( ) ) ;
437+ . AddEntity ( typeof ( Employment ) . FullName )
438+ . ListAsync ( ) ) ;
437439 Assert . AreEqual ( 1 , list . Count ) ;
438440
439441 Employment emp2 = ( Employment ) list [ 0 ] ;
@@ -444,9 +446,9 @@ public async Task AutoDetectAliasingAsync()
444446 s . Clear ( ) ;
445447
446448 list = await ( s . CreateSQLQuery ( EmploymentSQL )
447- . AddEntity ( typeof ( Employment ) . FullName )
448- . SetResultTransformer ( CriteriaSpecification . AliasToEntityMap )
449- . ListAsync ( ) ) ;
449+ . AddEntity ( typeof ( Employment ) . FullName )
450+ . SetResultTransformer ( CriteriaSpecification . AliasToEntityMap )
451+ . ListAsync ( ) ) ;
450452 Assert . AreEqual ( 1 , list . Count ) ;
451453 IDictionary m = ( IDictionary ) list [ 0 ] ;
452454 Assert . IsTrue ( m . Contains ( "Employment" ) ) ;
@@ -485,17 +487,17 @@ public async Task AutoDetectAliasingAsync()
485487 s . Clear ( ) ;
486488
487489 list = await ( s . CreateSQLQuery ( OrganizationJoinEmploymentSQL )
488- . AddEntity ( "org" , typeof ( Organization ) )
489- . AddJoin ( "emp" , "org.employments" )
490- . ListAsync ( ) ) ;
490+ . AddEntity ( "org" , typeof ( Organization ) )
491+ . AddJoin ( "emp" , "org.employments" )
492+ . ListAsync ( ) ) ;
491493 Assert . AreEqual ( 2 , list . Count ) ;
492494
493495 s . Clear ( ) ;
494496
495497 list = await ( s . CreateSQLQuery ( OrganizationFetchJoinEmploymentSQL )
496- . AddEntity ( "org" , typeof ( Organization ) )
497- . AddJoin ( "emp" , "org.employments" )
498- . ListAsync ( ) ) ;
498+ . AddEntity ( "org" , typeof ( Organization ) )
499+ . AddJoin ( "emp" , "org.employments" )
500+ . ListAsync ( ) ) ;
499501 Assert . AreEqual ( 2 , list . Count ) ;
500502
501503 s . Clear ( ) ;
@@ -569,8 +571,8 @@ public async Task MixAndMatchEntityScalarAsync()
569571 s . Clear ( ) ;
570572
571573 IList l = await ( s . CreateSQLQuery ( "select name, id, flength, name as scalarName from Speech" )
572- . SetResultSetMapping ( "speech" )
573- . ListAsync ( ) ) ;
574+ . SetResultSetMapping ( "speech" )
575+ . ListAsync ( ) ) ;
574576 Assert . AreEqual ( l . Count , 1 ) ;
575577
576578 await ( t . RollbackAsync ( ) ) ;
@@ -583,9 +585,9 @@ public async Task ParameterListAsync()
583585 using ( ISession s = OpenSession ( ) )
584586 {
585587 IList l = await ( s . CreateSQLQuery ( "select id from Speech where id in (:idList)" )
586- . AddScalar ( "id" , NHibernateUtil . Int32 )
587- . SetParameterList ( "idList" , new int [ ] { 0 , 1 , 2 , 3 } , NHibernateUtil . Int32 )
588- . ListAsync ( ) ) ;
588+ . AddScalar ( "id" , NHibernateUtil . Int32 )
589+ . SetParameterList ( "idList" , new int [ ] { 0 , 1 , 2 , 3 } , NHibernateUtil . Int32 )
590+ . ListAsync ( ) ) ;
589591 }
590592 }
591593
@@ -607,23 +609,26 @@ private double ExtractDoubleValue(object value)
607609
608610 public static void AssertClassAssignability ( System . Type source , System . Type target )
609611 {
610- Assert . IsTrue ( target . IsAssignableFrom ( source ) ,
611- "Classes were not assignment-compatible : source<" +
612- source . FullName +
613- "> target<" +
614- target . FullName + ">"
615- ) ;
612+ Assert . IsTrue (
613+ target . IsAssignableFrom ( source ) ,
614+ "Classes were not assignment-compatible : source<" +
615+ source . FullName +
616+ "> target<" +
617+ target . FullName + ">"
618+ ) ;
616619 }
617620
618621 class TestResultSetTransformer : IResultTransformer
619622 {
620623 public bool TransformTupleCalled { get ; set ; }
621624 public bool TransformListCalled { get ; set ; }
625+
622626 public object TransformTuple ( object [ ] tuple , string [ ] aliases )
623627 {
624628 this . TransformTupleCalled = true ;
625629 return tuple ;
626630 }
631+
627632 public IList TransformList ( IList collection )
628633 {
629634 this . TransformListCalled = true ;
@@ -716,5 +721,33 @@ public async Task CanExecuteFutureValueAsync()
716721 Assert . AreEqual ( "Ricardo" , v ) ;
717722 }
718723 }
724+
725+ [ Test ]
726+ public async Task HandlesManualSynchronizationAsync ( )
727+ {
728+ using ( var s = OpenSession ( ) )
729+ using ( s . BeginTransaction ( ) )
730+ {
731+ s . SessionFactory . Statistics . IsStatisticsEnabled = true ;
732+ s . SessionFactory . Statistics . Clear ( ) ;
733+
734+ // create an Organization...
735+ Organization jboss = new Organization ( "JBoss" ) ;
736+ await ( s . PersistAsync ( jboss ) ) ;
737+
738+ // now query on Employment, this should not cause an auto-flush
739+ await ( s . CreateSQLQuery ( EmploymentSQL ) . AddSynchronizedQuerySpace ( "ABC" ) . ListAsync ( ) ) ;
740+ Assert . AreEqual ( 0 , s . SessionFactory . Statistics . EntityInsertCount ) ;
741+
742+ // now try to query on Employment but this time add Organization as a synchronized query space...
743+ await ( s . CreateSQLQuery ( EmploymentSQL ) . AddSynchronizedEntityClass ( typeof ( Organization ) ) . ListAsync ( ) ) ;
744+ Assert . AreEqual ( 1 , s . SessionFactory . Statistics . EntityInsertCount ) ;
745+
746+ // clean up
747+ await ( s . DeleteAsync ( jboss ) ) ;
748+ await ( s . Transaction . CommitAsync ( ) ) ;
749+ s . Close ( ) ;
750+ }
751+ }
719752 }
720753}
0 commit comments