Search in sources :

Example 1 with ValueLoadContext

use of io.jmix.core.ValueLoadContext in project jmix by jmix-framework.

the class KeyValueCollectionLoaderImpl method load.

@Override
public void load() {
    if (container == null)
        throw new IllegalStateException("container is null");
    if (query == null && delegate == null)
        throw new IllegalStateException("both query and delegate are null");
    ValueLoadContext loadContext = createLoadContext();
    if (!sendPreLoadEvent(loadContext)) {
        return;
    }
    List<KeyValueEntity> list;
    if (delegate == null) {
        list = dataManager.loadValues(loadContext);
    } else {
        list = delegate.apply(loadContext);
    }
    if (dataContext != null) {
        List<KeyValueEntity> mergedList = new ArrayList<>(list.size());
        for (KeyValueEntity entity : list) {
            mergedList.add(dataContext.merge(entity));
        }
        container.setItems(mergedList);
    } else {
        container.setItems(list);
    }
    sendPostLoadEvent(list);
}
Also used : ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 2 with ValueLoadContext

use of io.jmix.core.ValueLoadContext in project jmix by jmix-framework.

the class OrderBasedEntityIdsLoader method loadNextIds.

@Override
public ResultHolder loadNextIds(EnqueueingSession session, int batchSize) {
    String entityName = session.getEntityName();
    MetaClass entityClass = metadata.getClass(entityName);
    String orderingPropertyName = session.getOrderingProperty();
    MetaProperty orderingProperty = entityClass.getProperty(orderingPropertyName);
    String lastProcessedRawOrderingValue = session.getLastProcessedValue();
    MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entityClass);
    if (primaryKeyProperty == null) {
        throw new RuntimeException(String.format("Entity '%s' doesn't have primary key", entityName));
    }
    String primaryKeyPropertyName = primaryKeyProperty.getName();
    ResultHolder result;
    if (metadataTools.isEmbedded(orderingProperty)) {
        log.warn("Sorted loading by embedded property is not supported - perform in-memory loading of all ids");
        result = loadAllInMemory(entityClass);
    } else {
        Object lastProcessedValue = convertRawValue(orderingProperty, lastProcessedRawOrderingValue);
        ValueLoadContext valueLoadContext = createValueLoadContext(entityClass, primaryKeyPropertyName, orderingPropertyName, lastProcessedValue, batchSize);
        List<KeyValueEntity> loadedValues = loadValues(valueLoadContext);
        List<Object> ids = loadedValues.stream().map(v -> v.getValue("objectId")).collect(Collectors.toList());
        Object lastLoadedOrderingValue = resolveLastLoadedOrderingValue(loadedValues, primaryKeyPropertyName, orderingPropertyName);
        result = new ResultHolder(ids, lastLoadedOrderingValue);
    }
    return result;
}
Also used : DataManager(io.jmix.core.DataManager) MetaClass(io.jmix.core.metamodel.model.MetaClass) Logger(org.slf4j.Logger) TransactionDefinition(org.springframework.transaction.TransactionDefinition) ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity) EntityIdsLoader(io.jmix.search.index.queue.EntityIdsLoader) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) EntityManager(javax.persistence.EntityManager) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) EnqueueingSession(io.jmix.search.index.queue.entity.EnqueueingSession) Query(javax.persistence.Query) List(java.util.List) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MetadataTools(io.jmix.core.MetadataTools) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) StoreAwareLocator(io.jmix.data.StoreAwareLocator) MetaClass(io.jmix.core.metamodel.model.MetaClass) ValueLoadContext(io.jmix.core.ValueLoadContext) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 3 with ValueLoadContext

use of io.jmix.core.ValueLoadContext in project jmix by jmix-framework.

the class DataStoreCrudValuesListener method beforeValueLoad.

@Override
public void beforeValueLoad(DataStoreBeforeValueLoadEvent event) {
    ValueLoadContext context = event.getLoadContext();
    LoadValuesAccessContext queryContext = new LoadValuesAccessContext(context.getQuery().getQueryString(), queryTransformerFactory, metadata);
    accessManager.applyConstraints(queryContext, context.getAccessConstraints());
    for (Integer index : queryContext.getDeniedSelectedIndexes()) {
        event.addDeniedProperty(index);
    }
}
Also used : LoadValuesAccessContext(io.jmix.data.accesscontext.LoadValuesAccessContext) ValueLoadContext(io.jmix.core.ValueLoadContext)

Example 4 with ValueLoadContext

use of io.jmix.core.ValueLoadContext in project jmix by jmix-framework.

the class KeyValueCollectionLoaderImpl method createLoadContext.

@Override
public ValueLoadContext createLoadContext() {
    ValueLoadContext loadContext = ValueLoadContext.create();
    loadContext.setStoreName(storeName);
    loadContext.setIdName(container.getIdName());
    for (MetaProperty property : container.getEntityMetaClass().getProperties()) {
        loadContext.addProperty(property.getName());
    }
    ValueLoadContext.Query query = loadContext.setQueryString(this.query);
    query.setCondition(condition);
    query.setSort(sort);
    query.setParameters(parameters);
    if (firstResult > 0)
        query.setFirstResult(firstResult);
    if (maxResults < Integer.MAX_VALUE)
        query.setMaxResults(maxResults);
    loadContext.setHints(hints);
    return loadContext;
}
Also used : ValueLoadContext(io.jmix.core.ValueLoadContext) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 5 with ValueLoadContext

use of io.jmix.core.ValueLoadContext in project jmix by jmix-framework.

the class KeyValueInstanceLoaderImpl method load.

@Override
public void load() {
    if (container == null)
        throw new IllegalStateException("container is null");
    if (query == null && delegate == null)
        throw new IllegalStateException("both query and delegate are null");
    ValueLoadContext loadContext = createLoadContext();
    if (!sendPreLoadEvent(loadContext)) {
        return;
    }
    KeyValueEntity result = null;
    if (delegate == null) {
        List<KeyValueEntity> list = dataManager.loadValues(loadContext);
        if (!list.isEmpty()) {
            result = list.get(0);
        }
    } else {
        result = delegate.apply(loadContext);
    }
    container.setItem(result);
    sendPostLoadEvent(result);
}
Also used : ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Aggregations

ValueLoadContext (io.jmix.core.ValueLoadContext)6 KeyValueEntity (io.jmix.core.entity.KeyValueEntity)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 DataManager (io.jmix.core.DataManager)1 Metadata (io.jmix.core.Metadata)1 MetadataTools (io.jmix.core.MetadataTools)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 StoreAwareLocator (io.jmix.data.StoreAwareLocator)1 LoadValuesAccessContext (io.jmix.data.accesscontext.LoadValuesAccessContext)1 EntityIdsLoader (io.jmix.search.index.queue.EntityIdsLoader)1 EnqueueingSession (io.jmix.search.index.queue.entity.EnqueueingSession)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1