Class QRecordWithJoinedRecords

java.lang.Object
com.kingsrook.qqq.backend.core.model.data.QRecord
com.kingsrook.qqq.backend.core.model.data.QRecordWithJoinedRecords
All Implemented Interfaces:
Serializable

public class QRecordWithJoinedRecords extends QRecord
Extension on QRecord, intended to be used where you've got records from multiple tables, and you want to combine them into a single "wide" joined record - but to do so without copying or modifying any of the individual records. e.g., given: - Order (id, orderNo, orderDate) (main table) - LineItem (id, sku, quantity) - Extrinsic (id, key, value) If set up in here as: - new QRecordWithJoinedRecords(order) .withJoinedRecordValues(lineItem) .withJoinedRecordValues(extrinsic) Then we'd have the appearance of values in the object like: - id, orderNo, orderDate, lineItem.id, lineItem.sku, lineItem.quantity, extrinsic.id, extrinsic.key, extrinsic.value Which, by the by, is how a query that returns joined records looks, and, is what BackendQueryFilterUtils can use to do filter. This is done without copying or mutating any of the records (which, if you just use QRecord.withJoinedRecordValues, then those values are copied into the main record) - because this object is just storing references to the input records. Note that this implies that, values changed in this record (e.g, calls to setValue) WILL impact the underlying records!
See Also:
  • Constructor Details

    • QRecordWithJoinedRecords

      public QRecordWithJoinedRecords(QRecord mainRecord)
  • Method Details

    • addJoinedRecordValues

      public void addJoinedRecordValues(String joinTableName, QRecord joinedRecord)
      Description copied from class: QRecord
      copy all values from 'joinedRecord' into this record's values map, prefixing field names with joinTableNam + "."
      Overrides:
      addJoinedRecordValues in class QRecord
    • withJoinedRecordValues

      public QRecordWithJoinedRecords withJoinedRecordValues(QRecord record, String joinTableName)
    • getValue

      public Serializable getValue(String fieldName)
      Description copied from class: QRecord
      Getter for a single field's value
      Overrides:
      getValue in class QRecord
    • setValue

      public void setValue(String fieldName, Object value)
      Description copied from class: QRecord
      Added when QRecords got exposed in scripts, and passing a constant String raised a class-cast exception, because it was some nashorn non-serializable type (though once inside *this* method, the value was a java.lang.String...)
      Overrides:
      setValue in class QRecord
    • setValue

      public void setValue(String fieldName, Serializable value)
      Overrides:
      setValue in class QRecord
    • removeValue

      public void removeValue(String fieldName)
      Overrides:
      removeValue in class QRecord
    • getValues

      public Map<String,Serializable> getValues()
      Description copied from class: QRecord
      Getter for values
      Overrides:
      getValues in class QRecord
    • getAssociatedRecords

      public Map<String,List<QRecord>> getAssociatedRecords()
      Description copied from class: QRecord
      Getter for associatedRecords
      Overrides:
      getAssociatedRecords in class QRecord
    • withAssociatedRecord

      public QRecord withAssociatedRecord(String name, QRecord associatedRecord)
      Description copied from class: QRecord
      Fluent setter for associatedRecord
      Overrides:
      withAssociatedRecord in class QRecord
    • withAssociatedRecords

      public QRecord withAssociatedRecords(Map<String,List<QRecord>> associatedRecords)
      Description copied from class: QRecord
      Fluent setter for associatedRecords
      Overrides:
      withAssociatedRecords in class QRecord
    • setAssociatedRecords

      public void setAssociatedRecords(Map<String,List<QRecord>> associatedRecords)
      Description copied from class: QRecord
      Setter for associatedRecords
      Overrides:
      setAssociatedRecords in class QRecord
    • withAssociatedRecords

      public QRecord withAssociatedRecords(String name, List<QRecord> associatedRecords)
      Description copied from class: QRecord
      Fluent setter for associatedRecords
      Overrides:
      withAssociatedRecords in class QRecord
    • buildCrossProduct

      public List<QRecordWithJoinedRecords> buildCrossProduct(String joinTable, List<QRecord> joinRecordList)
      Given an object of this type (`this`), add a list of join-records to it, producing a new list, which is `this` × joinRecordList. One may want to use this in a loop to build a larger cross product - more to come here in that spirit.
      Parameters:
      joinTable - name of the join table (e.g., to prefix the join fields)
      joinRecordList - list of join records. may not be null. may be 0+ size.
      Returns:
      list of new QRecordWithJoinedRecords, based on `this` with each joinRecord added (e.g., output list is same size as joinRecordList). Note that does imply an 'inner' style join - where - if the joinRecordList is empty, you'll get back an empty list!