org.springframework.data.repository.query.ReturnedType Java Examples
The following examples show how to use
org.springframework.data.repository.query.ReturnedType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartTreeFirestoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
public PartTreeFirestoreQuery(FirestoreQueryMethod queryMethod, FirestoreReactiveOperations reactiveOperations, FirestoreMappingContext mappingContext, FirestoreClassMapper classMapper) { this.queryMethod = queryMethod; this.reactiveOperations = reactiveOperations; ReturnedType returnedType = queryMethod.getResultProcessor().getReturnedType(); this.tree = new PartTree(queryMethod.getName(), returnedType.getDomainType()); this.persistentEntity = mappingContext.getPersistentEntity(returnedType.getDomainType()); this.mappingContext = mappingContext; this.classMapper = classMapper; validate(); }
Example #2
Source File: PartTreeFirestoreQueryTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private PartTreeFirestoreQuery setUpPartTreeFirestoreQuery(String methodName) { Parameters parametersMock = mock(Parameters.class); when(parametersMock.isEmpty()).thenReturn(true); when(this.queryMethod.getParameters()).thenReturn(parametersMock); when(this.queryMethod.getName()).thenReturn(methodName); ReturnedType returnedType = mock(ReturnedType.class); when(returnedType.getDomainType()).thenAnswer(invocation -> User.class); ResultProcessor resultProcessor = mock(ResultProcessor.class); when(resultProcessor.getReturnedType()).thenReturn(returnedType); when(this.queryMethod.getResultProcessor()).thenReturn(resultProcessor); return new PartTreeFirestoreQuery(this.queryMethod, this.firestoreTemplate, new FirestoreMappingContext(), this.classMapper); }
Example #3
Source File: EbeanQueryCreator.java From spring-data-ebean with Apache License 2.0 | 5 votes |
/** * Create a new {@link EbeanQueryCreator}. * * @param tree must not be {@literal null}. * @param type must not be {@literal null}. * @param expressionList must not be {@literal null}. * @param provider must not be {@literal null}. */ public EbeanQueryCreator(PartTree tree, ReturnedType type, ExpressionList expressionList, ParameterMetadataProvider provider) { super(tree); this.tree = tree; this.root = expressionList; this.provider = provider; this.returnedType = type; }
Example #4
Source File: JpaSpecificationExecutorWithProjectionImpl.java From specification-with-projection with MIT License | 5 votes |
@Override public <R> Optional<R> findOne(Specification<T> spec, Class<R> projectionType) { final ReturnedType returnedType = ReturnTypeWarpper.of(projectionType, getDomainClass(), projectionFactory); final TypedQuery<Tuple> query = getTupleQuery(spec, Sort.unsorted(), returnedType); try { final MyResultProcessor resultProcessor = new MyResultProcessor(projectionFactory,returnedType); final R singleResult = resultProcessor.processResult(query.getSingleResult(), new TupleConverter(returnedType)); return Optional.ofNullable(singleResult); } catch (NoResultException e) { return Optional.empty(); } }
Example #5
Source File: JpaSpecificationExecutorWithProjectionImpl.java From specification-with-projection with MIT License | 5 votes |
@Override public <R> Page<R> findAll(Specification<T> spec, Class<R> projectionType, Pageable pageable) { final ReturnedType returnedType = ReturnTypeWarpper.of(projectionType, getDomainClass(), projectionFactory); final TypedQuery<Tuple> query = getTupleQuery(spec, pageable.isPaged() ? pageable.getSort() : Sort.unsorted(), returnedType); final MyResultProcessor resultProcessor = new MyResultProcessor(projectionFactory,returnedType); if (pageable.isPaged()) { query.setFirstResult((int)pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } final List<R> resultList = resultProcessor.processResult(query.getResultList(), new TupleConverter(returnedType)); final Page<R> page = PageableExecutionUtils.getPage(resultList, pageable, () -> executeCountQuery(this.getCountQuery(spec, getDomainClass()))); return pageable.isUnpaged() ? new PageImpl(resultList) : page; }
Example #6
Source File: JpaSpecificationExecutorWithProjectionImpl.java From specification-with-projection with MIT License | 5 votes |
protected TypedQuery<Tuple> getTupleQuery(@Nullable Specification spec, Sort sort, ReturnedType returnedType) { if (!returnedType.needsCustomConstruction()){ return getQuery(spec,sort); } CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> query = builder.createQuery(Tuple.class); Root<T> root = this.applySpecificationToCriteria(spec, getDomainClass(), query); Predicate predicate = spec.toPredicate(root, query, builder); if (predicate != null) { query.where(predicate); } if (returnedType.needsCustomConstruction()) { List<Selection<?>> selections = new ArrayList<>(); for (String property : returnedType.getInputProperties()) { PropertyPath path = PropertyPath.from(property, returnedType.getReturnedType()); selections.add(toExpressionRecursively(root, path, true).alias(property)); } query.multiselect(selections); } else { throw new IllegalArgumentException("only except projection"); } if (sort.isSorted()) { query.orderBy(QueryUtils.toOrders(sort, root, builder)); } return this.applyRepositoryMethodMetadata(this.entityManager.createQuery(query)); }
Example #7
Source File: Neo4jQuerySupport.java From sdn-rx with Apache License 2.0 | 4 votes |
protected final List<String> getInputProperties(final ResultProcessor resultProcessor) { ReturnedType returnedType = resultProcessor.getReturnedType(); return returnedType.isProjecting() ? returnedType.getInputProperties() : Collections.emptyList(); }
Example #8
Source File: AbstractMybatisQuery.java From spring-data-mybatis with Apache License 2.0 | 3 votes |
/** * Creates a new {@link TupleConverter} for the given {@link ReturnedType}. * @param type must not be {@literal null}. */ public TupleConverter(ReturnedType type) { Assert.notNull(type, "Returned type must not be null!"); this.type = type; }