Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Query uniqueResult.

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

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

License:Open Source License

@Override
public VirtualappHB findVirtualAppFromVM(Integer vmID) throws PersistenceException {
    VirtualappHB virtualappHB;//from  ww  w  .ja  va 2s.  c om

    try {
        Query query = getSession().getNamedQuery(VIRTUAL_MACHINE_SEARCH_VAPP);
        query.setInteger("idVm", vmID);
        query.setParameter("type", NodeTypeEnum.VIRTUAL_IMAGE);

        virtualappHB = (VirtualappHB) query.uniqueResult();
    } catch (HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }

    return virtualappHB;

}

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 {/*from   ww  w .j  a  va 2 s .co 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.abiquo.abiserver.persistence.dao.virtualimage.hibernate.RepositoryDAOHibernate.java

License:Open Source License

@Override
public RepositoryHB findByDatacenterDAO(Integer datacenterId) throws PersistenceException {
    RepositoryHB repository;/*w w w .  j av a 2 s . c o  m*/

    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query query = session.createQuery(QUERY_GET_BY_DC);
    query.setInteger("idDatacenter", datacenterId);

    repository = (RepositoryHB) query.uniqueResult();

    return repository;
}

From source file:com.abiquo.abiserver.persistence.hibernate.HibernateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w  w  w  .  j  a va2  s .co  m*/
public T findUniqueByNamedQuery(final String name) {
    Query query = getSession().getNamedQuery(name);
    return (T) query.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.hibernate.HibernateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w w w  . ja va2 s  . com
public T findUniqueByNamedQuery(final String name, final Map<String, ?> params) {
    Query query = getSession().getNamedQuery(name);

    if (params != null) {
        for (Map.Entry<String, ?> param : params.entrySet()) {
            if (param.getValue() instanceof Collection) {
                query.setParameterList(param.getKey(), (Collection) param.getValue());
            } else {
                query.setParameter(param.getKey(), param.getValue());
            }
        }
    }

    return (T) query.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.SessionUtils.java

License:Open Source License

public static Object uniqueResult(Session session, String queryString, Object... params) {
    assert session != null;
    assert !StringUtils.isEmpty(queryString);
    assert params != null;

    Query query = createQueryWithParameters(session, queryString, params);
    return query.uniqueResult();
}

From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionListDAO.java

License:Open Source License

public TemplateDefinitionList findByNameAndEnterprise(final String nameEnt, final Enterprise ent) {
    Query query = getSession().createQuery(FIND_BY_NAME_AND_ENTERPRISE);
    query.setParameter("enterpriseId", ent.getId());
    query.setParameter("nameEnt", nameEnt);

    return (TemplateDefinitionList) query.uniqueResult();
}

From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java

License:Open Source License

/**
 * List of {@link HypervisorType} from all hypervisors in a datacenter.
 * //from ww w .ja v a  2  s . c om
 * @param datacenterId {@link Hypervisor} machines datacenter.
 * @return list of {@link HypervisorType} from all hypervisors in a datacenter.
 */
public boolean isVirtualImageConverted(final Integer vImageId, final DiskFormatType format) {
    Query query = getSession().createQuery(QUERY_IMAGE_CONVERTED);
    query.setParameter("idVirtualImage", vImageId);

    return (Long) query.uniqueResult() > 0;
}

From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java

License:Open Source License

public String getDatacenterUUIDByVirtualImageConversionID(final Integer idVirtualImageConversion) {
    Query query = getSession().createSQLQuery(DATACENTERUUID_BY_VIRTUALIMAGECONVERSION);
    query.setParameter("idVirtualImageConversion", idVirtualImageConversion);

    return (String) query.uniqueResult();
}

From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java

License:Open Source License

public VirtualMachine findByIdByVirtualApp(final VirtualAppliance vapp, final Integer vmId) {
    Query finalQuery = getSession().createQuery(BY_VAPP_AND_ID);
    finalQuery.setParameter("vapp_id", vapp.getId());
    finalQuery.setParameter("vm_id", vmId);

    return (VirtualMachine) finalQuery.uniqueResult();
}