List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:com.lp.server.system.fastlanereader.LieferartHandler.java
License:Open Source License
/** * sort//from ww w. j a v a 2 s . c o m * * @param sortierKriterien * SortierKriterium[] * @param selectedId * Object * @return QueryResult * @throws EJBExceptionLP */ public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null; int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRLieferart lieferart = (FLRLieferart) scrollableResult.get(0); Integer id = lieferart.getI_id(); if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.MediaartHandler.java
License:Open Source License
/** * sorts the data of the current query using the specified criterias and * returns the page of data where the row of selectedId is contained. * /*w w w.j a v a 2 s. c o m*/ * @param sortierKriterien * the new sort criterias. * @param selectedId * the id of the entity that should be included in the result * page. * @return the sorted data containing the page where the entity with the * specified id is located. * @throws EJBExceptionLP */ public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null; int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRMediaart mediaart = (FLRMediaart) scrollableResult.get(0); String cNr = mediaart.getC_nr(); if (selectedId.equals(cNr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.ParameteranwenderHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;//ww w. j a v a 2 s . c o m int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select " + FLR_PARAMETERANWENDER + ParameterFac.FLR_PARAMETERANWENDER_ID_COMP + FLR_PARAMETERANWENDER_FROM_CLAUSE + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); boolean idFound = false; if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRParameteranwenderPK id = (FLRParameteranwenderPK) scrollableResult.get(0); // TYPE OF KEY ATTRIBUTE !!! if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.ParameterHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/* w w w . j av a2s. co m*/ int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select parameter.c_nr from FLRParameter parameter " + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); boolean idFound = false; if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { String iId = (String) scrollableResult.get(0); if (selectedId.equals(iId)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.ParametermandantHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/*from w w w. j a va2s . c o m*/ int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select " + FLR_PARAMETERMANDANT + ParameterFac.FLR_PARAMETERMANDANT_ID_COMP + FLR_PARAMETERMANDANT_FROM_CLAUSE + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); boolean idFound = false; if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRParametermandantPK id = (FLRParametermandantPK) scrollableResult.get(0); // TYPE OF KEY ATTRIBUTE !!! if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.PositionsartHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;//from ww w . j ava 2 s .c om int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRPositionsart positionsart = (FLRPositionsart) scrollableResult.get(0); String cNr = positionsart.getC_nr(); if (selectedId.equals(cNr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.StatusHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;//from w w w. j a v a2 s .c om int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRStatus status = (FLRStatus) scrollableResult.get(0); String cNr = status.getC_nr(); if (selectedId.equals(cNr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.system.fastlanereader.ZahlungszielHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;//from w w w.j av a 2s . c o m int rowNumber = 0; if (selectedId != null && ((Integer) selectedId).intValue() >= 0) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRZahlungsziel zahlungsziel = (FLRZahlungsziel) scrollableResult.get(0); Integer id = zahlungsziel.getId(); if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.mysema.query.jpa.IntegrationBase.java
License:Apache License
@Test public void Scroll() { session.save(new Cat("Bob", 10)); session.save(new Cat("Steve", 11)); HibernateQuery query = new HibernateQuery(session); ScrollableResults results = query.from(QCat.cat).scroll(ScrollMode.SCROLL_INSENSITIVE, QCat.cat); while (results.next()) { System.out.println(results.get(0)); }//from w w w . ja v a 2 s . c o m results.close(); }
From source file:com.openkm.servlet.admin.RebuildIndexesServlet.java
License:Open Source License
/** * FlushToIndexes implementation/*from w w w . j a v a2 s . c om*/ */ @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; // Activity log UserActivity.log(request.getRemoteUser(), "ADMIN_FORCE_REBUILD_INDEXES", null, null, 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, nodeType, 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 { Config.SYSTEM_READONLY = false; Config.SYSTEM_MAINTENANCE = false; HibernateUtil.close(ftSession); HibernateUtil.close(session); } // End page footer(out); out.flush(); out.close(); log.debug("luceneIndexesFlushToIndexes: void"); }