BaseJpaDaoImpl implements BaseJpaDao { protected <T> Predicate getPredicateForInClause(CriteriaBuilder builder, Path<T> path, List<T> values) { int inClauseChunkSize = configurationHelper.getProperty(ConfigurationValue.DB_IN_CLAUSE_CHUNK_SIZE, Integer.class); Predicate predicate = null; int listSize = values.size(); for (int i = 0; i < listSize; i += inClauseChunkSize) { List<T> valuesSubList = values.subList(i, (listSize > (i + inClauseChunkSize) ? (i + inClauseChunkSize) : listSize)); predicate = (predicate == null ? path.in(valuesSubList) : builder.or(predicate, path.in(valuesSubList))); } return predicate; }  @Override void delete(T entity); @Override void detach(T entity); @Override List<T> findAll(Class<T> entityClass); @Override T findById(Class<T> entityClass, Object entityId); @Override List<T> findByNamedProperties(Class<T> entityClass, Map<String, ?> params); @Override T findUniqueByNamedProperties(Class<T> entityClass, Map<String, ?> params); @Override Timestamp getCurrentTimestamp(); @Override EntityManager getEntityManager(); @SuppressWarnings({"unchecked"}) @Override List<T> query(String queryString); @Override List<T> queryByNamedParams(String queryString, Map<String, ?> params); @Override T save(T entity); @Override T saveAndRefresh(T entity);  }
@Test public void testGetPredicateForInClauseOneChunk() { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class); Root<BusinessObjectDataEntity> businessObjectDataEntity = criteria.from(BusinessObjectDataEntity.class); Predicate predicate = baseJpaDaoImpl .getPredicateForInClause(builder, businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), getPartitionValueList(1000)); assertTrue(predicate instanceof InPredicate); assertEquals(1000, ((InPredicate) predicate).getValues().size()); }
@Test public void testGetPredicateForInClauseTwoChunks() { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class); Root<BusinessObjectDataEntity> businessObjectDataEntity = criteria.from(BusinessObjectDataEntity.class); Predicate predicate = baseJpaDaoImpl .getPredicateForInClause(builder, businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), getPartitionValueList(1001)); assertEquals(Predicate.BooleanOperator.OR, predicate.getOperator()); List<Expression<Boolean>> expressions = predicate.getExpressions(); assertEquals(2, expressions.size()); assertEquals(1000, ((InPredicate) expressions.get(0)).getValues().size()); assertEquals(1, ((InPredicate) expressions.get(1)).getValues().size()); }