Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content, Pageable pageable, long total) 

Source Link

Document

Constructor of PageImpl .

Usage

From source file:io.curly.advisor.command.ReviewHystrixCommands.java

private Page<Review> defaultFindAllByOwner(User user, Pageable pageable) {
    log.warn("User {} requested all its reviews but we fell back, current page is {}", user,
            pageable.getPageNumber());/* w ww .  j a  v  a  2s.  c o m*/
    return new PageImpl<>(Collections.<Review>emptyList(), pageable, 0);
}

From source file:org.jblogcms.core.comment.service.CommentServiceImplTest.java

@Before
public void setUp() throws Exception {
    comment1.setId(COMMENT_1_ID);//from ww w  .j a v a 2  s  .  co m
    comment1.setText(COMMENT_1_TEXT);

    comment2.setId(COMMENT_2_ID);
    comment2.setText(COMMENT_2_TEXT);

    comment3.setId(COMMENT_3_ID);
    comment3.setText(COMMENT_3_TEXT);

    existingComment.setId(EXISTING_COMMENT_ID);
    existingComment.setText(EXISTING_COMMENT_TEXT);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    comments = new PageImpl(commentList, pageable, COMMENTS_SIZE);
}

From source file:org.jblogcms.core.post.service.PostServiceImplTest.java

@Before
public void setUp() throws Exception {
    post1.setId(POST_1_ID);//from  w ww  . ja va  2  s .com
    post1.setTitle(POST_1_TITLE);

    post2.setId(POST_2_ID);
    post2.setTitle(POST_2_TITLE);

    post3.setId(POST_3_ID);
    post3.setTitle(POST_3_TITLE);

    existingPost.setId(EXISTING_POST_ID);
    existingPost.setTitle(EXISTING_POST_TITLE);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    posts = new PageImpl(postList, pageable, POSTS_SIZE);
}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

@Override
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, Specification<T> spec) {
    query.setFirstResult(pageable.getOffset());
    query.setMaxResults(pageable.getPageSize());

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

    return new PageImpl<T>(content, pageable, total);
}

From source file:org.jblogcms.core.account.service.AccountServiceImplTest.java

@Before
public void setUp() throws Exception {
    account1.setId(ACCOUNT_1_ID);/*w w w  .java2 s .c o  m*/
    account1.setEmail(ACCOUNT_1_EMAIL);

    account2.setId(ACCOUNT_2_ID);
    account2.setEmail(ACCOUNT_2_EMAIL);

    account3.setId(ACCOUNT_3_ID);
    account3.setEmail(ACCOUNT_3_EMAIL);

    existingAccount.setId(EXISTING_ACCOUNT_ID);
    existingAccount.setEmail(EXISTING_ACCOUNT_EMAIL);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    accounts = new PageImpl(accountList, pageable, ACCOUNTS_SIZE);
}

From source file:org.wallride.repository.TagRepositoryImpl.java

@Override
public Page<Tag> search(TagSearchRequest request, Pageable pageable) {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Tag.class).get();

    @SuppressWarnings("rawtypes")
    BooleanJunction<BooleanJunction> junction = qb.bool();
    junction.must(qb.all().createQuery());

    if (StringUtils.hasText(request.getKeyword())) {
        Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("synonyms");
        String[] fields = new String[] { "name" };
        MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
        parser.setDefaultOperator(QueryParser.Operator.AND);
        Query query = null;/* w  w w  . j  av a 2  s. c  o  m*/
        try {
            query = parser.parse(request.getKeyword());
        } catch (ParseException e1) {
            try {
                query = parser.parse(QueryParser.escape(request.getKeyword()));
            } catch (ParseException e2) {
                throw new RuntimeException(e2);
            }
        }
        junction.must(query);
    }

    if (StringUtils.hasText(request.getLanguage())) {
        junction.must(qb.keyword().onField("language").matching(request.getLanguage()).createQuery());
    }

    Query searchQuery = junction.createQuery();

    Session session = (Session) entityManager.getDelegate();
    Criteria criteria = session.createCriteria(Tag.class);

    Sort sort = new Sort(new SortField("sortName", SortField.Type.STRING));

    FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(searchQuery, Tag.class)
            .setCriteriaQuery(criteria).setSort(sort);
    persistenceQuery.setFirstResult(pageable.getOffset());
    persistenceQuery.setMaxResults(pageable.getPageSize());

    int resultSize = persistenceQuery.getResultSize();

    @SuppressWarnings("unchecked")
    List<Tag> results = persistenceQuery.getResultList();
    return new PageImpl<>(results, pageable, resultSize);
}

