List of usage examples for org.hibernate ScrollMode FORWARD_ONLY
ScrollMode FORWARD_ONLY
To view the source code for org.hibernate ScrollMode FORWARD_ONLY.
Click Source Link
From source file:mitm.application.djigzo.impl.hibernate.UserDAO.java
License:Open Source License
public CloseableIterator<String> searchEmail(String search, Integer firstResult, Integer maxResults, SortDirection sortDirection) {/*from www . j av a 2 s .c om*/ if (sortDirection == null) { sortDirection = SortDirection.ASC; } /* * We will use HQL because I do not (yet?) know how to return just a field instead of * an object when using the Criteria API. */ final String hql = "select n.email from " + entityName + " n where n.email LIKE :search order by n.email " + sortDirection; Query query = createQuery(hql); query.setParameter("search", search); if (firstResult != null) { query.setFirstResult(firstResult); } if (maxResults != null) { query.setMaxResults(maxResults); } ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); return new EmailIterator(scrollableResults); }
From source file:mitm.application.djigzo.impl.hibernate.UserPreferencesDAO.java
License:Open Source License
public CloseableIterator<String> getPreferencesIterator(String category) { /*//w w w. j a v a 2 s .com * We will use HQL because I do not (yet?) know how to return just a field instead of * an object when using the Criteria API. */ final String hql = "select p.name from " + entityName + " p where p.category = :category"; Query query = createQuery(hql); query.setString("category", category); ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); return new StringIterator(scrollableResults); }
From source file:mitm.application.djigzo.impl.hibernate.UserPreferencesDAO.java
License:Open Source License
public CloseableIterator<String> getPreferencesIterator(String category, Integer firstResult, Integer maxResults, SortDirection sortDirection) { if (sortDirection == null) { sortDirection = SortDirection.ASC; }//from w w w.j a v a 2 s.c om /* * We will use HQL because I do not (yet?) know how to return just a field instead of * an object when using the Criteria API. */ final String hql = "select p.name from " + entityName + " p where p.category = :category order by p.name " + sortDirection; Query query = createQuery(hql); query.setString("category", category); if (firstResult != null) { query.setFirstResult(firstResult); } if (maxResults != null) { query.setMaxResults(maxResults); } ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); return new StringIterator(scrollableResults); }
From source file:mitm.application.djigzo.impl.hibernate.UserPreferencesDAO.java
License:Open Source License
public CloseableIterator<String> getCategoryIterator() { /*//w w w. j a v a2 s . co m * We will use HQL because I do not (yet?) know how to return just a field instead of * an object when using the Criteria API. */ final String hql = "select distinct p.category from " + entityName + " p"; Query query = createQuery(hql); ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); return new StringIterator(scrollableResults); }
From source file:mitm.common.security.certstore.dao.X509CertStoreDAOHibernate.java
License:Open Source License
@Override public CloseableIterator<X509CertStoreEntryHibernate> getByEmail(String email, Match match, Expired expired, MissingKeyAlias missingKeyAlias, Date date, Integer firstResult, Integer maxResults) { /*/*from w ww . j a va 2 s . c o m*/ * we need to get distinct results using the distinct keyword. This is not supported by Criteria * AFAIK so we will need to use HQL */ String baseQuery = "select distinct c from " + entityName + " c"; Query query = createByEmailQuery(baseQuery, email, match, expired, missingKeyAlias, date); if (firstResult != null) { query.setFirstResult(firstResult); } if (maxResults != null) { query.setMaxResults(maxResults); } ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); return new X509CertStoreEntryIterator(results); }
From source file:mitm.common.security.certstore.dao.X509CertStoreDAOHibernate.java
License:Open Source License
private ScrollableResults findByCriterionScrollable(Collection<DatabaseCriterion> criterions, Integer firstResult, Integer maxResults) { Criteria criteria = createCriteria(criterions); if (firstResult != null) { criteria.setFirstResult(firstResult); }//from w ww . j a v a 2 s .c o m if (maxResults != null) { criteria.setMaxResults(maxResults); } /* * Sort on creation date */ criteria.addOrder(Order.asc(getColumnName(Field.CREATION_DATE))); return criteria.scroll(ScrollMode.FORWARD_ONLY); }
From source file:mitm.common.security.crlstore.dao.X509CRLStoreDAOHibernate.java
License:Open Source License
private ScrollableResults getEntriesScrollable(CRLSelector crlSelector, Integer firstResult, Integer maxResults) {// w w w. j a va 2s . c om Criteria criteria = createCriteria(entityName); criteria.add(Restrictions.eq("storeName", storeName)); if (crlSelector instanceof X509CRLSelector) { /* we can do some optimizations by using SQL */ X509CRLSelector x509CRLSelector = (X509CRLSelector) crlSelector; addSelectorCriterias(x509CRLSelector, criteria); } /* sort on thisUpdate date */ criteria.addOrder(Order.desc("crl.thisUpdate")); if (firstResult != null) { criteria.setFirstResult(firstResult); } if (maxResults != null) { criteria.setMaxResults(maxResults); } return criteria.scroll(ScrollMode.FORWARD_ONLY); }
From source file:monasca.thresh.infrastructure.persistence.hibernate.AlarmDefinitionSqlImpl.java
License:Apache License
@SuppressWarnings("unchecked") private List<SubExpression> findSubExpressions(final Session session, final String alarmDefId) { final List<SubExpression> subExpressions = Lists.newArrayList(); Map<String, Map<String, String>> dimensionMap = Maps.newHashMap(); final DetachedCriteria subAlarmDefinitionCriteria = DetachedCriteria .forClass(SubAlarmDefinitionDb.class, "sad").createAlias("alarmDefinition", "ad") .add(Restrictions.conjunction(Restrictions.eqProperty("sad.alarmDefinition.id", "ad.id"), Restrictions.eq("sad.alarmDefinition.id", alarmDefId))) .addOrder(Order.asc("sad.id")).setProjection(Projections.property("sad.id")); final ScrollableResults subAlarmDefinitionDimensionResult = session .createCriteria(SubAlarmDefinitionDimensionDb.class).add(Property .forName("subAlarmDefinitionDimensionId.subExpression.id").in(subAlarmDefinitionCriteria)) .setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY); final ScrollableResults subAlarmDefinitionResult = session .getNamedQuery(SubAlarmDefinitionDb.Queries.BY_ALARMDEFINITION_ID).setString("id", alarmDefId) .setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY); while (subAlarmDefinitionDimensionResult.next()) { final SubAlarmDefinitionDimensionDb dim = (SubAlarmDefinitionDimensionDb) subAlarmDefinitionDimensionResult .get()[0];/*from w w w.j a va 2s. c o m*/ final SubAlarmDefinitionDimensionId id = dim.getSubAlarmDefinitionDimensionId(); final String subAlarmId = (String) session.getIdentifier(id.getSubExpression()); final String name = id.getDimensionName(); final String value = dim.getValue(); if (!dimensionMap.containsKey(subAlarmId)) { dimensionMap.put(subAlarmId, Maps.<String, String>newTreeMap()); } dimensionMap.get(subAlarmId).put(name, value); session.evict(dim); } while (subAlarmDefinitionResult.next()) { final SubAlarmDefinitionDb def = (SubAlarmDefinitionDb) subAlarmDefinitionResult.get()[0]; final String id = def.getId(); final AggregateFunction function = AggregateFunction.fromJson(def.getFunction()); final String metricName = def.getMetricName(); final AlarmOperator operator = AlarmOperator.fromJson(def.getOperator()); final Double threshold = def.getThreshold(); final Integer period = def.getPeriod(); final Integer periods = def.getPeriods(); final Boolean deterministic = def.isDeterministic(); Map<String, String> dimensions = dimensionMap.get(id); if (dimensions == null) { dimensions = Collections.emptyMap(); } subExpressions.add(new SubExpression(id, new AlarmSubExpression(function, new MetricDefinition(metricName, dimensions), operator, threshold, period, periods, deterministic))); session.evict(def); } subAlarmDefinitionDimensionResult.close(); subAlarmDefinitionResult.close(); return subExpressions; }
From source file:net.jforum.actions.LuceneAdminActions.java
License:Open Source License
public void rebuildIndex() { Runnable indexingJob = new Runnable() { public void run() { Session session = null;/* w w w . j av a 2 s .co m*/ try { session = sessionFactory.openSession(); FullTextSession fullTextSession = Search.createFullTextSession(session); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); session.beginTransaction(); int index = 0; int batchSize = config.getInt(ConfigKeys.LUCENE_BATCH_SIZE); ScrollableResults results = fullTextSession.createCriteria(Post.class).createAlias("topic", "t") .scroll(ScrollMode.FORWARD_ONLY); while (results.next() && "1".equals(config.getValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING))) { index++; fullTextSession.index(results.get(0)); if (index % batchSize == 0) { session.clear(); } } session.getTransaction().commit(); } catch (Exception e) { if (session.getTransaction().isActive()) { session.getTransaction().rollback(); } } finally { if (session.isOpen() && session.isConnected()) { session.close(); } } } }; this.config.addProperty(ConfigKeys.LUCENE_CURRENTLY_INDEXING, "1"); Thread thread = new Thread(indexingJob); thread.start(); this.viewService.redirectToAction(Actions.LIST); }
From source file:net.jforum.controllers.LuceneAdminController.java
License:Open Source License
public void rebuildIndex() { Runnable indexingJob = new Runnable() { public void run() { Session session = null;//from www. j av a2 s . co m try { session = sessionFactory.openSession(); FullTextSession fullTextSession = Search.createFullTextSession(session); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); session.beginTransaction(); int index = 0; int batchSize = config.getInt(ConfigKeys.LUCENE_BATCH_SIZE); ScrollableResults results = fullTextSession.createCriteria(Post.class).createAlias("topic", "t") .scroll(ScrollMode.FORWARD_ONLY); while (results.next() && "1".equals(config.getValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING))) { index++; fullTextSession.index(results.get(0)); if (index % batchSize == 0) { session.clear(); } } session.getTransaction().commit(); } catch (Exception e) { if (session.getTransaction().isActive()) { session.getTransaction().rollback(); } } finally { if (session.isOpen() && session.isConnected()) { session.close(); } } } }; this.config.addProperty(ConfigKeys.LUCENE_CURRENTLY_INDEXING, "1"); Thread thread = new Thread(indexingJob); thread.start(); this.result.redirectTo(this).list(); }