Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

From source file:com.ibm.asset.trails.dao.jpa.LicenseDAOJpa.java

License:Open Source License

public void paginatedList(DisplayTagList data, Long accountId, int startIndex, int objectsPerPage,
        String psSort, String psDir) {
    psSort = decodeSort(psSort) + " " + psDir;

    Query q = entityManager.createNamedQuery("licenseTotalByAccount").setParameter("account", accountId);
    data.setFullListSize(((Long) q.getResultList().get(0)).intValue());

    Session session = (Session) entityManager.getDelegate();

    data.setList(session// w  ww.j a v  a2 s. c o m
            .createQuery(session.getNamedQuery("licenseBaseline").getQueryString() + " order by " + psSort)
            .setParameter("account", accountId).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
            .setFirstResult(startIndex).setMaxResults(objectsPerPage).list());
}

From source file:com.ibm.asset.trails.dao.jpa.LicenseDAOJpa.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<License> paginatedList(Long accountId, int startIndex, int objectsPerPage, String psSort,
        String psDir) {// ww  w. j a  v  a  2s .c o m
    psSort = decodeSort(psSort) + " " + psDir;
    List<License> licList = new ArrayList<License>();
    Session session = (Session) entityManager.getDelegate();

    licList = session
            .createQuery(session.getNamedQuery("licenseBaseline").getQueryString() + " order by " + psSort)
            .setParameter("account", accountId).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
            .setFirstResult(startIndex).setMaxResults(objectsPerPage).list();
    return licList;
}

From source file:com.ibm.asset.trails.dao.jpa.LicenseDAOJpa.java

License:Open Source License

@SuppressWarnings("unchecked")
public int getLicBaselineSize(Long accountId) {
    List<License> licList = new ArrayList<License>();
    Session session = (Session) entityManager.getDelegate();

    licList = session.createQuery(session.getNamedQuery("licenseBaseline").getQueryString())
            .setParameter("account", accountId).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
    if (licList != null) {
        return licList.size();
    }/*from   w w w.j av  a  2s.c om*/
    return 0;
}

From source file:com.ibm.ea.bravo.report.MainframeScan.java

