Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected boolean _load() {

LoadContext<E> loadContext = createLoadContext();

if (!sendPreLoadEvent(loadContext)) {
if (sendPreLoadEvent(loadContext)) {
return false;
}

Expand Down Expand Up @@ -192,17 +192,15 @@ public LoadContext<E> createLoadContext() {
* @return true if duplicate results are possible, false otherwise
*/
protected boolean canLeadToDuplicateResultsRecursive(Condition condition) {
if (condition instanceof LogicalCondition) {
LogicalCondition logicalCondition = (LogicalCondition) condition;
if (condition instanceof LogicalCondition logicalCondition) {
for (Condition childCondition : logicalCondition.getConditions()) {
boolean duplicatesPossible = canLeadToDuplicateResultsRecursive(childCondition);
if (duplicatesPossible) {
return true;
}
}
return false;
} else if (condition instanceof PropertyCondition) {
PropertyCondition propertyCondition = (PropertyCondition) condition;
} else if (condition instanceof PropertyCondition propertyCondition) {
MetaPropertyPath mpp = container.getEntityMetaClass().getPropertyPath(propertyCondition.getProperty());
if (mpp == null) {
return false;
Expand All @@ -220,15 +218,13 @@ protected boolean canLeadToDuplicateResultsRecursive(Condition condition) {
}
}

@Nullable
protected FetchPlan resolveFetchPlan() {
FetchPlan fp = this.fetchPlan;
if (fp == null && fetchPlanName != null) {
fp = fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName);
}
if (fp == null) {
fp = container.getFetchPlan();
}
return fp;
if (this.fetchPlan != null) return this.fetchPlan;

return fetchPlanName != null
? fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName)
: container.getFetchPlan();
}

protected boolean sendPreLoadEvent(LoadContext<E> loadContext) {
Expand All @@ -241,7 +237,7 @@ protected boolean sendPreLoadEvent(LoadContext<E> loadContext) {
DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this);
stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.PRE_LOAD, info);

return !preLoadEvent.isLoadPrevented();
return preLoadEvent.isLoadPrevented();
}

protected void sendPostLoadEvent(List<E> entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,50 +98,38 @@ public void load() {
if (container == null)
throw new IllegalStateException("container is null");

E entity;

LoadContext<E> loadContext = createLoadContext();

if (!needLoad())
if (sendPreLoadEvent(loadContext)) {
return;
}

if (loadFromRepositoryDelegate == null && delegate == null) {
if (!sendPreLoadEvent(loadContext)) {
return;
}
E entity;

Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry);
Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry);

if (loadFromRepositoryDelegate != null) {
entity = loadFromRepositoryDelegate
.apply(entityId, resolveFetchPlan())
.orElse(null);
} else if (delegate != null) {
entity = delegate.apply(loadContext);
} else {
if (skipLoading()) return;
entity = dataManager.load(loadContext);
}

DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this);
UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info);
DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this);
UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info);

if (entity == null) {
throw new EntityAccessException(container.getEntityMetaClass(), entityId);
}
} else {
if (!sendPreLoadEvent(loadContext)) {
if (entity == null) {
if (loadFromRepositoryDelegate != null || delegate != null) {
return;
}

Timer.Sample sample = UiMonitoring.startTimerSample(meterRegistry);

if (loadFromRepositoryDelegate != null) {
entity = loadFromRepositoryDelegate.apply(entityId, resolveFetchPlan()).orElse(null);
} else {
entity = delegate.apply(createLoadContext());
}

DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this);
UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.LOAD, info);

if (entity == null) {
return;
throw new EntityAccessException(container.getEntityMetaClass(), entityId);
}
}


if (dataContext != null) {
entity = dataContext.merge(entity, new MergeOptions().setFresh(true));
}
Expand All @@ -150,8 +138,8 @@ public void load() {
sendPostLoadEvent(entity);
}

protected boolean needLoad() {
return entityId != null || !Strings.isNullOrEmpty(query);
protected boolean skipLoading() {
return entityId == null & Strings.isNullOrEmpty(query);
}

/**
Expand All @@ -162,7 +150,7 @@ protected boolean needLoad() {
public LoadContext<E> createLoadContext() {
Class<E> entityClass = container.getEntityMetaClass().getJavaClass();

LoadContext<E> loadContext = new LoadContext(metadata.getClass(entityClass));
LoadContext<E> loadContext = new LoadContext<>(metadata.getClass(entityClass));

if (entityId != null) {
loadContext.setId(entityId);
Expand All @@ -179,15 +167,13 @@ public LoadContext<E> createLoadContext() {
return loadContext;
}

@Nullable
protected FetchPlan resolveFetchPlan() {
FetchPlan fp = this.fetchPlan;
if (fp == null && fetchPlanName != null) {
fp = fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName);
}
if (fp == null) {
fp = container.getFetchPlan();
}
return fp;
if (this.fetchPlan != null) return this.fetchPlan;

return fetchPlanName != null
? fetchPlanRepository.getFetchPlan(container.getEntityMetaClass(), fetchPlanName)
: container.getFetchPlan();
}

protected boolean sendPreLoadEvent(LoadContext<E> loadContext) {
Expand All @@ -200,7 +186,7 @@ protected boolean sendPreLoadEvent(LoadContext<E> loadContext) {
DataLoaderMonitoringInfo info = monitoringInfoProvider.apply(this);
UiMonitoring.stopDataLoaderTimerSample(sample, meterRegistry, DataLoaderLifeCycle.PRE_LOAD, info);

return !preLoadEvent.isLoadPrevented();
return preLoadEvent.isLoadPrevented();
}

protected void sendPostLoadEvent(E entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JmixImageTestView extends StandardView {
@Subscribe
public void onReady(ReadyEvent event) {
DocumentAttachment attachment = metadata.create(DocumentAttachment.class);
attachment.setPreview(RandomUtils.nextBytes(1));
attachment.setPreview(RandomUtils.secure().randomBytes(1));
documentAttachmentDc.setItem(attachment);
}
}