当前位置: 首页>>代码示例>>Java>>正文


Java Ordering类代码示例

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


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

示例1: toList

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<?> toList(Object object) {

	if (object == null) {
		throw new IllegalStateException("Unexpected null list");
	}

	if (!(object instanceof List)) {
		throw new IllegalStateException(
				"Unexpected object type. Should be a List, got: " + object.getClass().getName());
	}

	List<?> list = (List) object;

	// sort list before encoding, but do not filter it - we can filter during encoding
	if (!orderings.isEmpty() && list.size() > 1) {

		// don't mess up underlying relationship, sort a copy...
		list = new ArrayList<>(list);

		Ordering.orderList(list, orderings);
	}

	return list;
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:26,代码来源:ListEncoder.java

示例2: testSelectRequest_Sort

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_Sort() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(
               Collections.singletonList("[{\"property\":\"name\",\"direction\":\"DESC\"},{\"property\":\"address\",\"direction\":\"ASC\"}]"));

	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);

	assertEquals(2, resourceEntity.getOrderings().size());
	Iterator<Ordering> it = resourceEntity.getOrderings().iterator();
	Ordering o1 = it.next();
	Ordering o2 = it.next();
	assertEquals(SortOrder.DESCENDING, o1.getSortOrder());
	assertEquals("name", o1.getSortSpecString());
	assertEquals(SortOrder.ASCENDING, o2.getSortOrder());
	assertEquals("address", o2.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:20,代码来源:RequestParserTest.java

示例3: testSelectRequest_Sort_Dupes

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_Sort_Dupes() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(
               Collections.singletonList("[{\"property\":\"name\",\"direction\":\"DESC\"},{\"property\":\"name\",\"direction\":\"ASC\"}]"));

	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);

	assertEquals(1, resourceEntity.getOrderings().size());
	Iterator<Ordering> it = resourceEntity.getOrderings().iterator();
	Ordering o1 = it.next();
	assertEquals(SortOrder.DESCENDING, o1.getSortOrder());
	assertEquals(E2.NAME.getName(), o1.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:17,代码来源:RequestParserTest.java

示例4: testBuildQuery_Ordering

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testBuildQuery_Ordering() {

	Ordering o1 = E1.NAME.asc();
	Ordering o2 = E1.NAME.desc();

	SelectQuery<E1> query = new SelectQuery<E1>(E1.class);
	query.addOrdering(o1);

	ResourceEntity<E1> resourceEntity = getResourceEntity(E1.class);
	resourceEntity.getOrderings().add(o2);

	SelectContext<E1> context = new SelectContext<E1>(E1.class);
	context.setSelect(query);
	context.setEntity(resourceEntity);

	SelectQuery<E1> amended = makeQueryStage.buildQuery(context);
	assertSame(query, amended);
	assertEquals(2, amended.getOrderings().size());
	assertSame(o1, amended.getOrderings().get(0));
	assertSame(o2, amended.getOrderings().get(1));
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:23,代码来源:CayenneAssembleQueryStageTest.java

示例5: testSelectRequest_Sort_Group

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_Sort_Group() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(
			Collections.singletonList("[{\"property\":\"name\",\"direction\":\"DESC\"},{\"property\":\"address\",\"direction\":\"ASC\"}]"));
	when(params.get(SenchaSortProcessor.GROUP)).thenReturn(
			Collections.singletonList("[{\"property\":\"id\",\"direction\":\"DESC\"},{\"property\":\"address\",\"direction\":\"ASC\"}]"));


	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);

	assertEquals(3, resourceEntity.getOrderings().size());
	Iterator<Ordering> it = resourceEntity.getOrderings().iterator();
	Ordering o1 = it.next();
	Ordering o2 = it.next();
	Ordering o3 = it.next();

	assertEquals(SortOrder.DESCENDING, o1.getSortOrder());
	assertEquals("db:id", o1.getSortSpecString());
	assertEquals(SortOrder.ASCENDING, o2.getSortOrder());
	assertEquals("address", o2.getSortSpecString());
	assertEquals(SortOrder.DESCENDING, o3.getSortOrder());
	assertEquals("name", o3.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:27,代码来源:SenchaRequestParserTest.java

示例6: queryAssembled

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@QueryAssembled
public void queryAssembled(SelectContext<CrossMapTable> context) {
	context.getSelect().andQualifier(CrossMapTable.MAP_SET_ID.eq(_mapSetId));
	List<Ordering> orderings = new ArrayList<>();
	orderings.add(CrossMapTable.OPTION.asc());
	orderings.add(CrossMapTable.PRIORITY.asc());
	context.getSelect().addOrderings(orderings);
}
 
开发者ID:wardle,项目名称:rsterminology,代码行数:9,代码来源:CrossMapResource.java

示例7: processSimpleSorter

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
void processSimpleSorter(ResourceEntity<?> resourceEntity, String sort, String direction) {

		// TODO: do we need to support nested ID?
		LrEntity<?> entity = resourceEntity.getLrEntity();

		// note using "toString" instead of "getPath" to convert ASTPath to
		// String representation. This ensures "db:" prefix is preserved if
		// present
		sort = pathCache.getPathDescriptor(entity, new ASTObjPath(sort)).getPathExp().toString();

		// check for dupes...
		for (Ordering o : resourceEntity.getOrderings()) {
			if (sort.equals(o.getSortSpecString())) {
				return;
			}
		}

		if (direction == null) {
			direction = ASC;
		} else {
			checkInvalidDirection(direction);
		}

		SortOrder so = direction.equals(ASC) ? SortOrder.ASCENDING : SortOrder.DESCENDING;

		resourceEntity.getOrderings().add(new Ordering(sort, so));
	}
 
开发者ID:nhl,项目名称:link-rest,代码行数:28,代码来源:SortWorker.java

示例8: testSelectRequest_SortSimple_NoDir

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_SortSimple_NoDir() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(Collections.singletonList(E2.NAME.getName()));

	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);

	assertEquals(1, resourceEntity.getOrderings().size());
	Ordering o1 = resourceEntity.getOrderings().iterator().next();
	assertEquals(SortOrder.ASCENDING, o1.getSortOrder());
	assertEquals(E2.NAME.getName(), o1.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:15,代码来源:RequestParserTest.java

示例9: testSelectRequest_SortSimple_ASC

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_SortSimple_ASC() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(Collections.singletonList(E2.NAME.getName()));
	when(params.get("dir")).thenReturn(Collections.singletonList("ASC"));

	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);
	assertEquals(1, resourceEntity.getOrderings().size());
	Ordering o1 = resourceEntity.getOrderings().iterator().next();
	assertEquals(SortOrder.ASCENDING, o1.getSortOrder());
	assertEquals(E2.NAME.getName(), o1.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:15,代码来源:RequestParserTest.java

示例10: testSelectRequest_SortSimple_DESC

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testSelectRequest_SortSimple_DESC() {

	@SuppressWarnings("unchecked")
	MultivaluedMap<String, String> params = mock(MultivaluedMap.class);
	when(params.get("sort")).thenReturn(Collections.singletonList(E2.NAME.getName()));
	when(params.get("dir")).thenReturn(Collections.singletonList("DESC"));

	ResourceEntity<E2> resourceEntity = parser.parseSelect(getLrEntity(E2.class), params, null);
	assertEquals(1, resourceEntity.getOrderings().size());
	Ordering o1 = resourceEntity.getOrderings().iterator().next();
	assertEquals(SortOrder.DESCENDING, o1.getSortOrder());
	assertEquals(E2.NAME.getName(), o1.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:15,代码来源:RequestParserTest.java

示例11: testProcess_Array

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
@Test
public void testProcess_Array() {

	processor.process(entity, "[{\"property\":\"name\"},{\"property\":\"address\"}]", null);

	assertEquals(2, entity.getOrderings().size());

	Iterator<Ordering> it = entity.getOrderings().iterator();
	Ordering o1 = it.next();
	Ordering o2 = it.next();

	assertEquals(_E2.NAME.getName(), o1.getSortSpecString());
	assertEquals(_E2.ADDRESS.getName(), o2.getSortSpecString());
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:15,代码来源:SortProcessorTest.java

示例12: findObjects

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
<T> void findObjects(SelectContext<T> context) {

        Map<Object, T> typeBucket = db.bucketForType(context.getType());
        if (context.isById()) {
            T object = typeBucket.get(context.getId().get());
            context.setObjects(object != null ? Collections.singletonList(object) : Collections.<T>emptyList());
            return;
        }

        // clone the list and then filter/sort it as needed
        List<T> list = new ArrayList<>(typeBucket.values());

        Expression filter = context.getEntity().getQualifier();
        if (filter != null) {

            Iterator<T> it = list.iterator();
            while (it.hasNext()) {
                T t = it.next();
                if (!filter.match(t)) {
                    it.remove();
                }
            }
        }

        for (Ordering o : context.getEntity().getOrderings()) {
            o.orderList(list);
        }

        context.setObjects(list);
    }
 
开发者ID:nhl,项目名称:link-rest,代码行数:31,代码来源:PojoFetchStage.java

示例13: ListEncoder

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
public ListEncoder(Encoder elementEncoder, Expression filter, List<Ordering> orderings) {
	this.elementEncoder = elementEncoder;
	this.orderings = orderings;
	this.filter = filter;
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:6,代码来源:ListEncoder.java

示例14: getOrderings

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
public List<Ordering> getOrderings() {
    return orderings;
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:4,代码来源:ResourceEntity.java

示例15: buildQuery

import org.apache.cayenne.query.Ordering; //导入依赖的package包/类
<T> SelectQuery<T> buildQuery(SelectContext<T> context) {

        ResourceEntity<T> entity = context.getEntity();

        SelectQuery<T> query = basicSelect(context);

        if (!entity.isFiltered()) {
            int limit = context.getEntity().getFetchLimit();
            if (limit > 0) {
                query.setPageSize(limit);
            }
        }

        if (context.getParent() != null) {
            Expression qualifier = context.getParent().qualifier(entityResolver);
            query.andQualifier(qualifier);
        }

        if (entity.getQualifier() != null) {
            query.andQualifier(entity.getQualifier());
        }

        for (Ordering o : entity.getOrderings()) {
            query.addOrdering(o);
        }

        if (!entity.getChildren().isEmpty()) {
            PrefetchTreeNode root = new PrefetchTreeNode();

            int prefetchSemantics = context.getPrefetchSemantics();
            if (prefetchSemantics <= 0) {
                // it makes more sense to use joint prefetches for single object
                // queries...
                prefetchSemantics = context.isById() && context.getId().size() == 1
                        ? PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS : PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS;
            }

            appendPrefetches(root, entity, prefetchSemantics);
            query.setPrefetchTree(root);
        }

        return query;
    }
 
开发者ID:nhl,项目名称:link-rest,代码行数:44,代码来源:CayenneAssembleQueryStage.java


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