org.springframework.data.domain.Sort.iterator()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.springframework.data.domain.Sort.iterator()方法的一些代码示例,展示了Sort.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.iterator()方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:iterator

Sort.iterator介绍

暂无

代码示例

代码示例来源:origin: org.springframework.data/spring-data-geode

private boolean hasSort(Sort sort) {
  return sort != null && sort.iterator().hasNext();
}

代码示例来源:origin: org.springframework.data/spring-data-gemfire

private boolean hasSort(Sort sort) {
  return sort != null && sort.iterator().hasNext();
}

代码示例来源:origin: stackoverflow.com

@RequestMapping("/logged")
public String welcome(Model model, Pageable page, Sort sort) {
  model.addAttribute("page",topicRepository.findAll(page));
  model.addAttribute("sort",(sort !=null)?sort.iterator().next().getProperty():"");
  return "welcome";
}

代码示例来源:origin: com.orientechnologies/spring-data-orientdb-commons

/**
 * Apply sorting for the given query.
 *
 * @param query the query
 * @param sort the sort
 * @return the string
 */
public static String applySorting(String query, Sort sort) {
  Assert.hasText(query);
  
  if (null == sort || !sort.iterator().hasNext()) {
    return query;
  }
  
  throw new UnsupportedOperationException("Not implemented");
}

代码示例来源:origin: orientechnologies/spring-data-orientdb

/**
 * Apply sorting for the given query.
 *
 * @param query the query
 * @param sort the sort
 * @return the string
 */
public static String applySorting(String query, Sort sort) {
  Assert.hasText(query);
  
  if (null == sort || !sort.iterator().hasNext()) {
    return query;
  }
  
  throw new UnsupportedOperationException("Not implemented");
}

代码示例来源:origin: com.intoverflow.booster/booster-core

/**
 * 拼排序
 *
 * @param sort
 * @return
 */
public String prepareOrder(Sort sort) {
  if (sort == null || !sort.iterator().hasNext()) {
    return "";
  }
  StringBuilder orderBy = new StringBuilder("");
  orderBy.append(" order by ");
  orderBy.append(sort.toString().replace(":", " "));
  return orderBy.toString();
}

代码示例来源:origin: com.lodsve/lodsve-mybatis

