use of com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction 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());
}
use of com.yahoo.elide.datastores.jpa.transaction.AbstractJpaTransaction 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());
}
Aggregations