Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(String name, int val) 

Source Link

Document

Bind a named int-valued parameter.

Usage

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();//  w ww . j av  a  2 s.  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 {/* w w w .  ja v a2s  .  c  o  m*/
        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  ww  .j  a  v a 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 {/*www.j  ava2s . co  m*/
        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.VirtualMachineDAOHibernate.java

License:Open Source License

@Override
public VirtualappHB findVirtualAppFromVM(Integer vmID) throws PersistenceException {
    VirtualappHB virtualappHB;/*  www. ja  v a2  s.co m*/

    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.virtualimage.hibernate.RepositoryDAOHibernate.java

License:Open Source License

@Override
public RepositoryHB findByDatacenterDAO(Integer datacenterId) throws PersistenceException {
    RepositoryHB repository;//from   w w w .ja  v a2 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.server.core.cloud.NodeVirtualImageDAO.java

License:Open Source License

public List<Integer> findVirtualMachineIdsByVirtualAppliance(final VirtualAppliance virtualAppliance) {
    Query query = getSession().createQuery(MY_QUERY);
    query.setInteger("vappid", virtualAppliance.getId());

    return query.list();
}

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

License:Open Source License

public List<VirtualAppliance> findByEnterpriseAndDatacenter(final Integer entId, final Integer dcId) {
    Query query = getSession().createQuery(GET_VAPPS_BY_ENTERPRISE_AND_DATACENTER);
    query.setInteger("entId", entId);
    query.setInteger("dcId", dcId);

    return query.list();
}

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

License:Open Source License

/**
 * @param user, only users with restricted VDCs
 *///from  w ww  .j  av  a2  s . c om
public List<VirtualAppliance> findByEnterpriseAndDatacenter(final Integer entId, final Integer dcId,
        final User user) {
    Query query = getSession().createQuery(GET_VAPPS_BY_ENTERPRISE_AND_DATACENTER_AND_USER);
    query.setInteger("entId", entId);
    query.setInteger("dcId", dcId);
    query.setParameterList("allowedVDCs", availableVdsToUser(user));

    return query.list();
}

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

License:Open Source License

public List<VirtualMachine> findVirtualMachinesByVirtualAppliance(final Integer vappId, Integer startwith,
        Integer limit, final String filter, final OrderByEnum orderby, final boolean asc) {
    // List<VirtualMachine> vmList = null;

    // TypedQuery<VirtualMachine> query =
    // getEntityManager().createNamedQuery("VIRTUAL_MACHINE.BY_VAPP", VirtualMachine.class);
    // query.setParameter("vapp_id", vappId);
    // vmList = query.getResultList();
    String orderBy = defineOrderBy(orderby.getColumnHQL(), asc);
    Query query = getSession().getNamedQuery("VIRTUAL_MACHINE.BY_VAPP");

    String req = query.getQueryString() + orderBy;
    // Add order filter to the query
    Query queryWithOrder = getSession().createQuery(req);
    queryWithOrder.setInteger("vapp_id", vappId);
    queryWithOrder.setString("filterLike", filter.isEmpty() ? "%" : "%" + filter + "%");

    Integer size = queryWithOrder.list().size();

    // Limit 0 means no size filter
    if (limit == 0) {
        limit = size;//  w w w. j a  v a 2s . co  m
        startwith = 0;
    }

    queryWithOrder.setFirstResult(startwith);
    queryWithOrder.setMaxResults(limit);

    PagedList<VirtualMachine> vmList = new PagedList<VirtualMachine>(queryWithOrder.list());
    vmList.setTotalResults(size);
    vmList.setPageSize(limit > size ? size : limit);
    vmList.setCurrentElement(startwith);

    return vmList;
}