Search in sources :

Example 1 with DEFAULT_LOGGER

use of com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER in project elide by yahoo.

the class JpaDataStoreTransactionTest method testNoDelegationOnLoadRecords.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testNoDelegationOnLoadRecords(boolean delegateToInMemory) {
    AbstractJpaTransaction tx = new AbstractJpaTransaction(entityManager, (unused) -> {
    }, DEFAULT_LOGGER, delegateToInMemory) {

        @Override
        public boolean isOpen() {
            return false;
        }

        @Override
        public void begin() {
        }

        @Override
        protected Predicate<Collection<?>> isPersistentCollection() {
            return (unused) -> true;
        }
    };
    EntityProjection projection = EntityProjection.builder().type(Book.class).build();
    DataStoreIterable<Book> result = tx.loadObjects(projection, scope);
    assertFalse(result.needsInMemoryFilter());
    assertFalse(result.needsInMemorySort());
    assertFalse(result.needsInMemoryPagination());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Author(example.Author) ClassType(com.yahoo.elide.core.type.ClassType) PersistentSet(org.hibernate.collection.internal.PersistentSet) ArrayList(java.util.ArrayList) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AbstractJpaTransaction(com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction) BeforeAll(org.junit.jupiter.api.BeforeAll) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Relationship(com.yahoo.elide.core.request.Relationship) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RequestScope(com.yahoo.elide.core.RequestScope) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) DEFAULT_LOGGER(com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Mockito.when(org.mockito.Mockito.when) EntityManager(javax.persistence.EntityManager) Arguments(org.junit.jupiter.params.provider.Arguments) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Query(javax.persistence.Query) Stream(java.util.stream.Stream) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Collection(java.util.Collection) AbstractJpaTransaction(com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DEFAULT_LOGGER

use of com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER in project elide by yahoo.

the class JpaDataStoreTransactionTest method testGetRelationDelegation.

@ParameterizedTest
@MethodSource("getTestArguments")
public void testGetRelationDelegation(boolean delegateToInMemory, int numberOfAuthors, FilterExpression filter, boolean usesInMemory) throws Exception {
    AbstractJpaTransaction tx = new AbstractJpaTransaction(entityManager, (unused) -> {
    }, DEFAULT_LOGGER, delegateToInMemory, false) {

        @Override
        public boolean isOpen() {
            return false;
        }

        @Override
        public void begin() {
        }

        @Override
        protected Predicate<Collection<?>> isPersistentCollection() {
            return (unused) -> true;
        }
    };
    EntityProjection projection = EntityProjection.builder().type(Author.class).build();
    List<Author> authors = new ArrayList<>();
    Author author1 = mock(Author.class);
    authors.add(author1);
    for (int idx = 1; idx < numberOfAuthors; idx++) {
        authors.add(mock(Author.class));
    }
    when(query.getResultList()).thenReturn(authors);
    DataStoreIterable<Author> loadedAuthors = tx.loadObjects(projection, scope);
    assertFalse(loadedAuthors.needsInMemoryPagination());
    assertFalse(loadedAuthors.needsInMemorySort());
    assertFalse(loadedAuthors.needsInMemoryFilter());
    Relationship relationship = Relationship.builder().name("books").projection(EntityProjection.builder().type(Book.class).filterExpression(filter).build()).build();
    PersistentSet returnCollection = mock(PersistentSet.class);
    when(author1.getBooks()).thenReturn(returnCollection);
    DataStoreIterable<Book> loadedBooks = tx.getToManyRelation(tx, author1, relationship, scope);
    assertEquals(usesInMemory, loadedBooks.needsInMemoryFilter());
    assertEquals(usesInMemory, loadedBooks.needsInMemorySort());
    assertEquals(usesInMemory, loadedBooks.needsInMemoryPagination());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Author(example.Author) ClassType(com.yahoo.elide.core.type.ClassType) PersistentSet(org.hibernate.collection.internal.PersistentSet) ArrayList(java.util.ArrayList) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AbstractJpaTransaction(com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction) BeforeAll(org.junit.jupiter.api.BeforeAll) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Relationship(com.yahoo.elide.core.request.Relationship) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RequestScope(com.yahoo.elide.core.RequestScope) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) DEFAULT_LOGGER(com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Mockito.when(org.mockito.Mockito.when) EntityManager(javax.persistence.EntityManager) Arguments(org.junit.jupiter.params.provider.Arguments) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Query(javax.persistence.Query) Stream(java.util.stream.Stream) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) EntityProjection(com.yahoo.elide.core.request.EntityProjection) ArrayList(java.util.ArrayList) PersistentSet(org.hibernate.collection.internal.PersistentSet) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Collection(java.util.Collection) Author(example.Author) AbstractJpaTransaction(com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RequestScope (com.yahoo.elide.core.RequestScope)2 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)2 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)2 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)2 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)2 EntityProjection (com.yahoo.elide.core.request.EntityProjection)2 Relationship (com.yahoo.elide.core.request.Relationship)2 ClassType (com.yahoo.elide.core.type.ClassType)2 DEFAULT_LOGGER (com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER)2 AbstractJpaTransaction (com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction)2 Author (example.Author)2 Book (example.Book)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Predicate (java.util.function.Predicate)2 Stream (java.util.stream.Stream)2 EntityManager (javax.persistence.EntityManager)2