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


Java TypedQuery.setMaxResults方法代码示例

本文整理汇总了Java中javax.persistence.TypedQuery.setMaxResults方法的典型用法代码示例。如果您正苦于以下问题:Java TypedQuery.setMaxResults方法的具体用法?Java TypedQuery.setMaxResults怎么用?Java TypedQuery.setMaxResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.TypedQuery的用法示例。


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

示例1: list

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public <T> List<T> list(Pageable pageable) {
	if (parent != null) {
		applyPredicateToCriteria(sq);
		return parent.list(pageable);
	}
	if (pageable == null) {
		return list();
	} else {
		Sort sort = pageable.getSort();
		orders.addAll(QueryUtils.toOrders(sort, root, cb));
		applyPredicateToCriteria(criteria);
		TypedQuery<?> query = em.createQuery(criteria);
		
		query.setFirstResult(pageable.getOffset());
		query.setMaxResults(pageable.getPageSize());

		return transform(query, false);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:21,代码来源:LinqImpl.java

示例2: getUsers

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public List<UserModel> getUsers(RealmModel realm, int firstResult, int maxResults) {

	TypedQuery<UserEntity> query = em.createNamedQuery("getAllUsers", UserEntity.class);
	if (firstResult != -1) {
		query.setFirstResult(firstResult);
	}
	if (maxResults != -1) {
		query.setMaxResults(maxResults);
	}
	List<UserEntity> results = query.getResultList();
	List<UserModel> users = new LinkedList<>();
	for (UserEntity entity : results)
		users.add(new UserAdapter(session, realm, model, entity));
	return users;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:17,代码来源:AitEjbUserStorageProvider.java

示例3: findRange

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
public default List<E> findRange(Long from, Long to) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

    CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
    criteriaQuery.select(criteriaQuery.from(getEntityClass()));
    TypedQuery<E> query = entityManager.createQuery(criteriaQuery);
    query.setMaxResults(Math.toIntExact(to - from + 1));
    query.setFirstResult(Math.toIntExact(from));

    return query.getResultList();
}
 
开发者ID:daniel-shuy,项目名称:JAX-RS-JPA-CRUD,代码行数:13,代码来源:RepositoryCRUD.java

示例4: listAll

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@GET
@Produces("application/json")
public List<Person> listAll(@QueryParam("start") Integer startPosition,
		@QueryParam("max") Integer maxResult) {
	TypedQuery<Person> findAllQuery = em.createQuery(
			"SELECT DISTINCT p FROM Person p ORDER BY p.id", Person.class);
	if (startPosition != null) {
		findAllQuery.setFirstResult(startPosition);
	}
	if (maxResult != null) {
		findAllQuery.setMaxResults(maxResult);
	}
	final List<Person> results = findAllQuery.getResultList();
	return results;
}
 
开发者ID:gastaldi,项目名称:demo-ang2,代码行数:16,代码来源:PersonEndpoint.java

示例5: readPage

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
protected Page<T> readPage(final TypedQuery<T> query, final Pageable pageable, final Specification<T> spec) {
    query.setFirstResult(pageable.getOffset());
    query.setMaxResults(pageable.getPageSize());

    final Long total = QueryUtils.executeCountQuery(getCountQuery(spec));
    final List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T>emptyList();

    if (total > maximumRecords) {
        return new CustomPageImpl<>(content, pageable, maximumRecords, String.format(ERROR_MESSAGE, maximumRecords));
    } else {
        return new PageImpl<>(content, pageable, total);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:15,代码来源:CustomSimpleMaxedJpaRepository.java

示例6: findByLastname

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public List<Customer> findByLastname(String lastname, int page, int pageSize) {

	TypedQuery<Customer> query = em.createQuery("select c from Customer c where c.lastname = ?1", Customer.class);

	query.setParameter(1, lastname);
	query.setFirstResult(page * pageSize);
	query.setMaxResults(pageSize);

	return query.getResultList();
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:12,代码来源:CustomerServiceImpl.java

示例7: resultsWithStartAndLimit

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
/**
 * Returns the query result for a query with a start and limit parameter.
 * Negative starts and limits are ignored.
 * @param em The currently open entity manager.
 * @param query The query. Parameters must all be bound.
 * @param start The start index. Negative values are ignored.
 * @param limit The limit. Negative values are ignored.
 * @return The query result.
 */
protected List<P> resultsWithStartAndLimit(EntityManager em, TypedQuery<P> query, int start, int limit) {
	if (start >= 0) {
		query.setFirstResult(start);
    }
	if (limit >= 0) {
		query = query.setMaxResults(limit);
	}
	return query.getResultList();
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:19,代码来源:AbstractPersistenceRepository.java

示例8: getUsers

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public List<UserModel> getUsers(RealmModel realm, int firstResult, int maxResults) {

    TypedQuery<UserEntity> query = em.createNamedQuery("getAllUsers", UserEntity.class);
    if (firstResult != -1) {
        query.setFirstResult(firstResult);
    }
    if (maxResults != -1) {
        query.setMaxResults(maxResults);
    }
    List<UserEntity> results = query.getResultList();
    List<UserModel> users = new LinkedList<>();
    for (UserEntity entity : results) users.add(new UserAdapter(session, realm, model, entity));
    return users;
}
 
开发者ID:nmajorov,项目名称:keycloak_training,代码行数:16,代码来源:EjbExampleUserStorageProvider.java

示例9: searchForUser

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public List<UserModel> searchForUser(String search, RealmModel realm, int firstResult, int maxResults) {
    TypedQuery<UserEntity> query = em.createNamedQuery("searchForUser", UserEntity.class);
    query.setParameter("search", "%" + search.toLowerCase() + "%");
    if (firstResult != -1) {
        query.setFirstResult(firstResult);
    }
    if (maxResults != -1) {
        query.setMaxResults(maxResults);
    }
    List<UserEntity> results = query.getResultList();
    List<UserModel> users = new LinkedList<>();
    for (UserEntity entity : results) users.add(new UserAdapter(session, realm, model, entity));
    return users;
}
 
开发者ID:nmajorov,项目名称:keycloak_training,代码行数:16,代码来源:EjbExampleUserStorageProvider.java

示例10: getTopUsersWithoutCounter

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
public List<User> getTopUsersWithoutCounter(int n) {

        TypedQuery<User> query = em.createQuery(
                "select u from User u order by size(u.posts) + size(u.comments) DESC",
                User.class);
        query.setMaxResults(n);

        return query.getResultList();
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:10,代码来源:UserEJB.java

示例11: getRandomQuizzes

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
public List<Quiz> getRandomQuizzes(int n, long categoryId){

        TypedQuery<Long>  sizeQuery= em.createQuery("select count(q) from Quiz q where q.subCategory.parent.id=?1", Long.class);
        sizeQuery.setParameter(1, categoryId);
        long size = sizeQuery.getSingleResult();

        if(n > size){
            throw new IllegalArgumentException("Cannot chose " + n + " unique quizzes out of the " + size + " existing");
        }

        Random random = new Random();

        List<Quiz> quizzes = new ArrayList<>();
        Set<Integer> chosen = new HashSet<>();

        while(chosen.size() < n) {

            int k = random.nextInt((int)size);
            if(chosen.contains(k)){
                continue;
            }
            chosen.add(k);

            TypedQuery<Quiz> query = em.createQuery(
                    "select q from Quiz q where q.subCategory.parent.id=?1",
                    Quiz.class);
            query.setParameter(1, categoryId);
            query.setMaxResults(1);
            query.setFirstResult(k);

            quizzes.add(query.getSingleResult());
        }


        return  quizzes;
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:37,代码来源:QuizEjb.java

示例12: paging

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public <T> Page<T> paging(Pageable pageable) {
	if (parent != null) {
		applyPredicateToCriteria(sq);
		return parent.paging(pageable);
	}
	List<T> list;
	if (pageable == null) {
		list = list();
		return new PageImpl<T>(list);
	} else {
		Sort sort = pageable.getSort();
		if (sort != null) {
			orders.addAll(QueryUtils.toOrders(sort, root, cb));
		}
		applyPredicateToCriteria(criteria);
		TypedQuery<?> query = em.createQuery(criteria);
		
		query.setFirstResult(pageable.getOffset());
		query.setMaxResults(pageable.getPageSize());

		Long total = JpaUtil.count(criteria);
		List<T> content = Collections.<T> emptyList();
		if (total > pageable.getOffset()) {
			content = transform(query, false);
		}

		return new PageImpl<T>(content, pageable, total);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:31,代码来源:LinqImpl.java

示例13: search

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Override
public List<?> search(String entityName, String query, int limit, int pageNumber)
{
	List<T> resultsList = new ArrayList<>();
	
	Class<T> clazz = entityList.get(entityName);
	
	if(clazz == null) throw new RuntimeException("ENTITY.NOT.FOUND");
	
	boolean isValid = query == null ? true : validateQuery(query, clazz);  
	
	if(isValid) {
		
		CriteriaBuilder criteriaBuilder = entitymanager.getCriteriaBuilder();
		CriteriaQuery<T> cq = criteriaBuilder.createQuery(clazz);
		
		Root<T> root = cq.from(clazz);			
		
		if(query!=null) {
			Predicate predicate = populatePredicates(root, query);
			cq.where(predicate);				
		}
		
           cq.select(root);
           TypedQuery<T> q = entitymanager.createQuery(cq);
           q.setFirstResult((pageNumber-1) * limit);
           q.setMaxResults(limit);
           resultsList = q.getResultList();
           System.out.println(resultsList.size());
	} else {
		throw new RuntimeException("Property defined in the query is not valid, doesn't belong to the entity type:"+entityName);
	}
	return resultsList;
}
 
开发者ID:tairmansd,项目名称:CriteriaBuilder,代码行数:35,代码来源:CriteriaServiceImpl.java

示例14: findAll

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
/**
 * 分页条件查询
 * @param cq 条件
 * @param pageable 分页信息
 * @param <T> 领域类(实体类)范型
 * @return 分页结果
 */
public static <T> Page<T> findAll(CriteriaQuery<T> cq, Pageable pageable) {
	Class<T> domainClass = cq.getResultType();
	Root<T> root;
	if (CollectionUtils.isEmpty(cq.getRoots())) {
		root = cq.from(domainClass);
	} else {
		root = (Root<T>) cq.getRoots().iterator().next();
	}
	EntityManager em = getEntityManager(domainClass);
	if (pageable == null) {
		List<T> list = findAll(cq);
		return new PageImpl<T>(list);
	} else {
		Sort sort = pageable.getSort();
		cq.orderBy(QueryUtils.toOrders(sort, root, em.getCriteriaBuilder()));
		TypedQuery<T> query = em.createQuery(cq);
		
		query.setFirstResult(pageable.getOffset());
		query.setMaxResults(pageable.getPageSize());

		Long total = count(cq);
		List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T> emptyList();

		return new PageImpl<T>(content, pageable, total);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:35,代码来源:JpaUtil.java

示例15: personDTOResultTest

import javax.persistence.TypedQuery; //导入方法依赖的package包/类
@Test
   public void personDTOResultTest() {
StrQLBuilder sql = StrQLBuilder.createNative()
	.select("p.id_person as idPerson")
	.select("p.name AS name")
	.select("p.surname as \"surname\"")
	.select("p.enabled as enabled,p.alive as alive")
	.select("p.creation_date as creationDate")
	.select("p.age as age, p.height as height")
	.select("p.name as reallyLongPropertyToTestLongAliases")
	.select("p.name as \"reallyLongPropertyToTestLongAliases\"")
	.select("p.birthday")
	.select("p.name as parent.name")
	.from("Person p")
	.leftjoin("Job j").on("j.id_job = p.id_job").and("p.name = :name", "Luis")
	.where("p.name = :pname", "Luis")
	.andlike("p.name", ":name_pattern", "uis")
	.and("p.name IN :pnamearray", (Object) new String[] { "Luis" })
	.and("p.name IN :pnamelist", Arrays.asList("Luis"))
	.and("p.name IN (:pnamelist2)", Arrays.asList("Luis"))
	.order(by("surname", DESC).and("name"));

TypedQuery<PersonDTO> query = sql.createQuery(entityManager, PersonDTO.class);
query.setFirstResult(0);
query.setMaxResults(1);
List<PersonDTO> persons = query.getResultList();

assertThat(persons, hasSize(1));
PersonDTO person = persons.get(0);
assertThat(person, is(not(nullValue())));
assertThat(person.getIdPerson(), is(not(nullValue())));
assertThat(person.getName(), is("Luis"));
assertThat(person.getSurname(), is("Labiano"));
assertThat(person.getAge(), is(11));
assertThat(person.getHeight(), is(1.20f));
assertThat(person.getBirthday(), is(not(nullValue())));
assertThat(person.getCreationDate(), is(not(nullValue())));
assertThat(person.getEnabled(), is(Enabled.ENABLED));
assertThat(person.getAlive(), is(true));
assertThat(person.getReallyLongPropertyToTestLongAliases(), is("Luis"));
assertThat(person.getParent().getName(), is("Luis"));
   }
 
开发者ID:iaunzu,项目名称:strqlbuilder,代码行数:43,代码来源:StrQLBuilderNativeTest.java


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