Search in sources :

Example 26 with Tuple

use of com.querydsl.core.Tuple in project Settler by EmhyrVarEmreis.

the class UserService method getUsersWithValue.

public ResponseEntity<List<UserWithValueDTO>> getUsersWithValue(Long userId) {
    if (Objects.isNull(userId) || userId < 0) {
        userId = Security.currentUser().getId();
    }
    QUser user = QUser.user;
    QTransaction transaction = QTransaction.transaction;
    List<Tuple> fetch = new JPAQuery<>(entityManager).from(user, transaction).select(user, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(user.id.ne(userId)).where(transaction.owners.any().id.user.eq(user).or(transaction.contractors.any().id.user.eq(user))).groupBy(user.id, user.firstName, user.lastName, user.email, user.created, user.avatar, user.login, user.accountExpireDate).orderBy(transaction.value.sum().desc()).fetch();
    ModelMapper preparedModelMapper = getModelMapper();
    List<UserWithValueDTO> userWithValueDTOList = new ArrayList<>(fetch.size());
    for (Tuple tuple : fetch) {
        User u = tuple.get(user);
        Double d = tuple.get(transaction.value.sum());
        if (Objects.nonNull(u)) {
            userWithValueDTOList.add(new UserWithValueDTO(userId, preparedModelMapper.map(u, String.class), d));
        }
    }
    return new ResponseEntity<>(userWithValueDTOList, HttpStatus.OK);
}
Also used : QUser(pl.morecraft.dev.settler.domain.QUser) QTransaction(pl.morecraft.dev.settler.domain.QTransaction) ResponseEntity(org.springframework.http.ResponseEntity) User(pl.morecraft.dev.settler.domain.User) QUser(pl.morecraft.dev.settler.domain.QUser) ArrayList(java.util.ArrayList) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Tuple(com.querydsl.core.Tuple) ModelMapper(org.modelmapper.ModelMapper)

Example 27 with Tuple

use of com.querydsl.core.Tuple in project crnk-framework by crnk-project.

the class QueryDslTupleImplTest method setup.

@Before
public void setup() {
    expression = Mockito.mock(Expression.class);
    Tuple tuple = Mockito.mock(Tuple.class);
    Mockito.when(tuple.size()).thenReturn(2);
    Mockito.when(tuple.get(expression)).thenReturn("test");
    Mockito.when(tuple.toArray()).thenReturn(new Object[] { "0", "1" });
    Mockito.when(tuple.get(0, String.class)).thenReturn("0");
    Mockito.when(tuple.get(1, String.class)).thenReturn("1");
    Mockito.when(tuple.size()).thenReturn(2);
    Map<String, Integer> selectionBindings = new HashMap<>();
    impl = new QuerydslTupleImpl(tuple, selectionBindings);
}
Also used : Expression(com.querydsl.core.types.Expression) HashMap(java.util.HashMap) QuerydslTupleImpl(io.crnk.jpa.internal.query.backend.querydsl.QuerydslTupleImpl) Tuple(com.querydsl.core.Tuple) Before(org.junit.Before)

Example 28 with Tuple

use of com.querydsl.core.Tuple in project crnk-framework by crnk-project.

the class QuerydslExecutorImpl method getResultTuples.

@Override
public List<QuerydslTuple> getResultTuples() {
    List<?> results = executeQuery();
    List<QuerydslTuple> tuples = new ArrayList<>();
    for (Object result : results) {
        if (result instanceof Tuple) {
            tuples.add(new QuerydslTupleImpl((Tuple) result, selectionBindings));
        } else {
            tuples.add(new QuerydslObjectArrayTupleImpl(result, selectionBindings));
        }
    }
    return tuples;
}
Also used : QuerydslTuple(io.crnk.jpa.query.querydsl.QuerydslTuple) ArrayList(java.util.ArrayList) MetaDataObject(io.crnk.meta.model.MetaDataObject) QTuple(com.querydsl.core.types.QTuple) QuerydslTuple(io.crnk.jpa.query.querydsl.QuerydslTuple) Tuple(com.querydsl.core.Tuple)

Example 29 with Tuple

use of com.querydsl.core.Tuple in project midpoint by Evolveum.

the class SqaleRepositoryService method prepareUpdateContext.

/**
 * Read object for update and returns update context that contains it with specific get options.
 */
private <S extends ObjectType, Q extends QObject<R>, R extends MObject> RootUpdateContext<S, Q, R> prepareUpdateContext(@NotNull JdbcSession jdbcSession, @NotNull Class<S> schemaType, @NotNull UUID oid, Collection<SelectorOptions<GetOperationOptions>> getOptions, RepoModifyOptions options) throws SchemaException, ObjectNotFoundException {
    SqaleTableMapping<S, QObject<R>, R> rootMapping = sqlRepoContext.getMappingBySchemaType(schemaType);
    QObject<R> entityPath = rootMapping.defaultAlias();
    Path<?>[] selectExpressions = ObjectArrays.concat(rootMapping.selectExpressions(entityPath, getOptions), entityPath.containerIdSeq);
    Tuple result = jdbcSession.newQuery().select(selectExpressions).from(entityPath).where(entityPath.oid.eq(oid)).forUpdate().fetchOne();
    if (result == null || result.get(entityPath.fullObject) == null) {
        throw new ObjectNotFoundException(schemaType, oid.toString());
    }
    S object = rootMapping.toSchemaObject(result, entityPath, getOptions, jdbcSession, RepoModifyOptions.isForceReindex(options));
    R rootRow = rootMapping.newRowObject();
    rootRow.oid = oid;
    rootRow.containerIdSeq = result.get(entityPath.containerIdSeq);
    // This column is generated, some sub-entities need it, but we can't push it to DB.
    rootRow.objectType = MObjectType.fromSchemaType(object.getClass());
    return new RootUpdateContext<>(sqlRepoContext, jdbcSession, object, rootRow);
}
Also used : Path(com.querydsl.core.types.Path) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) RootUpdateContext(com.evolveum.midpoint.repo.sqale.update.RootUpdateContext) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Tuple(com.querydsl.core.Tuple)

