@Test void unsupportedQueryWithSortOnComputedAttributes() { @SuppressWarnings("unchecked") Query<Entity> q = mock(Query.class); Sort sort = mock(Sort.class); when(q.getSort()).thenReturn(sort); Attribute attr1 = mock(Attribute.class); when(repositoryEntityType.getAttribute("attr1")).thenReturn(attr1); when(attr1.hasExpression()).thenReturn(true); Attribute attr2 = mock(Attribute.class); when(repositoryEntityType.getAttribute("attr2")).thenReturn(attr2); when(attr2.hasExpression()).thenReturn(true); Sort.Order o1 = mock(Sort.Order.class); Sort.Order o2 = mock(Sort.Order.class); when(o1.getAttr()).thenReturn("attr1"); when(o2.getAttr()).thenReturn("attr2"); when(sort.spliterator()).thenReturn(newArrayList(o1, o2).spliterator()); indexedRepositoryDecorator.count(q); verify(searchService).count(repositoryEntityType, q); verify(delegateRepository, never()).count(q); }
@Override public long count(Query<Entity> q) { if (querySupported(q)) { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), DECORATED_REPOSITORY); return delegate().count(q); } else { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), INDEX_REPOSITORY); return tryTwice(() -> searchService.count(getEntityType(), q)); } }
IndexedRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public long count(Query<Entity> q) { if (querySupported(q)) { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), DECORATED_REPOSITORY); return delegate().count(q); } else { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), INDEX_REPOSITORY); return tryTwice(() -> searchService.count(getEntityType(), q)); } } }
IndexedRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public long count(Query<Entity> q) { if (querySupported(q)) { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), DECORATED_REPOSITORY); return delegate().count(q); } else { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), INDEX_REPOSITORY); return tryTwice(() -> searchService.count(getEntityType(), q)); } } IndexedRepositoryDecorator(
      Repository<Entity> delegateRepository,
      SearchService searchService,
      IndexJobScheduler indexJobScheduler); }
IndexedRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public long count(Query<Entity> q) { if (querySupported(q)) { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), DECORATED_REPOSITORY); return delegate().count(q); } else { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), INDEX_REPOSITORY); return tryTwice(() -> searchService.count(getEntityType(), q)); } } IndexedRepositoryDecorator(
      Repository<Entity> delegateRepository,
      SearchService searchService,
      IndexJobScheduler indexJobScheduler); @Override Entity findOne(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override long count(Query<Entity> q); @Override AggregateResult aggregate(AggregateQuery aggregateQuery); }
IndexedRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public long count(Query<Entity> q) { if (querySupported(q)) { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), DECORATED_REPOSITORY); return delegate().count(q); } else { LOG.debug( "public long count({}) entityTypeId: [{}] repository: [{}]", q, getEntityType().getId(), INDEX_REPOSITORY); return tryTwice(() -> searchService.count(getEntityType(), q)); } } IndexedRepositoryDecorator(
      Repository<Entity> delegateRepository,
      SearchService searchService,
      IndexJobScheduler indexJobScheduler); @Override Entity findOne(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override long count(Query<Entity> q); @Override AggregateResult aggregate(AggregateQuery aggregateQuery);  }