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.consult.app.dao.impl.UserDaoImpl.java

@Override
public List<Object> getReadyToCheckUser(Long startId, int count) {

    try {// w w  w  . j  a v  a 2  s  .com
        //         String content, Integer pushType, String token,
        //         Integer notificationType, int badgeCount
        String hql = "from User user " + "where user.userId>? and user.smsLocate=? order by user.userId asc";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, startId);
        query.setInteger(1, Constant.SMS_LOCATE_READY_TO_CHECK);
        query.setFirstResult(0);
        query.setMaxResults(count + 1);
        return query.list();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

From source file:com.consult.app.dao.impl.UserDaoImpl.java

@Override
public void disableSms(Long userId, int trigger) {
    try {/*from w  w w  .  j  av  a 2s.c  o m*/
        Query query = sessionFactory.getCurrentSession()
                .createQuery("update User obj set obj.pushSubscribe=? where obj.userId=?");
        query.setInteger(0, trigger);
        query.setLong(1, userId);
        if (query.executeUpdate() > 0) {
            JUserCache.getInstance().removeUser(userId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.consult.app.dao.impl.UserDaoImpl.java

public List<Object> searchDriverList(SearchDriverRequest req) {
    /**// w  ww . j  a va2s.c  o m
     * 
     */
    long possitionTime = System.currentTimeMillis() - TimeUtils.DAY * 14;
    Query query = null;
    StringBuffer querysql = new StringBuffer("");
    String truckLengthCondition = req.getTruckLength() <= 0d ? "" : "and p.truck_length=:truckLength";
    String sqlTem = "(select u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate,u.create_time as updateTime,p.order_count as orderCount,u.city as cityId,abs(u.city-:start) as sortFlag from users u, profiles p, %s sub, search_conditions sc where sub.user_id=u.user_id and u.user_id=p.user_id and p.user_type=1 and sub.search_id=sc.search_id and u.telephone>13000000000 "
            + truckLengthCondition
            + " and sub.push_subscribe=1 and u.push_subscribe=1 and u.type=1 and sub.type>0 and (sc.end=:end or sc.end=:endFather) and (sc.start=:start or sc.start=:startFather) and u.update_time>:before and u.update_time<:after and u.update_time>:possitionTime)";
    for (int i = 0; i < Constant.SHARD_TABLE_SUBSCRIBE.length; i++) {
        if (i == 0) {
            querysql.append("select t.* from (" + String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i])
                    + " union all ");
        } else if (i == Constant.SHARD_TABLE_SUBSCRIBE.length - 1) {
            querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i])
                    + ") t group by t.userId order by t.sortFlag asc,t.updateTime desc");//,t.orderCount desc
        } else {
            querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all ");
        }
    }

    query = sessionFactory.getCurrentSession().createSQLQuery(querysql.toString())
            .addScalar("userId", StandardBasicTypes.LONG).addScalar("picture", StandardBasicTypes.STRING)
            .addScalar("userName", StandardBasicTypes.STRING).addScalar("telephone", StandardBasicTypes.STRING)
            .addScalar("truckLength", StandardBasicTypes.DOUBLE)
            .addScalar("truckLoad", StandardBasicTypes.DOUBLE)
            .addScalar("truckType", StandardBasicTypes.INTEGER).addScalar("number", StandardBasicTypes.STRING)
            .addScalar("isAuthenticate", StandardBasicTypes.INTEGER)
            .addScalar("updateTime", StandardBasicTypes.LONG)
            .addScalar("orderCount", StandardBasicTypes.INTEGER).addScalar("cityId", StandardBasicTypes.INTEGER)
            .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class));
    if (req.getTruckLength() > 0) {
        query.setDouble("truckLength", req.getTruckLength());
    }
    query.setInteger("end", req.getEnd()).setInteger("endFather", req.getEndFather())
            .setInteger("start", req.getStart()).setInteger("startFather", req.getStartFather())
            .setLong("before", req.getBefore()).setLong("after", req.getAfter())
            .setLong("possitionTime", possitionTime);
    query.setMaxResults(req.getCount());
    @SuppressWarnings("unchecked")
    List<Object> all = query.list();
    return all;
}

From source file:com.copyright.common.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?HQL?Query.//from ww  w . ja  v a  2s .  c o  m
 * 
 * ?find()T,?T.
 * 
 * @param values ????,?.
 */
public Query createQuery(final String queryString, final Object... values) {
    Assert.hasText(queryString, "queryString?");
    Query query = getSession().createQuery(queryString);
    if (values != null && values.length > 0) {
        if (values[0] instanceof Hashtable) {
            Hashtable temp = (Hashtable) values[0];
            query = setParamHash(query, temp);
        } else {
            if (values[0] instanceof List) {
                List temp = (List) values[0];
                int size = temp.size();
                for (int i = 0; i < size; i++) {
                    Object param = temp.get(i);
                    //query.setParameter(i,values[i]); 
                    if (param instanceof String) {
                        String paramValue = (String) param;
                        query.setString(i, paramValue);
                    } else {
                        if (param instanceof Integer) {
                            Integer paramValue = (Integer) param;
                            query.setInteger(i, paramValue.intValue());
                        } else {
                            if (param instanceof Long) {
                                Long paramValue = (Long) param;
                                query.setLong(i, paramValue.longValue());
                            } else {
                                if (param instanceof Double) {
                                    Double paramValue = (Double) param;
                                    query.setDouble(i, paramValue.doubleValue());
                                } else {
                                    if (param instanceof Float) {
                                        Float paramValue = (Float) param;
                                        query.setFloat(i, paramValue.floatValue());
                                    }
                                }
                            }
                        }
                    }

                }
            } else {
                for (int i = 0; i < values.length; i++) {
                    query.setParameter(i, values[i]);
                }
            }

        }
    }

    return query;
}

