Class GeneralProcessUtils

java.lang.Object
com.kingsrook.qqq.backend.core.processes.utils.GeneralProcessUtils

public class GeneralProcessUtils extends Object
Utility methods for working with QQQ records and table actions inside user - defined QQQ processes steps.
  • Constructor Details

    • GeneralProcessUtils

      public GeneralProcessUtils()
  • Method Details

    • getForeignRecordMap

      public static Map<Serializable,QRecord> getForeignRecordMap(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) throws QException
      For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords. e.g., for a list of orders (with a clientId field), build a map of client.id => client record via getForeignRecordMap(input, orderList, "clientId", "client", "id")
      Throws:
      QException
    • getForeignRecordMap

      public static Map<Serializable,QRecord> getForeignRecordMap(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName, QQueryFilter additionalFilter) throws QException
      For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords. e.g., for a list of orders (with a clientId field), build a map of client.id => client record via getForeignRecordMap(input, orderList, "clientId", "client", "id")
      Throws:
      QException
    • getForeignRecordListingHashMap

      public static ListingHash<Serializable,QRecord> getForeignRecordListingHashMap(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTableForeignKeyName) throws QException
      For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTableForeignKeyName in the sourceTableForeignKeyFieldName on the sourceRecords. e.g., for a list of orders, build a ListingHash of order.id => List(OrderLine records) via getForeignRecordListingHashMap(input, orderList, "id", "orderLine", "orderId")
      Throws:
      QException
    • addForeignRecordsToRecordList

      public static void addForeignRecordsToRecordList(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) throws QException
      For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords. and set those foreign records as a value in the sourceRecords. e.g., for a list of orders (with a clientId field), setValue("client", QRecord(client)); via addForeignRecordsToRecordList(input, orderList, "clientId", "client", "id")
      Throws:
      QException
    • addForeignRecordsListToRecordList

      public static void addForeignRecordsListToRecordList(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTableForeignKeyName) throws QException
      For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTableForeignKeyName in the sourceTableForeignKeyFieldName on the sourceRecords. e.g., for a list of orders, setValue("orderLine", List(QRecord(orderLine))) via addForeignRecordsListToRecordList(input, orderList, "id", "orderLine", "orderId")
      Throws:
      QException
    • getRecordListByField

      public static List<QRecord> getRecordListByField(String tableName, String fieldName, Serializable fieldValue) throws QException
      Run a query on tableName, for where fieldName equals fieldValue, and return the list of QRecords.
      Throws:
      QException
    • getRecordByField

      public static Optional<QRecord> getRecordByField(String tableName, String fieldName, Serializable fieldValue) throws QException
      Query to get one record by a unique key value. That field can be the primary key, or any other field on the table. Note, if multiple rows do match the value, only 1 (determined in an unspecified way) is returned.
      Throws:
      QException
    • getEntityByField

      public static <T extends QRecordEntity> Optional<T> getEntityByField(String tableName, String fieldName, Serializable fieldValue, Class<T> entityClass) throws QException
      Query to get one entity by a unique key value. That field can be the primary key, or any other field on the table. Note, if multiple rows do match the value, only 1 (determined in an unspecified way) is returned.
      Throws:
      QException
    • getRecordByFieldOrElseThrow

      public static QRecord getRecordByFieldOrElseThrow(String tableName, String fieldName, Serializable fieldValue) throws QException
      Query to get one record by a unique key value.
      Throws:
      QException
    • getRecordByPrimaryKey

      public static Optional<QRecord> getRecordByPrimaryKey(String tableName, Serializable value) throws QException
      Query to get one record by its primary key value.
      Throws:
      QException
    • getRecordByPrimaryKeyOrElseThrow

      public static QRecord getRecordByPrimaryKeyOrElseThrow(String tableName, Serializable value) throws QException
      Query to get one record by its primary key value.
      Throws:
      QException
    • loadTable

      public static List<QRecord> loadTable(String tableName) throws QException
      Load all rows from a table. Note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • loadTable

      public static <T extends QRecordEntity> List<T> loadTable(String tableName, Class<T> entityClass) throws QException
      Load all rows from a table as a RecordEntity. Note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • loadTable

      public static <T extends QRecordEntity> List<T> loadTable(String tableName, Class<T> entityClass, QQueryFilter filter) throws QException
      Load all rows from a table as a RecordEntity, takes in a filter as well Note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • loadTableToMap

      public static Map<Serializable,QRecord> loadTableToMap(String tableName, String keyFieldName) throws QException
      Load all rows from a table, into a map, keyed by the keyFieldName. Note - null values from the key field are NOT put in the map. If multiple values are found for the key, they'll squash each other, and only one random value will appear. Also, note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • loadTableToMap

      public static <T extends QRecordEntity> Map<Serializable,T> loadTableToMap(String tableName, String keyFieldName, Class<T> entityClass, QQueryFilter filter) throws QException
      Load rows from a table matching the specified filter, into a map, keyed by the keyFieldName. Note - null values from the key field are NOT put in the map. If multiple values are found for the key, they'll squash each other, and only one (random) value will appear.
      Throws:
      QException
    • loadTableToMap

      public static Map<Serializable,QRecord> loadTableToMap(String tableName, String keyFieldName, QQueryFilter filter) throws QException
      Load rows from a table matching the specified filter, into a map, keyed by the keyFieldName. Note - null values from the key field are NOT put in the map. If multiple values are found for the key, they'll squash each other, and only one (random) value will appear.
      Throws:
      QException
    • loadTableToMap

      public static <T extends Serializable> Map<T,QRecord> loadTableToMap(String tableName, Class<T> keyType, String keyFieldName) throws QException
      Load all rows from a table, into a map, keyed by the keyFieldName - typed as the specified keyType. Note - null values from the key field are NOT put in the map. If multiple values are found for the key, they'll squash each other, and only one random value will appear. Also, note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • loadTableToMap

      public static <T extends QRecordEntity> Map<Serializable,T> loadTableToMap(String tableName, String keyFieldName, Class<T> entityClass) throws QException
      Note - null values from the key field are NOT put in the map.
      Throws:
      QException
    • loadTableToMap

      public static <T extends QRecordEntity> Map<Serializable,T> loadTableToMap(String tableName, String keyFieldName, Class<T> entityClass, Consumer<QueryInput> queryInputCustomizer) throws QException
      Note - null values from the key field are NOT put in the map.
      Throws:
      QException
    • loadTableToListingHash

      public static ListingHash<Serializable,QRecord> loadTableToListingHash(String tableName, String keyFieldName) throws QException
      Load all rows from a table, into a ListingHash, keyed by the keyFieldName. Note - null values from the key field are NOT put in the map. The ordering of the records is not specified. Also, note, this is inherently unsafe, if you were to call it on a table with too many rows... Caveat emptor.
      Throws:
      QException
    • validateSingleSelectedId

      public static Integer validateSingleSelectedId(RunBackendStepInput runBackendStepInput, String tableName) throws QException
      Ensure that a process has been initiated with a single record as input - and get that record id.
      Throws:
      QException
    • recordsToEntities

      public static <T extends QRecordEntity> List<T> recordsToEntities(Class<T> recordEntityClass, List<QRecord> records) throws QException
      Throws:
      QException
    • count

      public static Integer count(String tableName, QQueryFilter filter) throws QException
      Throws:
      QException