use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class StartState method handle.
@Override
public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) {
String entityName = ctx.term().getText();
EntityDictionary dictionary = state.getRequestScope().getDictionary();
Type<?> entityClass = dictionary.getEntityClass(entityName, state.getRequestScope().getApiVersion());
state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty(), state.getRequestScope().getEntityProjection()));
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class FilterExpressionCheck method ok.
/**
* The filter expression is evaluated in memory if it cannot be pushed to the data store by elide for any reason.
*
* @param object object returned from datastore
* @param requestScope Request scope object
* @param changeSpec Summary of modifications
* @return true if the object pass evaluation against FilterExpression.
*/
@Override
public final boolean ok(T object, RequestScope requestScope, Optional<ChangeSpec> changeSpec) {
EntityDictionary dictionary = coreScope(requestScope).getDictionary();
Type<?> entityClass = dictionary.lookupBoundClass(EntityDictionary.getType(object));
FilterExpression filterExpression = getFilterExpression(entityClass, requestScope);
return filterExpression.accept(new FilterExpressionCheckEvaluationVisitor(object, this, requestScope));
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class Resource method toPersistentResource.
public PersistentResource<?> toPersistentResource(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException {
EntityDictionary dictionary = requestScope.getDictionary();
Type<?> cls = dictionary.getEntityClass(type, requestScope.getApiVersion());
if (cls == null) {
throw new UnknownEntityException(type);
}
if (id == null) {
throw new InvalidObjectIdentifierException(id, type);
}
EntityProjection projection = EntityProjection.builder().type(cls).build();
return PersistentResource.loadRecord(projection, id, requestScope);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class SubscriptionWebSocketConfigurator method getEndpointInstance.
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
if (endpointClass.equals(SubscriptionWebSocket.class)) {
EntityDictionary dictionary = EntityDictionary.builder().build();
DataStore store = buildDataStore(dictionary);
Elide elide = buildElide(store, dictionary);
return (T) buildWebSocket(elide);
}
return super.getEndpointInstance(endpointClass);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class JPQLTransaction method getToManyRelation.
@Override
public <T, R> DataStoreIterable<R> getToManyRelation(DataStoreTransaction relationTx, T entity, Relationship relation, RequestScope scope) {
FilterExpression filterExpression = relation.getProjection().getFilterExpression();
Sorting sorting = relation.getProjection().getSorting();
Pagination pagination = relation.getProjection().getPagination();
EntityDictionary dictionary = scope.getDictionary();
Iterable val = (Iterable) com.yahoo.elide.core.PersistentResource.getValue(entity, relation.getName(), scope);
// If the query is safe for N+1 and the value is an ORM managed, persistent collection, run a JPQL query...
if (doInDatabase(entity) && val instanceof Collection && isPersistentCollection().test((Collection<?>) val)) {
/*
* If there is no filtering or sorting required in the data store, and the pagination is default,
* return the proxy and let Hibernate manage the SQL generation.
*/
if (filterExpression == null && sorting == null && (pagination == null || (pagination.isDefaultInstance()))) {
return new DataStoreIterableBuilder<R>(addSingleElement(val)).allInMemory().build();
}
RelationshipImpl relationship = new RelationshipImpl(dictionary.lookupEntityClass(EntityDictionary.getType(entity)), entity, relation);
if (pagination != null && pagination.returnPageTotals()) {
pagination.setPageTotals(getTotalRecords(relationship, scope.getDictionary()));
}
final Query query = new SubCollectionFetchQueryBuilder(relationship, dictionary, sessionWrapper).build();
if (query != null) {
return new DataStoreIterableBuilder(addSingleElement(query.list())).build();
}
}
return new DataStoreIterableBuilder<R>(addSingleElement(val)).allInMemory().build();
}
Aggregations