You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Angela Schreiber (Jira)" <ji...@apache.org> on 2022/07/13 14:14:00 UTC

[jira] [Updated] (OAK-9819) Improve Node.hasProperty/getProperty and Node.hasNode/getNode combinations

     [ https://issues.apache.org/jira/browse/OAK-9819?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Angela Schreiber updated OAK-9819:
----------------------------------
    Fix Version/s: 1.44.0

> Improve Node.hasProperty/getProperty and Node.hasNode/getNode combinations
> --------------------------------------------------------------------------
>
>                 Key: OAK-9819
>                 URL: https://issues.apache.org/jira/browse/OAK-9819
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: jackrabbit-api, jcr
>    Affects Versions: 1.42.0
>            Reporter: Joerg Hoh
>            Priority: Major
>             Fix For: 1.44.0
>
>         Attachments: OAK-9819.patch
>
>
> In many applications using JCR I see this pattern:
> {noformat:title=application code v1}
> if (jcrNode.hasProperty(PROP) {
>   value = jcrNode.getProperty(PROP);
> }
> {noformat}
> I checked the implementation behind and found that Oak's NodeImpl implements {{hasProperty}} almost identical to the {{getProperty}} with 
> {noformat}
> node.getPropertyOrNull(oakPath) != null;
> {noformat}
> That means that the above mentioned JCR code snippet invokes {{node.getPropertyOrNull}} twice. This could be improved by exposing a new method {{getPropertyOrNull}}, in which the above code could be written like this:
> {noformat:title=application code v2}
> tmpProp = jcrNode.getPropertyOrNull(PROP);
> if (tmpProp != null) {
>   value = tmpProp;
> }
> {noformat}
> In this case there just the {{jcrNode.getPropertyOrNull}} method would do a single call into call, saving us the overhead of a second if the property is there.
> Of course this cannot go into the JCR Node interface, but we could extend the {{JackrabbitNode}} with this.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)