You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@gmail.com> on 2007/10/21 20:33:30 UTC

microsling: Automatic JCR Session save or refresh

Hi all,

In SLING-73 [1], Lars Trieloff raises the question whether the JCR
Session should automatically be saved or refreshed by the ScriptSelector
after a script has run. His position is, that this might easily be
forgotten and most people would want such a behaviour.

I on the other hand think, that the decision to persist or not any
changes and the point in time of taking this decision and persiting or
not the changes are completely up to the script and the ScriptSelector
cannot and should not take an active role in this game. On the other
hand, the session should probably be refreshed (or logged out) at the
end of processing a request to cleanup and unsaved changes.

I think, we can place the responsibility to persist changes on the
shoulders of the script programmer just as it is done in SQL where
generally a transaction must be commited.

Along the lines of SQL, we could discuss whether we add support to the
SlingRequestContext to save/refresh the session at the end of request
processing depending on success or failure of the request if setting a
flag:

   SlingRequestContext.setAutoSave(boolean);

By default a session would always be refreshed, by calling
setAutoSave(true), the Session might be saved before logging it out in
case of a successfull (HTTP status 200, no exceptions thrown) request.

WDYT ?

Regards
Felix


[1] https://issues.apache.org/jira/browse/SLING-73


Re: microsling: Automatic JCR Session save or refresh

Posted by Lars Trieloff <la...@trieloff.net>.
Hi Felix, thanks for bringing this discussion to the list.

from my point of view, the script developer should have full control  
about when to persist or rollback the changes made to the session,  
but the default case should be as convenient as possible. So I think  
the proposed API addition is a good idea.

SlingRequestContext.setAutoSave(boolean);

This autoSave should be executed only when following conditions are met:
- the reqeuest method is not save (POST, PUT or something user-defined)
- the response code is 2**

The question for me is where this SlingRequestContext.setAutoSave 
(boolean); method should be called? In the script. In this case, I  
think it is easier to call session.save() or session.refresh()  
directly in the script.

If a script author wants to deviate from the default behavior, she  
just has to call session.refresh(false) as soon as the error case is  
detected or session.save() after the response status has been set or  
before the execption is thrown.

Lars


Am 21.10.2007 um 20:33 schrieb Felix Meschberger:

> Hi all,
>
> In SLING-73 [1], Lars Trieloff raises the question whether the JCR
> Session should automatically be saved or refreshed by the  
> ScriptSelector
> after a script has run. His position is, that this might easily be
> forgotten and most people would want such a behaviour.
>
> I on the other hand think, that the decision to persist or not any
> changes and the point in time of taking this decision and persiting or
> not the changes are completely up to the script and the ScriptSelector
> cannot and should not take an active role in this game. On the other
> hand, the session should probably be refreshed (or logged out) at the
> end of processing a request to cleanup and unsaved changes.
>
> I think, we can place the responsibility to persist changes on the
> shoulders of the script programmer just as it is done in SQL where
> generally a transaction must be commited.
>
> Along the lines of SQL, we could discuss whether we add support to the
> SlingRequestContext to save/refresh the session at the end of request
> processing depending on success or failure of the request if setting a
> flag:
>
>    SlingRequestContext.setAutoSave(boolean);
>
> By default a session would always be refreshed, by calling
> setAutoSave(true), the Session might be saved before logging it out in
> case of a successfull (HTTP status 200, no exceptions thrown) request.
>
> WDYT ?
>
> Regards
> Felix
>
>
> [1] https://issues.apache.org/jira/browse/SLING-73
>