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.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);//from  ww w. ja va 2 s  . c  o  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;
}

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

License:Open Source License

public List<VolumeManagement> getVolumesByVirtualMachine(final VirtualMachine vm, final FilterOptions filters) {
    if (filters != null) {
        // 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_ATTACHED_TO_VM);

        String req = query.getQueryString() + orderBy;
        // Add order filter to the query
        Query queryWithOrder = getSession().createQuery(req);
        queryWithOrder.setInteger("vmId", vm.getId());
        queryWithOrder.setParameter("state", VolumeState.ATTACHED);
        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);
        volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit());
        volumesList.setCurrentElement(filters.getStartwith());

        return volumesList;
    } else {//ww  w .  j a v  a2s  . c  om
        Criteria criteria = createCriteria(sameVirtualMachine(vm), sameState(VolumeState.ATTACHED));
        return getResultList(criteria);
    }
}

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

License:Open Source License

public List<VolumeManagement> getVolumesByVirtualAppliance(final VirtualAppliance vapp) {
    Query query = getSession().createQuery(VolumeManagement.BY_VAPP);
    query.setInteger("vappId", vapp.getId());
    return query.list();
}

From source file:com.abiquo.server.core.scheduler.MachineLoadRuleDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<MachineLoadRule> findByMachine(final Integer idMachine) {
    Query query = getSession().createQuery(QUERY_RULES_BY_MACHINE);
    query.setInteger("idMachine", idMachine);

    List<MachineLoadRule> rules = query.list();
    return rules;
}

From source file:com.alejandro.modelo.ModeloImagen.java

public static List<Imagen> getidInmueble(String idInmueble) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from w w w  . jav  a 2s.co  m*/
    String hql = "from Imagen where idInmueble = :idInmueble";

    Query q = session.createQuery(hql);
    q.setInteger("idInmueble", Integer.parseInt(idInmueble));
    List<Imagen> inmuebles = q.list();
    session.getTransaction().commit();
    session.close();
    return inmuebles;
}

From source file:com.alex.web.proyectofinal.DAOUsuarioImpl.java

/**
 * Este metodo busca un cliente por medio de su Id
 * @param id Este parametro es el Id del cliente que se quiere buscar
 * @return El tipo de retorno es el cliente buscado
 *///  w w  w.  j  a v a2s. c  o m
public Usuario buscarPorId(int id) {
    begin();
    Query q = getSession().createQuery("from Cliente where id = :id");
    q.setInteger("id", id);
    Usuario p = (Usuario) q.uniqueResult();
    commit();
    close();
    return p;

}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findBySQLQuery(final String sql, final Map map) {
    List data = getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createSQLQuery(sql);
            Iterator iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next().toString();
                Object obj = map.get(key);
                String[] keys = query.getNamedParameters();
                for (int i = 0; i < keys.length; i++) {
                    if (key != null && key.equals(keys[i])) {
                        if (obj instanceof String) {
                            query.setString(key, obj.toString());
                        }//from  ww  w  .j  av  a 2s .  c  om
                        if (obj instanceof Number) {
                            query.setInteger(key, Integer.parseInt(obj.toString()));
                        }
                        if (obj instanceof BigDecimal) {
                            query.setBigDecimal(key, (BigDecimal) obj);
                        }
                        if (obj instanceof List) {
                            query.setParameterList(key, (List) obj);
                        }
                    }
                }
            }
            return query.list();
        }
    });
    return data;
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findBySQLQuery(final String sql, final int begin, final int count, final Map map) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createSQLQuery(sql);
            Iterator iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next().toString();
                Object obj = map.get(key);
                String[] keys = query.getNamedParameters();
                for (int i = 0; i < keys.length; i++) {
                    if (key != null && key.equals(keys[i])) {
                        if (obj instanceof String) {
                            query.setString(key, obj.toString());
                        }//from ww w  .  j a v  a2 s  . c  o m
                        if (obj instanceof Number) {
                            query.setInteger(key, Integer.parseInt(obj.toString()));
                        }
                        if (obj instanceof BigDecimal) {
                            query.setBigDecimal(key, (BigDecimal) obj);
                        }
                        if (obj instanceof List) {
                            query.setParameterList(key, (List) obj);
                        }
                    }
                }
            }
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public String findCountBySQLQuery(final String countSql, final Map map) {
    List data = getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createSQLQuery(countSql);
            Iterator iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next().toString();
                Object obj = map.get(key);
                String[] keys = query.getNamedParameters();
                for (int i = 0; i < keys.length; i++) {
                    if (key != null && key.equals(keys[i])) {
                        if (obj instanceof String) {
                            query.setString(key, obj.toString());
                        }/*w  w  w .  ja v a 2 s .c om*/
                        if (obj instanceof Number) {
                            query.setInteger(key, Integer.parseInt(obj.toString()));
                        }
                        if (obj instanceof BigDecimal) {
                            query.setBigDecimal(key, (BigDecimal) obj);
                        }
                        if (obj instanceof List) {
                            query.setParameterList(key, (List) obj);
                        }
                    }
                }
            }
            return query.list();
        }
    });
    return data.get(0).toString();
}

From source file:com.app.inventario.dao.seguridad.IntentosLoginDAOImpl.java

public void actualizarIntentosFallidos(String usuario) throws HibernateException {
    try {/*  w  w  w .  j a v  a2  s. co  m*/
        //this.iniciaOperacion();
        IntentosLogin intento = this.obtenerIntentoLogin(usuario);
        if (intento == null) {
            IntentosLogin intentoAux = new IntentosLogin(usuario, 1, new Date());
            session.save(intentoAux);
        } else {
            if (intento.getCantidadIntentos() < 3) {
                Query query = session.createQuery(
                        "UPDATE IntentosLogin SET cantidadIntentos = :cantidadIntentos, ultimoAcceso = :ultimoAcceso  WHERE usuario = :username");
                query.setInteger("cantidadIntentos", intento.getCantidadIntentos() + 1);
                query.setDate("ultimoAcceso", new Date());
                query.setString("username", usuario);
                query.executeUpdate();
            } else if (intento.getCantidadIntentos() + 1 == 3) {
                Query query = session
                        .createQuery("UPDATE Usuario SET noBloqueado = false WHERE username = :usuario");
                query.setParameter("usuario", intento.getUsuario());
                query.executeUpdate();
            }
        }
    } catch (HibernateException he) {
        this.manejaExcepcion(he);
    } finally {
    }
}