[ 
https://issues.apache.org/jira/browse/JCR-2714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12898138#action_12898138
 ] 

Jukka Zitting commented on JCR-2714:
------------------------------------

The exact mechanism of how this is done can be debated, but I think it's a 
great idea that we could selectively relax constraint checks for trusted code 
inside jackrabbit-core. Something like this has the power to significantly 
simplify many parts of our codebase and avoid extra constructs like NodeStateEx 
or ProtectedItemModifier.

As an example, consider the current code snippet:

    PropertyState propState;
    if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
        propState = stateMgr.createNew(NameConstants.JCR_LOCKOWNER, nodeId);
        propState.setType(PropertyType.STRING);
        propState.setMultiValued(false);
    } else {
        propState = (PropertyState) stateMgr.getItemState(new 
PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
    }
    propState.setValues(new InternalValue[] { InternalValue.create(lockOwner) 
});
    nodeState.addPropertyName(NameConstants.JCR_LOCKOWNER);
    stateMgr.store(nodeState);

With a solution like the one Michael is proposing, this could be simplified to:

    node.setProperty(Property.JCR_LOCKOWNER, lockOwner);

I truly hope we'll find a consensus on how to implement this!


> Selective disabling of checks in ItemValidator
> ----------------------------------------------
>
>                 Key: JCR-2714
>                 URL: https://issues.apache.org/jira/browse/JCR-2714
>             Project: Jackrabbit Content Repository
>          Issue Type: Improvement
>          Components: jackrabbit-core
>    Affects Versions: 2.2.0
>            Reporter: Michael Dürig
>            Assignee: Michael Dürig
>         Attachments: JCR-2714.patch
>
>
> I would like to be able to selectively disable checks in ItemValidator in the 
> scope of an operation performed through methods of the SessionState class. 
> Doing so would provide simple means for internally modifying (for example) 
> protected items. Currently such modifications must be done 'manually' on the 
> item state level. This approach is very error prone and not very DRY.
> With my upcoming patch in place, setting a protected property would look like 
> this:
> final Node parent = ...
> final Value value = ...
> SessionState sessionState = sessionContext.getSessionState();
> Property property = sessionState.performUnchecked(new 
> SessionOperation<Property>() {
>     public Property perform(SessionContext context) throws 
> RepositoryException {
>         return parent.setProperty("foo", value);
>     }
> }, ItemValidator.CHECK_CONSTRAINTS);
> That is, users need to have access to the session context in order to disable 
> checks which makes this only usable from inside Jackrabbit. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to