I have two databases and I have to search for a list of products based on a range(from and to) from 1st DB but the problem is the number of ranges is unknown.
currently, from 1st DB I am getting a list of range(from and to). then using for loop to query the 2nd DB.
//1st getting list of ranges
List<Ranges> ranges = this.productRepository.getRangeFromAndTo();
//query to get ranges
@Query(value = "SELECT * FROM PRODUCT_RANGE WHERE productId = ?1 AND goodToUse = ?2 AND CHECKOUT is null", nativeQuery=true)
List<Range> getRangeFromAndTo(String productId, String goodToUse);
//using for loop to query 2nd db
ranges.forEach(range ->{ productService.countProducts(range.getRangeFrom(),fnnRange.getRangeTo());});
//this is the query
@Query(value="select Count(*) from RESOURCE where RESOURCE_VALUE between ?1 and ?2 and upper(RESOURCE_STATUS)=upper('available')", nativeQuery=true)
Long countByresourceValueBetween(String fnnRangeFrom, String fnnRangeTo);
I want to query the 2nd DB at one go to reduce the time.