diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/utils/GeneralProcessUtils.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/utils/GeneralProcessUtils.java index a76fe9b0..a3e81f44 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/utils/GeneralProcessUtils.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/utils/GeneralProcessUtils.java @@ -343,6 +343,36 @@ public class GeneralProcessUtils + /******************************************************************************* + ** 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. + *******************************************************************************/ + public static Map loadTableToMap(String tableName, String keyFieldName, Class entityClass, QQueryFilter filter) throws QException + { + QueryInput queryInput = new QueryInput(); + queryInput.setTableName(tableName); + queryInput.setFilter(filter); + QueryOutput queryOutput = new QueryAction().execute(queryInput); + List records = queryOutput.getRecords(); + + Map map = new HashMap<>(); + for(QRecord record : records) + { + Serializable value = record.getValue(keyFieldName); + if(value != null) + { + map.put(value, QRecordEntity.fromQRecord(entityClass, record)); + } + } + return (map); + } + + + /******************************************************************************* ** Load rows from a table matching the specified filter, into a map, keyed by the keyFieldName. ** @@ -412,7 +442,7 @@ public class GeneralProcessUtils *******************************************************************************/ public static Map loadTableToMap(String tableName, String keyFieldName, Class entityClass) throws QException { - return (loadTableToMap(tableName, keyFieldName, entityClass, null)); + return (loadTableToMap(tableName, keyFieldName, entityClass, (Consumer) null)); }