@Override public Iterator<QtiAssessmentResult> getIterator() { final ScrollableResults cinnamonScroll = (ScrollableResults) getHibernateTemplate() .execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { final Query query = getAllQuery(session); query.setReadOnly(true); return query.scroll(ScrollMode.FORWARD_ONLY); } }); return new ScrollableResultsIterator<QtiAssessmentResult>(cinnamonScroll); }
@Override public Iterator<QtiItemResult> getIterator() { final ScrollableResults cinnamonScroll = (ScrollableResults) getHibernateTemplate() .execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { final Query query = getAllQuery(session); query.setReadOnly(true); return query.scroll(ScrollMode.FORWARD_ONLY); } }); return new ScrollableResultsIterator<QtiItemResult>(cinnamonScroll); }
@Override public Iterator<QtiAssessmentItem> getIterator() { final ScrollableResults cinnamonScroll = (ScrollableResults) getHibernateTemplate() .execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { final Query query = session.createQuery("FROM QtiAssessmentItem WHERE institution = :institution"); query.setParameter("institution", CurrentInstitution.get()); query.setReadOnly(true); return query.scroll(ScrollMode.FORWARD_ONLY); } }); return new ScrollableResultsIterator<QtiAssessmentItem>(cinnamonScroll); }
@Override protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session) { // Find dupes and kill them (keep the latest one) final ScrollableResults dupes = session.createQuery(getDupesFrom() + " ORDER BY n.date DESC").scroll( ScrollMode.FORWARD_ONLY); final Set<String> visited = Sets.newHashSet(); while( dupes.next() ) { final FakeNotification dupe = (FakeNotification) dupes.get(0); final String key = dupe.itemid + dupe.reason + dupe.userTo + dupe.institution.id; // Ignore the most recent notification, we'll keep this one if( !visited.contains(key) ) { visited.add(key); } else { session.delete(dupe); session.flush(); session.clear(); } result.incrementStatus(); } }
@Override public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) { // TODO: Is this guaranteed to always be CriteriaImpl? CriteriaImpl criteriaImpl = (CriteriaImpl) criteria; errorIfClosed(); checkTransactionSynchStatus(); String entityName = criteriaImpl.getEntityOrClassName(); CriteriaLoader loader = new CriteriaLoader( getOuterJoinLoadable(entityName), factory, criteriaImpl, entityName, getLoadQueryInfluencers() ); autoFlushIfRequired( loader.getQuerySpaces() ); dontFlushFromFind++; try { return loader.scroll(this, scrollMode); } finally { delayedAfterCompletion(); dontFlushFromFind--; } }
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException { verifyParameters(); before(); Map namedParams = getNamedParams(); NativeSQLQuerySpecification spec = generateQuerySpecification( namedParams ); QueryParameters qp = getQueryParameters( namedParams ); qp.setScrollMode( scrollMode ); try { return getSession().scroll( spec, qp ); } finally { after(); } }
@Override public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) { // TODO: Is this guaranteed to always be CriteriaImpl? CriteriaImpl criteriaImpl = (CriteriaImpl) criteria; errorIfClosed(); String entityName = criteriaImpl.getEntityOrClassName(); CriteriaLoader loader = new CriteriaLoader( getOuterJoinLoadable( entityName ), factory, criteriaImpl, entityName, getLoadQueryInfluencers() ); return loader.scroll(this, scrollMode); }
void converteerToegangLeveringsautorisaties() { final Session session = (Session) entityManager.getDelegate(); final ScrollableResults scResults = session.createCriteria(ToegangLeveringsAutorisatie.class).scroll(ScrollMode.FORWARD_ONLY); while (scResults.next()) { final ToegangLeveringsAutorisatie toegang = (ToegangLeveringsAutorisatie) scResults.get(0); if (Stelsel.GBA == toegang.getLeveringsautorisatie().getStelsel()) { if (toegang.getLeveringsautorisatie().getDatumEinde() != null) { LOGGER.warn("ToegangLeveringsAutorisatie met id {} wordt niet geconverteerd, " + "want leveringsautorisatie '{}' met id {} is niet geldig", toegang.getId(), toegang.getLeveringsautorisatie().getNaam(), toegang.getLeveringsautorisatie().getId()); continue; } converteerToegangLeveringsAutorisatie(toegang); entityManager.flush(); entityManager.clear(); } } }
private void deleteProductCharacteristicValue(ProductCharacteristic productCharacteristic) { ScrollableResults scroll = null; try { OBCriteria<ProductCharacteristicValue> criteria = OBDal.getInstance().createCriteria( ProductCharacteristicValue.class); criteria.add(Restrictions.eq(ProductCharacteristicValue.PROPERTY_CHARACTERISTIC, productCharacteristic.getCharacteristic())); criteria.add(Restrictions.eq(ProductCharacteristicValue.PROPERTY_PRODUCT, productCharacteristic.getProduct())); scroll = criteria.scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (scroll.next()) { ProductCharacteristicValue productCharacteristicValue = (ProductCharacteristicValue) scroll .get(0); OBDal.getInstance().remove(productCharacteristicValue); i++; if (i % 100 == 0) { OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); } } } finally { scroll.close(); } }
/** * Get all the payment details with available credit */ public static ScrollableResults getPaymentsWithCredit(String businessPartnerId, String currencyId) { StringBuilder hql = new StringBuilder(); hql.append(" SELECT t1." + FIN_Payment.PROPERTY_ID); hql.append(" FROM " + FIN_Payment.ENTITY_NAME + " as t1"); hql.append(" WHERE t1." + FIN_Payment.PROPERTY_BUSINESSPARTNER + ".id = :businessPartnerId"); hql.append(" AND t1." + FIN_Payment.PROPERTY_CURRENCY + ".id = :currencyId"); hql.append(" AND t1." + FIN_Payment.PROPERTY_GENERATEDCREDIT + " <> 0"); hql.append(" AND t1." + FIN_Payment.PROPERTY_GENERATEDCREDIT + " <> t1." + FIN_Payment.PROPERTY_USEDCREDIT); final Query query = OBDal.getInstance().getSession().createQuery(hql.toString()); query.setParameter("businessPartnerId", businessPartnerId); query.setParameter("currencyId", currencyId); ScrollableResults scroll = query.scroll(ScrollMode.SCROLL_SENSITIVE); return scroll; }
private void initializeLines(CostAdjustment costAdjustment) { // initialize is related transaction adjusted flag to false OBCriteria<CostAdjustmentLine> critLines = OBDal.getInstance().createCriteria( CostAdjustmentLine.class); critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_COSTADJUSTMENT, costAdjustment)); critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_ISRELATEDTRANSACTIONADJUSTED, true)); ScrollableResults lines = critLines.scroll(ScrollMode.FORWARD_ONLY); long count = 1L; try { while (lines.next()) { CostAdjustmentLine line = (CostAdjustmentLine) lines.get(0); line.setRelatedTransactionAdjusted(false); OBDal.getInstance().save(line); if (count % 1000 == 0) { OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); } count++; } OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); } finally { lines.close(); } }
private void updateInitInventoriesTrxDate(Date startingDate, String ruleId) { StringBuffer where = new StringBuffer(); where.append(" as trx"); where.append(" join trx." + MaterialTransaction.PROPERTY_PHYSICALINVENTORYLINE + " as il"); where.append(" where il." + InventoryCountLine.PROPERTY_PHYSINVENTORY + ".id IN ("); where.append(" select cri." + CostingRuleInit.PROPERTY_INITINVENTORY + ".id"); where.append(" from " + CostingRuleInit.ENTITY_NAME + " as cri"); where.append(" where cri." + CostingRuleInit.PROPERTY_COSTINGRULE + ".id = :cr"); where.append(" )"); OBQuery<MaterialTransaction> trxQry = OBDal.getInstance().createQuery( MaterialTransaction.class, where.toString()); trxQry.setNamedParameter("cr", ruleId); trxQry.setFetchSize(1000); ScrollableResults trxs = trxQry.scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (trxs.next()) { MaterialTransaction trx = (MaterialTransaction) trxs.get(0); trx.setTransactionProcessDate(startingDate); OBDal.getInstance().save(trx); if ((i % 100) == 0) { OBDal.getInstance().flush(); OBDal.getInstance().getSession().clear(); } } trxs.close(); }
private ScrollableResults getTransactions(Set<String> childOrgs, Date startDate, Date endDate) { StringBuffer select = new StringBuffer(); select.append("select trx as trx"); select.append(" from " + MaterialTransaction.ENTITY_NAME + " as trx"); select.append(" where trx." + MaterialTransaction.PROPERTY_ORGANIZATION + ".id in (:orgs)"); select.append(" and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED + " = true"); select.append(" and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE + " >= (:startDate)"); if (endDate != null) { select.append(" and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE + " < (:endDate)"); } select.append(" order by trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE); Query stockLinesQry = OBDal.getInstance().getSession().createQuery(select.toString()); stockLinesQry.setParameterList("orgs", childOrgs); stockLinesQry.setTimestamp("startDate", startDate); if (endDate != null) { stockLinesQry.setTimestamp("endDate", endDate); } stockLinesQry.setFetchSize(1000); ScrollableResults stockLines = stockLinesQry.scroll(ScrollMode.FORWARD_ONLY); return stockLines; }
private ScrollableResults getCloseInventoryLines(Set<String> orgs) { StringBuffer where = new StringBuffer(); where.append(" as il"); where.append(" where exists (select 1 from " + CostingRuleInit.ENTITY_NAME + " as cri"); where.append(" where cri." + CostingRuleInit.PROPERTY_CLOSEINVENTORY + " = il." + InventoryCountLine.PROPERTY_PHYSINVENTORY + ")"); where.append(" and il." + InventoryCountLine.PROPERTY_ORGANIZATION + ".id IN (:orgs)"); where.append(" order by " + InventoryCountLine.PROPERTY_PRODUCT + ", il." + InventoryCountLine.PROPERTY_BOOKQUANTITY); OBQuery<InventoryCountLine> iclQry = OBDal.getInstance().createQuery(InventoryCountLine.class, where.toString()); iclQry.setNamedParameter("orgs", orgs); iclQry.setFilterOnActive(false); iclQry.setFilterOnReadableClients(false); iclQry.setFilterOnReadableOrganization(false); iclQry.setFetchSize(1000); return iclQry.scroll(ScrollMode.FORWARD_ONLY); }
/** * Computes the row number of a record which has the id which is passed in as a parameter. The * rownumber computation takes into account the filter and sorting settings of the the OBQuery * object. * * @param targetId * the record id * @return the row number or -1 if not found */ public int getRowNumber(String targetId) { String qryStr = createQueryString(); if (qryStr.toLowerCase().contains(FROM_SPACED)) { final int index = qryStr.indexOf(FROM_SPACED) + FROM_SPACED.length(); qryStr = qryStr.substring(index); } final Query qry = getSession() .createQuery("select " + usedAlias + "id " + FROM_SPACED + qryStr); setParameters(qry); final ScrollableResults results = qry.scroll(ScrollMode.FORWARD_ONLY); try { while (results.next()) { final String id = results.getString(0); if (id.equals(targetId)) { return results.getRowNumber(); } } } finally { results.close(); } return -1; }
public int doCriteriaQry() { final OBCriteria<MaterialTransaction> obc = OBDal.getInstance().createCriteria( MaterialTransaction.class); obc.add(Restrictions.isNotNull(MaterialTransaction.PROPERTY_UOM)); obc.addOrderBy(MaterialTransaction.PROPERTY_PRODUCT + "." + Product.PROPERTY_NAME, false); obc.setMaxResults(10); obc.setFirstResult(0); if (doScroll) { final ScrollableResults r = obc.scroll(ScrollMode.FORWARD_ONLY); int cnt = 0; while (r.next()) { cnt++; } return cnt; } final List<MaterialTransaction> cs = obc.list(); return cs.size(); }
public int doCriteriaQry() { OBCriteria<BusinessPartner> c = OBDal.getInstance().createCriteria(BusinessPartner.class); c.setFilterOnActive(false); c.setFilterOnReadableClients(false); c.setFilterOnReadableOrganization(false); c.setMaxResults(1000); if (doScroll) { final ScrollableResults r = c.scroll(ScrollMode.FORWARD_ONLY); int cnt = 0; while (r.next()) { cnt++; } return cnt; } final List<BusinessPartner> cs = c.list(); return cs.size(); }
public int doHqlQry() { OBQuery<BusinessPartner> q = OBDal.getInstance().createQuery(BusinessPartner.class, ""); q.setFilterOnActive(false); q.setFilterOnReadableClients(false); q.setFilterOnReadableOrganization(false); q.setMaxResult(1000); qryStr = "All BusinessPartners"; if (doScroll) { int cnt = 0; ScrollableResults scroller = q.scroll(ScrollMode.FORWARD_ONLY); while (scroller.next()) { cnt++; } return cnt; } final List<BusinessPartner> cs = q.list(); return cs.size(); }
/** * Runs the query by calling <code>org.hibernate.Query.scroll()</code>. * * @return scrollable results of the query */ public ScrollableResults scroll() { setMaxCount(); setQueryRunning(true); try { scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); } finally { setQueryRunning(false); } return scrollableResults; }
/** * @param query * The query. * @param n * The n'th element. * @param logPerformance * True, if the performance should be logged. * @param class1 * @param <T> * Return type of this method. * @return The n'th element or null. */ private <T> T getNthElement(org.hibernate.Query query, int n, boolean logPerformance) { StopWatch stopWatch = new StopWatch(); if (logPerformance) { stopWatch.start(); } query.setMaxResults(n); ScrollableResults scrollableResults = query.scroll(ScrollMode.SCROLL_INSENSITIVE); stopStopWatches(logPerformance, stopWatch, "QueryHelper#query.scroll"); resetAndStartStopWatch(logPerformance, stopWatch); if (scrollableResults.last()) { stopStopWatches(logPerformance, stopWatch, "QueryHelper#scrollableResults.setRowNumber" + n); resetAndStartStopWatch(logPerformance, stopWatch); return (T) scrollableResults.get(0); } return null; }
public PreparedStatement prepareQueryStatement( String sql, boolean scrollable, ScrollMode scrollMode) throws SQLException, HibernateException { logOpenPreparedStatement(); PreparedStatement ps = getPreparedStatement( connectionManager.getConnection(), sql, scrollable, scrollMode ); setStatementFetchSize( ps ); statementsToClose.add( ps ); lastQuery = ps; return ps; }
public CallableStatement prepareCallableQueryStatement( String sql, boolean scrollable, ScrollMode scrollMode) throws SQLException, HibernateException { logOpenPreparedStatement(); CallableStatement ps = ( CallableStatement ) getPreparedStatement( connectionManager.getConnection(), sql, scrollable, false, null, scrollMode, true ); setStatementFetchSize( ps ); statementsToClose.add( ps ); lastQuery = ps; return ps; }
private PreparedStatement getPreparedStatement( final Connection conn, final String sql, final boolean scrollable, final ScrollMode scrollMode) throws SQLException { return getPreparedStatement( conn, sql, scrollable, false, null, scrollMode, false ); }
public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) { errorIfClosed(); checkTransactionSynchStatus(); String entityName = criteria.getEntityOrClassName(); CriteriaLoader loader = new CriteriaLoader( getOuterJoinLoadable(entityName), factory, criteria, entityName, getEnabledFilters() ); autoFlushIfRequired( loader.getQuerySpaces() ); dontFlushFromFind++; try { return loader.scroll(this, scrollMode); } finally { dontFlushFromFind--; } }
private void cacheExistingStringClassIdentities() throws Exception { Logger.getLogger(getClass()).info("Loading String Class Identities"); final Session session = getService().getEntityManager().unwrap(Session.class); final org.hibernate.Query hQuery = session .createSQLQuery("select id, name, language from string_class_identity"); hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false); final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { final Long id = ((BigInteger) results.get()[0]).longValue(); final String name = (String) results.get()[1]; final String language = (String) results.get()[2]; final String identityCode = name + language; stringClassIdentityCache.put(identityCode, id); } results.close(); }
private void cacheExistingLexicalClassIdentities() throws Exception { Logger.getLogger(getClass()).info("Loading Lexical Class Identities"); final Session session = getService().getEntityManager().unwrap(Session.class); final org.hibernate.Query hQuery = session.createSQLQuery( "select id, language, normalizedName from lexical_class_identity"); hQuery.setReadOnly(true).setFetchSize(100000).setCacheable(false); final ScrollableResults results = hQuery.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { final Long id = ((BigInteger) results.get()[0]).longValue(); final String language = (String) results.get()[1]; final String normalizedName = (String) results.get()[2]; final String identityCode = language + normalizedName; lexicalClassIdentityCache.put(identityCode, id); } results.close(); }
private static void runStatelessHql() throws Exception { Stopwatch watch = Stopwatch.createStarted(); StatelessSession statelessSession = sessionFactory.openStatelessSession(); try { statelessSession.getTransaction().begin(); Query query = statelessSession .createQuery( " SELECT d.id, d.firstName, d.lastName, c.id, c.make " + " FROM Driver d " + " LEFT JOIN d.cars c WHERE index(c) LIKE 'Good'").setFetchSize(0).setReadOnly(true); ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY); while (scroll.next()) { LOG.info("Entry " + scroll.get(0)); } statelessSession.getTransaction().commit(); } catch (Exception ex) { statelessSession.getTransaction().rollback(); throw ex; } finally { statelessSession.close(); } LOG.info("StatelessHql:=" + watch.toString()); }
public ScrollableResultsIterator(final Query query, final Transformer<Object[], T> transformer) { this.results = query.scroll(ScrollMode.FORWARD_ONLY); if (query instanceof SQLQuery) { // The getReturnTypes doesn't work for SQLQueries... Assume an array array = true; } else { // this (extra) check to see if the query starts with "select new" is just to support the // following case: SELECT new A(e.prop1, e.prop2) FROM Entity e ... // in that case we musn't return an array in the next() method. array = query.getReturnTypes().length > 1 && !query.getQueryString().trim().toLowerCase().startsWith("select new"); } this.transformer = transformer; getNextObject(); DataIteratorHelper.registerOpen(this, true); }
@Override protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session) { ScrollableResults res = session.createQuery("from Term").scroll(ScrollMode.FORWARD_ONLY); while( res.next() ) { FakeTerm ft = (FakeTerm) res.get(0); ft.valueTemp = ft.value; // The next time is totally 4337 haX0r ft.valueHash = DigestUtils.md5Hex(ft.valueTemp); session.update(ft); result.incrementStatus(); } }
private ScrollMode getScrollMode(boolean scroll, boolean hasFirstRow, boolean useLimitOffSet, QueryParameters queryParameters) { final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); if ( canScroll ) { if ( scroll ) { return queryParameters.getScrollMode(); } if ( hasFirstRow && !useLimitOffSet ) { return ScrollMode.SCROLL_INSENSITIVE; } } return null; }
protected ScrollMode getScrollMode(boolean scroll, boolean hasFirstRow, boolean useLimitOffSet, QueryParameters queryParameters) { final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); if ( canScroll ) { if ( scroll ) { return queryParameters.getScrollMode(); } if ( hasFirstRow && !useLimitOffSet ) { return ScrollMode.SCROLL_INSENSITIVE; } } return null; }
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException { verifyParameters(); Map namedParams = getNamedParams(); before(); QueryParameters qp = getQueryParameters(namedParams); qp.setScrollMode(scrollMode); try { return getSession().scroll( expandParameterLists(namedParams), qp ); } finally { after(); } }
@Override public ScrollableResults scroll(ScrollMode scrollMode) { before(); try { return session.scroll(this, scrollMode); } finally { after(); } }
void converteerLeveringsautorisaties() { final Session session = (Session) entityManager.getDelegate(); final ScrollableResults scResults = session.createCriteria(Leveringsautorisatie.class).scroll(ScrollMode.FORWARD_ONLY); while (scResults.next()) { final Leveringsautorisatie leveringsautorisatie = (Leveringsautorisatie) scResults.get(0); if (Stelsel.GBA == leveringsautorisatie.getStelsel()) { converteerLeveringautorisatie(leveringsautorisatie); entityManager.flush(); entityManager.clear(); } } }
/** * Get the bank statement lines that are not yet matched to a transaction for the given financial * account. If the reconciliation passed as parameter is the last one, the method filters by the * bank statement lines with transaction date less or equal than the reconciliation's ending date */ public static ScrollableResults getPendingToBeMatchedBankStatementLines( String strFinancialAccountId, String strReconciliationId) { try { OBContext.setAdminMode(true); FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, strReconciliationId); boolean isLastReconciliation = MatchTransactionDao.islastreconciliation(reconciliation); final StringBuilder whereClause = new StringBuilder(); whereClause.append(" as bsl "); whereClause.append(" where bsl.").append(FIN_BankStatementLine.PROPERTY_BANKSTATEMENT); whereClause.append(".").append(FIN_BankStatement.PROPERTY_ACCOUNT).append(".id = :account"); whereClause.append(" and bsl.bankStatement.processed = 'Y'"); if (!isLastReconciliation) { whereClause.append(" and bsl.").append(FIN_BankStatementLine.PROPERTY_TRANSACTIONDATE) .append(" <= :endingdate"); } whereClause.append(" and bsl.financialAccountTransaction is null"); whereClause.append(" order by bsl.").append(FIN_BankStatementLine.PROPERTY_TRANSACTIONDATE); whereClause.append(", bsl.").append(FIN_BankStatementLine.PROPERTY_LINENO); whereClause.append(", bsl.").append(FIN_BankStatementLine.PROPERTY_BPARTNERNAME); final OBQuery<FIN_BankStatementLine> obData = OBDal.getInstance().createQuery( FIN_BankStatementLine.class, whereClause.toString()); obData.setNamedParameter("account", strFinancialAccountId); if (!isLastReconciliation) { obData.setNamedParameter("endingdate", reconciliation.getEndingDate()); } return obData.scroll(ScrollMode.FORWARD_ONLY); } finally { OBContext.restorePreviousMode(); } }
private void updateElementValues(Element _element, AcctSchema acctSchema, boolean assetPositive, boolean liabilityPositive, boolean ownersEquityPositive, boolean expensePositive, boolean revenuePositive) { StringBuffer where = new StringBuffer(); final String ACCOUNTSIGN_CREDIT = "C"; final String ACCOUNTSIGN_DEBIT = "D"; final String ACCOUNTTYPE_MEMO = "M"; Element element = OBDal.getInstance().get(Element.class, _element.getId()); where.append(ElementValue.PROPERTY_ACCOUNTINGELEMENT + ".id = :element"); OBQuery<ElementValue> elementValueQry = OBDal.getInstance().createQuery(ElementValue.class, where.toString()); elementValueQry.setFilterOnActive(false); elementValueQry.setFilterOnReadableClients(false); elementValueQry.setFilterOnReadableOrganization(false); elementValueQry.setNamedParameter("element", element.getId()); elementValueQry.setFetchSize(1000); ScrollableResults elementvalues = elementValueQry.scroll(ScrollMode.FORWARD_ONLY); try { // TODO: Review with Martin to see if flush is permitted in handlers // int i = 0; while (elementvalues.next()) { ElementValue elementValue = (ElementValue) elementvalues.get(0); boolean isCredit = getAccountSign(elementValue.getAccountType(), assetPositive, liabilityPositive, ownersEquityPositive, expensePositive, revenuePositive); if (!ACCOUNTTYPE_MEMO.equals(elementValue.getAccountType())) { elementValue.setAccountSign(isCredit ? ACCOUNTSIGN_CREDIT : ACCOUNTSIGN_DEBIT); } // if ((i % 100) == 0) { // OBDal.getInstance().flush(); // OBDal.getInstance().getSession().clear(); // element = OBDal.getInstance().get(Element.class, element.getId()); // } // i++; } } finally { elementvalues.close(); } }
/** * @return a result which can be scrolled forward only and the results are not cached */ public ScrollableResults scroll() { final Query qry = buildOBQuery().createQuery(); qry.setFetchSize(1000); qry.setCacheable(false); return qry.scroll(ScrollMode.FORWARD_ONLY); }
private ScrollableResults getPRLinesIncoming(PurchasingRun mrpPurchaseRun) { StringBuffer where = new StringBuffer(); where.append(" where " + PurchasingRunLine.PROPERTY_PURCHASINGPLAN + ".id = :purchaserun"); where.append(" and " + PurchasingRunLine.PROPERTY_QUANTITY + " > 0"); where.append(" order by " + PurchasingRunLine.PROPERTY_PRODUCT + "," + PurchasingRunLine.PROPERTY_PLANNEDDATE + ", CASE " + PurchasingRunLine.PROPERTY_TRANSACTIONTYPE + " WHEN 'ST' THEN 0 WHEN 'MS' THEN 2 ELSE 1 END"); OBQuery<PurchasingRunLine> soQry = OBDal.getInstance().createQuery(PurchasingRunLine.class, where.toString()); soQry.setNamedParameter("purchaserun", mrpPurchaseRun.getId()); soQry.setFetchSize(1000); return soQry.scroll(ScrollMode.FORWARD_ONLY); }