List of usage examples for org.hibernate ScrollableResults next
boolean next();
From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java
License:Open Source License
@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED) public void getNonInstanceBasedSWReport(PrintWriter pPrintWriter) { // TODO Auto-generated method stub printHeader(NON_INSTANCE_REPORT_NAME, null, NON_INSTANCE_REPORT_COLUMN_HEADERS, pPrintWriter); ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()).createSQLQuery( "SELECT sw.SOFTWARE_NAME, mf.NAME, non.RESTRICTION, ct.DESCRIPTION as ctDesc, CASE non.BASE_ONLY WHEN 1 THEN 'Y' ELSE 'N' END, st.DESCRIPTION as stDesc, non.REMOTE_USER, non.RECORD_TIME FROM EAADMIN.NON_INSTANCE non, EAADMIN.SOFTWARE sw, EAADMIN.MANUFACTURER mf, EAADMIN.CAPACITY_TYPE ct, EAADMIN.STATUS st WHERE non.SOFTWARE_ID = sw.SOFTWARE_ID AND non.MANUFACTURER_ID = mf.ID AND non.CAPACITY_TYPE_CODE = ct.CODE AND non.STATUS_ID = st.ID") .scroll(ScrollMode.FORWARD_ONLY); while (lsrReport.next()) { pPrintWriter.println(outputData(lsrReport.get())); }// www.j av a 2 s . c o m lsrReport.close(); }
From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED) public void getAlertHardwareCfgDataReport(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb, OutputStream pOutputStream) throws HibernateException, Exception { AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode") .setParameter("code", "HWCFGDTA").getSingleResult(); StringBuffer sb = new StringBuffer( "SELECT CASE WHEN VA.Alert_Age > 90 THEN 'Red' WHEN VA.Alert_Age > 45 THEN 'Yellow' ELSE 'Green' END, "); sb.append(/*from w ww. jav a 2s. co m*/ "H.Serial, MT.Name, H.processor_manufacturer, H.MAST_PROCESSOR_TYPE, H.PROCESSOR_MODEL, H.NBR_CORES_PER_CHIP, H.CHIPS, ") .append("H.PROCESSOR_COUNT, H.NBR_OF_CHIPS_MAX, H.CPU_GARTNER_MIPS, H.CPU_MIPS, H.CPU_MSU, ") .append("VA.Creation_Time, VA.Alert_Age, MT.Type, VA.Remote_User, VA.Comments, VA.Record_Time,AC.name as ac_name, ") .append("CC.target_date,CC.owner as cc_owner,CC.record_time as cc_record_time,CC.remote_user as cc_remote_user, CC.id as cc_id ") .append("FROM EAADMIN.V_Alerts VA, EAADMIN.Hardware H, EAADMIN.Machine_Type MT, EAADMIN.cause_code CC, EAADMIN.alert_cause AC ") .append("WHERE VA.Customer_Id = :customerId AND VA.Type = 'HWCFGDTA' AND VA.Open = 1 AND H.Id = VA.FK_Id AND MT.Id = H.Machine_Type_Id ") .append("and VA.id=CC.alert_id and CC.alert_type_id= :alertTypeId and CC.alert_cause_id=AC.id ORDER BY H.Serial ASC "); ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()).createSQLQuery(sb.toString()) .setLong("customerId", pAccount.getId()).setInteger("alertTypeId", alertType.getId().intValue()) .scroll(ScrollMode.FORWARD_ONLY); HSSFSheet sheet = phwb.createSheet("Alert Hardware Config " + pAccount.getAccount() + " Report"); printHeader(ALERT_HARDWARE_CFGDATA_REPORT_NAME, pAccount.getAccount(), ALERT_HARDWARE_CFGDATA_REPORT_COLUMN_HEADERS, sheet); int i = 3; while (lsrReport.next()) { int k = 1; if (i > 65535) { k++; sheet = phwb.createSheet("Alert Hardware Config " + pAccount.getAccount() + " Report" + k); i = 1; } HSSFRow row = sheet.createRow((int) i); outputData(lsrReport.get(), row); i++; } @SuppressWarnings("unchecked") Iterator<Object[]> vCauseCodeSummary = getEntityManager() .createNamedQuery("getValidCauseCodesByAlertTypeId").setParameter("alertTypeId", alertType.getId()) .getResultList().iterator(); HSSFSheet sheet_2 = phwb.createSheet("Valid Cause Codes"); HSSFRow rowhead0 = sheet_2.createRow((int) 0); outputData(ALERT_VALID_CAUSE_CODE_HEADERS, rowhead0); int j = 1; while (vCauseCodeSummary.hasNext()) { HSSFRow row = sheet_2.createRow((int) j); outputData(vCauseCodeSummary.next(), row); j++; } phwb.write(pOutputStream); }
From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java
License:Open Source License
@Override @Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED) public void getAlertUnlicensed(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb, OutputStream pOutputStream, String type, String code, String reportName, String sheetName) throws HibernateException, Exception { AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode") .setParameter("code", code).getSingleResult(); StringBuffer sb = new StringBuffer(unlicensedAlertQuery); ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()).createSQLQuery(sb.toString()) .setLong("customerId", pAccount.getId()).setParameter("type", type).setParameter("code", code) .scroll(ScrollMode.FORWARD_ONLY); HSSFSheet sheet = phwb.createSheet(sheetName + " " + pAccount.getAccount() + " Report"); printHeader(reportName, pAccount.getAccount(), UNLICENSED_GROUP_COLUMN_HEADERS, sheet); int i = 3;// ww w . j a v a 2s . c om while (lsrReport.next()) { int k = 1; if (i > 65535) { k++; sheet = phwb.createSheet("Alert Contract Scope " + pAccount.getAccount() + " Report" + k); i = 1; } HSSFRow row = sheet.createRow((int) i); outputData(lsrReport.get(), row); i++; } @SuppressWarnings("unchecked") Iterator<Object[]> vCauseCodeSummary = getEntityManager() .createNamedQuery("getValidCauseCodesByAlertTypeId").setParameter("alertTypeId", alertType.getId()) .getResultList().iterator(); HSSFSheet sheet_2 = phwb.createSheet("Valid Cause Codes"); HSSFRow rowhead0 = sheet_2.createRow((int) 0); outputData(ALERT_VALID_CAUSE_CODE_HEADERS, rowhead0); int j = 1; while (vCauseCodeSummary.hasNext()) { HSSFRow row = sheet_2.createRow((int) j); outputData(vCauseCodeSummary.next(), row); j++; } phwb.write(pOutputStream); }
From source file:com.ibm.ea.bravo.report.MainframeScan.java
public void execute(String[] args, HttpServletRequest request) { ScrollableResults list = null; try {// w w w .j a v a2 s .c om // get the report Session session = DelegateReport.getSession(); list = session.getNamedQuery("mainFrameScanReport").scroll(); // get the output writer PrintWriter os = new PrintWriter(outputStream, true); os.println(Constants.CONFIDENTIAL); // output the header os.println(tsv(HEADER)); // output the report while (list.next()) { os.println(tsv(list.get())); } os.close(); DelegateReport.closeSession(session); } catch (Exception e) { logger.error(e); } }
From source file:com.ikon.module.db.stuff.IndexHelper.java
License:Open Source License
protected int doRebuildIndex() throws Exception { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(org.hibernate.FlushMode.MANUAL); fullTextSession.setCacheMode(org.hibernate.CacheMode.IGNORE); fullTextSession.purgeAll(NodeDocumentVersion.class); fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class); String query = "select ndv from NodeDocumentVersion ndv"; ScrollableResults cursor = fullTextSession.createQuery(query).scroll(); cursor.last();/* w w w . j a v a2 s . c o m*/ int count = cursor.getRowNumber() + 1; log.warn("Re-building Wine index for " + count + " objects."); if (count > 0) { int batchSize = 300; cursor.first(); // Reset to first result row int i = 0; while (true) { fullTextSession.index(cursor.get(0)); if (++i % batchSize == 0) { fullTextSession.flushToIndexes(); fullTextSession.clear(); // Clear persistence context for each batch log.info("Flushed index update " + i + " from Thread " + Thread.currentThread().getName()); } if (cursor.isLast()) { break; } cursor.next(); } } cursor.close(); fullTextSession.flushToIndexes(); fullTextSession.clear(); // Clear persistence context for each batch fullTextSession.getSearchFactory().optimize(NodeDocumentVersion.class); return count; }
From source file:com.ikon.servlet.admin.RebuildIndexesServlet.java
License:Open Source License
/** * FlushToIndexes implementation/*from w w w . j av a 2 s.co m*/ */ @SuppressWarnings("rawtypes") private void luceneIndexesFlushToIndexes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("luceneIndexesFlushToIndexes({}, {})", request, response); PrintWriter out = response.getWriter(); response.setContentType(MimeTypeConfig.MIME_HTML); header(out, "Rebuild Lucene indexes", breadcrumb); out.flush(); FullTextSession ftSession = null; Session session = null; Transaction tx = null; try { Config.SYSTEM_MAINTENANCE = true; Config.SYSTEM_READONLY = true; out.println("<ul>"); out.println("<li>System into maintenance mode</li>"); FileLogger.info(BASE_NAME, "BEGIN - Rebuild Lucene indexes"); session = HibernateUtil.getSessionFactory().openSession(); ftSession = Search.getFullTextSession(session); ftSession.setFlushMode(FlushMode.MANUAL); ftSession.setCacheMode(CacheMode.IGNORE); tx = ftSession.beginTransaction(); Map<String, Long> total = new HashMap<String, Long>(); // Calculate number of entities for (Class cls : classes) { String nodeType = cls.getSimpleName(); out.println("<li>Calculate " + nodeType + "</li>"); out.flush(); long partial = NodeBaseDAO.getInstance().getCount(nodeType); FileLogger.info(BASE_NAME, "Number of {0}: {1}", nodeType, partial); out.println("<li>Number of " + nodeType + ": " + partial + "</li>"); out.flush(); total.put(nodeType, partial); } // Rebuild indexes out.println("<li>Rebuilding indexes</li>"); out.flush(); // Scrollable results will avoid loading too many objects in memory for (Class cls : classes) { String nodeType = cls.getSimpleName(); out.println("<li>Indexing " + nodeType + "</li>"); out.flush(); ProgressMonitor monitor = new ProgressMonitor(out, total.get(nodeType)); ScrollableResults results = ftSession.createCriteria(cls) .setFetchSize(Config.HIBERNATE_INDEXER_BATCH_SIZE_LOAD_OBJECTS) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { monitor.documentsAdded(1); ftSession.index(results.get(0)); // Index each element if (index++ % Config.HIBERNATE_INDEXER_BATCH_SIZE_LOAD_OBJECTS == 0) { ftSession.flushToIndexes(); // Apply changes to indexes ftSession.clear(); // Free memory since the queue is processed } } } tx.commit(); Config.SYSTEM_READONLY = false; Config.SYSTEM_MAINTENANCE = false; out.println("<li>System out of maintenance mode</li>"); out.flush(); // Finalized FileLogger.info(BASE_NAME, "END - Rebuild Lucene indexes"); out.println("<li>Index rebuilding completed!</li>"); out.println("</ul>"); out.flush(); } catch (Exception e) { tx.rollback(); out.println("<div class=\"warn\">Exception: " + e.getMessage() + "</div>"); out.flush(); } finally { HibernateUtil.close(ftSession); HibernateUtil.close(session); } // End page footer(out); out.flush(); out.close(); // Activity log UserActivity.log(request.getRemoteUser(), "ADMIN_FORCE_REBUILD_INDEXES", null, null, null); log.debug("luceneIndexesFlushToIndexes: void"); }
From source file:com.kanjiportal.portal.admin.LuceneManagementAction.java
License:Open Source License
public void reIndexKanji() { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); log.debug("Indexing kanjis ...."); long beforeKanjis = System.currentTimeMillis(); //Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(Kanji.class).setFetchSize(BATCH_SIZE) .setFetchMode("meanings", FetchMode.JOIN).setFetchMode("meanings.meaning.language", FetchMode.JOIN) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*from w w w .j av a2 s . co m*/ fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { entityManager.flush(); entityManager.clear(); log.debug("flush()"); } } log.debug("Indexing kanjis done"); long afterKanjis = System.currentTimeMillis(); facesMessages.add("Kanji Indexing done in #0 ms", afterKanjis - beforeKanjis); }
From source file:com.kanjiportal.portal.admin.LuceneManagementAction.java
License:Open Source License
public void reIndexDictionary() { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); long beforeDictionary = System.currentTimeMillis(); //Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(Dictionary.class).setFetchSize(BATCH_SIZE) .setFetchMode("translations", FetchMode.JOIN).setFetchMode("translations.language", FetchMode.JOIN) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*w ww . ja v a2 s .co m*/ fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { entityManager.flush(); entityManager.clear(); log.debug("flush()"); } } log.debug("Indexing dictionary done"); long afterDictionary = System.currentTimeMillis(); facesMessages.add("Dictionary Indexing done in #0 ms", afterDictionary - beforeDictionary); }
From source file:com.knowbout.epg.EPG.java
License:Apache License
private static void updateSitemap(String sitemap) { int lastslash = sitemap.lastIndexOf('/'); String inprogress = sitemap.substring(0, lastslash) + "/inprogress-" + sitemap.substring(lastslash + 1); String marker = "<!-- EVERYTHING BELOW IS AUTOMATICALLY GENERATED -->"; String baseurl = null;/*w ww . j av a 2s. c o m*/ try { PrintStream doc = new PrintStream(new GZIPOutputStream(new FileOutputStream(inprogress))); BufferedReader orig = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(sitemap)))); String line = orig.readLine(); while (line != null) { if ((line.indexOf("</urlset>") >= 0) || (line.indexOf(marker) >= 0)) { break; } if (baseurl == null) { if (line.indexOf("<loc>") >= 0) { int http = line.indexOf("http://"); int nextslash = line.indexOf("/", http + 7); baseurl = line.substring(http, nextslash); } } doc.println(line); line = orig.readLine(); } doc.println(marker); Set<String> teams = new HashSet<String>(); HibernateUtil.openSession(); try { ScrollableResults scroll = Program.selectAllTeams(); while (scroll.next()) { Program program = (Program) scroll.get(0); addToSitemap(doc, baseurl, program); teams.add(program.getSportName() + ":" + program.getTeamName()); } scroll = Program.selectAllShowsMoviesSports(); while (scroll.next()) { Program program = (Program) scroll.get(0); if (program.isSports()) { if (!teams.contains(program.getSportName() + ":" + program.getHomeTeamName())) { Program home = Program.selectByTeam(program.getSportName(), program.getHomeTeamName()); addToSitemap(doc, baseurl, home); teams.add(home.getSportName() + ":" + home.getTeamName()); } if (!teams.contains(program.getSportName() + ":" + program.getAwayTeamName())) { Program away = Program.selectByTeam(program.getSportName(), program.getAwayTeamName()); addToSitemap(doc, baseurl, away); teams.add(away.getSportName() + ":" + away.getTeamName()); } } else { addToSitemap(doc, baseurl, program); } } } finally { HibernateUtil.closeSession(); } doc.println("</urlset>"); doc.close(); orig.close(); File origFile = new File(sitemap); File backupFile = new File(sitemap + ".bak"); File inprogressFile = new File(inprogress); backupFile.delete(); if (!origFile.renameTo(backupFile)) { throw new IOException("Could not rename " + origFile + " to " + backupFile); } if (!inprogressFile.renameTo(origFile)) { throw new IOException("Could not rename " + inprogressFile + " to " + origFile); } } catch (FileNotFoundException e) { log.error("Could not write to " + inprogress, e); } catch (IOException e) { log.error("IO Exception for " + inprogress + " or " + sitemap, e); } }
From source file:com.leixl.easyframework.lucene.impl.LuceneEMovieDaoImpl.java
License:Open Source License
public Integer index(IndexWriter writer, Date startDate, Date endDate, Integer startId, Integer max) throws CorruptIndexException, IOException { Finder f = Finder.create("select bean from EMovie bean"); f.append(" where 1=1"); if (startId != null) { f.append(" and bean.id > :startId"); f.setParam("startId", startId); }// w ww. ja v a 2 s.co m if (startDate != null) { f.append(" and bean.createDate >= :startDate"); f.setParam("startDate", startDate); } if (endDate != null) { f.append(" and bean.createDate <= :endDate"); f.setParam("endDate", endDate); } f.append(" order by bean.id asc"); if (max != null) { f.setMaxResults(max); } Session session = getSession(); ScrollableResults movies = f.createQuery(getSession()).setCacheMode(CacheMode.IGNORE) .scroll(ScrollMode.FORWARD_ONLY); int count = 0; EMovie movie = null; while (movies.next()) { movie = (EMovie) movies.get(0); writer.addDocument(LuceneContent.createDocument(movie)); if (++count % 20 == 0) { session.clear(); } } if (count < max || movie == null) { // ???????? return null; } else { // ?ID return movie.getId(); } }