13
13
14
14
namespace NHibernate . Test . FilterTest
15
15
{
16
- [ TestFixture , Ignore ( "Filters not yet implemented" ) ]
16
+ [ TestFixture ]
17
17
public class DynamicFilterTest : TestCase
18
18
{
19
19
private ILog log = LogManager . GetLogger ( typeof ( DynamicFilterTest ) ) ;
@@ -32,7 +32,9 @@ public void SecondLevelCachedCollectionsFiltering()
32
32
ICollectionPersister persister = ( ( ISessionFactoryImplementor ) sessions )
33
33
. GetCollectionPersister ( typeof ( Salesperson ) . FullName + ".Orders" ) ;
34
34
Assert . IsTrue ( persister . HasCache , "No cache for collection" ) ;
35
- object [ ] cachedData = ( object [ ] ) persister . Cache . Cache . Get ( testData . steveId ) ;
35
+ CacheKey cacheKey =
36
+ new CacheKey ( testData . steveId , persister . KeyType , persister . Role , ( ISessionFactoryImplementor ) sessions ) ;
37
+ object [ ] cachedData = ( object [ ] ) persister . Cache . Cache . Get ( cacheKey ) ;
36
38
Assert . IsNotNull ( cachedData , "collection was not in cache" ) ;
37
39
38
40
session . Close ( ) ;
@@ -44,7 +46,7 @@ public void SecondLevelCachedCollectionsFiltering()
44
46
. UniqueResult ( ) ;
45
47
Assert . AreEqual ( 1 , sp . Orders . Count , "Filtered-collection not bypassing 2L-cache" ) ;
46
48
47
- object [ ] cachedData2 = ( object [ ] ) persister . Cache . Cache . Get ( testData . steveId ) ;
49
+ object [ ] cachedData2 = ( object [ ] ) persister . Cache . Cache . Get ( cacheKey ) ;
48
50
Assert . IsNotNull ( cachedData2 , "collection no longer in cache!" ) ;
49
51
Assert . AreSame ( cachedData , cachedData2 , "Different cache values!" ) ;
50
52
@@ -85,7 +87,7 @@ public void CombinedClassAndCollectionFiltersEnabled()
85
87
session . Clear ( ) ;
86
88
87
89
// test retreival through hql with the collection join fetched
88
- salespersons = session . CreateQuery ( "select s from Salesperson as s left join fetch s.orders " ) . List ( ) ;
90
+ salespersons = session . CreateQuery ( "select s from Salesperson as s left join fetch s.Orders " ) . List ( ) ;
89
91
Assert . AreEqual ( 1 , salespersons . Count , "Incorrect salesperson count" ) ;
90
92
sp = ( Salesperson ) salespersons [ 0 ] ;
91
93
Assert . AreEqual ( sp . Orders . Count , 1 , "Incorrect order count" ) ;
@@ -152,15 +154,16 @@ public void CriteriaQueryFilters()
152
154
153
155
log . Info ( "Criteria query against Product..." ) ;
154
156
IList products = session . CreateCriteria ( typeof ( Product ) )
155
- . Add ( Expression . Expression . Eq ( "stockNumber " , 124 ) )
157
+ . Add ( Expression . Expression . Eq ( "StockNumber " , 124 ) )
156
158
. List ( ) ;
157
159
Assert . AreEqual ( 1 , products . Count , "Incorrect product count" ) ;
158
160
159
161
session . Close ( ) ;
160
162
testData . Release ( ) ;
161
163
}
162
164
163
- public void testGetFilters ( )
165
+ [ Test ]
166
+ public void GetFilters ( )
164
167
{
165
168
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166
169
// Get() test
@@ -181,7 +184,8 @@ public void testGetFilters()
181
184
testData . Release ( ) ;
182
185
}
183
186
184
- public void testOneToManyFilters ( )
187
+ [ Test ]
188
+ public void OneToManyFilters ( )
185
189
{
186
190
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
191
// one-to-many loading tests
@@ -245,49 +249,50 @@ public void ManyToManyFilterOnCriteria()
245
249
testData . Release ( ) ;
246
250
}
247
251
248
- [ Test , Ignore ( "Statistics not implemented" ) ]
252
+ [ Test ]
249
253
public void ManyToManyFilterOnLoad ( )
250
254
{
251
- // TestData testData = new TestData(this);
252
- // testData.Prepare();
255
+ TestData testData = new TestData ( this ) ;
256
+ testData . Prepare ( ) ;
253
257
254
- // ISession session = OpenSession();
255
- // session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);
258
+ ISession session = OpenSession ( ) ;
259
+ session . EnableFilter ( "effectiveDate" ) . SetParameter ( "asOfDate" , DateTime . Today ) ;
256
260
257
- // Product prod = (Product) session.Get(typeof(Product), testData.prod1Id);
261
+ Product prod = ( Product ) session . Get ( typeof ( Product ) , testData . prod1Id ) ;
258
262
259
- //long initLoadCount = sessions.getStatistics().getCollectionLoadCount() ;
260
- //long initFetchCount = sessions.getStatistics().getCollectionFetchCount() ;
263
+ //long initLoadCount = sessions.Statistics.CollectionLoadCount ;
264
+ //long initFetchCount = sessions.Statistics.CollectionFetchCount ;
261
265
262
- //// should already have been initialized...
263
- //int size = prod.Categories.Count;
264
- //Assert.AreEqual(1, size, "Incorrect filtered collection count");
266
+ // should already have been initialized...
267
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( prod . Categories ) ) ;
268
+ int size = prod . Categories . Count ;
269
+ Assert . AreEqual ( 1 , size , "Incorrect filtered collection count" ) ;
265
270
266
- //long currLoadCount = sessions.getStatistics().getCollectionLoadCount() ;
267
- //long currFetchCount = sessions.getStatistics().getCollectionFetchCount() ;
271
+ //long currLoadCount = sessions.Statistics.CollectionLoadCount ;
272
+ //long currFetchCount = sessions.Statistics.CollectionFetchCount ;
268
273
269
274
//Assert.IsTrue(
270
275
// (initLoadCount == currLoadCount) && (initFetchCount == currFetchCount),
271
276
// "Load with join fetch of many-to-many did not trigger join fetch"
272
-
273
277
// );
274
278
275
- //// make sure we did not get back a collection of proxies
276
- //long initEntityLoadCount = sessions.getStatistics().getEntityLoadCount() ;
279
+ // make sure we did not get back a collection of proxies
280
+ //long initEntityLoadCount = sessions.Statistics.EntityLoadCount ;
277
281
278
- //foreach (Category cat in prod.Categories)
279
- //{
280
- // Console.WriteLine(" ===> " + cat.Name);
281
- //}
282
- //long currEntityLoadCount = sessions.getStatistics().getEntityLoadCount();
282
+ foreach ( Category cat in prod . Categories )
283
+ {
284
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( cat ) , "Load with join fetch of many-to-many did not trigger *complete* join fetch" ) ;
285
+ //Console.WriteLine(" ===> " + cat.Name);
286
+ }
287
+ //long currEntityLoadCount = sessions.Statistics.EntityLoadCount;
283
288
284
289
//Assert.IsTrue(
285
290
// (initEntityLoadCount == currEntityLoadCount),
286
291
// "Load with join fetch of many-to-many did not trigger *complete* join fetch"
287
292
// );
288
293
289
- // session.Close();
290
- // testData.Release();
294
+ session . Close ( ) ;
295
+ testData . Release ( ) ;
291
296
}
292
297
293
298
[ Test ]
@@ -322,7 +327,7 @@ public void ManyToManyFilterOnQuery()
322
327
ISession session = OpenSession ( ) ;
323
328
session . EnableFilter ( "effectiveDate" ) . SetParameter ( "asOfDate" , DateTime . Today ) ;
324
329
325
- IList result = session . CreateQuery ( "from Product p inner join fetch p.categories " ) . List ( ) ;
330
+ IList result = session . CreateQuery ( "from Product p inner join fetch p.Categories " ) . List ( ) ;
326
331
Assert . IsTrue ( result . Count > 0 , "No products returned from HQL many-to-many filter case" ) ;
327
332
328
333
Product prod = ( Product ) result [ 0 ] ;
@@ -334,92 +339,98 @@ public void ManyToManyFilterOnQuery()
334
339
testData . Release ( ) ;
335
340
}
336
341
337
- [ Test , Ignore ( "Statistics not implemented" ) ]
342
+ [ Test ]
338
343
public void ManyToManyBase ( )
339
344
{
340
- // TestData testData = new TestData(this);
341
- // testData.Prepare();
345
+ TestData testData = new TestData ( this ) ;
346
+ testData . Prepare ( ) ;
342
347
343
- // ISession session = OpenSession();
348
+ ISession session = OpenSession ( ) ;
344
349
345
- // Product prod = ( Product ) session.Get( typeof(Product), testData.prod1Id );
350
+ Product prod = ( Product ) session . Get ( typeof ( Product ) , testData . prod1Id ) ;
346
351
347
- //long initLoadCount = sessions.getStatistics().getCollectionLoadCount();
348
- //long initFetchCount = sessions.getStatistics().getCollectionFetchCount();
352
+ // TODO H3: Statistics
353
+ //long initLoadCount = sessions.Statistics.CollectionLoadCount;
354
+ //long initFetchCount = sessions.Statistics.CollectionFetchCount;
349
355
350
- //// should already have been initialized...
351
- //int size = prod.Categories.Count;
352
- //Assert.AreEqual(2, size, "Incorrect non-filtered collection count" );
356
+ // should already have been initialized...
357
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( prod . Categories ) , "Load with join fetch of many-to-many did not trigger join fetch" ) ;
358
+ int size = prod . Categories . Count ;
359
+ Assert . AreEqual ( 2 , size , "Incorrect non-filtered collection count" ) ;
353
360
354
- //long currLoadCount = sessions.getStatistics().getCollectionLoadCount() ;
355
- //long currFetchCount = sessions.getStatistics().getCollectionFetchCount() ;
361
+ //long currLoadCount = sessions.Statistics.CollectionLoadCount ;
362
+ //long currFetchCount = sessions.Statistics.CollectionFetchCount ;
356
363
357
364
//Assert.IsTrue(
358
365
// ( initLoadCount == currLoadCount ) && ( initFetchCount == currFetchCount ),
359
366
// "Load with join fetch of many-to-many did not trigger join fetch"
360
367
//);
361
368
362
- //// make sure we did not get back a collection of proxies
363
- //long initEntityLoadCount = sessions.getStatistics().getEntityLoadCount();
364
- //foreach (Category cat in prod.Categories)
365
- //{
366
- // Console.WriteLine(" ===> " + cat.Name);
367
- //}
368
- //long currEntityLoadCount = sessions.getStatistics().getEntityLoadCount();
369
+ // make sure we did not get back a collection of proxies
370
+ // TODO H3: statistics
371
+ //long initEntityLoadCount = sessions.Statistics.EntityLoadCount;
372
+ foreach ( Category cat in prod . Categories )
373
+ {
374
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( cat ) , "Load with join fetch of many-to-many did not trigger *complete* join fetch" ) ;
375
+ //Console.WriteLine(" ===> " + cat.Name);
376
+ }
377
+ //long currEntityLoadCount = sessions.Statistics.EntityLoadCount;
369
378
370
379
//Assert.IsTrue(
371
380
// ( initEntityLoadCount == currEntityLoadCount ),
372
381
// "Load with join fetch of many-to-many did not trigger *complete* join fetch"
373
382
//);
374
383
375
- // session.Close();
376
- // testData.Release();
384
+ session . Close ( ) ;
385
+ testData . Release ( ) ;
377
386
}
378
387
379
- [ Test , Ignore ( "Statistics not implemented" ) ]
388
+ [ Test ]
380
389
public void ManyToManyBaseThruCriteria ( )
381
390
{
382
- // TestData testData = new TestData(this);
383
- // testData.Prepare();
391
+ TestData testData = new TestData ( this ) ;
392
+ testData . Prepare ( ) ;
384
393
385
- // ISession session = OpenSession();
394
+ ISession session = OpenSession ( ) ;
386
395
387
- // IList result = session.CreateCriteria(typeof(Product))
388
- // .Add(Expression.Expression.Eq("id", testData.prod1Id))
389
- // .List();
396
+ IList result = session . CreateCriteria ( typeof ( Product ) )
397
+ . Add ( Expression . Expression . Eq ( "id" , testData . prod1Id ) )
398
+ . List ( ) ;
390
399
391
- // Product prod = (Product) result[0];
400
+ Product prod = ( Product ) result [ 0 ] ;
392
401
393
- //long initLoadCount = sessions.getStatistics().getCollectionLoadCount() ;
394
- //long initFetchCount = sessions.getStatistics().getCollectionFetchCount() ;
402
+ //long initLoadCount = sessions.Statistics.CollectionLoadCount ;
403
+ //long initFetchCount = sessions.Statistics.CollectionFetchCount ;
395
404
396
- //// should already have been initialized...
397
- //int size = prod.Categories.Count;
398
- //Assert.AreEqual(2, size, "Incorrect non-filtered collection count");
405
+ // should already have been initialized...
406
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( prod . Categories ) , "Load with join fetch of many-to-many did not trigger join fetch" ) ;
407
+ int size = prod . Categories . Count ;
408
+ Assert . AreEqual ( 2 , size , "Incorrect non-filtered collection count" ) ;
399
409
400
- //long currLoadCount = sessions.getStatistics().getCollectionLoadCount() ;
401
- //long currFetchCount = sessions.getStatistics().getCollectionFetchCount() ;
410
+ //long currLoadCount = sessions.Statistics.CollectionLoadCount ;
411
+ //long currFetchCount = sessions.Statistics.CollectionFetchCount ;
402
412
403
413
//Assert.IsTrue(
404
414
// (initLoadCount == currLoadCount) && (initFetchCount == currFetchCount),
405
415
// "Load with join fetch of many-to-many did not trigger join fetch"
406
416
// );
407
417
408
- //// make sure we did not get back a collection of proxies
409
- //long initEntityLoadCount = sessions.getStatistics().getEntityLoadCount();
410
- //foreach (Category cat in prod.Categories)
411
- //{
412
- // Console.WriteLine(" ===> " + cat.Name);
413
- //}
414
- //long currEntityLoadCount = sessions.getStatistics().getEntityLoadCount();
418
+ // make sure we did not get back a collection of proxies
419
+ //long initEntityLoadCount = sessions.Statistics.EntityLoadCount;
420
+ foreach ( Category cat in prod . Categories )
421
+ {
422
+ Assert . IsTrue ( NHibernateUtil . IsInitialized ( cat ) , "Load with join fetch of many-to-many did not trigger *complete* join fetch" ) ;
423
+ //Console.WriteLine(" ===> " + cat.Name);
424
+ }
425
+ //long currEntityLoadCount = sessions.Statistics.EntityLoadCount;
415
426
416
427
//Assert.IsTrue(
417
428
// (initEntityLoadCount == currEntityLoadCount),
418
429
// "Load with join fetch of many-to-many did not trigger *complete* join fetch"
419
430
// );
420
431
421
- // session.Close();
422
- // testData.Release();
432
+ session . Close ( ) ;
433
+ testData . Release ( ) ;
423
434
}
424
435
425
436
protected override string MappingsAssembly
0 commit comments