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.user.hibernate.EnterpriseDAOHibernate.java

License:Open Source License

@Override
public DatacenterLimitHB getDatacenterLimit(final int idEnterprise, final int idDatacenter) {
    final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    final Query query = session.getNamedQuery(GET_DATACENTER_LIMITS);
    query.setInteger("idEnterprise", idEnterprise);
    query.setInteger("idDatacenter", idDatacenter);

    return (DatacenterLimitHB) query.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.EnterpriseDAOHibernate.java

License:Open Source License

@Override
public EnterpriseHB getEnterpriseFromReservedVlanID(Integer vlanId) throws PersistenceException {
    try {//w  w w .j a  v a2  s  . c o  m
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(GET_ENTERPRISE_FROM_VLAN_ID);
        query.setInteger("vlan_id", vlanId);

        return (query.uniqueResult() == null) ? null : (EnterpriseHB) query.uniqueResult();

    } catch (HibernateException he) {
        throw new PersistenceException(he.getMessage());
    }
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.RoleDAOHibernate.java

License:Open Source License

@Override
public RoleHB getRoleByName(final String name) {
    RoleHB requestedRol = new RoleHB();

    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query userQuery = session.getNamedQuery(GET_ROLE_BY_NAME);
    userQuery.setString("name", name);
    requestedRol = (RoleHB) userQuery.uniqueResult();

    return requestedRol;
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java

License:Open Source License

/**
 * @see com.abiquo.abiserver.persistence.dao.user.UserDAO#getUserByLoginAuth(java.lang.String,
 *      com.abiquo.server.core.enterprise.User.AuthType)
 *///  w  ww  .  j  a va  2 s. c o  m
@Override
public UserHB getUserByLoginAuth(final String username, String authType) {
    UserHB requestedUser = new UserHB();

    if (authType == null) {
        authType = AuthType.ABIQUO.name();
    }
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query userQuery = session.getNamedQuery(GET_USER_BY_USER_NAME);
    userQuery.setString("username", username);
    userQuery.setString("authType", authType);
    requestedUser = (UserHB) userQuery.uniqueResult();
    return requestedUser;
}

From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java

License:Open Source License

@Override
public Object[] getCurrentUserCredentials(String user, String auth) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query query = session
            .createSQLQuery("select user, password from user where user = :name and authType = :auth");
    query.setString("name", user);
    query.setString("auth", auth);

    return (Object[]) query.uniqueResult();
}

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

License:Open Source License

@Override
public String findDatacenterUUIDByVASConversion(final int idVASC) {
    Query query = getSession().createSQLQuery(
            "select distinct(dc.uuid) from vappstateful_conversions vasc left outer join virtualapp va on vasc.idVirtualApp = va.idVirtualApp left outer join virtualdatacenter vdc on va.idVirtualDataCenter = vdc.idVirtualdataCenter left outer join datacenter dc on vdc.idDatacenter = dc.idDataCenter where vasc.id = :id");
    query.setParameter("id", idVASC);

    return (String) query.uniqueResult();
}

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

License:Open Source License

@Override
public Integer getVirtualDatacenterId(final Integer idVirtualApp) {
    Query query = getSession().getNamedQuery(VIRTUAL_DATACENTER_ID_BY_VIRTUAL_APP_ID);
    query.setInteger("idVirtualApp", idVirtualApp);

    return (Integer) query.uniqueResult();
}

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  w  w  .ja v a 2 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;//w w w .ja va  2 s. c  om

    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 w w.j  ava2s  . 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);
    }

}