org.springframework.data.util.StreamUtils Java Examples
The following examples show how to use
org.springframework.data.util.StreamUtils.
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: HazelcastPartTreeQuery.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
/** * <p> * Execute a retrieval query. The query engine will return this in an iterator, which may need conversion to a single * domain entity or a stream. * </P> * * @param query The query to run * @param queryMethod Holds metadata about the query, is paging etc * @return Query result */ private Object executeFindQuery(final KeyValueQuery<?> query, final QueryMethod queryMethod, final boolean distinct) { Iterable<?> resultSet = this.keyValueOperations.find(query, queryMethod.getEntityInformation().getJavaType()); if (!queryMethod.isCollectionQuery() && !queryMethod.isPageQuery() && !queryMethod.isSliceQuery() && !queryMethod .isStreamQuery()) { // Singleton result return resultSet.iterator().hasNext() ? resultSet.iterator().next() : null; } if (queryMethod.isStreamQuery()) { if (distinct) { return StreamUtils.createStreamFromIterator(resultSet.iterator()).distinct(); } return StreamUtils.createStreamFromIterator(resultSet.iterator()); } if (distinct) { return StreamUtils.createStreamFromIterator(resultSet.iterator()).distinct().collect(Collectors.toList()); } return resultSet; }
Example #2
Source File: DatastorePersistentPropertyImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public Iterable<? extends TypeInformation<?>> getPersistentEntityTypes() { return StreamUtils .createStreamFromIterator(super.getPersistentEntityTypes().iterator()) .filter((typeInfo) -> typeInfo.getType().isAnnotationPresent(Entity.class)) .collect(Collectors.toList()); }
Example #3
Source File: SpannerPersistentPropertyImpl.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
/** * Only provides types that are also annotated with {@link Table}. */ @Override public Iterable<? extends TypeInformation<?>> getPersistentEntityTypes() { return StreamUtils .createStreamFromIterator(super.getPersistentEntityTypes().iterator()) .filter((typeInfo) -> typeInfo.getType().isAnnotationPresent(Table.class)) .collect(Collectors.toList()); }
Example #4
Source File: EbeanQueryWrapper.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") <E> Stream<E> findStream() { if (queryType == QUERY) { return StreamUtils.createStreamFromIterator(((Query<E>) queryInstance).findIterate()); } throw new IllegalArgumentException("query not supported!"); }
Example #5
Source File: TemplateQueryParameterBinderFactory.java From spring-data-jpa-extra with Apache License 2.0 | 5 votes |
private static Iterable<QueryParameterSetter> createSetters(List<StringQuery.ParameterBinding> parameterBindings, DeclaredQuery declaredQuery, QueryParameterSetterFactory... strategies) { return parameterBindings.stream() // .map(it -> createQueryParameterSetter(it, strategies, declaredQuery)) // .collect(StreamUtils.toUnmodifiableList()); }
Example #6
Source File: HazelcastPartTreeQuery.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
/** * <p> * Execute this query instance, using any invocation parameters. * </P> * <p> * Expecting {@code findBy...()}, {@code countBy...()} or {@code deleteBy...()} * </P> * * @param parameters Any parameters * @return Query result */ @Override public Object execute(Object[] parameters) { KeyValueQuery<?> query = prepareQuery(parameters); if (this.isCount) { final Class<?> javaType = queryMethod.getEntityInformation().getJavaType(); if (this.isDistinct) { final Iterable<?> iterable = this.keyValueOperations.find(query, javaType); return StreamUtils.createStreamFromIterator(iterable.iterator()).distinct().count(); } else { return this.keyValueOperations.count(query, javaType); } } if (this.isDelete) { return this.executeDeleteQuery(query, queryMethod); } if (this.isExists) { query.setOffset(0); query.setRows(1); final Iterable<?> result = this.keyValueOperations.find(query, queryMethod.getEntityInformation().getJavaType()); return result.iterator().hasNext(); } if (queryMethod.isPageQuery() || queryMethod.isSliceQuery()) { return this.executePageSliceQuery(parameters, query, queryMethod); } if (queryMethod.isCollectionQuery() || queryMethod.isQueryForEntity() || queryMethod.isStreamQuery()) { return this.executeFindQuery(query, queryMethod, this.isDistinct); } String message = String.format("Query method '%s' not supported.", queryMethod.getName()); throw new UnsupportedOperationException(message); }
Example #7
Source File: OrderManagerTests.java From salespoint with Apache License 2.0 | 5 votes |
@Test // #240 void returnsAPageOfOrder() throws Exception { List<Order> orders = IntStream.range(0, 19).mapToObj(__ -> new Order(user, Cash.CASH)) // .peek(orderManager::save) // .collect(StreamUtils.toUnmodifiableList()); Pageable pageable = PageRequest.of(0, 10); Page<Order> result = orderManager.findAll(pageable); assertThat(result).containsExactlyInAnyOrderElementsOf(orders.subList(0, 10)); assertThat(orderManager.findAll(result.nextPageable())).containsExactlyInAnyOrderElementsOf(orders.subList(10, 19)); }