Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0-RC1
    • Component/s: None
    • Labels:
      None

      Description

      I have this OCL fragment as a finder query on an operation called
      "findValidByUser" of entity "MedicalCertificate":

      context MedicalCertificate::findValidByUser(userId:Long,date:Date) :
      Collection(MedicalCertificate) body findValidByUser :
      allInstances->select(certificate | certificate.user.id = userId and
      certificate.validityStart <= date and certificate.validityEnd >= date)

      note how there are two parameters to that operation, while I use them
      three times in total (userId is used once, and date is used twice)

      this translates into something like this (query + spring generated code):

      QUERY:
      ------
      from be.sylis.vw.akvdt.medicalcertificate.MedicalCertificate as
      certificate where certificate.user.id = ? certificate.validityStart > ? or
      certificate.validityEnd < ?", userId, date)

      JAVA:


      public List findValidByUser(...)
      {
      ...
      queryObject.setParameter(0, userId);
      queryObject.setParameter(1, date);
      ...

      IMHO it would be a better idea to do this instead:

      (in the query the question marks are replaced by the parameter names
      prefixed with a colon)

      (in the java code the parameter substitution is updated to reflect the
      change in the query)

      QUERY:
      ------
      from be.sylis.vw.akvdt.medicalcertificate.MedicalCertificate as
      certificate where certificate.user.id = :userId certificate.validityStart
      > :date or certificate.validityEnd < :date", userId, date)

      JAVA:


      public List findValidByUser(...)
      {
      ...
      queryObject.setLong("userId", userId);
      queryObject.setDate("date", date);
      ...

      doing so is IMO more inline with the OCL code, and it allows us to
      logically reuse parameters in the query itself

        Attachments

          Activity

            People

            • Assignee:
              chad Chad Brandon
              Reporter:
              wouter Wouter Zoons
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: