List of usage examples for org.hibernate ScrollMode SCROLL_INSENSITIVE
ScrollMode SCROLL_INSENSITIVE
To view the source code for org.hibernate ScrollMode SCROLL_INSENSITIVE.
Click Source Link
From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java
License:Open Source License
@SuppressWarnings("rawtypes") protected StorageResults createResults(Select select) { Paging paging = select.getPaging();// www. j av a 2s.com int pageSize = paging.getLimit(); boolean hasPaging = pageSize < Integer.MAX_VALUE; // Results if (!hasPaging) { if (storage instanceof HibernateStorage) { RDBMSDataSource dataSource = (RDBMSDataSource) storage.getDataSource(); if (dataSource.getDialectName() == RDBMSDataSource.DataSourceDialect.DB2) { // TMDM-7701: DB2 doesn't like use of SCROLL_INSENSITIVE for projections including a CLOB. if (select.isProjection()) { return createResults(criteria.scroll(ScrollMode.FORWARD_ONLY), true); } else { return createResults(criteria.scroll(ScrollMode.SCROLL_INSENSITIVE), false); } } else { return createResults(criteria.scroll(ScrollMode.SCROLL_INSENSITIVE), select.isProjection()); } } return createResults(criteria.scroll(ScrollMode.SCROLL_INSENSITIVE), select.isProjection()); } else { List list = criteria.list(); return createResults(list, select.isProjection()); } }
From source file:com.github.jmnarloch.hstreams.internal.QueryDelegateTest.java
License:Apache License
@Test public void testScroll1() throws Exception { // given/*from w w w .ja v a 2 s .co m*/ final ScrollMode scrollMode = ScrollMode.SCROLL_INSENSITIVE; // then verifyMethodCall(q -> q.scroll(scrollMode)); }
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)); }/* www . jav a2s . c o m*/ results.close(); }
From source file:com.querydsl.jpa.IntegrationBase.java
License:Apache License
@Test public void Scroll() { session.save(new Cat("Bob", 10)); session.save(new Cat("Steve", 11)); QCat cat = QCat.cat;//from w w w . j av a 2s . c o m HibernateQuery<?> query = new HibernateQuery<Void>(session); ScrollableResults results = query.from(cat).select(cat).scroll(ScrollMode.SCROLL_INSENSITIVE); while (results.next()) { assertNotNull(results.get(0)); } results.close(); }
From source file:de.innovationgate.webgate.api.jdbc.HibernateQueryIterator.java
License:Open Source License
public HibernateQueryIterator(Query q, HibernateResultSet resultSet) { _resultSet = resultSet;//from w ww . ja va 2s . com long timeBefore = System.currentTimeMillis(); _set = q.scroll(ScrollMode.SCROLL_INSENSITIVE); long timeAfter = System.currentTimeMillis(); if (resultSet != null) { resultSet.setExecutionTime(timeAfter - timeBefore); } _endReached = !_set.next(); }
From source file:de.innovationgate.webgate.api.jdbc.StructEntryIterator.java
License:Open Source License
public StructEntryIterator(WGDatabaseImpl parent, Query q) { _parent = parent; _set = q.scroll(ScrollMode.SCROLL_INSENSITIVE); _endReached = !_set.next(); }
From source file:de.iteratec.iteraplan.persistence.dao.SearchDAOImpl.java
License:Open Source License
/** {@inheritDoc} */ public void createIndexes(Set<Class<?>> classList) { Session session = this.getSession(); FullTextSession fullTextSession = getFullTextSession(); session.setFlushMode(FlushMode.MANUAL); // Disable flush operations session.setCacheMode(CacheMode.IGNORE); // Disable second-level cache operations int batchSize = 100; // data is read from the database for (Class<?> bbClass : classList) { ScrollableResults results = session.createCriteria(bbClass).setFetchSize(batchSize) .scroll(ScrollMode.SCROLL_INSENSITIVE); LOGGER.info("Indexing " + bbClass.getSimpleName()); int index = 0; while (results.next()) { index++;//from w ww .j a v a 2 s. co m // entities are indexed fullTextSession.index(results.get(0)); if (index % batchSize == 0) { fullTextSession.flushToIndexes(); fullTextSession.clear(); } } results.close(); LOGGER.info("Index for " + bbClass.getSimpleName() + " was created!"); } }
From source file:nl.strohalm.cyclos.dao.accounts.AccountDAOImpl.java
License:Open Source License
public IteratorList<AccountDailyDifference> iterateDailyDifferences(final MemberAccount account, final Period period) { Map<String, Object> params = new HashMap<String, Object>(); params.put("accountId", account.getId()); QueryParameter beginParameter = HibernateHelper.getBeginParameter(period); QueryParameter endParameter = HibernateHelper.getEndParameter(period); if (beginParameter != null) { params.put("begin", beginParameter.getValue()); }//from w w w.ja v a 2 s . c om if (endParameter != null) { params.put("end", endParameter.getValue()); } StringBuilder sql = new StringBuilder(); sql.append(" select type, date(d.date) as date, sum(amount) as amount "); sql.append(" from ( "); sql.append(" select 'B' as type, t.process_date as date, "); sql.append(" case when t.chargeback_of_id is null then "); sql.append(" case when t.from_account_id = :accountId then -t.amount else t.amount end "); sql.append(" else "); sql.append(" case when t.to_account_id = :accountId then t.amount else -t.amount end "); sql.append(" end as amount "); sql.append(" from transfers t "); sql.append(" where (t.from_account_id = :accountId or t.to_account_id = :accountId) "); sql.append(" and t.process_date is not null "); if (beginParameter != null) { sql.append(" and t.process_date " + beginParameter.getOperator() + " :begin"); } if (endParameter != null) { sql.append(" and t.process_date " + endParameter.getOperator() + " :end"); } sql.append(" union "); sql.append(" select 'R', r.date, r.amount "); sql.append(" from amount_reservations r "); sql.append(" where r.account_id = :accountId "); if (beginParameter != null) { sql.append(" and r.date " + beginParameter.getOperator() + " :begin"); } if (endParameter != null) { sql.append(" and r.date " + endParameter.getOperator() + " :end"); } sql.append(" ) d "); sql.append(" group by type, date(d.date) "); sql.append(" order by date(d.date) "); SQLQuery query = getSession().createSQLQuery(sql.toString()); query.addScalar("type", StandardBasicTypes.STRING); query.addScalar("date", StandardBasicTypes.CALENDAR_DATE); query.addScalar("amount", StandardBasicTypes.BIG_DECIMAL); getHibernateQueryHandler().setQueryParameters(query, params); ScrollableResults results = query.scroll(ScrollMode.SCROLL_INSENSITIVE); return new IteratorListImpl<AccountDailyDifference>(new DiffsIterator(results)); }
From source file:org.glite.security.voms.admin.persistence.tools.DeleteRecordsCommand.java
License:Apache License
@Override public void execute(CommandLine line) { AuditSearchDAO dao = DAOFactory.instance().getAuditSearchDAO(); AuditLogSearchParams params = addConstraintsFromCommandLine(line); ScrollableAuditLogSearchResults results = dao.scrollEventsMatchingParams(params, ScrollMode.SCROLL_INSENSITIVE); int count = 0; ScrollableResults scroll = results.getResults(); scroll.last();//from w w w . j a v a 2 s . c o m count = scroll.getRowNumber(); if (count + 1 == 0) { System.out.println("No events found"); return; } System.out.format("%d records will be deleted. Type 'yes' if you want to continue\n", count + 1); try { if (!getConfirmationFromUser()) { System.out.println("Aborting on user's request."); return; } } catch (IOException e) { throw new AuditLogCommandError(e); } scroll.beforeFirst(); System.out.println("Deleting events:"); count = 0; while (scroll.next()) { count++; AuditEvent event = (AuditEvent) scroll.get()[0]; printAuditLogEvent(event); dao.makeTransient(event); dao.flush(); HibernateFactory.getSession().evict(event); } System.out.format("%d events deleted.\n", count); }
From source file:org.opentaps.common.domain.order.PurchaseOrderLookupRepository.java
License:Open Source License
/** {@inheritDoc} */ public List<OrderViewForListing> findOrders() throws RepositoryException { // convert fromDateStr / thruDateStr into Timestamps if the string versions were given if (UtilValidate.isNotEmpty(fromDateStr)) { fromDate = UtilDate.toTimestamp(fromDateStr, timeZone, locale); }/*w w w .j a va 2 s.c o m*/ if (UtilValidate.isNotEmpty(thruDateStr)) { thruDate = UtilDate.toTimestamp(thruDateStr, timeZone, locale); } Session session = null; try { // get a hibernate session session = getInfrastructure().getSession(); Criteria criteria = session.createCriteria(OrderHeader.class); // always filter by the current organization criteria.add(Restrictions.eq(OrderHeader.Fields.billToPartyId.name(), organizationPartyId)); // filters by order type, we only want purchase order criteria.add(Restrictions.eq(OrderHeader.Fields.orderTypeId.name(), OrderTypeConstants.PURCHASE_ORDER)); // set the from/thru date filter if they were given if (fromDate != null) { criteria.add(Restrictions.ge(OrderHeader.Fields.orderDate.name(), fromDate)); } if (thruDate != null) { criteria.add(Restrictions.le(OrderHeader.Fields.orderDate.name(), thruDate)); } // filter the role assoc, there is only one supplier role per order Criteria roleCriteria = criteria.createAlias("orderRoles", "or"); roleCriteria.add(Restrictions.eq("or.id." + OrderRole.Fields.roleTypeId.name(), RoleTypeConstants.BILL_FROM_VENDOR)); // filter by order status if (findDesiredOnly) { List<String> statuses = UtilMisc.toList(StatusItemConstants.OrderStatus.ORDER_APPROVED, StatusItemConstants.OrderStatus.ORDER_CREATED, StatusItemConstants.OrderStatus.ORDER_HOLD); criteria.add(Restrictions.in(OrderHeader.Fields.statusId.name(), statuses)); } // filter by the given orderId string if (UtilValidate.isNotEmpty(orderId)) { criteria.add(Restrictions.ilike(OrderHeader.Fields.orderId.name(), orderId, MatchMode.START)); } // filter by exact matching status, if a statusId was given if (UtilValidate.isNotEmpty(statusId)) { criteria.add(Restrictions.eq(OrderHeader.Fields.statusId.name(), statusId)); } // filter by the user who created the order if given if (UtilValidate.isNotEmpty(createdBy)) { criteria.add(Restrictions.eq(OrderHeader.Fields.createdBy.name(), createdBy)); } // filter by the given orderName string if (UtilValidate.isNotEmpty(orderName)) { criteria.add(Restrictions.ilike(OrderHeader.Fields.orderName.name(), orderName, MatchMode.START)); } // filter by the given supplierPartyId string, from the OrderRole entity if (UtilValidate.isNotEmpty(supplierPartyId)) { roleCriteria.add(Restrictions.ilike("or.id." + OrderRole.Fields.partyId.name(), supplierPartyId, MatchMode.START)); } // filter by product, if given criteria.createAlias("orderItems", "oi"); if (UtilValidate.isNotEmpty(productPattern)) { try { // try to get product by using productPattern as productId Product product = getProductRepository().getProductById(productPattern); criteria.add( Restrictions.eq("oi." + OrderItem.Fields.productId.name(), product.getProductId())); } catch (EntityNotFoundException e) { // could not get the product by using productPattern as productId // find all the products that may match String likePattern = "%" + productPattern + "%"; EntityCondition conditionList = EntityCondition.makeCondition(EntityOperator.OR, EntityCondition.makeCondition(ProductAndGoodIdentification.Fields.productId.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition( ProductAndGoodIdentification.Fields.internalName.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition(ProductAndGoodIdentification.Fields.productName.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition(ProductAndGoodIdentification.Fields.comments.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition(ProductAndGoodIdentification.Fields.description.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition( ProductAndGoodIdentification.Fields.longDescription.getName(), EntityOperator.LIKE, likePattern), EntityCondition.makeCondition(ProductAndGoodIdentification.Fields.idValue.getName(), EntityOperator.LIKE, likePattern)); List<ProductAndGoodIdentification> products = findList(ProductAndGoodIdentification.class, conditionList); if (products.size() > 0) { criteria.add(Restrictions.in("oi." + OrderItem.Fields.productId.name(), Entity .getDistinctFieldValues(products, ProductAndGoodIdentification.Fields.productId))); } } } // specify the fields to return criteria.setProjection(Projections.projectionList() .add(Projections.distinct(Projections.property(OrderHeader.Fields.orderId.name()))) .add(Projections.property(OrderHeader.Fields.orderName.name())) .add(Projections.property(OrderHeader.Fields.statusId.name())) .add(Projections.property(OrderHeader.Fields.grandTotal.name())) .add(Projections.property(OrderHeader.Fields.orderDate.name())) .add(Projections.property(OrderHeader.Fields.currencyUom.name())) .add(Projections.property("or.id." + OrderRole.Fields.partyId.name()))); // set the order by if (orderBy == null) { orderBy = Arrays.asList(OrderHeader.Fields.orderDate.desc()); } // some substitution is needed to fit the hibernate field names // this also maps the calculated fields and indicates the non sortable fields Map<String, String> subs = new HashMap<String, String>(); subs.put("partyId", "or.id.partyId"); subs.put("partyName", "or.id.partyId"); subs.put("orderDateString", "orderDate"); subs.put("orderNameId", "orderId"); subs.put("statusDescription", "statusId"); HibernateUtil.setCriteriaOrder(criteria, orderBy, subs); ScrollableResults results = null; List<OrderViewForListing> results2 = new ArrayList<OrderViewForListing>(); try { // fetch the paginated results results = criteria.scroll(ScrollMode.SCROLL_INSENSITIVE); if (usePagination()) { results.setRowNumber(getPageStart()); } else { results.first(); } // convert them into OrderViewForListing objects which will also calculate or format some fields for display Object[] o = results.get(); int n = 0; // number of results actually read while (o != null) { OrderViewForListing r = new OrderViewForListing(); r.initRepository(this); int i = 0; r.setOrderId((String) o[i++]); r.setOrderName((String) o[i++]); r.setStatusId((String) o[i++]); r.setGrandTotal((BigDecimal) o[i++]); r.setOrderDate((Timestamp) o[i++]); r.setCurrencyUom((String) o[i++]); r.setPartyId((String) o[i++]); r.calculateExtraFields(getDelegator(), timeZone, locale); results2.add(r); n++; if (!results.next()) { break; } if (usePagination() && n >= getPageSize()) { break; } o = results.get(); } results.last(); // note: row number starts at 0 setResultSize(results.getRowNumber() + 1); } finally { results.close(); } return results2; } catch (InfrastructureException e) { throw new RepositoryException(e); } finally { if (session != null) { session.close(); } } }