List of usage examples for org.hibernate Criteria setCacheMode
public Criteria setCacheMode(CacheMode cacheMode);
From source file:com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricManager.java
License:Open Source License
public static List<Collection<MetricStatistics>> getManyMetricStatistics( List<GetMetricStatisticsParams> getMetricStatisticsParamses) { if (getMetricStatisticsParamses == null) throw new IllegalArgumentException("getMetricStatisticsParamses can not be null"); Date now = new Date(); Map<GetMetricStatisticsParams, Collection<MetricStatistics>> resultMap = Maps.newHashMap(); Multimap<Class, GetMetricStatisticsParams> hashGroupMap = LinkedListMultimap.create(); for (GetMetricStatisticsParams getMetricStatisticsParams : getMetricStatisticsParamses) { if (getMetricStatisticsParams == null) throw new IllegalArgumentException("getMetricStatisticsParams can not be null"); getMetricStatisticsParams.validate(now); Class metricEntityClass = MetricEntityFactory.getClassForEntitiesGet( getMetricStatisticsParams.getMetricType(), getMetricStatisticsParams.getDimensionHash()); hashGroupMap.put(metricEntityClass, getMetricStatisticsParams); }//from ww w . j a v a2 s .co m for (Class metricEntityClass : hashGroupMap.keySet()) { try (final TransactionResource db = Entities.transactionFor(metricEntityClass)) { // set some global criteria to start (for narrowing?) Date minDate = null; Date maxDate = null; Junction disjunction = Restrictions.disjunction(); Map<GetMetricStatisticsParams, TreeMap<GetMetricStatisticsAggregationKey, MetricStatistics>> multiAggregationMap = Maps .newHashMap(); for (GetMetricStatisticsParams getMetricStatisticsParams : hashGroupMap.get(metricEntityClass)) { multiAggregationMap.put(getMetricStatisticsParams, new TreeMap<GetMetricStatisticsAggregationKey, MetricStatistics>( GetMetricStatisticsAggregationKey.COMPARATOR_WITH_NULLS.INSTANCE)); Junction conjunction = Restrictions.conjunction(); conjunction = conjunction .add(Restrictions.lt("timestamp", getMetricStatisticsParams.getEndTime())); conjunction = conjunction .add(Restrictions.ge("timestamp", getMetricStatisticsParams.getStartTime())); conjunction = conjunction .add(Restrictions.eq("accountId", getMetricStatisticsParams.getAccountId())); conjunction = conjunction .add(Restrictions.eq("metricName", getMetricStatisticsParams.getMetricName())); conjunction = conjunction .add(Restrictions.eq("namespace", getMetricStatisticsParams.getNamespace())); conjunction = conjunction.add( Restrictions.eq("dimensionHash", hash(getMetricStatisticsParams.getDimensionMap()))); if (getMetricStatisticsParams.getUnits() != null) { conjunction = conjunction .add(Restrictions.eq("units", getMetricStatisticsParams.getUnits())); } disjunction = disjunction.add(conjunction); if (minDate == null || getMetricStatisticsParams.getStartTime().before(minDate)) { minDate = getMetricStatisticsParams.getStartTime(); } if (maxDate == null || getMetricStatisticsParams.getEndTime().after(maxDate)) { maxDate = getMetricStatisticsParams.getEndTime(); } } Criteria criteria = Entities.createCriteria(metricEntityClass); criteria = criteria.add(Restrictions.lt("timestamp", maxDate)); criteria = criteria.add(Restrictions.ge("timestamp", minDate)); criteria = criteria.add(disjunction); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.max("sampleMax")); projectionList.add(Projections.min("sampleMin")); projectionList.add(Projections.sum("sampleSize")); projectionList.add(Projections.sum("sampleSum")); projectionList.add(Projections.groupProperty("units")); projectionList.add(Projections.groupProperty("timestamp")); projectionList.add(Projections.groupProperty("accountId")); projectionList.add(Projections.groupProperty("metricName")); projectionList.add(Projections.groupProperty("metricType")); projectionList.add(Projections.groupProperty("namespace")); projectionList.add(Projections.groupProperty("dimensionHash")); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("timestamp")); ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { MetricEntity me = getMetricEntity(results); for (GetMetricStatisticsParams getMetricStatisticsParams : hashGroupMap .get(metricEntityClass)) { if (metricDataMatches(getMetricStatisticsParams, me)) { Map<GetMetricStatisticsAggregationKey, MetricStatistics> aggregationMap = multiAggregationMap .get(getMetricStatisticsParams); GetMetricStatisticsAggregationKey key = new GetMetricStatisticsAggregationKey(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatisticsParams.getDimensionHash()); MetricStatistics item = new MetricStatistics(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatisticsParams.getDimensions()); if (!aggregationMap.containsKey(key)) { aggregationMap.put(key, item); } else { MetricStatistics totalSoFar = aggregationMap.get(key); totalSoFar.setSampleMax(Math.max(item.getSampleMax(), totalSoFar.getSampleMax())); totalSoFar.setSampleMin(Math.min(item.getSampleMin(), totalSoFar.getSampleMin())); totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSampleSize()); totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSampleSum()); } } } } for (GetMetricStatisticsParams getMetricStatisticsParams : multiAggregationMap.keySet()) { resultMap.put(getMetricStatisticsParams, multiAggregationMap.get(getMetricStatisticsParams).values()); } } } List<Collection<MetricStatistics>> resultList = Lists.newArrayList(); for (GetMetricStatisticsParams getMetricStatisticsParams : getMetricStatisticsParamses) { if (resultMap.get(getMetricStatisticsParams) == null) { resultList.add(new ArrayList<MetricStatistics>()); } else { resultList.add(resultMap.get(getMetricStatisticsParams)); } } return resultList; }
From source file:com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricManager.java
License:Open Source License
public static Collection<MetricStatistics> getMetricStatistics( GetMetricStatisticsParams getMetricStatisticsParams) { if (getMetricStatisticsParams == null) throw new IllegalArgumentException("getMetricStatisticsParams can not be null"); Date now = new Date(); getMetricStatisticsParams.validate(now); Class metricEntityClass = MetricEntityFactory.getClassForEntitiesGet( getMetricStatisticsParams.getMetricType(), getMetricStatisticsParams.getDimensionHash()); Map<GetMetricStatisticsAggregationKey, MetricStatistics> aggregationMap = new TreeMap<GetMetricStatisticsAggregationKey, MetricStatistics>( GetMetricStatisticsAggregationKey.COMPARATOR_WITH_NULLS.INSTANCE); try (final TransactionResource db = Entities.transactionFor(metricEntityClass)) { Criteria criteria = Entities.createCriteria(metricEntityClass); criteria = criteria.add(Restrictions.eq("accountId", getMetricStatisticsParams.getAccountId())); criteria = criteria.add(Restrictions.eq("metricName", getMetricStatisticsParams.getMetricName())); criteria = criteria.add(Restrictions.eq("namespace", getMetricStatisticsParams.getNamespace())); criteria = criteria.add(Restrictions.lt("timestamp", getMetricStatisticsParams.getEndTime())); criteria = criteria.add(Restrictions.ge("timestamp", getMetricStatisticsParams.getStartTime())); criteria = criteria.add(Restrictions.eq("dimensionHash", getMetricStatisticsParams.getDimensionHash())); if (getMetricStatisticsParams.getUnits() != null) { criteria = criteria.add(Restrictions.eq("units", getMetricStatisticsParams.getUnits())); }/*from w w w. j a v a2s. c o m*/ ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.max("sampleMax")); projectionList.add(Projections.min("sampleMin")); projectionList.add(Projections.sum("sampleSize")); projectionList.add(Projections.sum("sampleSum")); projectionList.add(Projections.groupProperty("units")); projectionList.add(Projections.groupProperty("timestamp")); criteria.setProjection(projectionList); criteria.addOrder(Order.asc("timestamp")); ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { MetricEntity me = getMetricEntity(getMetricStatisticsParams.getAccountId(), getMetricStatisticsParams.getMetricName(), getMetricStatisticsParams.getNamespace(), getMetricStatisticsParams.getMetricType(), getMetricStatisticsParams.getDimensionHash(), results); GetMetricStatisticsAggregationKey key = new GetMetricStatisticsAggregationKey(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatisticsParams.getDimensionHash()); MetricStatistics item = new MetricStatistics(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatisticsParams.getDimensions()); if (!aggregationMap.containsKey(key)) { aggregationMap.put(key, item); } else { MetricStatistics totalSoFar = aggregationMap.get(key); totalSoFar.setSampleMax(Math.max(item.getSampleMax(), totalSoFar.getSampleMax())); totalSoFar.setSampleMin(Math.min(item.getSampleMin(), totalSoFar.getSampleMin())); totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSampleSize()); totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSampleSum()); } } } return Lists.newArrayList(aggregationMap.values()); }
From source file:com.eucalyptus.cluster.callback.reporting.FullTableScanAbsoluteMetricConverter.java
License:Open Source License
protected static List<AbsoluteMetricQueueItem> dealWithAbsoluteMetrics( Iterable<AbsoluteMetricQueueItem> dataBatch) { List<AbsoluteMetricQueueItem> regularMetrics = Lists.newArrayList(); List<SimpleAbsoluteMetricHistory> absoluteMetricsToInsert = Lists.newArrayList(); SortedAbsoluteMetrics sortedAbsoluteMetrics = sortAbsoluteMetrics(dataBatch); regularMetrics.addAll(sortedAbsoluteMetrics.getRegularMetrics()); AbsoluteMetricMap absoluteMetricMap = sortedAbsoluteMetrics.getAbsoluteMetricMap(); try (final TransactionResource db = Entities.transactionFor(AbsoluteMetricHistory.class)) { int count = 0; Criteria criteria = Entities.createCriteria(AbsoluteMetricHistory.class); ScrollableResults absoluteMetrics = criteria.setCacheMode(CacheMode.IGNORE) .scroll(ScrollMode.FORWARD_ONLY); while (absoluteMetrics.next()) { AbsoluteMetricHistory absoluteMetricHistory = (AbsoluteMetricHistory) absoluteMetrics.get(0); if (absoluteMetricMap.containsKey(absoluteMetricHistory.getNamespace(), absoluteMetricHistory.getMetricName(), absoluteMetricHistory.getDimensionName(), absoluteMetricHistory.getDimensionValue())) { MetricsAndOtherFields metricsAndOtherFields = absoluteMetricMap.getMetricsAndOtherFields( absoluteMetricHistory.getNamespace(), absoluteMetricHistory.getMetricName(), absoluteMetricHistory.getDimensionName(), absoluteMetricHistory.getDimensionValue()); Map<TimestampAndMetricValue, MetricDatum> metricDatumMap = metricsAndOtherFields .getMetricDatumMap(); SequentialMetrics sequentialMetrics = calculateSequentialMetrics(absoluteMetricHistory, metricDatumMap, metricsAndOtherFields.getAccountId(), metricsAndOtherFields.getRelativeMetricName()); absoluteMetricMap.removeEntries(absoluteMetricHistory.getNamespace(), absoluteMetricHistory.getMetricName(), absoluteMetricHistory.getDimensionName(), absoluteMetricHistory.getDimensionValue()); for (AbsoluteMetricQueueItem regularMetric : sequentialMetrics.getRegularMetrics()) { if (AbsoluteMetricHelper.AWS_EBS_NAMESPACE.equals(regularMetric.getNamespace())) { if (AbsoluteMetricHelper.VOLUME_READ_OPS_METRIC_NAME .equals(regularMetric.getMetricDatum().getMetricName())) { // special case regularMetrics.add(AbsoluteMetricHelper.createVolumeThroughputMetric( regularMetric.getAccountId(), regularMetric.getNamespace(), regularMetric.getMetricDatum())); } else if (AbsoluteMetricHelper.VOLUME_TOTAL_READ_WRITE_TIME_METRIC_NAME .equals(regularMetric.getMetricDatum().getMetricName())) { AbsoluteMetricHelper.convertVolumeTotalReadWriteTimeToVolumeIdleTime( regularMetric.getMetricDatum()); }//ww w. j a v a2s . c o m } regularMetrics.add(regularMetric); } absoluteMetricHistory.setTimestamp(sequentialMetrics.getUpdateTimestamp()); absoluteMetricHistory.setLastMetricValue(sequentialMetrics.getUpdateValue()); if (++count % AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_UNTIL_SESSION_FLUSH == 0) { Entities.flushSession(AbsoluteMetricHistory.class); Entities.clearSession(AbsoluteMetricHistory.class); } } } db.commit(); } // Now parse entries only in the map... for (AbsoluteMetricMap.NamespaceMetricNameAndDimension namespaceMetricNameAndDimension : absoluteMetricMap .keySet()) { AbsoluteMetricHistory absoluteMetricHistory = new AbsoluteMetricHistory(); absoluteMetricHistory.setNamespace(namespaceMetricNameAndDimension.getNamespace()); absoluteMetricHistory.setMetricName(namespaceMetricNameAndDimension.getMetricName()); absoluteMetricHistory.setDimensionName(namespaceMetricNameAndDimension.getDimensionName()); absoluteMetricHistory.setDimensionValue(namespaceMetricNameAndDimension.getDimensionValue()); MetricsAndOtherFields metricsAndOtherFields = absoluteMetricMap.get(namespaceMetricNameAndDimension); Map<TimestampAndMetricValue, MetricDatum> metricDataMap = metricsAndOtherFields.getMetricDatumMap(); if (metricDataMap.size() == 0) continue; TimestampAndMetricValue firstValue = metricDataMap.keySet().iterator().next(); metricDataMap.remove(firstValue); absoluteMetricHistory.setLastMetricValue(firstValue.getMetricValue()); absoluteMetricHistory.setTimestamp(firstValue.getTimestamp()); if (metricDataMap.size() != 0) { SequentialMetrics sequentialMetrics = calculateSequentialMetrics(absoluteMetricHistory, metricDataMap, metricsAndOtherFields.getAccountId(), metricsAndOtherFields.getRelativeMetricName()); for (AbsoluteMetricQueueItem regularMetric : sequentialMetrics.getRegularMetrics()) { if (AbsoluteMetricHelper.AWS_EBS_NAMESPACE.equals(regularMetric.getNamespace())) { if (AbsoluteMetricHelper.VOLUME_READ_OPS_METRIC_NAME .equals(regularMetric.getMetricDatum().getMetricName())) { // special case regularMetrics.add( AbsoluteMetricHelper.createVolumeThroughputMetric(regularMetric.getAccountId(), regularMetric.getNamespace(), regularMetric.getMetricDatum())); } else if (AbsoluteMetricHelper.VOLUME_TOTAL_READ_WRITE_TIME_METRIC_NAME .equals(regularMetric.getMetricDatum().getMetricName())) { AbsoluteMetricHelper.convertVolumeTotalReadWriteTimeToVolumeIdleTime( regularMetric.getMetricDatum()); } } regularMetrics.add(regularMetric); } absoluteMetricHistory.setTimestamp(sequentialMetrics.getUpdateTimestamp()); absoluteMetricHistory.setLastMetricValue(sequentialMetrics.getUpdateValue()); } absoluteMetricsToInsert.add(convertToSimpleAbsoluteMetricHistory(absoluteMetricHistory)); } // insert all new points try (final TransactionResource db = Entities.transactionFor(AbsoluteMetricHistory.class)) { int count = 0; for (SimpleAbsoluteMetricHistory simpleAbsoluteMetricHistory : absoluteMetricsToInsert) { Entities.persist(convertToAbsoluteMetricHistory(simpleAbsoluteMetricHistory)); if (++count % AbsoluteMetricQueue.ABSOLUTE_METRIC_NUM_DB_OPERATIONS_UNTIL_SESSION_FLUSH == 0) { Entities.flushSession(AbsoluteMetricHistory.class); Entities.clearSession(AbsoluteMetricHistory.class); } } db.commit(); } return regularMetrics; }
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * Initializes a Criteria Query.//from w w w . j av a2s .c o m * Mandatory Attributes:<ul> * <li><b>name</b>: The unqualified class name driving the criteria query.</li> * </ul> * Optional Attributes:<ul> * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li> * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li> * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li> * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li> * <li><b>cacheMode</b>: The cache options for the queried objects.</li> * <li><b>flushMode</b>: The session flush options.</li> * <li><b>fetchMode</b>: The collection fetch options for the query.</li> * <li><b>lockMode</b>: The row lock options for the queried rows.</li> * <li><b>timeOut</b>: The query timeout option.</li> * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li> * </ul> * @param attrs The attributes of the processed node. * @return An appended or new CriteriaSpecification * @throws SAXException */ protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException { if (inDetached) { return criteriaStack.peek(); } String name = attrs.getValue("name"); String prefix = attrs.getValue("prefix"); if (prefix != null) { className = prefix + "." + name; } else { className = name; } String maxSize = attrs.getValue("maxSize"); String fetchSize = attrs.getValue("fetchSize"); String firstResult = attrs.getValue("firstResult"); String cacheEnabled = attrs.getValue("cacheEnabled"); String cacheMode = attrs.getValue("cacheMode"); String flushMode = attrs.getValue("flushMode"); String fetchMode = attrs.getValue("fetchMode"); String lockMode = attrs.getValue("lockMode"); String timeOut = attrs.getValue("timeOut"); String rowCountOnly = attrs.getValue("rowCountOnly"); Criteria newCriteria = null; try { if (criteriaStack.size() == 0) { newCriteria = session.createCriteria(className); } else { newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className); } criteriaStack.push(newCriteria); if ("true".equalsIgnoreCase(rowCountOnly)) { newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount()) ); setRowCountOnly(true); } if (maxSize != null && isRowCountOnly() == false) { newCriteria.setMaxResults(Integer.parseInt(maxSize)); } if (fetchSize != null && isRowCountOnly() == false) { newCriteria.setFetchSize(Integer.parseInt(fetchSize)); } if (firstResult != null && isRowCountOnly() == false) { newCriteria.setFirstResult(Integer.parseInt(firstResult)); } if (timeOut != null) { newCriteria.setTimeout(Integer.parseInt(timeOut)); } if ("true".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(true); } else if ("false".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(false); } if (fetchMode != null && fetchMode.length() > 0) { if ("JOIN".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.JOIN); } else if ("SELECT".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.SELECT); } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } if (cacheMode != null && cacheMode.length() > 0) { if ("GET".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.GET); } else if ("IGNORE".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.IGNORE); } else if ("NORMAL".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.NORMAL); } else if ("PUT".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.PUT); } else if ("REFRESH".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.REFRESH); } else { newCriteria.setCacheMode(CacheMode.NORMAL); } } if (lockMode != null && lockMode.length() > 0) { if ("NONE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.NONE); } else if ("READ".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.READ); } else if ("UPGRADE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE); } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT); } else if ("WRITE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.WRITE); } else { throw new SAXException("lockMode[" + lockMode + "] Not Recognized"); } } if (flushMode != null && flushMode.length() > 0) { if ("ALWAYS".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.ALWAYS); } else if ("AUTO".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.AUTO); } else if ("COMMIT".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.COMMIT); } else if ("NEVER".equalsIgnoreCase(flushMode)) { // NEVER is deprecated, so we won't throw an exception but we'll ignore it. } else { throw new SAXException("flushMode[" + flushMode + "] Not Recognized"); } } return newCriteria; } catch (Exception e) { throw new SAXException("Unable to configure class " + className, e); } }
From source file:info.jtrac.hibernate.HibernateJtracDao.java
License:Apache License
public List<Item> findAllItems(final int firstResult, final int batchSize) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) { session.clear();/* w w w .j a va2 s. c om*/ Criteria criteria = session.createCriteria(Item.class); criteria.setCacheMode(CacheMode.IGNORE); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFetchMode("history", FetchMode.JOIN); criteria.add(Restrictions.ge("id", (long) firstResult)); criteria.add(Restrictions.lt("id", (long) firstResult + batchSize)); return criteria.list(); } }); }
From source file:info.jtrac.repository.HibernateJtracDao.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w ww. ja v a 2 s .c om*/ @Transactional(propagation = Propagation.SUPPORTS) public List<Item> findAllItems(final int firstResult, final int batchSize) { entityManager.clear(); Session session = getSession(); Criteria criteria = session.createCriteria(Item.class); criteria.setCacheMode(CacheMode.IGNORE); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFetchMode("history", FetchMode.JOIN); criteria.add(Restrictions.ge("id", (long) firstResult)); criteria.add(Restrictions.lt("id", (long) firstResult + batchSize)); return criteria.list(); }
From source file:lt.bsprendimai.ddesk.SearchParameters.java
License:Apache License
public List<TicketInfo> getTicketList() { // System.out.println("Getting list at page "+page); try {/*from ww w . j a v a 2 s. c om*/ Criteria crit = SessionHolder.currentSession().getSess().createCriteria(TicketInfo.class); if (getSpe().sortEditDate != null) { if (getSpe().sortEditDate) crit.addOrder(Order.asc("editDate")); else crit.addOrder(Order.desc("editDate")); } else if (getSpe().sortAsignee != null) { if (getSpe().sortAsignee) crit.addOrder(Order.asc("asignee")); else crit.addOrder(Order.desc("asignee")); } else if (getSpe().sortStatus != null) { if (getSpe().sortStatus) crit.addOrder(Order.asc("status")); else crit.addOrder(Order.desc("status")); } else if (getSpe().sortPriority != null) { if (getSpe().sortPriority) crit.addOrder(Order.asc("priority")); else crit.addOrder(Order.desc("priority")); } else if (getSpe().sortCompany != null) { if (getSpe().sortCompany) crit.addOrder(Order.asc("companyName")); else crit.addOrder(Order.desc("companyName")); } else if (getSpe().sortReportDate != null) { if (getSpe().sortReportDate) crit.addOrder(Order.asc("reportDate")); else crit.addOrder(Order.desc("reportDate")); } else if (getSpe().sortName != null) { if (getSpe().sortName) crit.addOrder(Order.asc("name")); else crit.addOrder(Order.desc("name")); } else if (getSpe().sortUniqueId != null) { if (getSpe().sortUniqueId) crit.addOrder(Order.asc("uniqueId")); else crit.addOrder(Order.desc("uniqueId")); } else if (getSpe().sortPlaned != null) { if (getSpe().sortPlaned) crit.addOrder(Order.asc("planedDate")); else crit.addOrder(Order.desc("planedDate")); } else if (getSpe().sortType != null) { if (getSpe().sortType) crit.addOrder(Order.asc("type")); else crit.addOrder(Order.desc("type")); } else if (getSpe().sortVersion != null) { if (getSpe().sortVersion) crit.addOrder(Order.asc("version")); else crit.addOrder(Order.desc("version")); } else { crit.addOrder(Order.desc("id")); } if (spe.status != null)// for verbosity, if != to initial state crit.add(Expression.eq("status", spe.status)); else { if (spe.accepted > 0) {// for verbosity, if != to initial state if (spe.accepted == 1) crit.add(Expression.ge("status", Status.ACCEPTED)); else crit.add(Expression.lt("status", Status.ACCEPTED)); } if (spe.closed > 0) {// for verbosity, if != to initial state if (spe.closed == 1) crit.add(Expression.isNotNull("dateClosed")); else crit.add(Expression.isNull("dateClosed")); } } if (spe.chargeable != 0)// for verbosity, if != to initial state crit.add(Expression.eq("chargeable", spe.chargeable == 1)); if (spe.ticketName != null && !spe.ticketName.trim().equals(""))// for verbosity, if != // to initial state crit.add(Expression.like("name", spe.ticketName, MatchMode.ANYWHERE)); if (spe.uniqueId != null && !spe.uniqueId.trim().equals(""))// for verbosity, if != to // initial state crit.add(Expression.ilike("uniqueId", spe.uniqueId, MatchMode.START)); if (spe.person != null)// for verbosity, if != to initial state crit.add(Expression.eq("person", spe.person)); if (spe.company != null)// for verbosity, if != to initial state crit.add(Expression.eq("company", spe.company)); if (spe.priority != null)// for verbosity, if != to initial state crit.add(Expression.eq("priority", spe.priority)); if (spe.assigned != null) {// for verbosity, if != to initial state if (spe.assigned >= 0) crit.add(Expression.eq("assignedTo", spe.assigned)); else { if (spe.assigned == -2) crit.add(Expression.isNotNull("assignedTo")); else crit.add(Expression.isNull("assignedTo")); } } if (spe.project != null)// for verbosity, if != to initial state crit.add(Expression.eq("project", spe.project)); if (spe.module != null)// for verbosity, if != to initial state crit.add(Expression.eq("module", spe.module)); if (spe.version != null)// for verbosity, if != to initial state crit.add(Expression.eq("version", spe.version)); if (spe.type != null)// for verbosity, if != to initial state crit.add(Expression.eq("type", spe.type)); if (ti.getUserHandler().isPartner()) { Disjunction dis = Expression.disjunction(); dis.add(Expression.eq("projectsCompany", ti.getUserHandler().getUser().getCompany())); dis.add(Expression.eq("assignedTo", ti.getUserHandler().getUser().getId())); dis.add(Expression.eq("reportBy", ti.getUserHandler().getUser().getId())); crit.add(dis); } if (spe.forDate != null) { Calendar c = Calendar.getInstance(); c.setTime(spe.forDate); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); long time1 = c.getTimeInMillis(); c.set(Calendar.HOUR, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); long time2 = c.getTimeInMillis(); crit.add(Expression.between("planedDate", new Date(time1), new Date(time2))); } crit.setCacheMode(CacheMode.NORMAL); crit.setMaxResults(PAGE_STEP); crit.setFirstResult(page * PAGE_STEP); List<TicketInfo> l = (List<TicketInfo>) crit.list(); this.lastEmpty = l.size() == 0 || l.size() < PAGE_STEP; return l; } catch (Exception ex) { SessionHolder.endSession(); UIMessenger.addFatalKeyMessage("error.transaction.abort", ti.getUserHandler().getUserLocale()); ex.printStackTrace(); return TicketAccessor.getEMPTYInfoList(); } }
From source file:org.candlepin.gutterball.curator.ComplianceSnapshotCurator.java
License:Open Source License
/** * Retrieves an iterator over the compliance snapshots for the specified consumer. * * @param consumerUUID// w w w. j ava 2 s . com * The UUID for the consumer for which to retrieve compliance snapshots. * * @param startDate * The start date to use to filter snapshots retrieved. If specified, only snapshots occurring * after the start date, and the snapshot immediately preceding it, will be retrieved. * * @param endDate * The end date to use to filter snapshots retrieved. If specified, only snapshots occurring * before the end date will be retrieved. * * @param pageRequest * A PageRequest instance containing paging information from the request. If null, no paging * will be performed. * * @return * A Page instance containing an iterator over the snapshots for the specified consumer, and * the paging information for the query. */ @SuppressWarnings("checkstyle:indentation") public Page<Iterator<Compliance>> getSnapshotIteratorForConsumer(String consumerUUID, Date startDate, Date endDate, PageRequest pageRequest) { Page<Iterator<Compliance>> page = new Page<Iterator<Compliance>>(); page.setPageRequest(pageRequest); Session session = this.currentSession(); Criteria query = session.createCriteria(Compliance.class, "comp1"); query.createAlias("comp1.consumer", "cons1"); query.add(Restrictions.eq("cons1.uuid", consumerUUID)); if (startDate != null) { DetachedCriteria subquery = DetachedCriteria.forClass(Compliance.class, "comp2"); subquery.createAlias("comp2.consumer", "cons2"); subquery.createAlias("cons2.consumerState", "state2"); subquery.add(Restrictions.or(Restrictions.isNull("state2.deleted"), Restrictions.gt("state2.deleted", startDate))); subquery.add(Restrictions.lt("state2.created", startDate)); subquery.add(Restrictions.eqProperty("cons2.uuid", "cons1.uuid")); subquery.add(Restrictions.lt("comp2.date", startDate)); subquery.setProjection(Projections.projectionList().add(Projections.max("comp2.date"))); query.add(Restrictions.disjunction().add(Restrictions.ge("comp1.date", startDate)) .add(Subqueries.propertyEq("comp1.date", subquery))); } if (endDate != null) { query.add(Restrictions.le("comp1.date", endDate)); } query.setCacheMode(CacheMode.IGNORE); query.setReadOnly(true); if (pageRequest != null && pageRequest.isPaging()) { page.setMaxRecords(this.getRowCount(query)); query.setFirstResult((pageRequest.getPage() - 1) * pageRequest.getPerPage()); query.setMaxResults(pageRequest.getPerPage()); if (pageRequest.getSortBy() != null) { query.addOrder( pageRequest.getOrder() == PageRequest.Order.ASCENDING ? Order.asc(pageRequest.getSortBy()) : Order.desc(pageRequest.getSortBy())); } } page.setPageData(new AutoEvictingColumnarResultsIterator<Compliance>(session, query.scroll(ScrollMode.FORWARD_ONLY), 0)); return page; }
From source file:org.candlepin.model.DetachedCandlepinQuery.java
License:Open Source License
/** * {@inheritDoc}/* w ww . j a v a2s .c o m*/ */ @Override @Transactional @SuppressWarnings("unchecked") public int forEach(int column, boolean evict, ResultProcessor<T> processor) { if (processor == null) { throw new IllegalArgumentException("processor is null"); } Criteria executable = this.getExecutableCriteria(); // We always override the cache mode here to ensure we don't evict things that may be in // cache from another request. if (evict) { executable.setCacheMode(CacheMode.GET); } ScrollableResults cursor = executable.scroll(ScrollMode.FORWARD_ONLY); int count = 0; try { boolean cont = true; if (evict) { while (cont && cursor.next()) { T result = (T) cursor.get(column); cont = processor.process(result); this.session.evict(result); ++count; } } else { while (cont && cursor.next()) { cont = processor.process((T) cursor.get(column)); ++count; } } } finally { cursor.close(); } return count; }
From source file:org.candlepin.model.DetachedCandlepinQuery.java
License:Open Source License
/** * {@inheritDoc}/* ww w.j av a2s . c o m*/ */ @Override public ResultIterator<T> iterate(int column, boolean evict) { Criteria executable = this.getExecutableCriteria(); // We always override the cache mode here to ensure we don't evict things that may be in // cache from another request. if (evict) { executable.setCacheMode(CacheMode.GET); } ScrollableResults cursor = executable.scroll(ScrollMode.FORWARD_ONLY); return new ColumnarResultIterator<>(this.session, cursor, column, evict); }