Search in sources :

Example 51 with EntityDictionary

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()));
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 52 with EntityDictionary

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));
}
Also used : FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) FilterExpressionCheckEvaluationVisitor(com.yahoo.elide.core.filter.visitors.FilterExpressionCheckEvaluationVisitor)

Example 53 with EntityDictionary

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);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) UnknownEntityException(com.yahoo.elide.core.exceptions.UnknownEntityException) InvalidObjectIdentifierException(com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 54 with EntityDictionary

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);
}
Also used : JMSDataStore(com.yahoo.elide.datastores.jms.JMSDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 55 with EntityDictionary

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();
}
Also used : Pagination(com.yahoo.elide.core.request.Pagination) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Query(com.yahoo.elide.datastores.jpql.porting.Query) SubCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder) Collection(java.util.Collection) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) Sorting(com.yahoo.elide.core.request.Sorting)

Aggregations

EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)87 Test (org.junit.jupiter.api.Test)31 RequestScope (com.yahoo.elide.core.RequestScope)27 Include (com.yahoo.elide.annotation.Include)17 Entity (javax.persistence.Entity)17 HashSet (java.util.HashSet)16 Type (com.yahoo.elide.core.type.Type)13 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)10 Map (java.util.Map)10 BeforeAll (org.junit.jupiter.api.BeforeAll)10 PersistentResource (com.yahoo.elide.core.PersistentResource)9 Set (java.util.Set)9 ReadPermission (com.yahoo.elide.annotation.ReadPermission)8 ClassType (com.yahoo.elide.core.type.ClassType)8 List (java.util.List)8 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)7 DataStore (com.yahoo.elide.core.datastore.DataStore)7 InvalidObjectIdentifierException (com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException)7 Check (com.yahoo.elide.core.security.checks.Check)7