mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
SPRINT-15: added methods to get lists and maps of record entities
This commit is contained in:
@ -37,6 +37,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
|
||||
import com.kingsrook.qqq.backend.core.utils.ListingHash;
|
||||
|
||||
|
||||
@ -203,6 +204,30 @@ public class GeneralProcessUtils
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** 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.
|
||||
*******************************************************************************/
|
||||
public static <T extends QRecordEntity> List<T> loadTable(AbstractActionInput parentActionInput, String tableName, Class<T> entityClass) throws QException
|
||||
{
|
||||
QueryInput queryInput = new QueryInput(parentActionInput.getInstance());
|
||||
queryInput.setSession(parentActionInput.getSession());
|
||||
queryInput.setTableName(tableName);
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
|
||||
List<T> rs = new ArrayList<>();
|
||||
for(QRecord record : queryOutput.getRecords())
|
||||
{
|
||||
rs.add(QRecordEntity.fromQRecord(entityClass, record));
|
||||
}
|
||||
|
||||
return (rs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Load all rows from a table, into a map, keyed by the keyFieldName.
|
||||
**
|
||||
@ -236,6 +261,31 @@ public class GeneralProcessUtils
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Note - null values from the key field are NOT put in the map.
|
||||
*******************************************************************************/
|
||||
public static <T extends QRecordEntity> Map<Serializable, T> loadTableToMap(AbstractActionInput parentActionInput, String tableName, String keyFieldName, Class<T> entityClass) throws QException
|
||||
{
|
||||
QueryInput queryInput = new QueryInput(parentActionInput.getInstance());
|
||||
queryInput.setSession(parentActionInput.getSession());
|
||||
queryInput.setTableName(tableName);
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
List<QRecord> records = queryOutput.getRecords();
|
||||
|
||||
Map<Serializable, T> 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 all rows from a table, into a ListingHash, keyed by the keyFieldName.
|
||||
**
|
||||
|
Reference in New Issue
Block a user