• Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Trunk
    • Fix Version/s: 14.12.01
    • Component/s: framework
    • Labels:


      As discussed on the dev list here:

      Attached is an initial implementation of builder classes (of sorts) that make use of method chaining in order to simplify use of the Delegator interface to query entities.

      Rather than taking all possible query parameters into a single method as the delegator does, this implementation instead builds a query through a succession of distinct method calls.

      A simple example:

      // Using the Delegator interface directly
      eli = delegator.find("FinAccountTrans", condition, null, null, UtilMisc.toList("-transactionDate"), null);
      // Using the new implementation
      eli = EntityBuilderUtil.list(delegator).from("FinAccountTrans").where(condition).orderBy("-transactionDate").iterator();

      A more complex example:

      // Delegator
      EntityCondition queryConditionsList = EntityCondition.makeCondition(allConditions, EntityOperator.AND);
      EntityFindOptions options = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
      options.setMaxRows(viewSize * (viewIndex + 1));
      EntityListIterator iterator = delegator.find("OrderHeader", queryConditionsList, null, null, UtilMisc.toList("orderDate DESC"), options);
      // becomes
      EntityListIterator iterator = EntityBuilderUtil.list(delegator).distinct()
                                                                     .orderBy("orderDate DESC")
                                                                     .maxRows(viewSize * (viewIndex + 1))

      A couple of issues with the implementation so far that I'm not entirely happy with:

      • I'm not so sure that I like EntityBuilderUtil.list(delegator) in place of something like EntityList.use(delegator). The latter requires less typing and I think is more intuitive than typing EntityBuilderUtil because of its similarities to the corresponding minilang method calls, I actually kept having trouble remembering what it was called when converting some delegator calls over. It also requires a little more typing (16-17 characters vs. 12-13), not a big deal but every little bit helps with what would be a very commonly used class.
      • I'm struggling to see the point of having the GenericQueryBuilder interface, the two classes share very little in the way of API and its use seems a little superfluous to me.

      Opinions on the above points or anything else to do with the implementation are most welcome. I'd like to get the API locked down (and hopefully some javadocs in place) before committing.

      1. builder.patch
        18 kB
        Scott Gray
      2. builder.patch
        18 kB
        Scott Gray
      3. builder.patch
        15 kB
        Scott Gray

        Issue Links


          Jacques Le Roux made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Arun Patidar made changes -
          Link This issue is related to OFBIZ-5844 [ OFBIZ-5844 ]
          Scott Gray made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Fix Version/s Upcoming Branch [ 12327361 ]
          Resolution Fixed [ 1 ]
          Scott Gray made changes -
          Attachment builder.patch [ 12669162 ]
          Scott Gray made changes -
          Attachment builder.patch [ 12669026 ]
          Scott Gray made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Scott Gray made changes -
          Field Original Value New Value
          Attachment builder.patch [ 12465971 ]
          Scott Gray created issue -


            • Assignee:
              Scott Gray
              Scott Gray
            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: