Example usage for org.hibernate ScrollableResults close

List of usage examples for org.hibernate ScrollableResults close

Introduction

In this page you can find the example usage for org.hibernate ScrollableResults close.

Prototype

void close();

Source Link

Document

Release resources immediately.

Usage

From source file:com.amalto.core.storage.hibernate.ProjectionIterator.java

License:Open Source License

public ProjectionIterator(MappingRepository mappingMetadataRepository, final ScrollableResults results,
        List<TypedExpression> selectedFields, final Set<ResultsCallback> callbacks) {
    this(mappingMetadataRepository, new CloseableIterator<Object>() {

        private boolean hasNext;

        private boolean isClosed = false;

        private boolean consumedResult = true;

        @Override//from   w w w.  ja  v a 2s  . com
        public boolean hasNext() {
            if (!consumedResult) {
                return hasNext;
            }
            try {
                hasNext = results.next();
                consumedResult = false;
                return hasNext;
            } catch (Exception e) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Unable to check for next result.", e); //$NON-NLS-1$
                }
                return false;
            }
        }

        @Override
        public Object next() {
            consumedResult = true;
            return results.get();
        }

        @Override
        public void remove() {
        }

        @Override
        public void close() throws IOException {
            if (!isClosed) {
                try {
                    results.close();
                } finally {
                    isClosed = true;
                }
            }
        }
    }, selectedFields, callbacks);
}

From source file:com.appeligo.alerts.PendingAlert.java

License:Apache License

