use of com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer in project midpoint by Evolveum.
the class QAuditEventRecordMapping method createRowTransformer.
@Override
public ResultListRowTransformer<AuditEventRecordType, QAuditEventRecord, MAuditEventRecord> createRowTransformer(SqlQueryContext<AuditEventRecordType, QAuditEventRecord, MAuditEventRecord> sqlQueryContext, JdbcSession jdbcSession) {
return new ResultListRowTransformer<>() {
@Override
public void beforeTransformation(List<Tuple> rowTuples, QAuditEventRecord entityPath) {
if (rowTuples.isEmpty()) {
return;
}
Instant minTimestamp = Instant.MAX;
Instant maxTimestamp = Instant.MIN;
Map<Long, MAuditEventRecord> rowMap = new HashMap<>();
for (Tuple rowTuple : rowTuples) {
MAuditEventRecord row = Objects.requireNonNull(rowTuple.get(entityPath));
rowMap.put(row.id, row);
if (row.timestamp.isBefore(minTimestamp)) {
minTimestamp = row.timestamp;
}
if (row.timestamp.isAfter(maxTimestamp)) {
maxTimestamp = row.timestamp;
}
}
QAuditDelta qd = QAuditDeltaMapping.get().defaultAlias();
jdbcSession.newQuery().select(qd).from(qd).where(qd.recordId.in(rowMap.keySet()).and(qd.timestamp.between(minTimestamp, maxTimestamp))).fetch().forEach(d -> rowMap.get(d.recordId).addDelta(d));
QAuditRefValue qr = QAuditRefValueMapping.get().defaultAlias();
jdbcSession.newQuery().select(qr).from(qr).where(qr.recordId.in(rowMap.keySet()).and(qr.timestamp.between(minTimestamp, maxTimestamp))).fetch().forEach(r -> rowMap.get(r.recordId).addRefValue(r));
}
@Override
public AuditEventRecordType transform(Tuple tuple, QAuditEventRecord entityPath, Collection<SelectorOptions<GetOperationOptions>> options) {
return toSchemaObjectSafe(tuple, entityPath, options, jdbcSession, false);
}
};
}
use of com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer 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