use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class EntityTypeUtilsTest method testCreateFetchForReindexingIndexingDepth2.
@Test
public void testCreateFetchForReindexingIndexingDepth2() {
EntityType entityType = createMockEntityType();
when(entityType.getIndexingDepth()).thenReturn(2);
Fetch expectedFetch = new Fetch().field("MyEntityTypeAttr").field("MyEntityTypeRefAttr", new Fetch().field("MyRefEntityTypeAttr").field("MyRefEntityTypeRefAttr", new Fetch().field("MyRefRefEntityTypeAttr").field("MyRefRefEntityTypeRefAttr")));
assertEquals(EntityTypeUtils.createFetchForReindexing(entityType), expectedFetch);
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class QueryImplTest method fetchFetch.
@Test
public void fetchFetch() {
Fetch fetch = new Fetch().field("field0");
assertEquals(fetch, new QueryImpl<>().fetch(fetch).getFetch());
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class QueryImplTest method fetch.
@Test
public void fetch() {
Fetch fetch = new QueryImpl<>().fetch();
assertFalse(fetch.iterator().hasNext());
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AbstractRepositoryTest method findAllStreamFetch.
@SuppressWarnings("unchecked")
@Test
public void findAllStreamFetch() {
Fetch fetch = new Fetch();
Object id0 = "id0";
Object id1 = "id1";
Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn(id0).getMock();
Entity entity1 = when(mock(Entity.class).getIdValue()).thenReturn(id1).getMock();
Stream<Object> entityIds = Stream.of(id0, id1);
doReturn(Stream.of(entity0, entity1)).when(abstractRepository).findAll(ArgumentMatchers.any(Query.class));
Stream<Entity> expectedEntities = abstractRepository.findAll(entityIds, fetch);
assertEquals(expectedEntities.collect(Collectors.toList()), Arrays.asList(entity0, entity1));
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class L3Cache method createCacheLoader.
/**
* Create a cacheloader that loads entity ids from the repository and stores them together with their query
*
* @return the {@link CacheLoader}
*/
private CacheLoader<Query<Entity>, List<Object>> createCacheLoader(final Repository<Entity> repository) {
String repositoryName = repository.getName();
Fetch idAttributeFetch = new Fetch().field(repository.getEntityType().getIdAttribute().getName());
return new CacheLoader<Query<Entity>, List<Object>>() {
/**
* Loads {@link Entity} identifiers for a {@link Query}
* @param query the cache key to load
* @return {@link List} of identifier {@link Object}s
*/
@Override
public List<Object> load(@Nonnull Query<Entity> query) {
LOG.trace("Loading identifiers from repository {} for query {}", repositoryName, query);
return repository.findAll(new QueryImpl<>(query).fetch(idAttributeFetch)).map(Entity::getIdValue).collect(toList());
}
};
}
Aggregations