use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class AggregationDataStoreTransactionTest method loadObjectsBypassCache.
@Test
public void loadObjectsBypassCache() {
Mockito.reset(queryLogger);
query = Query.builder().source(playerStatsTable).bypassingCache(true).build();
NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
QueryResult queryResult = QueryResult.builder().data(DATA).build();
when(queryEngine.executeQuery(query, qeTransaction)).thenReturn(queryResult);
when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
assertEquals(DATA, Lists.newArrayList(transaction.loadObjects(entityProjection, scope)));
Mockito.verify(queryEngine, never()).getTableVersion(any(), any());
Mockito.verifyNoInteractions(cache);
Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(false));
Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class AggregationDataStoreTransactionTest method loadObjectsNoTableVersion.
@Test
public void loadObjectsNoTableVersion() {
Mockito.reset(queryLogger);
NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
QueryResult queryResult = QueryResult.builder().data(DATA).build();
when(queryEngine.executeQuery(query, qeTransaction)).thenReturn(queryResult);
when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
transaction.loadObjects(entityProjection, scope);
String cacheKey = ";" + queryKey;
Mockito.verify(cache).get(cacheKey);
Mockito.verify(cache).put(cacheKey, queryResult);
Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(false));
Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
use of com.yahoo.elide.core.request.EntityProjection 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.core.request.EntityProjection 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());
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class SubscriptionDataFetcher method get.
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
OperationDefinition.Operation op = environment.getOperationDefinition().getOperation();
if (op != OperationDefinition.Operation.SUBSCRIPTION) {
throw new InvalidEntityBodyException(String.format("%s not supported for subscription models.", op));
}
/* build environment object, extracts required fields */
Environment context = new Environment(environment, nonEntityDictionary);
/* safe enable debugging */
if (log.isDebugEnabled()) {
logContext(log, RelationshipOp.FETCH, context);
}
if (context.isRoot()) {
String entityName = context.field.getName();
String aliasName = context.field.getAlias();
EntityProjection projection = context.requestScope.getProjectionInfo().getProjection(aliasName, entityName);
Flowable<PersistentResource> recordPublisher = PersistentResource.loadRecords(projection, new ArrayList<>(), context.requestScope).toFlowable(BackpressureStrategy.BUFFER).onBackpressureBuffer(bufferSize, true, false);
return recordPublisher.map(SubscriptionNodeContainer::new);
}
// as the PersistentResourceFetcher.
return context.container.processFetch(context);
}
Aggregations