• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OrderByItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.olingo.server.api.uri.queryoption.OrderByItem的典型用法代码示例。如果您正苦于以下问题:Java OrderByItem类的具体用法?Java OrderByItem怎么用?Java OrderByItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OrderByItem类属于org.apache.olingo.server.api.uri.queryoption包,在下文中一共展示了OrderByItem类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: toSort

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
/**
 * Converts {@link OrderByItem} to {@link Sort} needed for
 * {@link Pagination}.
 * 
 * @param orderByItem
 *            order by item
 * @return sort instance, or null in case order by item wasn't specific type
 */
protected Sort toSort(OrderByItem orderByItem) {
    Expression expression = orderByItem.getExpression();
    if (expression instanceof Member) {
        UriInfoResource resourcePath = ((Member) expression).getResourcePath();
        UriResource uriResource = resourcePath.getUriResourceParts().get(0);
        if (uriResource instanceof UriResourcePrimitiveProperty) {
            EdmProperty edmProperty = ((UriResourcePrimitiveProperty) uriResource)
                    .getProperty();
            String property = edmProperty.getName();
            if (edmProperty instanceof ElasticEdmProperty) {
                ElasticEdmProperty entityTypeProperty = (ElasticEdmProperty) edmProperty;
                property = addKeywordIfNeeded(entityTypeProperty.getEField(),
                        entityTypeProperty.getAnnotations());
            }
            return new Sort(property,
                    orderByItem.isDescending() ? Sort.Direction.DESC : Sort.Direction.ASC);
        }
    }
    return null;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:29,代码来源:RequestCreator.java


示例2: parseOrderByOption

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
private void parseOrderByOption(OrderByOption orderByOption, final EdmType contextType,
    final List<String> entitySetNames, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  if (orderByOption != null) {
    final String optionValue = orderByOption.getText();
    UriTokenizer orderByTokenizer = new UriTokenizer(optionValue);
    final OrderByOption option = new OrderByParser(edm, odata).parse(orderByTokenizer,
        contextType instanceof EdmStructuredType ? (EdmStructuredType) contextType : null,
        entitySetNames,
        aliases);
    checkOptionEOF(orderByTokenizer, orderByOption.getName(), optionValue);
    for (final OrderByItem item : option.getOrders()) {
      ((OrderByOptionImpl) orderByOption).addOrder(item);
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:17,代码来源:Parser.java


示例3: appendOrdering

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
public void appendOrdering(String alias,OrderByOption orderByOption) throws ODataApplicationException {

		if(orderByOption != null){
			getSelect().setOrderByElements(new ArrayList<OrderByElement>());
			for( OrderByItem item: orderByOption.getOrders()){
				OrderByElement element = new OrderByElement();
				element.setAsc(!item.isDescending());
				FilterExpressionVisitor expressionVisitor = new FilterExpressionVisitor(alias);
				try {
					SQLExpression orderByItem = item.getExpression().accept(expressionVisitor);
					element.setColumnReference(orderByItem);
					getSelect().getOrderByElements().add(element);
				} catch (ExpressionVisitException  e) {
					throw internalError(e);
				}

			}
		}
	}
 
开发者ID:jbaliuka,项目名称:sql-analytic,代码行数:20,代码来源:ReadCommand.java


示例4: configureSorting

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
private static void configureSorting(UriInfo uriInfo, SearchRequestBuilder searchRequest) {
  if (uriInfo.getOrderByOption() == null) {
    return;
  }

  for (OrderByItem orderByItem : uriInfo.getOrderByOption().getOrders()) {
    searchRequest.addSort(
        MemberMapper.toFieldName((Member) orderByItem.getExpression()),
        orderByItem.isDescending() ? SortOrder.DESC : SortOrder.ASC);
  }
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:12,代码来源:EntityRepository.java


示例5: appendOrderByItemsJson

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
private void appendOrderByItemsJson(final JsonGenerator gen, final List<OrderByItem> orders) throws IOException {
  gen.writeStartArray();
  for (final OrderByItem item : orders) {
    gen.writeStartObject();
    gen.writeStringField("nodeType", "order");
    gen.writeStringField("sortorder", item.isDescending() ? "desc" : "asc");
    gen.writeFieldName("expression");
    appendExpressionJson(gen, item.getExpression());
    gen.writeEndObject();
  }
  gen.writeEndArray();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:13,代码来源:DebugTabUri.java


示例6: getOrders

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
@Override
public List<OrderByItem> getOrders() {
  return Collections.unmodifiableList(orders);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:5,代码来源:OrderByOptionImpl.java


示例7: addOrder

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
public OrderByOptionImpl addOrder(final OrderByItem order) {
  orders.add(order);
  return this;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:5,代码来源:OrderByOptionImpl.java


示例8: readEntityCollection

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, 
    ContentType responseFormat) throws ODataApplicationException, SerializerException {

	// 1st retrieve the requested EntitySet from the uriInfo (representation of the parsed URI)
	List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
	// in our example, the first segment is the EntitySet
	UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
	EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();

	// 2nd: fetch the data from backend for this requested EntitySetName and deliver as EntitySet
	EntityCollection entityCollection = storage.readEntitySetData(edmEntitySet);
	List<Entity> entityList = entityCollection.getEntities();
	
	// 3rd apply $orderby
	OrderByOption orderByOption = uriInfo.getOrderByOption();
	if (orderByOption != null) {
		List<OrderByItem> orderItemList = orderByOption.getOrders();
		final OrderByItem orderByItem = orderItemList.get(0); // in our example we support only one
		Expression expression = orderByItem.getExpression();
		if(expression instanceof Member){
			UriInfoResource resourcePath = ((Member)expression).getResourcePath();
			UriResource uriResource = resourcePath.getUriResourceParts().get(0);
			if (uriResource instanceof UriResourcePrimitiveProperty) {
				EdmProperty edmProperty = ((UriResourcePrimitiveProperty)uriResource).getProperty();
				final String sortPropertyName = edmProperty.getName();

				// do the sorting for the list of entities  
				Collections.sort(entityList, new Comparator<Entity>() {

					// we delegate the sorting to the native sorter of Integer and String
					public int compare(Entity entity1, Entity entity2) {
						int compareResult = 0;

						if(sortPropertyName.equals("ID")){
							Integer integer1 = (Integer) entity1.getProperty(sortPropertyName).getValue();
							Integer integer2 = (Integer) entity2.getProperty(sortPropertyName).getValue();
							
							compareResult = integer1.compareTo(integer2);
						}else{
							String propertyValue1 = (String) entity1.getProperty(sortPropertyName).getValue();
							String propertyValue2 = (String) entity2.getProperty(sortPropertyName).getValue();
							
							compareResult = propertyValue1.compareTo(propertyValue2);
						}

						// if 'desc' is specified in the URI, change the order of the list 
						if(orderByItem.isDescending()){
							return - compareResult; // just convert the result to negative value to change the order
						}
						
						return compareResult;
					}
				});
			}
		}
	}
	
	
	// 4th: create a serializer based on the requested format (json)
	ODataSerializer serializer = odata.createSerializer(responseFormat);

	// and serialize the content: transform from the EntitySet object to InputStream
	EdmEntityType edmEntityType = edmEntitySet.getEntityType();
	ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();

	final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
	EntityCollectionSerializerOptions opts =
			EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
   SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, 
                                                                   entityCollection, opts);
	InputStream serializedContent = serializerResult.getContent();

	// 5th: configure the response object: set the body, headers and status code
	response.setContent(serializedContent);
	response.setStatusCode(HttpStatusCode.OK.getStatusCode());
	response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:78,代码来源:DemoEntityCollectionProcessor.java


示例9: applyOrderQueryOption

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
private List<Entity> applyOrderQueryOption(List<Entity> entityList, OrderByOption orderByOption) {

    if (orderByOption != null) {
      List<OrderByItem> orderItemList = orderByOption.getOrders();
      final OrderByItem orderByItem = orderItemList.get(0); // in our example we support only one
      Expression expression = orderByItem.getExpression();
      if (expression instanceof Member) {
        UriInfoResource resourcePath = ((Member) expression).getResourcePath();
        UriResource uriResource = resourcePath.getUriResourceParts().get(0);
        if (uriResource instanceof UriResourcePrimitiveProperty) {
          EdmProperty edmProperty = ((UriResourcePrimitiveProperty) uriResource).getProperty();
          final String sortPropertyName = edmProperty.getName();

          // do the sorting for the list of entities  
          Collections.sort(entityList, new Comparator<Entity>() {

            // we delegate the sorting to the native sorter of Integer and String
            public int compare(Entity entity1, Entity entity2) {
              int compareResult = 0;

              if (sortPropertyName.equals("ID")) {
                Integer integer1 = (Integer) entity1.getProperty(sortPropertyName).getValue();
                Integer integer2 = (Integer) entity2.getProperty(sortPropertyName).getValue();

                compareResult = integer1.compareTo(integer2);
              } else {
                String propertyValue1 = (String) entity1.getProperty(sortPropertyName).getValue();
                String propertyValue2 = (String) entity2.getProperty(sortPropertyName).getValue();

                compareResult = propertyValue1.compareTo(propertyValue2);
              }

              // if 'desc' is specified in the URI, change the order of the list 
              if (orderByItem.isDescending()) {
                return -compareResult; // just convert the result to negative value to change the order
              }

              return compareResult;
            }
          });
        }
      }
    }
    
    return entityList;
  }
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:47,代码来源:DemoEntityCollectionProcessor.java


示例10: applyOrderByOption

import org.apache.olingo.server.api.uri.queryoption.OrderByItem; //导入依赖的package包/类
/**
 * This method applies order by option query to the given entity collection.
 *
 * @param orderByOption    Order by option
 * @param entitySet        Entity Set
 * @param edmBindingTarget Binding Target
 */
public static void applyOrderByOption(final OrderByOption orderByOption, final EntityCollection entitySet,
                                      final EdmBindingTarget edmBindingTarget) {
    Collections.sort(entitySet.getEntities(), new Comparator<Entity>() {
        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public int compare(final Entity e1, final Entity e2) {
            // Evaluate the first order option for both entity
            // If and only if the result of the previous order option is equals to 0
            // evaluate the next order option until all options are evaluated or they are not equals
            int result = 0;
            for (int i = 0; i < orderByOption.getOrders().size() && result == 0; i++) {
                try {
                    final OrderByItem item = orderByOption.getOrders().get(i);
                    final TypedOperand op1 = item.getExpression()
                                                 .accept(new ExpressionVisitorImpl(e1, edmBindingTarget))
                                                 .asTypedOperand();
                    final TypedOperand op2 = item.getExpression()
                                                 .accept(new ExpressionVisitorImpl(e2, edmBindingTarget))
                                                 .asTypedOperand();
                    if (op1.isNull() || op2.isNull()) {
                        if (op1.isNull() && op2.isNull()) {
                            result = 0; // null is equals to null
                        } else {
                            result = op1.isNull() ? -1 : 1;
                        }
                    } else {
                        Object o1 = op1.getValue();
                        Object o2 = op2.getValue();

                        if (o1.getClass() == o2.getClass() && o1 instanceof Comparable) {
                            result = ((Comparable) o1).compareTo(o2);
                        } else {
                            result = 0;
                        }
                    }
                    result = item.isDescending() ? result * -1 : result;
                } catch (ExpressionVisitException | ODataApplicationException e) {
                    throw new RuntimeException(e);
                }
            }
            return result;
        }
    });
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:52,代码来源:QueryHandler.java



注:本文中的org.apache.olingo.server.api.uri.queryoption.OrderByItem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Switch类代码示例发布时间:2022-05-22
下一篇:
Java IconNodeWidget类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap