List of usage examples for org.springframework.data.domain Page hasContent
boolean hasContent();
From source file:org.apache.shiro.web.session.mgt.OnlineWebSessionManager.java
/** * ?session? session//from www . j ava 2 s . c om */ @Override public void validateSessions() { if (log.isInfoEnabled()) { log.info("invalidation sessions..."); } int invalidCount = 0; int timeout = (int) getGlobalSessionTimeout(); Date expiredDate = DateUtils.addMilliseconds(new Date(), 0 - timeout); PageRequest pageRequest = new PageRequest(0, 100); Page<UserOnline> page = userOnlineService.findExpiredUserOnlineList(expiredDate, pageRequest); //?? while (page.hasContent()) { List<String> needOfflineIdList = Lists.newArrayList(); for (UserOnline userOnline : page.getContent()) { try { SessionKey key = new DefaultSessionKey(userOnline.getId()); Session session = retrieveSession(key); //cache db if (session != null) { session.setAttribute(ShiroConstants.ONLY_CLEAR_CACHE, true); } validate(session, key); } catch (InvalidSessionException e) { if (log.isDebugEnabled()) { boolean expired = (e instanceof ExpiredSessionException); String msg = "Invalidated session with id [" + userOnline.getId() + "]" + (expired ? " (expired)" : " (stopped)"); log.debug(msg); } invalidCount++; needOfflineIdList.add(userOnline.getId()); } } if (needOfflineIdList.size() > 0) { try { userOnlineService.batchOffline(needOfflineIdList); } catch (Exception e) { log.error("batch delete db session error.", e); } } pageRequest = new PageRequest(0, pageRequest.getPageSize()); page = userOnlineService.findExpiredUserOnlineList(expiredDate, pageRequest); } if (log.isInfoEnabled()) { String msg = "Finished invalidation session."; if (invalidCount > 0) { msg += " [" + invalidCount + "] sessions were stopped."; } else { msg += " No sessions were stopped."; } log.info(msg); } }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDao.java
/** * Checks if this search was by made with too big page number specified * * @param searchResults search results//from ww w .ja v a 2 s .co m * @return true if page number is too big */ private boolean isSearchedAboveLastPage(Page<Topic> searchResults) { return !searchResults.hasContent() && searchResults.getNumber() > searchResults.getTotalPages(); }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test public void testSearchWithFullyDirtySearchText() { configureMocks(StringUtils.EMPTY, StringUtils.EMPTY); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(StringUtils.EMPTY, DEFAULT_PAGE_REQUEST, Arrays.asList(1L)); Assert.assertTrue(!searchResultPage.hasContent(), "Search result must be empty."); }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test(dataProvider = "parameterFullPhraseSearch") public void testFullPhraseSearch(String content) { Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.setTitle(content);//from w ww. ja va 2s . c om saveAndFlushIndexes(Arrays.asList(expectedTopic)); configureMocks(content, content); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(content, DEFAULT_PAGE_REQUEST, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty."); for (Topic topic : searchResultPage.getContent()) { Assert.assertEquals(expectedTopic.getTitle(), topic.getTitle(), "Content from the index should be the same as in the database."); } }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test public void testFullPhraseSearchPageNumberTooLow() { Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.setTitle(TOPIC_CONTENT); saveAndFlushIndexes(Arrays.asList(expectedTopic)); configureMocks(TOPIC_CONTENT, TOPIC_CONTENT); PageRequest pageRequest = new PageRequest("-1", PAGE_SIZE); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(TOPIC_CONTENT, pageRequest, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertEquals(searchResultPage.getNumber(), 1); Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty."); for (Topic topic : searchResultPage.getContent()) { Assert.assertEquals(expectedTopic.getTitle(), topic.getTitle(), "Content from the index should be the same as in the database."); }/*from ww w .j ava 2s .c om*/ }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test public void testFullPhraseSearchPageNumberTooBig() { Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.setTitle(TOPIC_CONTENT); saveAndFlushIndexes(Arrays.asList(expectedTopic)); configureMocks(TOPIC_CONTENT, TOPIC_CONTENT); PageRequest pageRequest = new PageRequest("1000", 50); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(TOPIC_CONTENT, pageRequest, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertEquals(searchResultPage.getNumber(), 1); Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty."); for (Topic topic : searchResultPage.getContent()) { Assert.assertEquals(expectedTopic.getTitle(), topic.getTitle(), "Content from the index should be the same as in the database."); }/*from w ww. j av a 2 s .c o m*/ }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test(dataProvider = "parameterFullPhraseSearch") public void testPostContentSearch(String content) { Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.getLastPost().setPostContent(content); saveAndFlushIndexes(Arrays.asList(expectedTopic)); configureMocks(content, content);// w w w. j a v a 2 s . c o m Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(content, DEFAULT_PAGE_REQUEST, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty."); for (Topic topic : searchResultPage.getContent()) { Assert.assertEquals(expectedTopic.getTitle(), topic.getTitle(), "Content from the index should be the same as in the database."); } }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test(dataProvider = "parameterPiecePhraseSearch") public void testPiecePhraseSearch(String firstPiece, char delimeter, String secondPiece) { String content = firstPiece + delimeter + secondPiece; Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.setTitle(content);//from w w w. j ava 2s. co m saveAndFlushIndexes(Arrays.asList(expectedTopic)); for (String piece : Arrays.asList(firstPiece, secondPiece)) { configureMocks(piece, piece); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(piece, DEFAULT_PAGE_REQUEST, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertTrue(searchResultPage.hasContent(), "Search result must not be empty."); } }
From source file:org.jtalks.jcommune.model.dao.search.hibernate.TopicHibernateSearchDaoTest.java
@Test(dataProvider = "parameterIncorrectPhraseSearch") public void testIncorrectPhraseSearch(String correct, String incorrect) { Topic expectedTopic = PersistedObjectsFactory.getDefaultTopic(); expectedTopic.setTitle(correct);/*w ww. java 2 s . c o m*/ saveAndFlushIndexes(Arrays.asList(expectedTopic)); configureMocks(incorrect, incorrect); Page<Topic> searchResultPage = topicSearchDao.searchByTitleAndContent(incorrect, DEFAULT_PAGE_REQUEST, Arrays.asList(expectedTopic.getBranch().getId())); Assert.assertTrue(!searchResultPage.hasContent(), "Search result must be empty."); }