Scoped extends SimpleQuery<EntityHandle<O>, Boolean> { public Scoped(Query<EntityHandle<O>> scope, Query<EntityHandle<O>> query) { super(new SimpleAttribute<EntityHandle<O>, Boolean>() { @Override public Boolean getValue(EntityHandle<O> object, QueryOptions queryOptions) { return false; } }); this.scope = scope; this.query = query; } Scoped(Query<EntityHandle<O>> scope, Query<EntityHandle<O>> query);   }
@Test @SneakyThrows public void testScoped() { HybridTimestamp ts1 = repository.publish(new TestCommand("1")).get(); HybridTimestamp ts2 = repository.publish(new TestCommand("2")).get(); HybridTimestamp ts3 = repository.publish(new TestCommand("2")).get(); HybridTimestamp ts4 = repository.publish(new TestCommand("3")).get(); try (ResultSet<EntityHandle<TestEvent>> rs = repository.query(TestEvent.class, scoped(equal(TestEvent.PROP, "1"), min(TestEvent.TIMESTAMP)))) { assertEquals(rs.uniqueResult().get().timestamp(), ts1); } try (ResultSet<EntityHandle<TestEvent>> rs = repository.query(TestEvent.class, scoped(equal(TestEvent.PROP, "2"), min(TestEvent.TIMESTAMP)))) { assertEquals(rs.uniqueResult().get().timestamp(), ts2); } try (ResultSet<EntityHandle<TestEvent>> rs = repository.query(TestEvent.class, scoped(equal(TestEvent.PROP, "1"), max(TestEvent.TIMESTAMP)))) { assertEquals(rs.uniqueResult().get().timestamp(), ts1); } try (ResultSet<EntityHandle<TestEvent>> rs = repository.query(TestEvent.class, scoped(equal(TestEvent.PROP, "2"), max(TestEvent.TIMESTAMP)))) { assertEquals(rs.uniqueResult().get().timestamp(), ts3); } }