From source file:com.copyright.common.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * /*  w w w.  jav a  2s . c  o  m*/
 * @param query
 * @param values
 * @return
 */
private Query setParamHash(Query query, Hashtable<String, ?> values) {
    if (values != null) {
        //query.setProperties(values);
        Enumeration parameterNames = values.keys();
        while (parameterNames.hasMoreElements() == true) {
            String pName = (String) parameterNames.nextElement();
            Object param = values.get(pName);
            if (param instanceof String) {
                String paramValue = (String) param;
                query.setString(pName, paramValue);
            } else {
                if (param instanceof Integer) {
                    Integer paramValue = (Integer) param;
                    query.setInteger(pName, paramValue.intValue());
                } else {
                    if (param instanceof Double) {
                        Double paramValue = (Double) param;
                        query.setDouble(pName, paramValue.doubleValue());
                    }
                }

            }

        }

    }
    return query;
}

From source file:com.cosw.productsmaster.main.Funciones.java

/**
 * Valor a pagar, por proveedor, de un pedido
 * @param s La sesion//from  w ww.j av  a2 s .c o  m
 * @param idPedido El identificador del pedido
 * @return Retorna una lista con el proveedor y el valor a pagar.
 */
public static List<Object[]> valorPagarProveedorPedido(Session s, int idPedido) {
    Query q1 = s.createQuery("SELECT proveedor, SUM(detail.cantidad * detail.precioUnitario)" + "FROM Pedido p "
            + "INNER JOIN p.detalleCompras detail " + "INNER JOIN detail.productos product "
            + "INNER JOIN product.proveedores proveedor " + "WHERE p.idPedidos = :idPedido "
            + "GROUP BY proveedor");
    q1.setInteger("idPedido", idPedido);
    return q1.list();
}

From source file:com.diana.dao.CiudadDAO.java

public Ciudad getCiudad(int idCiudad) {
    Ciudad ciudad = null;/*w  w w.  j a  va2  s  .  com*/
    Transaction trns = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        String queryString = "from Ciudad where id = :idCiudad";
        Query query = session.createQuery(queryString);
        query.setInteger("idCiudad", idCiudad);
        ciudad = (Ciudad) query.uniqueResult();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return ciudad;
}

From source file:com.duroty.application.admin.manager.AdminManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from www.j  a v a2 s.c  o  m
 *
 * @param hsession DOCUMENT ME!
 * @param user DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
protected int getUsedQuotaSize(org.hibernate.Session hsession, Users user) throws MailException {
    try {
        Query query = hsession.getNamedQuery("used-quota-size");
        query.setInteger("user", new Integer(user.getUseIdint()));

        Integer value = (Integer) query.uniqueResult();

        return value.intValue();
    } catch (Exception ex) {
        return 0;
    } finally {
    }
}

From source file:com.duroty.application.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!//from  w  w  w .  j  a va2  s  .  c o m
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void applyLabel(Session hsession, String repositoryName, Integer label, Integer[] idints)
        throws FilesException {
    if ((idints == null) || (idints.length == 0)) {
        throw new FilesException("ErrorMessages.messages.selection.null");
    }

    try {
        if ((label == null) || (label.intValue() <= 0)) {
            return;
        }

        Users user = getUser(hsession, repositoryName);

        Criteria crit = hsession.createCriteria(Label.class);
        crit.add(Restrictions.eq("labIdint", label));
        crit.add(Restrictions.eq("users", user));

        Label hlabel = (Label) crit.uniqueResult();

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            LabMes labMes = new LabMes(new LabMesId(message, hlabel));
            hsession.saveOrUpdate(labMes);
            hsession.flush();
        }

        hsession.flush();
    } catch (Exception e) {
        throw new FilesException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*w  w w . ja v a  2s.co m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param mids DOCUMENT ME!
 * @param flag DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public void flagFiles(Session hsession, String repositoryName, Integer[] idints) throws FilesException {
    if ((idints == null) || (idints.length == 0)) {
        throw new FilesException("ErrorMessages.messages.selection.null");
    }

    try {
        Users user = getUser(hsession, repositoryName);

        Query query = hsession.getNamedQuery("messages-by-attachments");
        query.setParameterList("idints", idints);
        query.setInteger("user", user.getUseIdint());

        ScrollableResults scroll = query.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            if (message.isMesFlagged()) {
                message.setMesFlagged(false);
            } else {
                message.setMesFlagged(true);
            }

            hsession.update(message);
            hsession.flush();
        }

        hsession.flush();
    } catch (Exception e) {
        throw new FilesException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}