Example 30 with Tuple

use of com.querydsl.core.Tuple in project midpoint by Evolveum.

the class SqaleRepositoryService method readByOid.

/**
 * Read object using provided {@link JdbcSession} as a part of already running transaction.
 */
private <S extends ObjectType> S readByOid(@NotNull JdbcSession jdbcSession, @NotNull Class<S> schemaType, @NotNull UUID oid, Collection<SelectorOptions<GetOperationOptions>> options) throws SchemaException, ObjectNotFoundException {
    SqaleTableMapping<S, QObject<MObject>, MObject> rootMapping = sqlRepoContext.getMappingBySchemaType(schemaType);
    QObject<MObject> root = rootMapping.defaultAlias();
    Tuple result = jdbcSession.newQuery().from(root).select(rootMapping.selectExpressions(root, options)).where(root.oid.eq(oid)).fetchOne();
    if (result == null || result.get(root.fullObject) == null) {
        throw new ObjectNotFoundException(schemaType, oid.toString());
    }
    return rootMapping.toSchemaObject(result, root, options, jdbcSession, false);
}
Also used : MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Tuple(com.querydsl.core.Tuple)

Aggregations

Tuple (com.querydsl.core.Tuple)55 Test (org.junit.Test)41 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)10 Pair (com.mysema.commons.lang.Pair)7 QTuple (com.querydsl.core.types.QTuple)6 Expression (com.querydsl.core.types.Expression)4 StringPath (com.querydsl.core.types.dsl.StringPath)4 AbstractBaseTest (com.querydsl.sql.AbstractBaseTest)4 QCat (com.querydsl.jpa.domain.QCat)3 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)3 QEmployee (com.querydsl.sql.domain.QEmployee)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)2 ResultListRowTransformer (com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 QueryMetadata (com.querydsl.core.QueryMetadata)2 Group (com.querydsl.core.group.Group)2