Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

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

Prototype

public Object uniqueResult() throws HibernateException;

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.server.core.infrastructure.MachineDAO.java

License:Open Source License

public Machine findByIp(final Datacenter datacenter, final String ip) {
    Criteria crit = createCriteria();
    crit.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    crit.add(sameDatacenter(datacenter));
    crit.add(Restrictions.eq("hypervisor.ip", ip));

    return (Machine) crit.uniqueResult();
}

From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java

License:Open Source License

/**
 * Return a single {@link IpPoolManagement}
 * //from   w  ww .  j av  a  2s. co m
 * @param vlan {@link VLANNetwork} oject which the Ip should belong to.
 * @param ipId identifier of the Ip.
 * @return the found object.
 */
public IpPoolManagement findIp(final VLANNetwork vlan, final Integer ipId) {
    Criteria criteria = getSession().createCriteria(IpPoolManagement.class);
    Criterion vlanEqual = Restrictions.eq(IpPoolManagement.VLAN_NETWORK_PROPERTY, vlan);
    Criterion ipEqual = Restrictions.eq(PersistentEntity.ID_PROPERTY, ipId);

    criteria.add(vlanEqual).add(ipEqual);

    return (IpPoolManagement) criteria.uniqueResult();
}

From source file:com.abiquo.server.core.infrastructure.RepositoryDAO.java

License:Open Source License

public com.abiquo.server.core.infrastructure.Repository findByDatacenter(Datacenter datacenter) {
    Criteria criteria = createCriteria(thisDatacenter(datacenter));

    return (com.abiquo.server.core.infrastructure.Repository) criteria.uniqueResult();// getSingleResult(criteria);
}

From source file:com.abiquo.server.core.infrastructure.RepositoryDAO.java

License:Open Source License

public boolean existRepositoryInOtherDatacenter(Datacenter datacenter, String repositoryLocation) {
    Criterion notDatacenter = Restrictions.not(thisDatacenter(datacenter));
    Criteria criteria = createCriteria(notDatacenter, thisLocation(repositoryLocation));

    criteria.setProjection(Projections.projectionList().add(Projections.rowCount()));

    Long count = (Long) criteria.uniqueResult();
    return count != null && count.intValue() > 0;
}

From source file:com.abiquo.server.core.infrastructure.RepositoryDAO.java

License:Open Source License

public boolean existRepositoryInSameDatacenter(Datacenter datacenter, String repositoryLocation) {
    Criteria criteria = createCriteria(thisDatacenter(datacenter), thisLocation(repositoryLocation));
    criteria.setProjection(Projections.projectionList().add(Projections.rowCount()));

    Long count = (Long) criteria.uniqueResult();
    return count != null && count.intValue() > 0;
}

From source file:com.abiquo.server.core.infrastructure.RepositoryDAO.java

License:Open Source License

public com.abiquo.server.core.infrastructure.Repository findByRepositoryLocation(String repositoryLocation) {
    Criteria criteria = createCriteria(thisLocation(repositoryLocation));

    return (com.abiquo.server.core.infrastructure.Repository) criteria.uniqueResult(); // getSingleResult(criteria);
}

From source file:com.abiquo.server.core.infrastructure.storage.InitiatorMappingDAO.java

License:Open Source License

public InitiatorMapping findByVolumeAndInitiator(final Integer idVolumeManagement, final String initiatorIqn) {
    Criteria criteria = createCriteria(Restrictions.eq("volume.id", idVolumeManagement))
            .add(Restrictions.eq("initiatorIqn", initiatorIqn));
    Object obj = criteria.uniqueResult();
    return (InitiatorMapping) obj;
}

From source file:com.abiquo.server.core.infrastructure.storage.StorageDeviceDAO.java

License:Open Source License

public StorageDevice getDeviceById(final Integer datacenterId, final Integer deviceId) {
    Criteria criteria = createCriteria(Restrictions.eq("id", deviceId),
            Restrictions.eq("datacenter.id", datacenterId));
    Object obj = criteria.uniqueResult();
    return (StorageDevice) obj;
}

From source file:com.abiquo.server.core.infrastructure.storage.StorageDeviceDAO.java

License:Open Source License

public StorageDevice findDeviceByManagementIP(final Integer datacenterId, final String managementIp) {
    Criteria criteria = createCriteria(Restrictions.eq("managementIp", managementIp),
            Restrictions.eq("datacenter.id", datacenterId));
    Object obj = criteria.uniqueResult();
    return (StorageDevice) obj;
}

From source file:com.abiquo.server.core.infrastructure.storage.StoragePoolDAO.java

License:Open Source License

public StoragePool findPoolById(final Integer deviceId, final String poolId) {
    Criteria criteria = createCriteria(Restrictions.eq("device.id", deviceId))
            .add(Restrictions.eq("idStorage", poolId));
    Object obj = criteria.uniqueResult();
    return (StoragePool) obj;
}