@SuppressWarnings("unchecked")
public static PendingAlert getNextAlert() {
    Permissions.checkUser(Permissions.SUPERUSER);
    Session session = getSession();/*from w ww . jav a  2 s. c o  m*/
    Query query = session.getNamedQuery("PendingAlert.getNextAlerts");
    ScrollableResults results = query.scroll();
    results.beforeFirst();
    PendingAlert pendingAlert = null;
    if (results.next()) {
        pendingAlert = (PendingAlert) results.get(0);
    }
    results.close();
    return pendingAlert;
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from   ww w . ja  v  a2s  .com
 *
 * @param hsession DOCUMENT ME!
 * @param user DOCUMENT ME!
 * @param mid DOCUMENT ME!
 * @param midReferences DOCUMENT ME!
 * @param date DOCUMENT ME!
 * @param beforeSent DOCUMENT ME!
 * @param isHtml DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private Vector readReference(Session hsession, Users user, String mid, String midReferences, Date date1,
        boolean beforeSent, boolean isHtml, boolean displayImages) {
    Vector references = new Vector();
    ByteArrayOutputStream baos = null;

    try {
        Locale locale = new Locale(user.getUseLanguage());
        TimeZone timeZone = TimeZone.getDefault();

        Date now = new Date();
        Calendar calendar = Calendar.getInstance(timeZone, locale);
        calendar.setTime(now);

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale);
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale);
        SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale);

        Criteria crit = hsession.createCriteria(Message.class);
        crit.add(Restrictions.not(Restrictions.eq("mesName", mid)));
        crit.add(Restrictions.eq("mesReferences", midReferences));
        crit.add(Restrictions.eq("users", user));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", this.folderSpam)));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", this.folderTrash)));
        crit.add(Restrictions.not(Restrictions.eq("mesBox", FOLDER_DELETE)));

        if (beforeSent) {
            crit.add(Restrictions.le("mesDate", date1));
        } else {
            crit.add(Restrictions.gt("mesDate", date1));
        }

        crit.addOrder(Order.asc("mesDate"));

        ScrollableResults scroll = crit.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            message.setMesRecent(false);
            hsession.update(message);
            hsession.flush();

            MessageObj obj = new MessageObj(message.getMesName());

            obj.setBox(message.getMesBox());

            obj.setFrom(message.getMesFrom());
            obj.setTo(message.getMesTo());
            obj.setReplyTo(message.getMesReplyTo());
            obj.setCc(message.getMesCc());

            if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) {
                obj.setHasAttachment(true);

                Set set = message.getAttachments();
                Iterator it = set.iterator();
                Vector attachments = new Vector();

                while (it.hasNext()) {
                    Attachment attachment = (Attachment) it.next();
                    AttachmentObj attachmentObj = new AttachmentObj();
                    attachmentObj.setIdint(attachment.getAttPart());
                    attachmentObj.setName(attachment.getAttName());

                    int size = attachment.getAttSize();
                    size /= 1024;

                    if (size > 1024) {
                        size /= 1024;
                        attachmentObj.setSize(size + " MB");
                    } else {
                        attachmentObj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
                    }

                    String extension = (String) this.extensions.get(attachment.getAttContentType());

                    if (StringUtils.isBlank(extension)) {
                        extension = "generic";
                    }

                    attachmentObj.setExtension(extension);

                    attachmentObj.setContentType(attachment.getAttContentType());
                    attachments.addElement(attachmentObj);
                    obj.setAttachments(attachments);
                }
            } else {
                obj.setHasAttachment(false);
            }

            int size = message.getMesSize();
            size /= 1024;

            if (size > 1024) {
                size /= 1024;
                obj.setSize(size + " MB");
            } else {
                obj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
            }

            if (message.getMesBox().equals(folderSent)) {
                try {
                    obj.setEmail(message.getMesTo());
                } catch (Exception e) {
                    obj.setEmail("unknown to");
                }
            } else {
                obj.setEmail(message.getMesFrom());
            }

            Date date = message.getMesDate();

            if (date != null) {
                Calendar calendar2 = Calendar.getInstance(timeZone, locale);
                calendar2.setTime(date);

                if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR))
                        && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH))
                        && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) {
                    obj.setDateStr(formatter2.format(calendar2.getTime()));
                } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
                    obj.setDateStr(formatter1.format(calendar2.getTime()));
                } else {
                    obj.setDateStr(formatter3.format(calendar2.getTime()));
                }
            }

            obj.setDate(date);

            if (message.getLabMeses() != null) {
                Iterator it = message.getLabMeses().iterator();
                StringBuffer label = new StringBuffer();

                while (it.hasNext()) {
                    if (label.length() > 0) {
                        label.append(", ");
                    }

                    LabMes labMes = (LabMes) it.next();
                    label.append(labMes.getId().getLabel().getLabName());
                }

                obj.setLabel(label.toString());
            }

            try {
                if (StringUtils.isBlank(message.getMesSubject())) {
                    obj.setSubject("(no subject)");
                } else {
                    obj.setSubject(message.getMesSubject());
                }
            } catch (Exception ex) {
                obj.setSubject("(no subject)");
            }

            if (message.isMesFlagged()) {
                obj.setFlagged(true);
            } else {
                obj.setFlagged(false);
            }

            if (message.isMesRecent()) {
                obj.setRecent(true);
            } else {
                obj.setRecent(false);
            }

            String priority = "normal";

            if (MessageUtilities.isHighPriority(message.getMesHeaders())) {
                priority = "high";
            } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) {
                priority = "low";
            }

            obj.setPriority(priority);

            String body = message.getMesBody();

            if (!StringUtils.isBlank(body)) {
                obj.setBody(bodyCleaner(body, displayImages));
            } else {
                obj.setBody("");
            }

            references.addElement(obj);
        }

        scroll.close();
    } catch (Exception ex) {
        return null;
    } finally {
        IOUtils.closeQuietly(baos);
    }

    if (references.size() <= 0) {
        return null;
    }

    return references;
}

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  va2s  . c o m
        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.evolveum.midpoint.repo.sql.helpers.ObjectRetriever.java

License:Apache License

