@Test void findAllQueryOneToManyEquals() throws Exception { String oneToManyAttrName = "oneToManyAttr"; String refIdAttrName = "refEntityId"; Attribute refIdAttr = mock(Attribute.class); when(refIdAttr.getName()).thenReturn(refIdAttrName); when(refIdAttr.getDataType()).thenReturn(INT); when(refIdAttr.isUnique()).thenReturn(true); String xrefAttrName = "xrefAttr"; Attribute xrefAttr = mock(Attribute.class); when(xrefAttr.getName()).thenReturn(xrefAttrName); EntityType refEntityMeta = mock(EntityType.class); when(refEntityMeta.getId()).thenReturn("refEntityId"); when(refEntityMeta.getIdAttribute()).thenReturn(refIdAttr); doReturn(refIdAttr).when(refEntityMeta).getAttribute(refIdAttrName); String idAttrName = "entityId"; Attribute idAttr = mock(Attribute.class); when(idAttr.getName()).thenReturn(idAttrName); when(idAttr.getDataType()).thenReturn(STRING); Attribute oneToManyAttr = mock(Attribute.class); when(oneToManyAttr.getName()).thenReturn(oneToManyAttrName); when(oneToManyAttr.getDataType()).thenReturn(ONE_TO_MANY); when(oneToManyAttr.getRefEntity()).thenReturn(refEntityMeta); when(oneToManyAttr.isMappedBy()).thenReturn(true); when(oneToManyAttr.getMappedBy()).thenReturn(xrefAttr); when(entityType.getId()).thenReturn("entityId"); when(entityType.getIdAttribute()).thenReturn(idAttr); when(entityType.getAttribute("entityId")).thenReturn(idAttr); doReturn(oneToManyAttr).when(entityType).getAttribute(oneToManyAttrName); when(entityType.getAtomicAttributes()).thenReturn(newArrayList(idAttr, oneToManyAttr)); EntityType entityType = this.entityType; postgreSqlRepo = new PostgreSqlRepository(postgreSqlEntityFactory, jdbcTemplate, dataSource, entityType); int queryValue = 2; QueryRule queryRule = new QueryRule(oneToManyAttrName, EQUALS, queryValue); when(query.getRules()).thenReturn(singletonList(queryRule)); String sql = "SELECT DISTINCT this.\"entityId\", (SELECT array_agg(\"refEntityId\" ORDER BY \"refEntityId\" ASC) FROM \"refEntityId#07f902bf\" WHERE this.\"entityId\" = \"refEntityId#07f902bf\".\"xrefAttr\") AS \"oneToManyAttr\" FROM \"entityId#fc2928f6\" AS this LEFT JOIN \"refEntityId#07f902bf\" AS \"oneToManyAttr_filter1\" ON (this.\"entityId\" = \"oneToManyAttr_filter1\".\"xrefAttr\") WHERE \"oneToManyAttr_filter1\".\"refEntityId\" = ? ORDER BY \"entityId\" ASC LIMIT 1000"; when(postgreSqlEntityFactory.createRowMapper(entityType, null)).thenReturn(rowMapper); Entity entity0 = mock(Entity.class); when(jdbcTemplate.query(sql, new Object[] {queryValue}, rowMapper)) .thenReturn(singletonList(entity0)); assertEquals(singletonList(entity0), postgreSqlRepo.findAll(query).collect(toList())); }
@Override public Stream<Entity> findAll(Query<Entity> q) { return stream(findAllBatching(q)); }
PostgreSqlRepository extends AbstractRepository { @Override public Stream<Entity> findAll(Query<Entity> q) { return stream(findAllBatching(q)); } }
PostgreSqlRepository extends AbstractRepository { @Override public Stream<Entity> findAll(Query<Entity> q) { return stream(findAllBatching(q)); } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); }
PostgreSqlRepository extends AbstractRepository { @Override public Stream<Entity> findAll(Query<Entity> q) { return stream(findAllBatching(q)); } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); @Override Iterator<Entity> iterator(); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override EntityType getEntityType(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); }
PostgreSqlRepository extends AbstractRepository { @Override public Stream<Entity> findAll(Query<Entity> q) { return stream(findAllBatching(q)); } PostgreSqlRepository(
      PostgreSqlEntityFactory postgreSqlEntityFactory,
      JdbcTemplate jdbcTemplate,
      DataSource dataSource,
      EntityType entityType); @Override Iterator<Entity> iterator(); @Override Set<RepositoryCapability> getCapabilities(); @Override Set<Operator> getQueryOperators(); @Override EntityType getEntityType(); @Override long count(Query<Entity> q); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize);  }