use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class QTupleTest method alias.
@Test
public void alias() {
Expression<?> expr = str1.as("s");
QTuple qTuple = new QTuple(expr);
Tuple tuple = qTuple.newInstance("arg");
assertEquals("arg", tuple.get(expr));
assertEquals("arg", tuple.get(Expressions.stringPath("s")));
}
use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class QueryPerformanceTest method byId_twoCols_qdsl.
@Test
public void byId_twoCols_qdsl() {
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
QCat cat = QCat.cat;
Tuple row = query().from(cat).where(cat.id.eq(i + 100)).select(cat.id, cat.name).fetchOne();
assertNotNull(row);
}
System.err.println("by id - 2 cols - dsl" + (System.currentTimeMillis() - start));
}
use of com.querydsl.core.Tuple 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.querydsl.core.Tuple 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();
}
};
}
use of com.querydsl.core.Tuple in project midpoint by Evolveum.
the class QAccessCertificationWorkItemMapping method loadCase.
private PrismContainerValue<AccessCertificationCaseType> loadCase(JdbcSession jdbcSession, UUID ownerOid, Long accessCertCaseCid) {
QAccessCertificationCaseMapping mapping = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping();
QAccessCertificationCase root = mapping.defaultAlias();
Tuple result = jdbcSession.newQuery().from(root).select(mapping.selectExpressions(root, Collections.emptyList())).where(root.ownerOid.eq(ownerOid).and(root.cid.eq(accessCertCaseCid))).fetchOne();
if (result == null) {
throw new SystemException("Case owner:" + ownerOid + " cid:" + accessCertCaseCid + " does not exist.");
}
try {
// noinspection unchecked
return mapping.toSchemaObject(result, root, Collections.emptyList()).asPrismContainerValue();
} catch (SchemaException e) {
throw new SystemException(e);
}
}
Aggregations