use of com.evolveum.midpoint.repo.sqlbase.SqlQueryContext in project midpoint by Evolveum.
the class QOperationExecutionMapping method createRowTransformer.
@Override
public ResultListRowTransformer<OperationExecutionType, QOperationExecution<OR>, MOperationExecution> createRowTransformer(SqlQueryContext<OperationExecutionType, QOperationExecution<OR>, MOperationExecution> sqlQueryContext, JdbcSession jdbcSession) {
Map<UUID, ObjectType> owners = new HashMap<>();
return new ResultListRowTransformer<>() {
@Override
public void beforeTransformation(List<Tuple> rowTuples, QOperationExecution<OR> entityPath) throws SchemaException {
Set<UUID> ownerOids = rowTuples.stream().map(row -> Objects.requireNonNull(row.get(entityPath)).ownerOid).collect(Collectors.toSet());
// TODO do we need get options here as well? Is there a scenario where we load container
// and define what to load for referenced/owner object?
QObject<?> o = QObjectMapping.getObjectMapping().defaultAlias();
List<Tuple> result = jdbcSession.newQuery().select(o.oid, o.fullObject).from(o).where(o.oid.in(ownerOids)).fetch();
for (Tuple row : result) {
UUID oid = Objects.requireNonNull(row.get(o.oid));
ObjectType owner = parseSchemaObject(row.get(o.fullObject), oid.toString(), ObjectType.class);
owners.put(oid, owner);
}
}
@Override
public OperationExecutionType transform(Tuple rowTuple, QOperationExecution<OR> entityPath, Collection<SelectorOptions<GetOperationOptions>> options) {
MOperationExecution row = Objects.requireNonNull(rowTuple.get(entityPath));
ObjectType object = Objects.requireNonNull(owners.get(row.ownerOid), () -> "Missing owner with OID " + row.ownerOid + " for OperationExecution with ID " + row.cid);
PrismContainer<OperationExecutionType> opexContainer = object.asPrismObject().findContainer(ObjectType.F_OPERATION_EXECUTION);
if (opexContainer == null) {
throw new SystemException("Object " + object + " has no operation execution as expected from " + row);
}
PrismContainerValue<OperationExecutionType> pcv = opexContainer.findValue(row.cid);
if (pcv == null) {
throw new SystemException("Object " + object + " has no operation execution with ID " + row.cid);
}
return pcv.asContainerable();
}
};
}
Aggregations