Example usage for org.hibernate ScrollableResults get

List of usage examples for org.hibernate ScrollableResults get

Introduction

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

Prototype

Object[] get();

Source Link

Document

Get the current row of results.

Usage

From source file:ch.qos.logback.audit.persistent.AuditEventDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
static public List<Object[]> findMaxSubject() throws HibernateException {
    Session s = null;/*from  w  w w.j  ava 2 s  . com*/
    try {
        s = openSession();

        //      Query q = s.createQuery("select grp.sc, grp.sub from ( " +
        //
        //      " select count(subject) as sub, subject from "
        //          + AuditEvent.class.getName() + " GROUP BY subject) AS grp");

        Query q = s.createQuery("select count(ae.subject), ae.subject FROM " + AE_CLASS + " AS ae "
                + "GROUP BY ae.subject ORDER BY count(ae.subject) desc");
        ScrollableResults sr = q.scroll();
        List<Object[]> l = new ArrayList<Object[]>();
        int i = 0;
        while (sr.next()) {
            System.out.println(i++);
            Object[] oa = sr.get();
            l.add(oa);
        }

        return l;
    } finally {
        close(s);
    }
}

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/*w  w  w  .  java 2  s.  co  m*/
        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.aw.core.dao.DAOHbm.java

License:Open Source License

public List listAbortable(SQLQuery sqlQuery) {
    ScrollableResults ss = sqlQuery.scroll(ScrollMode.FORWARD_ONLY);
    AWQueryAbortable queryAbortable = AWQueryAbortable.instance();
    List results = new ArrayList(AWQueryAbortable.DEF_LIST_SIZE);
    queryAbortable.resetRowCount();//from  www.j  a  va2s.c o  m
    while (ss.next()) {
        if (queryAbortable.isAborted())
            break;
        results.add(ss.get());
        queryAbortable.incRowCount();
    }
    return results;
}

From source file:com.farmafene.commons.hibernate.HBPaginaFactory.java

License:Open Source License

/**
 * Metodo factora/* ww  w .j  a v a  2  s.  co 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.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   w  w w  . jav  a2s  .com
    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 2 s.  com
            "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);
}

From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java

License:Open Source License

@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED)
public void getAlertHardwareLparReport(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb,
        OutputStream pOutputStream) throws HibernateException, Exception {

    AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode")
            .setParameter("code", "HW_LPAR").getSingleResult();

    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, HL.Name AS HL_Name, H.Serial, MT.Name AS MT_Name, VA.Creation_Time, VA.Alert_Age, MT.Type, HL.OS_Type, VA.Remote_User, VA.Comments, VA.Record_Time, AC.name as ac_name, CC.target_date, CC.owner as cc_owner,CC.record_time as cc_record_time,CC.remote_user as cc_remote_user, CC.id as cc_id FROM EAADMIN.V_Alerts VA, EAADMIN.Hardware_Lpar HL, EAADMIN.Hardware H, EAADMIN.Machine_Type MT, EAADMIN.cause_code CC, EAADMIN.alert_cause AC WHERE VA.Customer_Id = :customerId AND VA.Type = 'HARDWARE_LPAR' AND VA.Open = 1 AND HL.Id = VA.FK_Id AND H.Id = HL.Hardware_Id AND MT.Id = H.Machine_Type_Id and VA.id=CC.alert_id and CC.alert_type_id = :alertTypeId and CC.alert_cause_id=AC.id ORDER BY HL.Name ASC")
            .setLong("customerId", pAccount.getId()).setInteger("alertTypeId", alertType.getId().intValue())
            .scroll(ScrollMode.FORWARD_ONLY);
    HSSFSheet sheet = phwb.createSheet("Alert HwLPAR Report");
    printHeader(ALERT_HARDWARE_LPAR_REPORT_NAME, pAccount.getAccount(),
            ALERT_HARDWARE_LPAR_REPORT_COLUMN_HEADERS, sheet);
    int i = 3;/*from  www  .j ava  2  s.  c  o  m*/
    while (lsrReport.next()) {
        int k = 1;
        if (i > 65535) {
            k++;
            sheet = phwb.createSheet("Alert HWLpar 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);
}

From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java

License:Open Source License

@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED)
public void getAlertHardwareReport(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb,
        OutputStream pOutputStream) throws HibernateException, Exception {

    AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode")
            .setParameter("code", "HARDWARE").getSingleResult();

    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, H.Serial, MT.Name, VA.Creation_Time, VA.Alert_Age, MT.Type, VA.Remote_User, VA.Comments, VA.Record_Time,  AC.name as ac_name, CC.target_date,CC.owner as cc_owner,CC.record_time as cc_record_time,CC.remote_user as cc_remote_user, CC.id as cc_id FROM EAADMIN.V_Alerts VA, EAADMIN.Hardware H, EAADMIN.Machine_Type MT, EAADMIN.cause_code CC, EAADMIN.alert_cause AC WHERE VA.Customer_Id = :customerId AND VA.Type = 'HARDWARE' AND VA.Open = 1 AND H.Id = VA.FK_Id AND MT.Id = H.Machine_Type_Id and VA.id=CC.alert_id and CC.alert_type_id = :alertTypeId and CC.alert_cause_id=AC.id ORDER BY H.Serial ASC")
            .setLong("customerId", pAccount.getId()).setInteger("alertTypeId", alertType.getId().intValue())
            .scroll(ScrollMode.FORWARD_ONLY);
    HSSFSheet sheet = phwb.createSheet("Alert Hardware Report");
    printHeader(ALERT_HARDWARE_REPORT_NAME, pAccount.getAccount(), ALERT_HARDWARE_REPORT_COLUMN_HEADERS, sheet);
    int i = 3;/* w w  w  .  j  a v a2  s.  c om*/
    while (lsrReport.next()) {
        int k = 1;
        if (i > 65535) {
            k++;
            sheet = phwb.createSheet("Alert HW 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);
}

From source file:com.ibm.asset.trails.service.impl.ReportServiceImpl.java

License:Open Source License

@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED)
public void getAlertSoftwareLparReport(Account pAccount, String remoteUser, String lsName, HSSFWorkbook phwb,
        OutputStream pOutputStream) throws HibernateException, Exception {

    AlertType alertType = (AlertType) getEntityManager().createNamedQuery("getAlertTypeByCode")
            .setParameter("code", "SW_LPAR").getSingleResult();

    ScrollableResults lsrReport = ((Session) getEntityManager().getDelegate()).createSQLQuery(SQL_QUERY_SW_LPAR)
            .setLong("customerId", pAccount.getId()).setString("type", "SOFTWARE_LPAR")
            .setInteger("alertTypeId", alertType.getId().intValue()).scroll(ScrollMode.FORWARD_ONLY);

    HSSFSheet sheet = phwb.createSheet("Alert SwLpar Report");
    printHeader(ALERT_SOFTWARE_LPAR_REPORT_NAME, pAccount.getAccount(), ALERT_SW_LPAR_REPORT_COLUMN_HEADERS,
            sheet);/* w  ww .  j  ava  2s.  c  o  m*/
    int i = 3;
    while (lsrReport.next()) {
        int k = 1;
        if (i > 65535) {
            k++;
            sheet = phwb.createSheet("Alert SWLpar 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);
}

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  a2 s  . 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();
}