public void execute(String[] args, HttpServletRequest request) {
    ScrollableResults list = null;//ww w.java2  s.  com

    try {

        // get the report

        Session session = DelegateReport.getSession();

        list = session.getNamedQuery("mainFrameScanReport").scroll();

        // get the output writer
        PrintWriter os = new PrintWriter(outputStream, true);

        os.println(Constants.CONFIDENTIAL);

        // output the header
        os.println(tsv(HEADER));

        // output the report
        while (list.next()) {
            os.println(tsv(list.get()));
        }
        os.close();
        DelegateReport.closeSession(session);

    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param customer//ww w.j a v a  2  s . c  o  m
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static List<InstalledSoftware> getMsHardwareBaseline(Customer customer)
        throws HibernateException, NamingException {

    List<InstalledSoftware> hardwareBaselineList = null;

    Session session = getHibernateSession();

    hardwareBaselineList = session.getNamedQuery("getMsInstalledSoftwareBaselineOS")
            .setEntity("customer", customer).list();
    session.close();

    return hardwareBaselineList;
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param msHardwareBaselineId//from w  w  w  .j  a va 2  s.co  m
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static SoftwareLpar getSoftwareLpar(int id) throws HibernateException, NamingException {

    SoftwareLpar softwareLpar = null;

    Session session = getHibernateSession();

    softwareLpar = (SoftwareLpar) session.getNamedQuery("getSoftwareLpar").setInteger("id", id).uniqueResult();

    session.close();

    return softwareLpar;
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param podName//from w ww  .ja v a 2s .  c o  m
 * @param remoteUser
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static List getBaselineReport(Customer customer, String remoteUser)
        throws HibernateException, NamingException {

    List baseline = null;

    Session session = getHibernateSession();

    baseline = session.getNamedQuery("getMsHardwareBaselineByCustomer").setEntity("customer", customer).list();

    session.close();

    Vector baselineVector = new Vector();

    if (baseline != null) {
        Iterator j = baseline.iterator();

        while (j.hasNext()) {
            MsHardwareBaseline msHardwareBaseline = (MsHardwareBaseline) j.next();

            Vector tempList = new Vector();
            tempList.add(new String("" + customer.getAccountNumber()));
            tempList.add(msHardwareBaseline.getNodeName());
            tempList.add(msHardwareBaseline.getSerialNumber());
            tempList.add(msHardwareBaseline.getMachineType());
            tempList.add(msHardwareBaseline.getMachineModel());
            if (msHardwareBaseline.getProcessorCount() == null) {
                tempList.add("");
            } else {
                tempList.add(new String("" + msHardwareBaseline.getProcessorCount()));
            }
            tempList.add(msHardwareBaseline.getNodeOwner());
            tempList.add(msHardwareBaseline.getStatus());
            tempList.add(msHardwareBaseline.getCountry());

            baselineVector.add(tempList);
        }
    }
    return baselineVector;
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param customer//from  w  w w. ja  v a  2 s . c o  m
 * @param nodeName
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static SoftwareLpar getSoftwareLparByNodeName(Customer customer, String name)
        throws HibernateException, NamingException {

    SoftwareLpar softwareLpar = null;

    Session session = getHibernateSession();

    softwareLpar = (SoftwareLpar) session.getNamedQuery("getSoftwareLparByNodeName")
            .setEntity("customer", customer).setString("name", name).uniqueResult();

    session.close();

    return softwareLpar;
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param podName/*from w w  w  .  jav a  2s  .  c o  m*/
 * @param remoteUser
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static List getPodBaselineReport(String podName, String remoteUser)
        throws HibernateException, NamingException {

    List baseline = null;

    Session session = getHibernateSession();

    baseline = session.getNamedQuery("getMsHardwareBaselineByPod").setString("podName", podName).list();

    session.close();

    Vector baselineVector = new Vector();

    if (baseline != null) {
        Iterator j = baseline.iterator();

        while (j.hasNext()) {
            MsHardwareBaseline msHardwareBaseline = (MsHardwareBaseline) j.next();

            Vector tempList = new Vector();

            tempList.add(msHardwareBaseline.getCustomer().getPod().getPodName());
            tempList.add(msHardwareBaseline.getCustomer().getIndustry().getIndustryName());
            tempList.add(msHardwareBaseline.getCustomer().getSector().getSectorName());
            tempList.add(msHardwareBaseline.getCustomer().getCustomerType().getCustomerTypeName());

            if (msHardwareBaseline.getCustomer().getMisldAccountSettings() != null) {
                if (msHardwareBaseline.getCustomer().getMisldAccountSettings()
                        .getLicenseAgreementType() == null) {
                    tempList.add("");
                } else {
                    tempList.add(msHardwareBaseline.getCustomer().getMisldAccountSettings()
                            .getLicenseAgreementType().getLicenseAgreementTypeName());
                }
            } else {
                tempList.add("");
            }

            tempList.add(new String("" + msHardwareBaseline.getCustomer().getAccountNumber()));
            tempList.add(msHardwareBaseline.getCustomer().getCustomerName());
            tempList.add(msHardwareBaseline.getNodeName());
            tempList.add(msHardwareBaseline.getSerialNumber());
            tempList.add(msHardwareBaseline.getMachineType());
            tempList.add(msHardwareBaseline.getMachineModel());
            if (msHardwareBaseline.getProcessorCount() == null) {
                tempList.add("");
            } else {
                tempList.add(new String("" + msHardwareBaseline.getProcessorCount()));
            }
            tempList.add(msHardwareBaseline.getNodeOwner());
            tempList.add(msHardwareBaseline.getStatus());
            tempList.add(msHardwareBaseline.getCountry());

            baselineVector.add(tempList);
        }
    }
    return baselineVector;
}

From source file:com.ibm.tap.misld.delegate.baseline.MsHardwareBaselineReadDelegate.java

/**
 * @param remoteUser/*from  www. j a  va 2 s  .co m*/
 * @return
 * @throws NamingException
 * @throws HibernateException
 */
public static List getDuplicateHostnameReport(String remoteUser) throws HibernateException, NamingException {
    List baseline = null;

    Session session = getHibernateSession();

    baseline = session.getNamedQuery("getDuplicateHostnames").list();

    session.close();

    Vector baselineVector = new Vector();

    if (baseline != null) {
        Iterator j = baseline.iterator();

        while (j.hasNext()) {

            Vector tempList = new Vector();

            Object[] pair = (Object[]) j.next();
            tempList.add(pair[0]);
            tempList.add(pair[1]);
            tempList.add(pair[2]);
            tempList.add(pair[3]);
            tempList.add("" + pair[4]);
            tempList.add(pair[5]);
            tempList.add(pair[6]);
            tempList.add(pair[7]);
            tempList.add(pair[8]);
            tempList.add(pair[9]);
            tempList.add(pair[10]);
            tempList.add(pair[11]);

            baselineVector.add(tempList);
        }
    }
    return baselineVector;
}