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.infrastructure.hibernate.PhysicalMachineDAOHibernate.java

License:Open Source License

@Override
public PhysicalmachineHB findByIp(final String hypervisorIp, final Integer idDataCenter) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    Query pmQuery = session.getNamedQuery(PHYSICALMACHINE_GET_FROM_IP);
    pmQuery.setString("ipPhysicalMachine", hypervisorIp);
    pmQuery.setInteger("idDataCenter", idDataCenter);

    PhysicalmachineHB pm = (PhysicalmachineHB) pmQuery.uniqueResult();

    return pm;//from w ww .  j a  v a  2  s.com
}

From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.RemoteServiceDAOHibernate.java

License:Open Source License

public String getRemoteServiceUriByType(final Integer idDatacenter, final RemoteServiceType remoteServiceType) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    Query pmQuery = session.getNamedQuery(REMOTE_SERVICE_GET_REMOTE_SERVICES_LOCATION_BY_TYPE);
    pmQuery.setInteger("idDataCenter", idDatacenter);
    pmQuery.setParameter("remoteServiceType", remoteServiceType);

    return (String) pmQuery.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.NetworkAssigmntDAOHibernate.java

License:Open Source License

public NetworkAssignmentHB findByVlan(final Integer vlanNetworkId) {
    Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    Query query = session.getNamedQuery(GET_BY_VLAN);
    query.setInteger("vlanNetworkId", vlanNetworkId);

    return (NetworkAssignmentHB) query.uniqueResult();
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.NetworkDAOHibernate.java

License:Open Source License

@Override
public VlanNetworkHB findVlanWithName(Integer networkId, String vlanNetworkName) throws PersistenceException {
    VlanNetworkHB namedVLAN;/*from  w ww.  java 2 s.  c  o m*/

    try {
        Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        Query query = session.getNamedQuery(GET_VLAN_WITH_NAME_BY_NETWORK_ID);
        query.setInteger("network_id", networkId);
        query.setString("vlan_network_name", vlanNetworkName);

        namedVLAN = (VlanNetworkHB) query.uniqueResult();

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

    return namedVLAN;
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public Integer getFreeVLANTag(final Integer idRack) {
    Integer freeVlanTag = 0;//from  w  w w .j ava2  s.co m

    final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
    final Query query = session.getNamedQuery(GET_MAX_FREE_TAG);
    query.setInteger("idRack", idRack);

    final Integer latestVlanTagUsed = (Integer) query.uniqueResult();

    if (latestVlanTagUsed != null) {
        freeVlanTag = latestVlanTagUsed + 1;
        if (freeVlanTag > AbiCloudConstants.VLAN_MAX) {
            return null; // "The VLAN tag limitation has been reached ";
        }

    } else {
        freeVlanTag = 3;
    }

    if (freeVlanTag == 2) {
        if (freeVlanTag == AbiCloudConstants.VLAN_MAX) {
            return null; // "The VLAN tag limitation has been reached ";
        }

        freeVlanTag++;
    }

    return freeVlanTag;
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public VlanNetworkHB getDefaultVLAN(final Integer idNetwork) throws PersistenceException {
    VlanNetworkHB defaultVLAN;//ww  w  . j a v a2s.  co m

    try {
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(GET_DEFAULT_VLAN_BY_NETWORK_ID);
        query.setInteger("network_id", idNetwork);

        defaultVLAN = (VlanNetworkHB) query.uniqueResult();

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

    return defaultVLAN;
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public Long howManyUsedIPs(final Integer vlanNetworkId) throws PersistenceException {
    try {/*from  w  ww .j  a va2s  . c om*/
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(GET_NUMBER_IPS_USED_BY_VLAN);
        query.setInteger("vlan_network_id", vlanNetworkId);
        return (Long) query.uniqueResult();
    } catch (final HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public Long howManyVDCs(final Integer vlanNetworkId) throws PersistenceException {
    try {/*w  w w .  ja va2  s. c  om*/
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(GET_NUMBER_VDCS_USED_BY_VLAN);
        query.setInteger("vlan_network_id", vlanNetworkId);
        return (Long) query.uniqueResult();
    } catch (final HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

From source file:com.abiquo.abiserver.persistence.dao.networking.hibernate.VlanNetworkDAOHibernate.java

License:Open Source License

@Override
public Boolean isPrivateVLAN(final Integer vlanNetworkId) throws PersistenceException {
    try {//w w  w  .j  a va2  s  .  c  o m
        final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();
        final Query query = session.getNamedQuery(IS_PUBLIC_VLAN);
        query.setInteger("vlan_network_id", vlanNetworkId);
        return (Long) query.uniqueResult() == 0L;
    } catch (final HibernateException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
}

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

License:Open Source License

@Override
public EnterpriseHB findByVirtualAppliance(final Integer idVirtualApp) {
    final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession();

    final Query query = session.getNamedQuery(GET_BY_VIRTAL_APP);
    query.setInteger("idVirtualApp", idVirtualApp);

    return (EnterpriseHB) query.uniqueResult();
}