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);
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations