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.server.core.enterprise.RoleDAO.java
License:Open Source License
public List<Privilege> findPrivilegesByIdRole(final Integer idRole) { Query query = getSession().createQuery(QUERY_PRIVILEGES_FROM_ROLE); query.setInteger("idRole", idRole); List<Privilege> privileges = query.list(); return privileges; }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
private List<Machine> findFirstCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final Enterprise enterprise) { List<Machine> machines = null; Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameter("enterpriseId", enterprise.getId()); machines = query.list();//from ww w . ja v a2 s. c o m if (machines == null || machines.size() == 0) { whyNotCandidateMachines(idRack, idVirtualDatacenter, hdRequiredOnDatastore, enterprise, null); } return machines; }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
private List<Machine> findFirstCandidateMachinesReservedRestricted(final Integer idRack, final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final Enterprise enterprise) { List<Machine> machines = null; List<Machine> reservMachines = findReservedMachines(enterprise); if (reservMachines != null && reservMachines.size() != 0) { List<Integer> reserveds = new LinkedList<Integer>(); for (Machine m : reservMachines) { reserveds.add(m.getId());/*from w w w .j ava2 s.co m*/ } Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_RESERVED); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameterList("reserveds", reserveds); machines = query.list(); if (machines == null || machines.size() == 0) { whyNotCandidateMachines(idRack, idVirtualDatacenter, hdRequiredOnDatastore, enterprise, reserveds); } return machines; } else { final String msg = String.format( "Enterprise works in restricted reserved machines mode but no machine is reserved. Current enterprise: %s", enterprise.getName()); throw new PersistenceException(msg); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
protected List<Machine> findFirstCandidateMachinesReservedRestrictedHAExclude(final Integer idRack, final Integer idVirtualDatacenter, final Enterprise enterprise, final Integer originalHypervisorId) { List<Machine> machines = null; List<Machine> reservMachines = findReservedMachines(enterprise); if (reservMachines != null && reservMachines.size() != 0) { List<Integer> reserveds = new LinkedList<Integer>(); for (Machine m : reservMachines) { reserveds.add(m.getId());/*from w ww.jav a 2 s .c o m*/ } Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_RESERVED_HA_EXCLUDE_ORIGINAL); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameterList("reserveds", reserveds); query.setInteger("enterpriseId", enterprise.getId()); query.setInteger("originalHypervisorId", originalHypervisorId); machines = query.list(); if (machines == null || machines.size() == 0) { whyNotCandidateMachines(idRack, idVirtualDatacenter, 0l, enterprise, reserveds); } return machines; } else { final String msg = String.format( "Enterprise works in restricted reserved machines mode but no machine is reserved. Current enterprise: %s", enterprise.getName()); throw new PersistenceException(msg); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
/** * Do not require additional space on the datastore. Used during HA, selects a machine different * of the ''originalHypervisorId'' with the same ''datastoreUuid'' enabled. *//*ww w .j ava 2 s . co m*/ public List<Machine> findCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter, final Enterprise enterprise, final String datastoreUuid, final Integer originalHypervisorId) { List<Machine> machines = null; if (enterprise.getIsReservationRestricted()) { machines = findFirstCandidateMachinesReservedRestrictedHAExclude(idRack, idVirtualDatacenter, enterprise, originalHypervisorId); } else { Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_HA_EXCLUDE_ORIGINAL); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameter("enterpriseId", enterprise.getId()); query.setParameter("originalHypervisorId", originalHypervisorId); machines = query.list(); } if (machines == null || machines.size() == 0) { Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameter("enterpriseId", enterprise.getId()); machines = query.list(); if (machines == null || machines.size() == 0) { throw new PersistenceException(String.format( "There isn't any MANAGED machine on the required rack [%d] and virtual datacenter [%d] available for the current enterpirse [%s]. " + "Pleas check the machine reservation policies.", idRack, idVirtualDatacenter, enterprise.getName())); } else { throw new PersistenceException(String.format( "The only MANAGED machine on the required rack [%d] and virtual datacenter [%d] available for the current enterpirse [%s]" + "is the target of the high availability (so can't be used) ", idRack, idVirtualDatacenter, enterprise.getName())); } } // StringBuilder sbcandidates = new StringBuilder(); List<Integer> candidatesids = new LinkedList<Integer>(); for (Machine m : machines) { candidatesids.add(m.getId()); } // with datastore Query datastoreQuery = getSession().createQuery(QUERY_CANDIDATE_DATASTORE_HA_DATASTOREUUID); datastoreQuery.setParameterList("candidates", candidatesids); datastoreQuery.setParameter("datastoreUuid", datastoreUuid); List<Integer> includedIds = datastoreQuery.list(); if (includedIds.size() == 0) { throw new PersistenceException(String .format("There isn't any machine with the required shared datastore [%s]", datastoreUuid)); } // execute the enterprise exclusion rule Query excludedQuery = getSession().createQuery(QUERY_CANDIDATE_NO_ENTERPRISE_EXCLUDED); excludedQuery.setParameter("enterpriseId", enterprise.getId()); List<Integer> excludedMachineIds = excludedQuery.list(); List<Machine> notExcludedMachines = new LinkedList<Machine>(); for (Machine m : machines) { Integer machineId = m.getId(); if (!excludedMachineIds.contains(machineId) && includedIds.contains(machineId)) { notExcludedMachines.add(m); } } if (notExcludedMachines.size() == 0) { throw new PersistenceException("All the candiate machines are excluded by other enterprsies " + "with virtual machines deployed on it. Please check the enterprise affinity rules."); } return notExcludedMachines; }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
private void whyNotCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final Enterprise enterprise, final List<Integer> reserveds) throws PersistenceException { if (reserveds != null) { StringBuilder reservedMachinesB = new StringBuilder( String.format("Enterprise %s has the following machine reservations : ", enterprise.getName())); for (Integer mid : reserveds) { reservedMachinesB.append(mid + ' '); }/*ww w. j a va2s.com*/ /** * rack and hypervisor type */ Query query1 = getSession().createQuery(WHY_QUERY_CANDIDATE_SAME_VDC_RACK_AND_TYPE_AND_RESERVED); query1.setInteger("idVirtualDataCenter", idVirtualDatacenter); query1.setInteger("idRack", idRack); query1.setParameterList("reserveds", reserveds); List<Integer> query1res = query1.list(); if (query1res.size() == 0) { throw new PersistenceException(String.format( "%s\nThere isn't any machine on the required rack [%d] and virtual datacenter [%d]. " + "Please check the racks and hypervisor technology on the infrastructure.", reservedMachinesB.toString(), idRack, idVirtualDatacenter)); } /** * rack, hypervisor type and managed state */ Query query2 = getSession().createQuery(QUERY_CANDIDATE_MACHINES_RESERVED); query2.setInteger("idVirtualDataCenter", idVirtualDatacenter); query2.setInteger("idRack", idRack); query2.setParameter("state", MachineState.MANAGED); query2.setParameterList("reserveds", reserveds); List<Integer> query2res = query2.list(); if (query2res.size() == 0) { throw new PersistenceException(String.format( "%s\nThere isn't any MANAGED machine on the required rack [%d] and virtual datacenter [%d]. " + "Please check the machine health on the infrastructure.", reservedMachinesB.toString(), idRack, idVirtualDatacenter)); } /** * rack, hypervisor type, managed state, enterprise reservation and datastore capacity. */ throw new PersistenceException( String.format("%s\nThere isn't any machine with the required datastore capacity [%d]", reservedMachinesB.toString(), hdRequiredOnDatastore)); } // reserved machines else { /** * rack and hypervisor type */ Query query1 = getSession().createQuery(WHY_QUERY_CANDIDATE_SAME_VDC_RACK_AND_TYPE); query1.setInteger("idVirtualDataCenter", idVirtualDatacenter); query1.setInteger("idRack", idRack); List<Integer> query1res = query1.list(); if (query1res.size() == 0) { throw new PersistenceException(String.format( "There isn't any machine on the required rack [%d] and virtual datacenter [%d]. " + "Please check the racks and hypervisor technology on the infrastructure.", idRack, idVirtualDatacenter)); } /** * rack, hypervisor type and managed state */ Query query2 = getSession().createQuery(WHT_QUERY_CANDIDATE_SAME_VDC_RACK_AND_TYPE_AND_STATE); query2.setInteger("idVirtualDataCenter", idVirtualDatacenter); query2.setInteger("idRack", idRack); query2.setParameter("state", MachineState.MANAGED); List<Integer> query2res = query2.list(); if (query2res.size() == 0) { throw new PersistenceException(String.format( "There isn't any MANAGED machine on the required rack [%d] and virtual datacenter [%d]. " + "Please check the machine health on the infrastructure.", idRack, idVirtualDatacenter)); } /** * rack, hypervisor type, managed state and enterprise reservation */ Query query3 = getSession().createQuery(QUERY_CANDIDATE_MACHINES); query3.setInteger("idVirtualDataCenter", idVirtualDatacenter); query3.setInteger("idRack", idRack); query3.setParameter("state", MachineState.MANAGED); query3.setParameter("enterpriseId", enterprise.getId()); List<Integer> query3res = query3.list(); if (query3res.size() == 0) { throw new PersistenceException(String.format( "There isn't any MANAGED machine on the required rack [%d] and virtual datacenter [%d] available for the current enterpirse [%s]. " + "Pleas check the machine reservation policies.", idRack, idVirtualDatacenter, enterprise.getName())); } /** * rack, hypervisor type, managed state, enterprise reservation and datastore capacity. */ throw new PersistenceException(String.format( "There isn't any machine with the required datastore capacity [%d]", hdRequiredOnDatastore)); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
License:Open Source License
public Long getTotalUsedCoresExceptMachine(final Machine machine) { Query query = getSession().createQuery(QUERY_USED_CORES_EXCEPT_MACHINE); query.setInteger("id", machine.getId()); Long result = (Long) query.uniqueResult(); // If there are no results (no other machines in DB) return 0 return result == null ? 0L : result; }
From source file:com.abiquo.server.core.infrastructure.RackDAO.java
License:Open Source License
public Long getNumberOfDeployedVlanNetworks(final Integer rackId) { Query query = getSession().createQuery(COUNT_DEPLOYED_VLA); query.setInteger("idRack", rackId); Long numberOfDeployedNetworks = (Long) query.uniqueResult(); return numberOfDeployedNetworks; }
From source file:com.abiquo.server.core.infrastructure.RackDAO.java
License:Open Source License
public List<Rack> findAllNotManagedRacksByDatacenter(final Integer datacenterId, final String filter) { String hql = HQL_NOT_MANAGED_RACKS_BY_DATACENTER; if (filter != null && !filter.isEmpty()) { hql += " AND nmr.name like :filter"; }//from w ww.j ava 2 s. co m Query q = getSession().createQuery(hql); q.setInteger("idDatacenter", datacenterId); if (filter != null && !filter.isEmpty()) { q.setString("filter", "%" + filter + "%"); } return q.list(); }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<VolumeManagement> getVolumesByVirtualDatacenter(final VirtualDatacenter vdc, final FilterOptions filters) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc()); Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_BY_VDC); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setInteger("vdcId", vdc.getId()); queryWithOrder.setString("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = queryWithOrder.list().size(); queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size);// w w w.ja v a 2 s . co m volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }