當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。