From source file:me.doshou.admin.monitor.web.controller.SQLExecutorController.java

@PageableDefaults(pageNumber = 0, value = 10)
@RequestMapping(value = "/sql", method = RequestMethod.POST)
public String executeQL(final @RequestParam("sql") String sql, final Model model, final Pageable pageable) {

    model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em));

    String lowerCaseSQL = sql.trim().toLowerCase();
    final boolean isDML = lowerCaseSQL.startsWith("insert") || lowerCaseSQL.startsWith("update")
            || lowerCaseSQL.startsWith("delete");
    final boolean isDQL = lowerCaseSQL.startsWith("select");

    if (!isDML && !isDQL) {
        model.addAttribute(Constants.ERROR,
                "SQL????insert?update?delete?select");
        return showSQLForm();
    }/*from www  .  j a v  a  2  s  .c  o  m*/
    try {
        new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
            @Override
            public Void doInTransaction(TransactionStatus status) {

                if (isDML) {
                    Query query = em.createNativeQuery(sql);
                    int updateCount = query.executeUpdate();
                    model.addAttribute("updateCount", updateCount);
                } else {
                    String findSQL = sql;
                    String countSQL = "select count(*) count from (" + findSQL + ") o";
                    Query countQuery = em.createNativeQuery(countSQL);
                    Query findQuery = em.createNativeQuery(findSQL);
                    findQuery.setFirstResult(pageable.getOffset());
                    findQuery.setMaxResults(pageable.getPageSize());

                    Page page = new PageImpl(findQuery.getResultList(), pageable,
                            ((BigInteger) countQuery.getSingleResult()).longValue());

                    model.addAttribute("resultPage", page);

                    em.unwrap(Session.class).doWork(new Work() {
                        @Override
                        public void execute(final Connection connection) throws SQLException {
                            PreparedStatement psst = connection.prepareStatement(sql);
                            ResultSetMetaData metaData = psst.getMetaData();

                            List<String> columnNames = Lists.newArrayList();
                            for (int i = 1, l = metaData.getColumnCount(); i <= l; i++) {
                                columnNames.add(metaData.getColumnLabel(i));
                            }
                            psst.close();
                            model.addAttribute("columnNames", columnNames);
                        }
                    });
                }

                return null;
            }
        });
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        model.addAttribute(Constants.ERROR, sw.toString());
    }

    return showSQLForm();
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

@Override
public Page<ConsultantModel> findAllConsultants(Pageable pageable) {
    Page<Consultant> consultantPage = consultantRepository.findAll(pageable);
    return new PageImpl<>(mysqlConsultantToModelConverter.convertList(consultantPage.getContent()), pageable,
            consultantPage.getTotalElements());
}

From source file:com.luna.common.repository.UserRepository2Impl.java

/**
 * ?/?//from w w  w  . ja  va  2  s  .  c  o  m
 *
 * @param searchable
 * @return
 */
public Page<User> findAllByCustom(final Searchable searchable) {
    long total = countAllByCustom(searchable);
    List<User> contentList = repositoryHelper.findAll(findAllQL, searchable, customSearchCallback);
    return new PageImpl(contentList, searchable.getPage(), total);
}