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.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
// generic Hibernate query list cast
public List<VirtualappHB> findByUsingVirtualImage(final String virtualImageId) throws PersistenceException {
    List<VirtualappHB> apps;

    try {//from   ww  w. j  a v a  2 s.  c  o  m
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(FIND_BY_USED_VIRTUAL_IMAGE);
        query.setString("usedVIId", virtualImageId);
        query.setParameter("type", NodeTypeEnum.VIRTUAL_IMAGE);

        apps = query.list();
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }

    return apps;
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<VirtualappHB> findByUsingVirtualImageOnRepository(final Integer idRepository) {
    List<VirtualappHB> apps;
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query query = session.getNamedQuery(FIND_BY_USED_VIRTUAL_IMAGE_ON_REPOSITORY);
    query.setInteger("idRepo", idRepository);
    query.setParameter("type", NodeTypeEnum.VIRTUAL_IMAGE);

    apps = query.list();/*ww w  .java  2s  . c o m*/

    return apps;
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualApplianceDAOHibernate.java

License:Open Source License

@Override
public VirtualappHB getVirtualAppByVirtualMachine(final Integer vmId) throws PersistenceException {
    try {//from   w  ww.  j a v a2  s .  c  om
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(VIRTUAL_APPLIANCE_BY_VIRTUAL_MACHINE_ID);
        query.setInteger("vmId", vmId);
        return (VirtualappHB) query.uniqueResult();
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java

License:Open Source License

@Override
public VirtualDataCenterHB getVirtualDatacenterFromNetworkId(Integer idNetwork) throws PersistenceException {
    VirtualDataCenterHB vdcHB;/*from  w w  w  . j ava 2s.c o  m*/

    try {
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(VIRTUAL_DATACENTER_GET_BY_NETWORK);
        query.setInteger("network_id", idNetwork);
        vdcHB = (VirtualDataCenterHB) query.uniqueResult();
    } catch (HibernateException he) {
        throw new PersistenceException(he.getMessage(), he);
    }

    return vdcHB;
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java

License:Open Source License

@Override
public VirtualDataCenterHB getVirtualDatacenterFromVirtualAppliance(Integer vappId)
        throws PersistenceException {
    try {//  w  ww. ja v  a  2 s .c  om
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(VIRTUAL_DATACENTER_GET_BY_VAPP);
        query.setInteger("vappId", vappId);
        return (VirtualDataCenterHB) query.uniqueResult();
    } catch (HibernateException he) {
        throw new PersistenceException(he.getMessage(), he);
    }

}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java

License:Open Source License

@Override
public Collection<VirtualDataCenterHB> getVirtualDatacentersFromEnterprise(Integer enterpriseId) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    return session.getNamedQuery(VIRTUAL_DATACENTERS_BY_ENTERPRISE).setParameter("enterpriseId", enterpriseId)
            .list();//from w ww .  j a va 2 s  .  c  o  m
}

From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java

License:Open Source License

@Override
public Collection<VirtualDataCenterHB> getVirtualDatacentersFromEnterpriseAndDatacenter(Integer enterpriseId,
        Integer datacenterId) {//from  w w w. jav  a  2  s.co  m
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    return session.getNamedQuery(VIRTUAL_DATACENTERS_BY_ENTERPRISE_AND_DATACENTER)
            .setParameter("enterpriseId", enterpriseId).setParameter("datacenterId", datacenterId).list();
}

From source file:com.abiquo.abiserver.persistence.dao.virtualhardware.hibernate.ResourceManagementDAOHibernate.java

License:Open Source License

@Override
public ResourceManagementHB getResourceManagementPrivateEthernetByVS(VirtualmachineHB vmHB)
        throws PersistenceException {
    try {//  w w  w  .  j  av a  2 s .  c  o  m
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(GET_RESOURCE_MANAGEMENT_ETHERNET_BY_MAC);
        query.setString("idVM", vmHB.getIdVm().toString());

        ResourceManagementHB result = (ResourceManagementHB) query.uniqueResult();

        return result;
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

From source file:com.adsapient.shared.dao.HibernateEntityDao.java

License:Open Source License

public List getBannerList(final Integer status) {
    return (List) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            session.setCacheMode(CacheMode.IGNORE);
            Query query = session.getNamedQuery("loadBanners").setInteger("STATUS", status);
            return query.list();
        }/*from   ww w  . ja v  a2s  . c om*/
    });
}

From source file:com.adsapient.shared.dao.HibernateEntityDao.java

License:Open Source License

public Integer executeQueryUpdate(final String queryName) {
    return (Integer) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            session.setCacheMode(CacheMode.IGNORE);
            Transaction tx = session.beginTransaction();
            Query query = session.getNamedQuery(queryName);
            Integer res = query.executeUpdate();
            tx.commit();/*from   ww  w  .  ja  v a2  s  . c o m*/
            return res;
        }
    });
}