on 08-23-2016 5:44 PM
What does local view mean? Is there any "global" view? Let's see this method (from de/hybris/platform/catalog/impl/DefaultCatalogVersionService.java:181):
@Override
public Collection<CatalogVersionModel> getAllReadableCatalogVersions(final PrincipalModel principal)
{
ServicesUtil.validateParameterNotNull(principal, "Parameter 'principal' must not be null");
final Collection<CatalogVersionModel> readableCatalogVersions = (Collection<CatalogVersionModel>) getSessionService()
.executeInLocalView(new SessionExecutionBody()
{
@Override
public Object execute()
{
try
{
searchRestrictionService.disableSearchRestrictions();
return catalogVersionDao.findReadableCatalogVersions(principal);
}
finally
{
searchRestrictionService.enableSearchRestrictions();
}
}
});
return readableCatalogVersions;
}
What changes if I rewrite it this way:
@Override
public Collection<CatalogVersionModel> getAllReadableCatalogVersions(final PrincipalModel principal)
{
ServicesUtil.validateParameterNotNull(principal, "Parameter 'principal' must not be null");
final Collection<CatalogVersionModel> readableCatalogVersions = (Collection<CatalogVersionModel>) getSessionService()
try
{
searchRestrictionService.disableSearchRestrictions();
return catalogVersionDao.findReadableCatalogVersions(principal);
}
finally
{
searchRestrictionService.enableSearchRestrictions();
}
return readableCatalogVersions;
}
As far as I know whenever the code is being executed JaloSession and consequently SessionContext exists and it will be used when needed. I suppose that this method can be used to do something on behalf of another user but it does not make any sense for me to specify that the code has to be executed in a "local view". What does that mean? Why we need this?
I believe it makes a copy of your current session context.
The session context could be used by multiple threads at the same time and you don't want your changes to unexpectedly change things running in another thread. This way you make the change just for the running thread and roll it back again afterwards (even if there was an exception)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
executeInLocalView is useful if you need to execute some code, for example run a flexible search query, in the context of a different user, than the logged in user. Or with disabled search restrictions. in other words: you bypass restrictions for the logged in user for specific purposes.
See also:
https://wiki.hybris.com/display/forum/Difference+between+normal+flexisearch+and+executeInLocalView
https://answers.sap.com/questions/12757402/execute-flexible-query-in-admin-context.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When a web request is being executed, the controller, facades, services, and DAOs are executing in the context of the logged-in user (or the anonymous user). When a cron job executes, this is not true. Sometimes you need to execute something in a cron job in the context of a user, such as recalculate the cart when there is user-specific pricing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.