Search in sources :

Example 21 with Fetch

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test)

Example 22 with Fetch

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());
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test)

Example 23 with Fetch

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());
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test)

Example 24 with Fetch

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));
}
Also used : Fetch(org.molgenis.data.Fetch) Entity(org.molgenis.data.Entity) Query(org.molgenis.data.Query) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 25 with Fetch

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());
        }
    };
}
Also used : Fetch(org.molgenis.data.Fetch) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.data.Query) Nonnull(javax.annotation.Nonnull) CacheLoader(com.google.common.cache.CacheLoader)

Aggregations

Fetch (org.molgenis.data.Fetch)36 Test (org.testng.annotations.Test)28 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)12 EntityType (org.molgenis.data.meta.model.EntityType)10 Entity (org.molgenis.data.Entity)9 Attribute (org.molgenis.data.meta.model.Attribute)7 List (java.util.List)3 Query (org.molgenis.data.Query)3 TransactionDefinition (org.springframework.transaction.TransactionDefinition)3 ConstraintViolation (org.molgenis.data.validation.ConstraintViolation)2 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)2 Stopwatch (com.google.common.base.Stopwatch)1 Stopwatch.createStarted (com.google.common.base.Stopwatch.createStarted)1 CacheLoader (com.google.common.cache.CacheLoader)1 com.google.common.collect (com.google.common.collect)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 String.format (java.lang.String.format)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1