本文整理汇总了Java中org.springframework.data.domain.SliceImpl类的典型用法代码示例。如果您正苦于以下问题:Java SliceImpl类的具体用法?Java SliceImpl怎么用?Java SliceImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SliceImpl类属于org.springframework.data.domain包,在下文中一共展示了SliceImpl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: list
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Transactional(readOnly = true)
public Slice<ListAnnouncementDTO> list(final ListAnnouncementRequest request, final Pageable pageRequest) {
final ListAnnouncementFilter filter = new ListAnnouncementFilter(occupationRepository);
if (!activeUserService.isModeratorOrAdmin()) {
filter.withSubscriberPerson(activeUserService.requireActivePerson());
}
final Optional<Organisation> maybeOrganisation = resolveOrganisation(request);
switch (request.getDirection()) {
case SENT:
maybeOrganisation.ifPresent(filter::withFromOrganisation);
break;
case RECEIVED:
maybeOrganisation.ifPresent(filter::withSubscriberOrganisation);
break;
default:
throw new IllegalArgumentException("Invalid direction");
}
return filter.buildPredicate()
.map(predicate -> announcementRepository.findAllAsSlice(predicate, pageRequest))
.map(slice -> transform(pageRequest, slice))
.orElseGet(() -> new SliceImpl<>(emptyList()));
}
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:27,代码来源:ListAnnouncementFeature.java
示例2: findSlice
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Override
public <T> Slice<T> findSlice(Query<T> query) {
List<T> list = findAllInternal(query);
Pageable pageable = query.getPageable();
if (pageable != null) {
boolean hasNext = ((pageable.getPageNumber() + 1) * pageable.getPageSize() < total(query));
return new SliceImpl<T>(list, query.getPageable(), hasNext);
} else {
return new SliceImpl<T>(list);
}
}
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:12,代码来源:SnowdropTemplate.java
示例3: doExecute
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();
Object createQuery = query.createQuery(values);
List<Object> resultList = null;
int pageSize = pageable.getPageSize();
if (createQuery instanceof Query) {
Query ormQuery = (Query) createQuery;
ormQuery.setMaxRows(pageSize + 1);
ormQuery.findList();
} else if (createQuery instanceof SqlQuery) {
SqlQuery sqlQuery = (SqlQuery) createQuery;
sqlQuery.setMaxRows(pageSize + 1);
sqlQuery.findList();
} else {
throw new InvalidEbeanQueryMethodException("query must be Query or SqlQuery");
}
boolean hasNext = resultList != null && resultList.size() > pageSize;
return new SliceImpl<Object>(hasNext ? resultList.subList(0, pageSize) : resultList, pageable, hasNext);
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:30,代码来源:AbstractEbeanQueryExecution.java
示例4: doExecute
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Override
protected Object doExecute(AbstractMybatisQuery query, Object[] values) {
MybatisParameters parameters = query.getQueryMethod().getParameters();
Map<String, Object> parameter = new HashMap<String, Object>();
int c = 0;
for (MybatisParameter param : parameters.getBindableParameters()) {
String name = param.getName();
if (StringUtils.isEmpty(name)) {
name = "p" + c;
}
parameter.put(name, values[param.getIndex()]);
c++;
}
Pageable pageable = (Pageable) values[parameters.getPageableIndex()];
if (parameters.hasSortParameter()) {
parameter.put("_sorts", values[parameters.getSortIndex()]);
} else {
parameter.put("_sorts", pageable.getSort());
}
parameter.put("offset", pageable.getOffset());
parameter.put("pageSize", pageable.getPageSize() + 1);
parameter.put("offsetEnd", pageable.getOffset() + pageable.getPageSize());
List<Object> resultList = query.getSqlSessionTemplate().selectList(query.getStatementId(), parameter);
int pageSize = pageable.getPageSize();
boolean hasNext = resultList.size() > pageSize;
return new SliceImpl<Object>(hasNext ? resultList.subList(0, pageSize) : resultList, pageable, hasNext);
}
开发者ID:hatunet,项目名称:spring-data-mybatis,代码行数:32,代码来源:MybatisQueryExecution.java
示例5: toSlice
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
private static <S> Slice<S> toSlice(final List<S> results, final Pageable page) {
boolean hasNext = false;
if (results.size() > page.getPageSize()) {
// Remove the extra element
results.remove(results.size() - 1);
hasNext = true;
}
return new SliceImpl<>(results, page, hasNext);
}
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:10,代码来源:BaseRepositoryImpl.java
示例6: findByCanaryUuids
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Test
public void findByCanaryUuids() throws Exception {
List<UUID> canaryUuids = Collections.singletonList(UUID.randomUUID());
Slice<EncryptedValue> encryptedValues = new SliceImpl(Collections.singletonList(new EncryptedValue()));
when(encryptedValueRepository.findByEncryptionKeyUuidIn(eq(canaryUuids), any())).thenReturn(encryptedValues);
assertThat(subject.findByCanaryUuids(canaryUuids), equalTo(encryptedValues));
}
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:9,代码来源:EncryptedValueDataServiceTest.java
示例7: beforeEach
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Before
public void beforeEach() {
oldUuid = UUID.randomUUID();
UUID activeUuid = UUID.randomUUID();
encryptedValueDataService = mock(EncryptedValueDataService.class);
keySet = new EncryptionKeySet();
keySet.add(oldUuid, mock(Key.class));
keySet.add(activeUuid, mock(Key.class));
keySet.setActive(activeUuid);
encryptedValue1 = mock(EncryptedValue.class);
encryptedValue2 = mock(EncryptedValue.class);
encryptedValue3 = mock(EncryptedValue.class);
encryptionKeyCanaryMapper = mock(EncryptionKeyCanaryMapper.class);
inactiveCanaries = newArrayList(oldUuid);
when(encryptedValueDataService.findByCanaryUuids(inactiveCanaries))
.thenReturn(new SliceImpl<>(asList(encryptedValue1, encryptedValue2)))
.thenReturn(new SliceImpl<>(asList(encryptedValue3)))
.thenReturn(new SliceImpl<>(new ArrayList<>()));
final EncryptionKeyRotator encryptionKeyRotator = new EncryptionKeyRotator(encryptedValueDataService,
encryptionKeyCanaryMapper,
keySet);
encryptionKeyRotator.rotate();
}
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:30,代码来源:EncryptionKeyRotatorTest.java
示例8: findPaginated
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
* This specific implementation pages by series.
* </p>
*/
@Override
@Transactional(readOnly = true)
public Slice<Album> findPaginated(int currentPage, Order... orders) {
// Adjust the page number: Spring Data counts from 0
currentPage--;
if (orders.length > 0) {
throw new UnsupportedOperationException("It is not possible to override the order for pages of albums");
}
Pageable pageable = new PageRequest(currentPage,
configurationService.getConfiguration().getPageSizeForAlbums());
Slice<MetaSeries> metaSlice = metaSeriesRepo.findAll(pageable);
// At the very least, there will be that many elements
List<Album> albumList = new ArrayList<Album>(metaSlice.getNumberOfElements());
// Add all albums
for (MetaSeries meta : metaSlice) {
if (meta.getSeries() != null) {
LOGGER.debug("Adding all {} albums from {}", meta.getSeries().getAlbums().size(),
meta.getSeries().getIdentifyingName());
albumList.addAll(meta.getSeries().getAlbums());
} else {
LOGGER.debug("Adding one shot album: {}", meta.getAlbum().getIdentifyingName());
albumList.add(meta.getAlbum());
}
}
return new SliceImpl<Album>(albumList, pageable, metaSlice.hasNext());
}
开发者ID:The4thLaw,项目名称:demyo,代码行数:37,代码来源:AlbumService.java
示例9: executePageSliceQuery
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
/**
* <P>
* Slices and pages are similar ways to iterate through the result set in blocks, mimicking a cursor. A
* {@link org.springframework.data.domain.Slice Slice} is a simpler concept, only requiring to know if further blocks
* of data are available. A {@link org.springframework.data.domain.Page Page} requires to know how many blocks of data
* are available in total.
* </P>
*
* @param parameters For the query
* @param query The query to run
* @param queryMethod Holds metadata about the query
* @return Query result
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object executePageSliceQuery(final Object[] parameters, final KeyValueQuery<?> query,
final QueryMethod queryMethod) {
long totalElements = -1;
int indexOfPageRequest = queryMethod.getParameters().getPageableIndex();
Pageable pageRequest = (Pageable) parameters[indexOfPageRequest];
/* TODO Eliminate count call for Slice, retrieve "rows+1" instead to determine if next page exists.
*/
if (query.getCritieria() == null) {
totalElements = this.keyValueOperations.count(queryMethod.getEntityInformation().getJavaType());
} else {
totalElements = this.keyValueOperations.count(query, queryMethod.getEntityInformation().getJavaType());
}
int requiredRows = pageRequest.getPageSize();
query.setOffset(pageRequest.getOffset());
query.setRows(pageRequest.getPageSize());
Iterable<?> resultSet = this.keyValueOperations.find(query, queryMethod.getEntityInformation().getJavaType());
List<?> content = IterableConverter.toList(resultSet);
if (queryMethod.isPageQuery()) {
return new PageImpl(content, pageRequest, totalElements);
} else {
boolean hasNext = totalElements > (query.getOffset() + query.getRows());
if (content.size() > requiredRows) {
content = content.subList(0, requiredRows);
}
return new SliceImpl(content, pageRequest, hasNext);
}
}
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:48,代码来源:HazelcastPartTreeQuery.java
示例10: createSlice
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
private Slice<T> createSlice(List<T> allResults, Pageable pageable) {
Iterator<T> iterator = allResults.iterator();
int processedCount = 0;
if (pageable.getOffset() > 0) {
processedCount = scanThroughResults(iterator, pageable.getOffset());
if (processedCount < pageable.getOffset())
return new SliceImpl<T>(new ArrayList<T>());
}
List<T> results = readPageOfResultsRestrictMaxResultsIfNecessary(iterator, pageable.getPageSize());
// Scan ahead to retrieve the next page count
boolean hasMoreResults = scanThroughResults(iterator, 1) > 0;
if (getResultsRestrictionIfApplicable() != null && getResultsRestrictionIfApplicable().intValue() <= results.size()) hasMoreResults = false;
return new SliceImpl<T>(results, pageable, hasMoreResults);
}
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:16,代码来源:AbstractDynamoDBQuery.java
示例11: transform
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
private Slice<ListAnnouncementDTO> transform(final Pageable pageRequest, final Slice<Announcement> slice) {
return new SliceImpl<>(announcementDTOTransformer.transform(slice.getContent()), pageRequest, slice.hasNext());
}
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:4,代码来源:ListAnnouncementFeature.java
示例12: findByFilterOrderByLinkedDistributionSet
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Override
public Slice<Target> findByFilterOrderByLinkedDistributionSet(final Pageable pageable,
final Long orderByDistributionId, final FilterParams filterParams) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
// select case expression to retrieve the case value as a column to be
// able to order based on
// this column, installed first,...
final Expression<Object> selectCase = cb.selectCase()
.when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id),
orderByDistributionId), 1)
.when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id),
orderByDistributionId), 2)
.otherwise(100);
// multiselect statement order by the select case and controllerId
query.distinct(true);
// build the specifications and then to predicates necessary by the
// given filters
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(buildSpecificationList(filterParams),
targetRoot, query, cb);
// if we have some predicates then add it to the where clause of the
// multiselect
if (specificationsForMultiSelect.length > 0) {
query.where(specificationsForMultiSelect);
}
// add the order to the multi select first based on the selectCase
query.orderBy(cb.asc(selectCase), cb.desc(targetRoot.get(JpaTarget_.id)));
// the result is a Object[] due the fact that the selectCase is an extra
// column, so it cannot
// be mapped directly to a Target entity because the selectCase is not a
// attribute of the
// Target entity, the the Object array contains the Target on the first
// index (case of the
// multiselect order) of the array and
// the 2nd contains the selectCase int value.
final int pageSize = pageable.getPageSize();
final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset())
.setMaxResults(pageSize + 1).getResultList();
final boolean hasNext = resultList.size() > pageSize;
return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext);
}
开发者ID:eclipse,项目名称:hawkbit,代码行数:45,代码来源:JpaTargetManagement.java
示例13: findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Override
public Slice<AssignedSoftwareModule> findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) {
final List<AssignedSoftwareModule> resultList = new ArrayList<>();
final int pageSize = pageable.getPageSize();
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
// get the assigned software modules
final CriteriaQuery<JpaSoftwareModule> assignedQuery = cb.createQuery(JpaSoftwareModule.class);
final Root<JpaSoftwareModule> assignedRoot = assignedQuery.from(JpaSoftwareModule.class);
assignedQuery.distinct(true);
final ListJoin<JpaSoftwareModule, JpaDistributionSet> assignedDsJoin = assignedRoot
.join(JpaSoftwareModule_.assignedTo);
// build the specifications and then to predicates necessary by the
// given filters
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, typeId),
assignedRoot, assignedQuery, cb,
cb.equal(assignedDsJoin.get(JpaDistributionSet_.id), orderByDistributionId));
// if we have some predicates then add it to the where clause of the
// multi select
assignedQuery.where(specPredicate);
assignedQuery.orderBy(cb.asc(assignedRoot.get(JpaSoftwareModule_.name)),
cb.asc(assignedRoot.get(JpaSoftwareModule_.version)));
// don't page the assigned query on database, we need all assigned
// software modules to filter
// them out in the unassigned query
final List<JpaSoftwareModule> assignedSoftwareModules = entityManager.createQuery(assignedQuery)
.getResultList();
// map result
if (pageable.getOffset() < assignedSoftwareModules.size()) {
assignedSoftwareModules
.subList(pageable.getOffset(), Math.min(assignedSoftwareModules.size(), pageable.getPageSize()))
.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, true)));
}
if (assignedSoftwareModules.size() >= pageSize) {
return new SliceImpl<>(resultList);
}
// get the unassigned software modules
final CriteriaQuery<JpaSoftwareModule> unassignedQuery = cb.createQuery(JpaSoftwareModule.class);
unassignedQuery.distinct(true);
final Root<JpaSoftwareModule> unassignedRoot = unassignedQuery.from(JpaSoftwareModule.class);
Predicate[] unassignedSpec;
if (!assignedSoftwareModules.isEmpty()) {
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id).in(
assignedSoftwareModules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))));
} else {
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
unassignedQuery, cb);
}
unassignedQuery.where(unassignedSpec);
unassignedQuery.orderBy(cb.asc(unassignedRoot.get(JpaSoftwareModule_.name)),
cb.asc(unassignedRoot.get(JpaSoftwareModule_.version)));
final List<JpaSoftwareModule> unassignedSoftwareModules = entityManager.createQuery(unassignedQuery)
.setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
.setMaxResults(pageSize).getResultList();
// map result
unassignedSoftwareModules.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, false)));
return new SliceImpl<>(resultList);
}
开发者ID:eclipse,项目名称:hawkbit,代码行数:67,代码来源:JpaSoftwareModuleManagement.java
示例14: findPaginated
import org.springframework.data.domain.SliceImpl; //导入依赖的package包/类
@Transactional(readOnly = true)
@Override
public Slice<Tag> findPaginated(int currentPage, Order... orders) {
return new SliceImpl<>(repo.findAllWithUsageCounts());
}
开发者ID:The4thLaw,项目名称:demyo,代码行数:6,代码来源:TagService.java
注:本文中的org.springframework.data.domain.SliceImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论