public static String applySortSql(String sql, Sort sort) {
  if (null == sort || !sort.iterator().hasNext()) {
    return sql;
  }
  StringBuilder builder = new StringBuilder(sql);
  if (!ORDER_BY.matcher(sql).matches()) {
    builder.append(" order by ");
  } else {
    builder.append(", ");
  }
  for (Sort.Order order : sort) {
    builder.append(getOrderClause(order)).append(", ");
  }
  builder.delete(builder.length() - 2, builder.length());
  return builder.toString();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-spanner

public static StringBuilder applySort(Sort sort, StringBuilder sql,
    Function<Order, String> sortedPropertyNameFunction) {
  if (sort == null || sort.isUnsorted()) {
    return sql;
  }
  sql.append(" ORDER BY ");
  StringJoiner sj = new StringJoiner(" , ");
  sort.iterator().forEachRemaining((o) -> {
    String sortedPropertyName = sortedPropertyNameFunction.apply(o);
    String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")"
        : sortedPropertyName;
    sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC"));
  });
  return sql.append(sj);
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

public static StringBuilder applySort(Sort sort, StringBuilder sql,
    Function<Order, String> sortedPropertyNameFunction) {
  if (sort == null || sort.isUnsorted()) {
    return sql;
  }
  sql.append(" ORDER BY ");
  StringJoiner sj = new StringJoiner(" , ");
  sort.iterator().forEachRemaining((o) -> {
    String sortedPropertyName = sortedPropertyNameFunction.apply(o);
    String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")"
        : sortedPropertyName;
    sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC"));
  });
  return sql.append(sj);
}

代码示例来源:origin: com.nurkiewicz.jdbcrepository/jdbcrepository

protected String sortingClauseIfRequired(Sort sort) {
  if (sort == null) {
    return "";
  }
  StringBuilder orderByClause = new StringBuilder();
  orderByClause.append(" ORDER BY ");
  for(Iterator<Sort.Order> iterator = sort.iterator(); iterator.hasNext();) {
    final Sort.Order order = iterator.next();
    orderByClause.
        append(order.getProperty()).
        append(" ").
        append(order.getDirection().toString());
    if (iterator.hasNext()) {
      orderByClause.append(COMMA);
    }
  }
  return orderByClause.toString();
}

代码示例来源:origin: nurkiewicz/spring-data-jdbc-repository

protected String sortingClauseIfRequired(Sort sort) {
  if (sort == null) {
    return "";
  }
  StringBuilder orderByClause = new StringBuilder();
  orderByClause.append(" ORDER BY ");
  for(Iterator<Sort.Order> iterator = sort.iterator(); iterator.hasNext();) {
    final Sort.Order order = iterator.next();
    orderByClause.
        append(order.getProperty()).
        append(" ").
        append(order.getDirection().toString());
    if (iterator.hasNext()) {
      orderByClause.append(COMMA);
    }
  }
  return orderByClause.toString();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-dataflow-server-core

@Override
public Iterable<D> findAll(Sort sort) {
  Assert.notNull(sort, "sort must not be null");
  Iterator<Sort.Order> iter = sort.iterator();
  String query = findAllQuery + "ORDER BY ";
  while (iter.hasNext()) {
    Sort.Order order = iter.next();
    query = query + order.getProperty() + " " + order.getDirection();
    if (iter.hasNext()) {
      query = query + ", ";
    }
  }
  return jdbcTemplate.query(query, rowMapper);
}

代码示例来源:origin: com.intoverflow.booster/booster-core

private void orderBy(Sort sort) {
  if (sort != null) {
    Iterator<Sort.Order> iter = sort.iterator();
    StringBuilder orderby = new StringBuilder();
    while (iter.hasNext()) {
      Sort.Order order = iter.next();
      if (orderby.length() > 0) {
        orderby.append(", ");
      }
      String property = order.getProperty();
      orderby.append(property).append(" ")
        .append(order.getDirection().name().toLowerCase());
    }
    if (orderby.length() > 0) {
      PageHelper.orderBy(orderby.toString());
    }
  }
}

代码示例来源:origin: org.pustefixframework/pustefix-core

@Override
public void serialize(Object obj, SerializationContext context, XMLWriter writer) throws SerializationException {
  
  if(obj instanceof Sort) {
    Sort sort = (Sort)obj;
    Iterator<Order> it = sort.iterator();
    while(it.hasNext()) {
      Order order = it.next();
      writer.writeStartElement("order");
      context.serialize(order, writer);
      writer.writeEndElement();
    }
  } else throw new SerializationException("Illegal type: "+obj.getClass().getName());
  
}

代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-metadata-modeshape

protected void appendSort(StringBuilder bldr, Pageable pageable) {
  boolean first = true;
  if (pageable.getSort() != null && pageable.getSort().iterator().hasNext()) {
    bldr.append("ORDER BY ");
    for (Sort.Order order : pageable.getSort()) {
      if (!first) {
        bldr.append(", ");
        first = false;
      }
      String jcrPropName = deriveJcrPropertyName(order.getProperty());
      bldr.append(jcrPropName).append(" ").append(order.getDirection()).append(" NULLS LAST ");
    }
  }
}

代码示例来源:origin: io.github.hexagonframework.data/spring-data-ebean

/**
 * Convert spring data Sort to Ebean OrderBy.
 *
 * @param sort
 * @param <T>
 * @return
 */
public static <T> OrderBy<T> convertToEbeanOrderBy(Sort sort) {
  if (sort == null) {
    return null;
  }
  List<String> list = new ArrayList<>();
  Iterator<Sort.Order> orderIterator = sort.iterator();
  while (orderIterator.hasNext()) {
    Sort.Order so = orderIterator.next();
    list.add(so.getProperty() + " " + so.getDirection());
  }
  return new OrderBy<T>(StringUtils.collectionToCommaDelimitedString(list));
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

public Sort getMappedSort(Sort sort, CassandraPersistentEntity<?> entity) {
  Assert.notNull(sort, "Sort must not be null");
  Assert.notNull(entity, "CassandraPersistentEntity must not be null");
  if (!sort.iterator().hasNext()) {
    return sort;
  }
  List<Order> mappedOrders = new ArrayList<>();
  for (Order order : sort) {
    ColumnName columnName = ColumnName.from(order.getProperty());
    Field field = createPropertyField(entity, columnName);
    Order mappedOrder = getCqlIdentifier(columnName, field)
        .map(cqlIdentifier -> new Order(order.getDirection(), cqlIdentifier.toCql())).orElse(order);
    mappedOrders.add(mappedOrder);
  }
  return Sort.by(mappedOrders);
}

代码示例来源:origin: metatron-app/metatron-discovery

@RequestMapping(path = "/queryhistories/list", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<?> queryHistoryList(
    @RequestParam("queryEditorId") String queryEditorId,
    @RequestParam(required = false) String queryPattern,
    Pageable pageable, PersistentEntityResourceAssembler resourceAssembler) {
 LOGGER.debug("queryEditorId : {}", queryEditorId);
 LOGGER.debug("queryPattern : {}", queryPattern);
 LOGGER.debug("pageable : {}", pageable);
 // Get Predicate
 Predicate searchPredicated = QueryHistoryPredicate.searchListNotDeleted(queryEditorId, queryPattern);
 // 기본 정렬 조건 셋팅
 if(pageable.getSort() == null || !pageable.getSort().iterator().hasNext()) {
  pageable = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(),
      new Sort(Sort.Direction.ASC, "createdTime", "name"));
 }
 Page<QueryHistory> queryHistories = queryHistoryRepository.findAll(searchPredicated, pageable);
 return ResponseEntity.ok(this.pagedResourcesAssembler.toResource(queryHistories, resourceAssembler));
}

代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-operational-metadata-jpa

/**
 * Update the Pageable sort filter and resolve any filter strings if needed
 */
public static Pageable resolveSortFilters(EntityPathBase base, Pageable pageable) {
  if (pageable != null && pageable.getSort() != null) {
    List<Sort.Order> sortList = Lists.newArrayList(pageable.getSort().iterator());
    boolean anyMatch = sortList.stream().anyMatch(order -> containsFilterMappings(base, order.getProperty()));
    //if there is a match reconstruct pageable
    if (anyMatch) {
      List<Sort.Order> updatedSortOrder = sortList.stream().map(order -> new Sort.Order(order.getDirection(), resolvedFilter(base, order.getProperty()))).collect(Collectors.toList());
      Sort sort = new Sort(updatedSortOrder);
      Pageable updatedPageable = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
      return updatedPageable;
    }
  }
  return pageable;
}

代码示例来源:origin: ConsenSys/eventeum

@Override
public Page<ContractEventDetails> getContractEventsForSignature(String eventSignature, PageRequest pagination) {
  final Sort.Order firstOrder = pagination.getSort().iterator().next();
  return client.getContractEvents(pagination.getPageNumber(),
                     pagination.getPageSize(),
                     firstOrder.getProperty(),
                     firstOrder.getDirection(),
                     eventSignature);
}

相关文章