List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public Long getNumberStorageDevicesByDatacenter(final Integer idDatacenter) { Long numberOfStorageDevices;//from ww w .j a v a2 s . c o m final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query sdQuery = session .createSQLQuery("select count(sd.id) from storage_device sd where sd.idDataCenter = :idDataCenter"); sdQuery.setInteger("idDataCenter", idDatacenter); numberOfStorageDevices = ((BigInteger) sdQuery.list().get(0)).longValue(); return numberOfStorageDevices; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public void updateUsedResourcesByDatacenter(final Integer idDatacenter) { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final String update = "update physicalmachine p, " + "(SELECT hy.idPhysicalMachine, IFNULL(SUM(vm.ram),0) ram, IFNULL(SUM(vm.cpu),0) cpu " + "FROM virtualmachine vm right join hypervisor hy on vm.idHypervisor = hy.id, " + "physicalmachine pm, rack r " + "WHERE (vm.state is null or vm.state != 'NOT_DEPLOYED') AND pm.idPhysicalMachine = hy.idPhysicalMachine " + "AND pm.idRack = r.idRack AND r.idDatacenter = :idDatacenter " + "group by hy.idPhysicalMachine) x " + "SET p.ramused = x.ram, p.cpuused = x.cpu where p.idPhysicalMachine = x.idPhysicalMachine "; final Query pmQuery = session.createSQLQuery(update); pmQuery.setInteger("idDatacenter", idDatacenter); pmQuery.executeUpdate();/*w ww .j a va 2s.c om*/ }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public DatacenterHB getDatacenterWhereThePrivateNetworkStays(final Integer networkId) throws PersistenceException { DatacenterHB datacenter;//ww w .j av a 2 s . c o m try { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(DATACENTER_GET_BY_PRIVATE_NETWORK_ID); query.setInteger("networkId", networkId); datacenter = (DatacenterHB) query.uniqueResult(); } catch (final HibernateException he) { throw new PersistenceException(he.getMessage(), he); } return datacenter; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public DatacenterHB getDatacenterWhereThePublicNetworkStays(final Integer idNetwork) throws PersistenceException { DatacenterHB datacenter;//from w ww . jav a 2s. co m try { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(DATACENTER_GET_BY_PUBLIC_NETWORK_ID); query.setInteger("networkId", idNetwork); datacenter = (DatacenterHB) query.uniqueResult(); } catch (final HibernateException he) { throw new PersistenceException(he.getMessage(), he); } return datacenter; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<DatacenterHB> getAllowedDatacenters(final int idEnterprise) { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(GET_ALLOWED_DATACENTERS); query.setInteger("idEnterprise", idEnterprise); return query.list(); }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w ww . j a va2 s .com*/ public ArrayList<RackHB> getRacks(final Integer datacenterId, final String filters) { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(GET_RACKS_BY_DATACENTER); query.setInteger("idDatacenter", datacenterId); query.setString("filterLike", filters == null || filters.isEmpty() ? "%" : "%" + filters + "%"); return (ArrayList<RackHB>) query.list(); }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.HyperVisorDAOHibernate.java
License:Open Source License
@Override public List<Integer> getUsedPortsFromDB(Integer idHypervisor, Integer idPhysicalMachine) { Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query query = session.getNamedQuery(GET_VDRP); query.setInteger("idHyper", idHypervisor); query.setInteger("idPM", idPhysicalMachine); return query.list(); }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.HyperVisorDAOHibernate.java
License:Open Source License
@Override public HypervisorHB getHypervisorFromPhysicalMachine(Integer pmId) { Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query query = session.getNamedQuery(GET_HYPER_FROM_PHYSICALMACHINE); query.setInteger("pmId", pmId); return (HypervisorHB) query.uniqueResult(); }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.PhysicalMachineDAOHibernate.java
License:Open Source License
@Override public List<PhysicalmachineHB> getByRackAndVirtualDatacenter(final Integer idRack, final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final EnterpriseHB enterprise) { // "(pm.ram - pm.ramUsed) >= " + vimage.getRamRequired() + // " and (pm.cpu - pm.cpuUsed) >= " + vimage.getCpuRequired(); Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query pmQuery = session.getNamedQuery(FIRST_PASS_QUERY); pmQuery.setInteger("idVirtualDataCenter", idVirtualDatacenter); pmQuery.setInteger("idRack", idRack); pmQuery.setLong("hdRequiredOnRepository", hdRequiredOnDatastore); pmQuery.setParameter("enterprise", enterprise); return pmQuery.list(); }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.PhysicalMachineDAOHibernate.java
License:Open Source License
@Override public Long getNumberOfDeployedVirtualMachines(final PhysicalmachineHB pmHB) { Long numberOfDeployedMachines; Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query pmQuery = session.getNamedQuery(PHYSICALMACHINE_GET_NUMBER_OF_DEPLOYED_MACHINES); pmQuery.setInteger("idphysicalmachine", pmHB.getIdPhysicalMachine()); numberOfDeployedMachines = (Long) pmQuery.uniqueResult(); return numberOfDeployedMachines; }