@Test void unsupportedQueryWithComputedAttributes() { @SuppressWarnings("unchecked") Query<Entity> q = mock(Query.class); QueryRule qRule1 = mock(QueryRule.class); QueryRule qRule2 = mock(QueryRule.class); when(qRule1.getField()).thenReturn("attr1"); when(qRule2.getField()).thenReturn("attr2"); when(qRule1.getOperator()).thenReturn(EQUALS); when(qRule2.getOperator()).thenReturn(OR); when(qRule1.getNestedRules()).thenReturn(Collections.emptyList()); when(qRule2.getNestedRules()).thenReturn(Collections.emptyList()); when(q.getRules()).thenReturn(newArrayList(qRule1, qRule2)); 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); 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);  }