Class GeneralProcessUtils
java.lang.Object
com.kingsrook.qqq.backend.core.processes.utils.GeneralProcessUtils
Utility methods for working with QQQ records and table actions inside user -
defined QQQ processes steps.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addForeignRecordsListToRecordList
(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTableForeignKeyName) For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTableForeignKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.static void
addForeignRecordsToRecordList
(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.static Integer
count
(String tableName, QQueryFilter filter) static <T extends QRecordEntity>
Optional<T> getEntityByField
(String tableName, String fieldName, Serializable fieldValue, Class<T> entityClass) Query to get one entity by a unique key value.static ListingHash
<Serializable, QRecord> getForeignRecordListingHashMap
(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTableForeignKeyName) For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTableForeignKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.static Map
<Serializable, QRecord> getForeignRecordMap
(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName) For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.static Map
<Serializable, QRecord> getForeignRecordMap
(List<QRecord> sourceRecords, String sourceTableForeignKeyFieldName, String foreignTableName, String foreignTablePrimaryKeyName, QQueryFilter additionalFilter) For a list of sourceRecords, lookup records in the foreignTableName, that have their foreignTablePrimaryKeyName in the sourceTableForeignKeyFieldName on the sourceRecords.getRecordByField
(String tableName, String fieldName, Serializable fieldValue) Query to get one record by a unique key value.static QRecord
getRecordByFieldOrElseThrow
(String tableName, String fieldName, Serializable fieldValue) Query to get one record by a unique key value.getRecordByPrimaryKey
(String tableName, Serializable value) Query to get one record by its primary key value.static QRecord
getRecordByPrimaryKeyOrElseThrow
(String tableName, Serializable value) Query to get one record by its primary key value.getRecordListByField
(String tableName, String fieldName, Serializable fieldValue) Run a query on tableName, for where fieldName equals fieldValue, and return the list of QRecords.Load all rows from a table.static <T extends QRecordEntity>
List<T> Load all rows from a table as a RecordEntity.static <T extends QRecordEntity>
List<T> loadTable
(String tableName, Class<T> entityClass, QQueryFilter filter) 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...static ListingHash
<Serializable, QRecord> loadTableToListingHash
(String tableName, String keyFieldName) Load all rows from a table, into a ListingHash, keyed by the keyFieldName.static <T extends Serializable>
Map<T, QRecord> loadTableToMap
(String tableName, Class<T> keyType, String keyFieldName) Load all rows from a table, into a map, keyed by the keyFieldName - typed as the specified keyType.static Map
<Serializable, QRecord> loadTableToMap
(String tableName, String keyFieldName) Load all rows from a table, into a map, keyed by the keyFieldName.static Map
<Serializable, QRecord> loadTableToMap
(String tableName, String keyFieldName, QQueryFilter filter) Load rows from a table matching the specified filter, into a map, keyed by the keyFieldName.static <T extends QRecordEntity>
Map<Serializable, T> loadTableToMap
(String tableName, String keyFieldName, Class<T> entityClass) Note - null values from the key field are NOT put in the map.static <T extends QRecordEntity>
Map<Serializable, T> loadTableToMap
(String tableName, String keyFieldName, Class<T> entityClass, QQueryFilter filter) Load rows from a table matching the specified filter, into a map, keyed by the keyFieldName.static <T extends QRecordEntity>
Map<Serializable, T> loadTableToMap
(String tableName, String keyFieldName, Class<T> entityClass, Consumer<QueryInput> queryInputCustomizer) Note - null values from the key field are NOT put in the map.static <T extends QRecordEntity>
List<T> recordsToEntities
(Class<T> recordEntityClass, List<QRecord> records) static Integer
validateSingleSelectedId
(RunBackendStepInput runBackendStepInput, String tableName) Ensure that a process has been initiated with a single record as input - and get that record id.
-
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
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
- Throws:
QException
-