Uploaded image for project: 'Jackrabbit Oak'
  1. Jackrabbit Oak
  2. OAK-9819

Improve Node.hasProperty/getProperty and Node.hasNode/getNode combinations

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.42.0
    • 1.44.0, 1.22.15
    • jackrabbit-api, jcr
    • None

    Description

      In many applications using JCR I see this pattern:

      application code v1
      if (jcrNode.hasProperty(PROP) {
        value = jcrNode.getProperty(PROP);
      }
      

      I checked the implementation behind and found that Oak's NodeImpl implements hasProperty almost identical to the getProperty with

      node.getPropertyOrNull(oakPath) != null;
      

      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:

      application code v2
      tmpProp = jcrNode.getPropertyOrNull(PROP);
      if (tmpProp != null) {
        value = tmpProp;
      }
      

      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.

      Attachments

        1. OAK-9819.patch
          3 kB
          Angela Schreiber

        Issue Links

          Activity

            People

              angela Angela Schreiber
              joerghoh Joerg Hoh
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: