List of usage examples for org.hibernate ScrollableResults next
boolean next();
From source file:com.duroty.task.PurgeTrashAndSpam.java
License:Open Source License
/** * DOCUMENT ME!/*from w w w .j a v a 2 s. com*/ */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); // 2002 int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ... int day = cal.get(Calendar.DAY_OF_MONTH); // 1... Calendar cal1 = new GregorianCalendar(year, month - 1, day, 0, 0, 0); Date date = new Date(cal1.getTimeInMillis()); Criteria criteria = hsession.createCriteria(Message.class); criteria.add(Restrictions.in("mesBox", new String[] { this.folderSpam, this.folderTrash })); criteria.add(Restrictions.le("mesDate", date)); criteria.addOrder(Order.asc("mesDate")); ScrollableResults scroll = criteria.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); Users user = message.getUsers(); try { messageable.deleteMimeMessage(message.getMesName(), user); } catch (Exception e) { DLog.log(DLog.INFO, this.getClass(), e.getMessage() + " for user " + user.getUseUsername()); } hsession.delete(message); hsession.flush(); Thread.sleep(100); } } catch (Exception e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
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); }// w w w . ja va 2 s. c o 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 ww w. ja 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()); }//from w w w . ja va 2s. c om } 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.eucalyptus.reporting.art.generator.AbstractArtGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") protected <ET> void foreach(final Class<ET> eventClass, final Criterion criterion, final boolean ascending, final Predicate<? super ET> callback) { final EntityTransaction transaction = Entities.get(eventClass); ScrollableResults results = null; try {//from w ww .j a v a 2 s .c om results = Entities.createCriteria(eventClass).setReadOnly(true).setCacheable(false) .setCacheMode(CacheMode.IGNORE).setFetchSize(100).add(criterion) .addOrder(ascending ? Order.asc(TIMESTAMP_MS) : Order.desc(TIMESTAMP_MS)) .scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { final ET event = (ET) results.get(0); if (!callback.apply(event)) { break; } Entities.evict(event); } } finally { if (results != null) try { results.close(); } catch (Exception e) { } transaction.rollback(); } }
From source file:com.farmafene.commons.hibernate.HBPaginaFactory.java
License:Open Source License
/** * Metodo factora// w w w .j a va2s .c o m * * @param begin * primer registro * @param size * tamao pgina * @param result * dnde buscar * @return pgina generada * @since 1.0.0 */ public HBPagina<T> getPagina(int begin, int size, ScrollableResults result) { HBPaginaImp lista = new HBPaginaImp(); if (lista.getFirst() < 1) { lista.setFirst(1); } if (lista.getPageSize() < 0) { lista.setPageSize(0); } result.beforeFirst(); result.scroll(lista.getFirst() - 1); for (int i = 0; result.next() && (lista.getPageSize() == 0 || i < lista.getPageSize()); i++) { T obj = handler.makeObject(result.get()); if (obj != null) { lista.getLista().add(obj); } } if (result.last()) { lista.setTotalSize(result.getRowNumber() + 1); } else { lista.setTotalSize(0); lista.setFirst(0); } return lista; }
From source file:com.hmsinc.epicenter.tools.reclassifier.Reclassifier.java
License:Open Source License
@Transactional public void run() { setup();/*from w w w.j a va 2 s. c om*/ final String destinationTable = (arguments.length > 4) ? arguments[4] : DEFAULT_TABLE_NAME; final String query = new StringBuilder("INSERT INTO ").append(destinationTable) .append(INSERT_CLASSIFICATION).toString(); final BatchSqlUpdate updater = new BatchSqlUpdate(modelDataSource, query); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.setBatchSize(BATCH_SIZE); updater.compile(); final StatelessSession ss = ((Session) entityManager.getDelegate()).getSessionFactory() .openStatelessSession(); final Criteria c = ss.createCriteria(target.getInteractionClass()) .add(Restrictions.eq("patientClass", target.getPatientClass())).addOrder(Order.asc("id")) .setCacheable(false); if (arguments.length > 2) { c.add(Restrictions.gt("id", Long.valueOf(arguments[2]))); } if (arguments.length > 3) { c.add(Restrictions.lt("id", Long.valueOf(arguments[3]))); } final ScrollableResults sr = c.scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (sr.next()) { final Interaction interaction = (Interaction) sr.get(0); final Set<Classification> classifications = classificationService.classify(interaction, target); save(interaction, classifications, updater); i++; if (i % BATCH_SIZE == 0) { logger.info("Processed {} interactions (current id: {})", i, interaction.getId()); } ((Session) entityManager.getDelegate()).evict(interaction); } sr.close(); updater.flush(); }
From source file:com.ibm.asset.trails.dao.jpa.VSoftwareLparDAOJpa.java
public void paginatedList(DisplayTagList data, Account account, ReconSetting reconSetting, int startIndex, int objectsPerPage, String sort, String dir) { Criteria criteria = getHibernateSessionCriteria(); criteria.createAlias("hardwareLpar", "hl") .createAlias("hl.hardwareLparEff", "hle", CriteriaSpecification.LEFT_JOIN) .createAlias("hl.hardware", "h").createAlias("h.machineType", "mt") .createAlias("installedSoftwares", "is") .createAlias("is.scheduleF", "sf", CriteriaSpecification.LEFT_JOIN) .createAlias("sf.scope", "scope", CriteriaSpecification.LEFT_JOIN) .createAlias("is.softwareLpar", "sl").createAlias("is.alert", "aus") .createAlias("aus.reconcile", "r", CriteriaSpecification.LEFT_JOIN) .createAlias("r.usedLicenses", "ul", CriteriaSpecification.LEFT_JOIN) .createAlias("ul.license", "license", CriteriaSpecification.LEFT_JOIN) .createAlias("r.reconcileType", "rt", CriteriaSpecification.LEFT_JOIN) .createAlias("is.software", "sw") .createAlias("sw.manufacturer", "mf", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.eq("account", account)); if (reconSetting.getReconcileType() != null) { criteria.add(Restrictions.eq("rt.id", reconSetting.getReconcileType())); }// ww w . j av a 2 s.c o m if (StringUtils.isNotBlank(reconSetting.getAlertStatus())) { boolean open = false; if (reconSetting.getAlertStatus().equals("OPEN")) { open = true; criteria.add(Restrictions.eq("aus.open", open)); } else { criteria.add(Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id"))); } } else { criteria.add(Restrictions.or(Restrictions.eq("aus.open", true), Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id")))); } if (null != reconSetting.getAlertFrom() && reconSetting.getAlertFrom().intValue() >= 0) { criteria.add(Restrictions.ge("aus.alertAge", reconSetting.getAlertFrom())); } if (null != reconSetting.getAlertTo() && reconSetting.getAlertTo().intValue() >= 0) { criteria.add(Restrictions.le("aus.alertAge", reconSetting.getAlertTo())); } if (StringUtils.isNotBlank(reconSetting.getAssigned())) { if (reconSetting.getAssigned().equals("Assigned")) { criteria.add(Restrictions.ne("aus.remoteUser", "STAGING")); } if (reconSetting.getAssigned().equals("Unassigned")) { criteria.add(Restrictions.eq("aus.remoteUser", "STAGING")); } } if (StringUtils.isNotBlank(reconSetting.getAssignee())) { criteria.add(Restrictions.eq("aus.remoteUser", reconSetting.getAssignee()).ignoreCase()); } if (StringUtils.isNotBlank(reconSetting.getOwner())) { if (reconSetting.getOwner().equalsIgnoreCase("IBM")) { criteria.add(Restrictions.eq("h.owner", reconSetting.getOwner()).ignoreCase()); } else if (reconSetting.getOwner().equalsIgnoreCase("Customer")) { ArrayList<String> lalOwner = new ArrayList<String>(); lalOwner.add("CUST"); lalOwner.add("CUSTO"); criteria.add(Restrictions.in("h.owner", lalOwner)); } } // I'm not sure why the heck we aren't just getting a list of strings? if (reconSetting.getCountries().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getCountries().length; i++) { if (StringUtils.isNotBlank(reconSetting.getCountries()[i])) { list.add(reconSetting.getCountries()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.country", list)); } } if (reconSetting.getNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getNames()[i])) { list.add(reconSetting.getNames()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("hl.name", list)); } } if (reconSetting.getSwcmIDs().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSwcmIDs().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSwcmIDs()[i])) { list.add(reconSetting.getSwcmIDs()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("license.extSrcId", list)); } } if (reconSetting.getSerialNumbers().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSerialNumbers().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSerialNumbers()[i])) { list.add(reconSetting.getSerialNumbers()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.serial", list)); } } if (reconSetting.getProductInfoNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getProductInfoNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getProductInfoNames()[i])) { list.add(reconSetting.getProductInfoNames()[i]); } } if (list.size() > 0) { criteria.add(Restrictions.in("sw.softwareName", list)); } } if (StringUtils.isNotBlank(reconSetting.getScope())) { if ("Not specified".equalsIgnoreCase(reconSetting.getScope())) { criteria.add(Restrictions.isNull("scope.description")); } else { criteria.add(Restrictions.eq("scope.description", reconSetting.getScope())); } } if (StringUtils.isNotBlank(reconSetting.getFinanResp())) { if ("Not Specified".trim().equalsIgnoreCase(reconSetting.getFinanResp())) { criteria.add(Restrictions.isNull("sf.SWFinanceResp")); } else { criteria.add(Restrictions.eq("sf.SWFinanceResp", reconSetting.getFinanResp())); } } criteria.setProjection(Projections.projectionList().add(Projections.property("aus.id").as("alertId")) .add(Projections.property("r.id").as("reconcileId")) .add(Projections.property("aus.alertAge").as("alertAgeI")) .add(Projections.property("is.id").as("installedSoftwareId")) .add(Projections.property("hl.name").as("hostname")) .add(Projections.property("sl.name").as("sl_hostname")) .add(Projections.property("hl.spla").as("spla")) .add(Projections.property("hl.sysplex").as("sysplex")) .add(Projections.property("hl.internetIccFlag").as("internetIccFlag")) .add(Projections.property("h.serial").as("serial")) .add(Projections.property("h.country").as("country")) .add(Projections.property("h.owner").as("owner")) .add(Projections.property("h.mastProcessorType").as("mastProcessorType")) .add(Projections.property("h.processorManufacturer").as("processorManufacturer")) .add(Projections.property("h.mastProcessorModel").as("mastProcessorModel")) .add(Projections.property("h.nbrCoresPerChip").as("nbrCoresPerChip")) .add(Projections.property("h.nbrOfChipsMax").as("nbrOfChipsMax")) .add(Projections.property("h.cpuLsprMips").as("cpuLsprMips")) .add(Projections.property("h.cpuIfl").as("cpuIFL")) .add(Projections.property("hl.partLsprMips").as("partLsprMips")) .add(Projections.property("h.cpuGartnerMips").as("cpuGartnerMips")) .add(Projections.property("hl.partGartnerMips").as("partGartnerMips")) .add(Projections.property("hl.effectiveThreads").as("effectiveThreads")) .add(Projections.property("hl.vcpu").as("vcpu")).add(Projections.property("h.cpuMsu").as("cpuMsu")) .add(Projections.property("hl.partMsu").as("partMsu")) .add(Projections.property("hl.serverType").as("lparServerType")) .add(Projections.property("h.shared").as("shared")) .add(Projections.property("h.multi_tenant").as("multi_tenant")) .add(Projections.property("mt.type").as("assetType")) .add(Projections.property("mt.name").as("assetName")) .add(Projections.property("h.hardwareStatus").as("hardwareStatus")) .add(Projections.property("hl.lparStatus").as("lparStatus")) .add(Projections.property("processorCount").as("processorCount")) .add(Projections.property("sw.softwareName").as("productInfoName")) .add(Projections.property("sw.softwareId").as("productInfoId")) .add(Projections.property("sw.pid").as("pid")) .add(Projections.property("mf.manufacturerName").as("manufacturerName")) .add(Projections.property("rt.name").as("reconcileTypeName")) .add(Projections.property("rt.id").as("reconcileTypeId")) .add(Projections.property("aus.remoteUser").as("assignee")) .add(Projections.property("h.processorCount").as("hardwareProcessorCount")) .add(Projections.property("hle.processorCount").as("hwLparEffProcessorCount")) .add(Projections.property("hl.osType").as("osType")) .add(Projections.property("hle.status").as("hwLparEffProcessorStatus")) .add(Projections.property("h.chips").as("chips"))); criteria.setResultTransformer(new AliasToBeanResultTransformer(ReconWorkspace.class)); criteria.addOrder(Order.desc("aus.open")); if (dir.equalsIgnoreCase("ASC")) { criteria.addOrder(Order.asc(sort)); } else { criteria.addOrder(Order.desc(sort)); } ArrayList<ReconWorkspace> list = new ArrayList<ReconWorkspace>(); ScrollableResults itemCursor = criteria.scroll(); itemCursor.beforeFirst(); if (itemCursor.next()) { itemCursor.scroll(startIndex); int i = 0; while (objectsPerPage > i++) { ReconWorkspace rw = (ReconWorkspace) itemCursor.get(0); if (null != rw.getHwLparEffProcessorStatus() && rw.getHwLparEffProcessorStatus().equalsIgnoreCase("INACTIVE")) { rw.setHwLparEffProcessorCount(0); } list.add(rw); if (!itemCursor.next()) break; } data.setList(list); itemCursor.last(); data.setFullListSize(itemCursor.getRowNumber() + 1); itemCursor.close(); addSchedulef2List(account, data.getList()); } else { data.setList(null); data.setFullListSize(0); itemCursor.close(); } }
From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java
License:Open Source License
@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED) public void getAlertExpiredMaintReport(Account pAccount, String remoteUser, String lsName, PrintWriter pPrintWriter) throws HibernateException, Exception { ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()).createSQLQuery( "SELECT CASE WHEN VA.Alert_Age > 90 THEN 'Red' WHEN VA.Alert_Age > 45 THEN 'Yellow' ELSE 'Green' END, COALESCE(S.software_name, L.Full_Desc), L.Quantity, L.Expire_Date, L.Ext_Src_Id, VA.Creation_Time, VA.Alert_Age, VA.Remote_User, VA.Comments, VA.Record_Time FROM EAADMIN.V_Alerts VA, EAADMIN.License L LEFT OUTER JOIN EAADMIN.License_Sw_Map LSM ON LSM.License_Id = L.Id LEFT OUTER JOIN EAADMIN.software S ON S.software_id = LSM.Software_Id WHERE VA.Customer_Id = :customerId AND VA.Type = 'EXPIRED_MAINT' AND VA.Open = 1 AND L.Id = VA.Fk_Id ORDER BY COALESCE(S.software_name, L.Full_Desc) ASC") .setLong("customerId", pAccount.getId()).setString("type", "EXPIRED_MAINT") .scroll(ScrollMode.FORWARD_ONLY); printHeader(ALERT_EXPIRED_MAINT_REPORT_NAME, pAccount.getAccount(), ALERT_EXPIRED_MAINT_REPORT_COLUMN_HEADERS, pPrintWriter); while (lsrReport.next()) { pPrintWriter.println(outputData(lsrReport.get())); }/* w w w .j a v a 2 s . c o m*/ lsrReport.close(); }
From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java
License:Open Source License
@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED) public void getAlertExpiredScanReport(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb, OutputStream pOutputStream) throws HibernateException, Exception { AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode") .setParameter("code", "EXP_SCAN").getSingleResult(); StringBuffer dataQuery = new StringBuffer( "SELECT CASE WHEN VA.Alert_Age > 90 THEN 'Red' WHEN VA.Alert_Age > 45 THEN 'Yellow' ELSE 'Green' END, "); dataQuery.append(/* w w w . j a v a 2s . c o m*/ "SL.Name, SL.Bios_Serial, VA.Creation_Time, VA.Alert_Age, MT.Type, HL.OS_Type, VA.Remote_User, VA.Comments, ") .append("VA.Record_Time , AC.name as ac_name, CC.target_date,CC.owner as cc_owner,CC.record_time as cc_record_time, ") .append("CC.remote_user as cc_remote_user, CC.id as cc_id ").append("FROM EAADMIN.V_Alerts VA ") .append("JOIN EAADMIN.Software_Lpar SL ON SL.Id = VA.FK_Id ") .append("JOIN EAADMIN.cause_code CC ON (VA.id = CC.alert_id AND CC.alert_type_id = :alertTypeId) ") .append("JOIN EAADMIN.alert_cause AC ON CC.alert_cause_id = AC.id ") .append("LEFT OUTER JOIN EAADMIN.hw_sw_composite HSC on HSC.software_lpar_id = SL.id ") .append("LEFT OUTER JOIN EAADMIN.hardware_lpar HL on HL.id = HSC.hardware_lpar_id ") .append("LEFT OUTER JOIN EAADMIN.hardware H on H.id = HL.hardware_id ") .append("LEFT OUTER JOIN EAADMIN.machine_type MT on MT.id = H.machine_type_id ") .append("WHERE VA.Customer_Id = :customerId AND VA.Type = :type AND VA.Open = 1 ") .append("ORDER BY SL.Name ASC"); ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()) .createSQLQuery(dataQuery.toString()).setLong("customerId", pAccount.getId()) .setString("type", "EXPIRED_SCAN").setInteger("alertTypeId", alertType.getId().intValue()) .scroll(ScrollMode.FORWARD_ONLY); HSSFSheet sheet = phwb.createSheet("Alert Unexpired SW Lpar " + pAccount.getAccount() + " Report"); printHeader(ALERT_EXPIRED_SCAN_REPORT_NAME, pAccount.getAccount(), ALERT_EXPIRED_SCAN_REPORT_COLUMN_HEADERS, sheet); int i = 3; while (lsrReport.next()) { int k = 1; if (i > 65535) { k++; sheet = phwb.createSheet("Alert Unexpired SW Lpar " + pAccount.getAccount() + " Report Sheet" + k); i = 1; } HSSFRow row = sheet.createRow((int) i); outputData(lsrReport.get(), row); i++; } @SuppressWarnings("unchecked") Iterator<Object[]> vCauseCodeSummary = getEntityManager() .createNamedQuery("getValidCauseCodesByAlertTypeId").setParameter("alertTypeId", alertType.getId()) .getResultList().iterator(); HSSFSheet sheet_2 = phwb.createSheet("Valid Cause Codes"); HSSFRow rowhead0 = sheet_2.createRow((int) 0); outputData(ALERT_VALID_CAUSE_CODE_HEADERS, rowhead0); int j = 1; while (vCauseCodeSummary.hasNext()) { HSSFRow row = sheet_2.createRow((int) j); outputData(vCauseCodeSummary.next(), row); j++; } phwb.write(pOutputStream); }