@@ -541,6 +541,12 @@ public List<Product> readAllActiveProducts(int page, int pageSize) {
541
541
Date currentDate = DateUtil .getCurrentDateAfterFactoringInDateResolution (cachedDate , currentDateResolution );
542
542
return readAllActiveProductsInternal (page , pageSize , currentDate );
543
543
}
544
+
545
+ @ Override
546
+ public List <Product > readAllActiveProducts (Integer pageSize , Long lastId ) {
547
+ Date currentDate = DateUtil .getCurrentDateAfterFactoringInDateResolution (cachedDate , currentDateResolution );
548
+ return readAllActiveProductsInternal (pageSize , currentDate , lastId );
549
+ }
544
550
545
551
@ Override
546
552
@ Deprecated
@@ -557,6 +563,15 @@ protected List<Product> readAllActiveProductsInternal(int page, int pageSize, Da
557
563
558
564
return query .setFirstResult (firstResult ).setMaxResults (pageSize ).getResultList ();
559
565
}
566
+
567
+ protected List <Product > readAllActiveProductsInternal (Integer pageSize , Date currentDate , Long lastId ) {
568
+ CriteriaQuery <Product > criteria = getCriteriaForActiveProducts (currentDate , lastId );
569
+ TypedQuery <Product > query = em .createQuery (criteria );
570
+ query .setHint (QueryHints .HINT_CACHEABLE , true );
571
+ query .setHint (QueryHints .HINT_CACHE_REGION , "query.Catalog" );
572
+
573
+ return query .setMaxResults (pageSize ).getResultList ();
574
+ }
560
575
561
576
@ Override
562
577
public List <Product > readAllActiveProducts () {
@@ -620,24 +635,31 @@ protected Long readCountAllActiveProductsInternal(Date currentDate) {
620
635
}
621
636
622
637
protected CriteriaQuery <Product > getCriteriaForActiveProducts (Date currentDate ) {
638
+ return getCriteriaForActiveProducts (currentDate , null );
639
+ }
640
+
641
+ protected CriteriaQuery <Product > getCriteriaForActiveProducts (Date currentDate , Long lastId ) {
623
642
// Set up the criteria query that specifies we want to return Products
624
643
CriteriaBuilder builder = em .getCriteriaBuilder ();
625
644
CriteriaQuery <Product > criteria = builder .createQuery (Product .class );
626
-
645
+
627
646
// The root of our search is Product
628
647
Root <ProductImpl > product = criteria .from (ProductImpl .class );
629
-
648
+
630
649
// We need to filter on active date on the sku
631
650
Join <Product , Sku > sku = product .join ("defaultSku" );
632
651
product .fetch ("defaultSku" );
633
-
652
+
634
653
// Product objects are what we want back
635
654
criteria .select (product );
636
-
655
+
637
656
// Ensure the product is currently active
638
657
List <Predicate > restrictions = new ArrayList <Predicate >();
639
658
attachActiveRestriction (currentDate , product , sku , restrictions );
640
-
659
+ if (lastId != null ) {
660
+ restrictions .add (builder .gt (product .get ("id" ).as (Long .class ), lastId ));
661
+ }
662
+
641
663
// Add the restrictions to the criteria query
642
664
criteria .where (restrictions .toArray (new Predicate [restrictions .size ()]));
643
665
0 commit comments