List of usage examples for org.hibernate ScrollableResults next
boolean next();
From source file:fr.gael.dhus.service.KeyStoreService.java
License:Open Source License
/** * Retrieves entries of a keyStore, oldest first. * @param keyStoreName the name of the keyStore * @return an Iterator of KeyStoreEntry/*w w w . ja va2 s .c om*/ */ public Iterator<KeyStoreEntry> getOldestEntries(String keyStoreName) { final ScrollableResults entries = keyStoreEntryDao.readOldestEntries(keyStoreName); return new Iterator<KeyStoreEntry>() { @Override public boolean hasNext() { return entries.next(); } @Override public KeyStoreEntry next() { return (KeyStoreEntry) entries.get(0); } @Override public void remove() { throw new UnsupportedOperationException("Remove not supported."); } }; }
From source file:fr.mael.microrss.dao.impl.UserArticleDaoImpl.java
License:Open Source License
private void manageResults(Class clazz, FullTextSession searchSession) { ScrollableResults results = searchSession.createCriteria(clazz).setFetchMode("article", FetchMode.JOIN) .setFetchSize(100).scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*w w w. j a v a 2s . c om*/ searchSession.index(results.get(0)); if (index % 100 == 0) { searchSession.flushToIndexes(); searchSession.clear(); } } searchSession.flushToIndexes(); searchSession.clear(); }
From source file:gallery.service.rss.RssServiceImpl.java
License:Apache License
@Override @Transactional(readOnly = true)//from w w w . jav a2 s .com public void create() { if (generating) { logger.info("xml is allready generating ..."); return; } try { generating = true; logger.info("start generate xml"); long time = System.currentTimeMillis(); File img_dir = new File(wallpaper_service.getStorePath(), Config.ENCLOSURE_IMG_SUBDIR); //get main wallpaper page Channel chan; List<Pages> temp = pages_service.getByPropertiesValueOrdered(null, MAIN_PSEUDONYMES, MAIN_VALUES, null, null); if (temp.isEmpty()) { chan = new Channel(gallery.web.Config.SITE_NAME, gallery.web.Config.SITE_NAME, gallery.web.Config.SITE_NAME); } else { //TODO localize it !!! IAutoreplaceService.IReplacement repl = autoreplace_service.getAllReplacements("ru"); String title = repl.replaceAll(temp.get(0).getTitle()); String description = repl.replaceAll(temp.get(0).getDescription()); chan = new Channel(title, gallery.web.Config.SITE_NAME, description); } RSS rss = new RSS(); chan.setImage(new Channel.Image(gallery.web.Config.SITE_NAME + Config.LOGO_WEBDIR, chan.getTitle(), chan.getLink(), 0, 0, null)); chan.setLastBuildDate(new java.util.Date()); rss.addChannel(chan); ScrollableResults sr = wallpaper_service.getScrollableResults( "id, id_pages, description, title, date_upload, name", "active", Boolean.TRUE, new String[] { "date_upload" }, new String[] { "DESC" }); int max_elements = 100; sr.beforeFirst(); while (sr.next() && (max_elements-- > 0)) { try { Item item = new Item(sr.getString(2), gallery.web.Config.SITE_NAME + "index.htm?id_pages_nav=" + sr.getLong(1) + "&id_photo_nav=" + sr.getLong(0), sr.getString(3)); item.setPubDate(sr.getDate(4)); long fileLen = (new File(img_dir, sr.getString(5))).length(); if (fileLen > 0) { item.setEnclosure(new Item.Enclosure( gallery.web.Config.SITE_NAME + Config.ENCLOSURE_IMG_WEBDIR + sr.getString(5), fileLen, "image/jpeg")); } //item.addCategory(new Item.Category("test")); chan.addItem(item); } finally { //TODO: mb add some logging here } } sr.close(); try { new RSSFeedGeneratorImpl().generateToFile(rss, new File(path, Config.RSS_FILE_NAME), "UTF-8"); } catch (Exception e) { logger.error("error while saving rss to file", e); } time = System.currentTimeMillis() - time; logger.info("end generate xml. generated in: " + time); } finally { generating = false; } }
From source file:gov.nih.nci.caarray.plugins.nimblegen.NdfHandler.java
License:BSD License
private int loadProbes(ArrayDesignDetails details, Map<String, LogicalProbe> logicalProbes, ScrollableResults results) throws IOException { int count = 0; results.beforeFirst();/*from ww w . j ava 2 s .c o m*/ String lastSeqId = null; while (results.next()) { final Object[] values = results.get(); final Map<String, Object> vals = new HashMap<String, Object>(); vals.put(PROBE_ID, values[0]); vals.put(SEQ_ID, values[1]); vals.put(CONTAINER2, values[2]); vals.put(X, values[3]); vals.put(Y, values[4]); if (lastSeqId != null && !vals.get(SEQ_ID).equals(lastSeqId)) { logicalProbes.clear(); flushAndClearSession(); } lastSeqId = (String) vals.get(SEQ_ID); final PhysicalProbe p = createPhysicalProbe(details, vals, logicalProbes); getArrayDao().save(p); ++count; } return count; }
From source file:gov.nih.nci.indexgen.Indexer.java
License:BSD License
/** * Generates lucene documents//from www .jav a 2s . c o m */ public void run() { System.out.println("Started " + entity.getEntityName()); long start = System.currentTimeMillis(); try { fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); Transaction transaction = fullTextSession.beginTransaction(); // Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createQuery("from " + entity.getEntityName()) .scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (results.next()) { fullTextSession.index(results.get(0)); if (++i % batchSize == 0) fullTextSession.clear(); } transaction.commit(); } finally { fullTextSession.close(); } long end = System.currentTimeMillis(); System.out.println("Completed " + entity.getEntityName() + " in " + (end - start) + " ms"); }
From source file:gr.abiss.calipso.service.impl.UserServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = false)/* www.jav a2 s . co m*/ public void expireResetPasswordTokens() { // get a hibernate session suitable for read-only access to large datasets StatelessSession session = ((Session) this.repository.getEntityManager().getDelegate()).getSessionFactory() .openStatelessSession(); Date yesterday = DateUtils.addDays(new Date(), -1); // send email notifications for account confirmation tokens that expired org.hibernate.Query query = session.createQuery( "SELECT new gr.abiss.calipso.model.UserDTO(u.id, u.firstName, u.lastName,u.username, u.email, u.emailHash) FROM User u " + "WHERE u.password IS NULL and u.resetPasswordTokenCreated IS NOT NULL and u.resetPasswordTokenCreated < :yesterday"); query.setParameter("yesterday", yesterday); query.setFetchSize(Integer.valueOf(1000)); query.setReadOnly(true); query.setLockMode("a", LockMode.NONE); ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { UserDTO dto = (UserDTO) results.get(0); // TODO: send expiration email this.emailService.sendAccountConfirmationExpired(new User(dto)); } results.close(); session.close(); // expire tokens, including password reset requests this.repository.expireResetPasswordTokens(yesterday); }
From source file:it.jugpadova.blo.EventBo.java
License:Apache License
public void regenerateLuceneIndexes() { Session session = this.eventDao.getHibernateTemplate().getSessionFactory().getCurrentSession(); FullTextSession fullTextSession = Search.createFullTextSession(session); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); ScrollableResults results = fullTextSession.createCriteria(Event.class).scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*from w ww . j a va 2s. c o m*/ fullTextSession.index(results.get(0)); //index each element if (index % 50 == 0) { fullTextSession.clear(); //clear every batchSize since the queue is processed } } }
From source file:jp.go.nict.langrid.dao.hibernate.HibernateOverUseStateDao.java
License:Open Source License
private OverUseState getNextOverUseState(ScrollableResults iLog) { if (!iLog.next()) return null; Object[] row = iLog.get();/* w ww . ja v a2 s.c om*/ LimitType t = (LimitType) iLog.get(6); long currentValue = 0; if (t.equals(LimitType.FREQUENCY)) { currentValue = ((Number) iLog.get(8)).longValue(); } else { currentValue = ((Number) iLog.get(9)).longValue(); } return new OverUseState((String) iLog.get(0), (String) iLog.get(1), (String) iLog.get(2), (String) iLog.get(3), (Calendar) iLog.get(4), (Period) iLog.get(5), t, (Integer) iLog.get(7), currentValue, (Calendar) iLog.get(10)); }
From source file:kr.debop4j.data.ogm.dao.HibernateOgmDao.java
License:Apache License
@Override public void indexAll(Class<?> clazz, int batchSize) { if (isDebugEnabled) log.debug("[{}]? ? ??? ...", clazz); clearIndex(clazz);//from w w w .ja va2 s .c o m if (batchSize < DEFAUALT_BATCH_SIZE) batchSize = DEFAUALT_BATCH_SIZE; FullTextSession fts = getFullTextSession(); FlushMode currentFlushMode = fts.getFlushMode(); CacheMode currentCacheMode = fts.getCacheMode(); fts.setFlushMode(FlushMode.MANUAL); fts.setCacheMode(CacheMode.IGNORE); try { Transaction tx = fts.beginTransaction(); ScrollableResults results = fts.createCriteria(clazz).scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { fts.index(results.get(0)); if (++index % batchSize == 0) { fts.flushToIndexes(); fts.clear(); if (isTraceEnabled) log.trace("?? . index=[{}]", index); } } fts.flushToIndexes(); tx.commit(); log.info("[{}]? [{}] ??? !!!", clazz, index); } finally { fts.setFlushMode(currentFlushMode); fts.setCacheMode(currentCacheMode); } }