public <T extends ObjectType> void searchObjectsIterativeAttempt(Class<T> type, ObjectQuery query,
        ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options,
        OperationResult result) throws SchemaException {
    Session session = null;//from w w w .  j a  va  2 s  .co  m
    try {
        session = baseHelper.beginReadOnlyTransaction();
        RQuery rQuery;
        if (isUseNewQueryInterpreter(query)) {
            QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
            rQuery = engine.interpret(query, type, options, false, session);
        } else {
            QueryEngine engine = new QueryEngine(getConfiguration(), prismContext);
            rQuery = engine.interpret(query, type, options, false, session);
        }

        ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY);
        try {
            Iterator<GetObjectResult> iterator = new ScrollableResultsIterator(results);
            while (iterator.hasNext()) {
                GetObjectResult object = iterator.next();

                PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, session, result);
                if (!handler.handle(prismObject, result)) {
                    break;
                }
            }
        } finally {
            if (results != null) {
                results.close();
            }
        }

        session.getTransaction().commit();
    } catch (SchemaException | QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
}

From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java

License:Apache License

private <T extends ObjectType> void searchObjectsIterativeAttempt(Class<T> type, ObjectQuery query,
        ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options,
        OperationResult result) throws SchemaException {

    Session session = null;//from  w  ww .  j a  va 2  s.  c o  m
    try {
        session = beginReadOnlyTransaction();
        QueryEngine engine = new QueryEngine(getConfiguration(), getPrismContext());
        RQuery rQuery = engine.interpret(query, type, options, false, session);

        ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY);
        try {
            Iterator<GetObjectResult> iterator = new ScrollableResultsIterator(results);
            while (iterator.hasNext()) {
                GetObjectResult object = iterator.next();

                PrismObject<T> prismObject = updateLoadedObject(object, type, options, session);
                if (!handler.handle(prismObject, result)) {
                    break;
                }
            }
        } finally {
            if (results != null) {
                results.close();
            }
        }

        session.getTransaction().commit();
    } catch (SchemaException | QueryException | RuntimeException ex) {
        handleGeneralException(ex, session, result);
    } finally {
        cleanupSessionAndResult(session, result);
    }
}

From source file:com.hmsinc.epicenter.tools.reclassifier.Reclassifier.java

License:Open Source License

@Transactional
public void run() {

    setup();/*from  ww  w  . ja v  a 2 s  .  c o m*/

    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()));
    }/*  www.  j  a  va2 s .  co  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()));
    }/*from  ww w  . j  a v  a 2 s. co  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 getAccountDataExceptionReport(Account pAccount, String remoteUser, String lsName, String pAlertCode,
        PrintWriter pPrintWriter) throws HibernateException, Exception {
    String sql_query_data_exception = null;
    String[] header_of_data_exception = null;
    for (DataExceptionTypeEnum l : DataExceptionTypeEnum.values()) {
        if (pAlertCode.equals(l.name().toString())) {
            if (l.getLevel().equals("SWLPAR")) {
                sql_query_data_exception = SQL_QUERY_ACCOUNT_DATAEXCEPTION_SWLPAR_Report;
                header_of_data_exception = ACCOUNT_DATA_EXCEPTIONS_REPORT_SWLPAR_COLUMN_HEADERS;
            }/*from  w w  w.j  a v a2s.co  m*/
            if (l.getLevel().equals("HWLPAR")) {
                sql_query_data_exception = SQL_QUERY_ACCOUNT_DATAEXCEPTION_HWLPAR_Report;
                header_of_data_exception = ACCOUNT_DATA_EXCEPTIONS_REPORT_HWLPAR_COLUMN_HEADERS;
            }
            if (l.getLevel().equals("INSTSW")) {
                sql_query_data_exception = SQL_QUERY_ACCOUNT_DATAEXCEPTION_SWDSCEXP_Report;
                header_of_data_exception = ACCOUNT_DATA_EXCEPTIONS_REPORT_SWDSCEXP_COLUMN_HEADERS;
            }
        }
    }

    ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate())
            .createSQLQuery(sql_query_data_exception).setLong("open", 1).setLong("customerId", pAccount.getId())
            .setString("alertCode", pAlertCode).scroll(ScrollMode.FORWARD_ONLY);

    printHeader(ACCOUNT_DATA_EXCEPTIONS_REPORT_NAME, pAccount.getAccount(), header_of_data_exception,
            pPrintWriter);
    while (lsrReport.next()) {
        pPrintWriter.println(outputData(lsrReport.get()));
    }
    lsrReport.close();
}