List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.abiquo.abiserver.persistence.dao.virtualhardware.hibernate.ResourceManagementDAOHibernate.java
License:Open Source License
@Override public ResourceManagementHB getResourceManagementPrivateEthernetByVS(VirtualmachineHB vmHB) throws PersistenceException { try {//from w ww. ja va2 s . c om Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query query = session.getNamedQuery(GET_RESOURCE_MANAGEMENT_ETHERNET_BY_MAC); query.setString("idVM", vmHB.getIdVm().toString()); ResourceManagementHB result = (ResourceManagementHB) query.uniqueResult(); return result; } catch (HibernateException e) { throw new PersistenceException(e.getMessage(), e); } }
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;/*from w ww .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; }
From source file:com.abiquo.server.core.enterprise.OneTimeTokenSessionDAO.java
License:Open Source License
/** * Consume the given token. Which actually deletes the token. Returns the number of rows * affected by the update. Ideally only 1. * //from w w w . j a va2 s .c om * @param token token to be consumed. * @return number of rows affected. */ public int consumeToken(String token) { Query query = this.getSession().createQuery(CONSUME_TOKEN); query.setString("token", token); return query.executeUpdate(); }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find next IpPoolManagement created and available by a vLAN with filter options * /*from w ww .j a va 2 s. c om*/ * @param vlanId identifier of the vlan. * @param excludedIps ips excluded from result if exists * @return next available IP address. */ public IpPoolManagement findNextIpAvailable(final Integer vlanId, final String... excludedIps) { // Get the query that counts the total results. Query query = getSession() .createQuery(BY_VLAN_NEXT_AVAILABLE + defineOrderBy(IpPoolManagement.OrderByEnum.IP, Boolean.TRUE)); query.setMaxResults(1); query.setParameter("vlan_id", vlanId); // query.setLockMode("next_ip", LockMode.PESSIMISTIC_WRITE); if (excludedIps != null && excludedIps.length != 0) { query.setParameterList("excludedIp", Arrays.asList(excludedIps)); } else { query.setString("excludedIp", null); } List<IpPoolManagement> result = query.list(); return result.isEmpty() ? null : result.get(0); }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find next IpPoolManagement created and available by a vLAN with filter options * //from www. j av a 2 s.co m * @param vlanId identifier of the vlan. * @param excludedIps ips excluded from result if exists * @return next available IP address. */ public IpPoolManagement findNextExternalIpAvailable(final Integer vlanId, final String... excludedIps) { // Get the query that counts the total results. Query query = getSession().createQuery( BY_VLAN_NEXT_EXTERNAL_IP_AVAILABLE + defineOrderBy(IpPoolManagement.OrderByEnum.IP, Boolean.TRUE)); query.setMaxResults(1); query.setParameter("vlan_id", vlanId); // query.setLockMode("next_ip", LockMode.PESSIMISTIC_WRITE); if (excludedIps != null && excludedIps.length != 0) { query.setParameterList("excludedIp", Arrays.asList(excludedIps)); } else { query.setString("excludedIp", null); } List<IpPoolManagement> result = query.list(); return result.isEmpty() ? null : result.get(0); }
From source file:com.abiquo.server.core.infrastructure.RackDAO.java
License:Open Source License
public List<Rack> findRacks(final Datacenter datacenter, final String filter) { assert datacenter != null; assert isManaged2(datacenter); if (filter != null && !filter.isEmpty()) { Query query = getSession().createSQLQuery(QUERY_GET_FILTERED_RACKS); query.setParameter("idDatacenter", datacenter.getId()); query.setString("filter", "%" + filter + "%"); List<Rack> racks = getSQLQueryResults(getSession(), query, Rack.class, 0); return racks; }//from w ww . j a va 2 s .c om Criteria criteria = createCriteria(sameDatacenter(datacenter)); criteria.addOrder(Order.asc(Rack.NAME_PROPERTY)); List<Rack> result = getResultList(criteria); return result; }
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 a v a 2 s. c o 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> getVolumesByPool(final StoragePool sp, 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_POOL); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setString("poolId", sp.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);/* www .j av a2 s. c o m*/ volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }
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 .j a v a 2 s.c o m*/ volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<VolumeManagement> getAvailableVolumes(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_AVAILABLES); 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(); // Limit 0 means no size filter if (filters.getLimit() == 0) { filters.setLimit(size);// w w w . j av a2s . co m filters.setStartwith(0); } queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size); volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }