Example usage for org.hibernate Query setBigDecimal

List of usage examples for org.hibernate Query setBigDecimal

Introduction

In this page you can find the example usage for org.hibernate Query setBigDecimal.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setBigDecimal(String name, BigDecimal val) 

Source Link

Document

Bind a named BigDecimal-valued parameter.

Usage

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  www .j ava  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   w  ww . j a v a2s.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);
                        }
                    }
                }
            }
            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());
                        }//from   w w  w  .  j a  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.cis.paseaproduccionweb.dao.HistorialesDao.java

public Integer getLastVersion(String nombre, BigDecimal sistemaId) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;//from  w w  w  . ja v a  2 s . c o  m
    Object resultado;

    try {
        tx = session.getTransaction();
        tx.begin();
        Query q = session.getNamedQuery("SP_ULTIMA_VERSION_HISTORIAL");
        q.setString(0, nombre);
        q.setBigDecimal(1, sistemaId);
        resultado = q.uniqueResult();
        tx.commit();
        return (Integer) resultado;
    } catch (Exception e) {
        if (tx != null)
            tx.rollback();
        ErroresDao dError = new ErroresDao();
        PpErrores error = new PpErrores();
        Date date = new Date();

        error.setStacktrace(e.toString());
        error.setFecha(date);
        dError.insertarError(error);
    } finally {
        session.close();
    }
    return 0;
}

From source file:com.cloud.bridge.util.QueryHelper.java

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;/* w  w w .  ja va2 s . c o  m*/
    if (params != null && params.length > 0) {
        for (Object param : params) {
            if (param instanceof Byte)
                query.setByte(pos++, ((Byte) param).byteValue());
            else if (param instanceof Short)
                query.setShort(pos++, ((Short) param).shortValue());
            else if (param instanceof Integer)
                query.setInteger(pos++, ((Integer) param).intValue());
            else if (param instanceof Long)
                query.setLong(pos++, ((Long) param).longValue());
            else if (param instanceof Float)
                query.setFloat(pos++, ((Float) param).floatValue());
            else if (param instanceof Double)
                query.setDouble(pos++, ((Double) param).doubleValue());
            else if (param instanceof Boolean)
                query.setBoolean(pos++, ((Boolean) param).booleanValue());
            else if (param instanceof Character)
                query.setCharacter(pos++, ((Character) param).charValue());
            else if (param instanceof Date)
                query.setDate(pos++, (Date) param);
            else if (param instanceof Calendar)
                query.setCalendar(pos++, (Calendar) param);
            else if (param instanceof CalendarDateParam)
                query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue());
            else if (param instanceof TimestampParam)
                query.setTimestamp(pos++, ((TimestampParam) param).timestampValue());
            else if (param instanceof TimeParam)
                query.setTime(pos++, ((TimeParam) param).timeValue());
            else if (param instanceof String)
                query.setString(pos++, (String) param);
            else if (param instanceof TextParam)
                query.setText(pos++, ((TextParam) param).textValue());
            else if (param instanceof byte[])
                query.setBinary(pos++, (byte[]) param);
            else if (param instanceof BigDecimal)
                query.setBigDecimal(pos++, (BigDecimal) param);
            else if (param instanceof BigInteger)
                query.setBigInteger(pos++, (BigInteger) param);
            else if (param instanceof Locale)
                query.setLocale(pos++, (Locale) param);
            else if (param instanceof EntityParam)
                query.setEntity(pos++, ((EntityParam) param).entityValue());
            else if (param instanceof Serializable)
                query.setSerializable(pos++, (Serializable) param);
            else
                query.setEntity(pos++, param);
        }
    }
}

From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java

License:Open Source License

public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters,
        final boolean cacheable) {
    return executeListResult(ContentKey.class, new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query compiled = session.createQuery(hqlQuery);
            compiled.setCacheable(cacheable);

            for (String key : parameters.keySet()) {
                Object value = parameters.get(key);
                if (value instanceof Date) {
                    compiled.setTimestamp(key, (Date) value);
                } else if (value instanceof String) {
                    compiled.setString(key, (String) value);
                } else if (value instanceof Boolean) {
                    compiled.setBoolean(key, (Boolean) value);
                } else if (value instanceof Long) {
                    compiled.setLong(key, (Long) value);
                } else if (value instanceof Integer) {
                    compiled.setInteger(key, (Integer) value);
                } else if (value instanceof Byte) {
                    compiled.setByte(key, (Byte) value);
                } else if (value instanceof byte[]) {
                    compiled.setBinary(key, (byte[]) value);
                } else if (value instanceof Float) {
                    compiled.setFloat(key, (Float) value);
                } else if (value instanceof Double) {
                    compiled.setDouble(key, (Double) value);
                } else if (value instanceof BigDecimal) {
                    compiled.setBigDecimal(key, (BigDecimal) value);
                } else if (value instanceof Short) {
                    compiled.setShort(key, (Short) value);
                } else if (value instanceof BigInteger) {
                    compiled.setBigInteger(key, (BigInteger) value);
                } else if (value instanceof Character) {
                    compiled.setCharacter(key, (Character) value);
                } else {
                    compiled.setParameter(key, value);
                }//from w w  w .jav a2  s. c o  m
            }

            final List result = compiled.list();

            LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size());

            for (Object value : result) {
                if (value instanceof ContentKey) {
                    distinctContentKeySet.add((ContentKey) value);
                } else {
                    Object[] valueList = (Object[]) value;
                    distinctContentKeySet.add(((ContentKey) valueList[0]));
                }
            }

            List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size());
            distinctContentKeyList.addAll(distinctContentKeySet);
            return distinctContentKeyList;
        }
    });
}

From source file:com.exilant.eGov.src.domain.GeneralLedgerDetail.java

License:Open Source License

@Transactional
public void insert() throws SQLException {
    setId(String.valueOf(PrimaryKeyGenerator.getNextKey("GeneralLedgerDetail")));

    final String insertQuery = "INSERT INTO GeneralLedgerDetail (id, generalLedgerId, detailKeyId, detailTypeId,amount) "
            + "VALUES ( ?, ?, ?, ?, ?)";

    final Query pst = persistenceService.getSession().createSQLQuery(insertQuery);
    pst.setLong(0, Long.valueOf(id));
    pst.setLong(1, Long.valueOf(glId));
    pst.setLong(2, Long.valueOf(detailKeyId));
    pst.setLong(3, Long.valueOf(detailTypeId));
    pst.setBigDecimal(4, new BigDecimal(detailAmt));
    pst.executeUpdate();/*from   w  ww.  j  a  v  a  2s.com*/
    if (LOGGER.isInfoEnabled())
        LOGGER.info(insertQuery);
}

From source file:com.farmafene.aurius.dao.DiccionarioFactoryImpl.java

License:Open Source License

/**
 * {@inheritDoc}//from w ww.ja  va2s . c o  m
 * 
 * @see com.farmafene.aurius.core.IDiccionarioFactory#getServicio(java.lang.String)
 */
public Servicio getServicio(String id) throws IllegalArgumentException {

    if (logger.isDebugEnabled()) {
        logger.debug("getServicio(" + id + ")");
    }
    String grupo = FormatUtil.getAplicacionFromIdServicio(id);
    BigDecimal svr_id = new BigDecimal(FormatUtil.getOperacionFromIdServicio(id));

    Session sess = null;
    ServicioSvr svr = null;
    SessionFactory sf = DiccionarioSessionFactory.getSessionFactory();
    sess = sf.getCurrentSession();
    Query q = sess.createQuery("select s from ServicioSvr s,ServicioDesc d where " + "s.id.grupo = d.id.grupo"
            + " and s.id.id = d.id.id" + " and s.id.version = d.version"
            + " and d.id.grupo=:grupo and d.id.id=:id");
    q.setString("grupo", grupo);
    q.setBigDecimal("id", svr_id);
    if (logger.isDebugEnabled()) {
        logger.debug("getServicio(): Begin Query");
    }
    svr = (ServicioSvr) q.uniqueResult();
    if (svr != null) {
        svr.getDescripcion().getRoles();
        if (logger.isDebugEnabled()) {
            logger.debug("getServicio(): End Query");
        }
    }
    return getServicioFromServicioSvr(svr);

}

From source file:com.flexcore.dao_orm.PagosDAO.java

@Override
public Pagos crearPago(Pagos pago) {

    Transaction trans = session.beginTransaction();

    Query q = session.createSQLQuery(" { call crearPagoORM (?, ?, ?) }")
            .setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    q.setInteger(0, pago.getIdCuentaOrigen());
    q.setInteger(1, pago.getIdCuentaDestino());
    q.setBigDecimal(2, pago.getMonto());
    q.executeUpdate();/*ww w  . ja v  a2s .  co  m*/

    trans.commit();
    session.close();
    return pago;

}

From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java

License:Open Source License

private void setObjectFromType(Object value, Query query, int i) {
    if (value instanceof Date) {
        query.setDate(i, (Date) value);
    } else if (value instanceof BigDecimal) {
        query.setBigDecimal(i, (BigDecimal) value);
    } else if (value instanceof BigInteger) {
        query.setBigInteger(i, (BigInteger) value);
    } else {/*from   w w w  . j a v  a2s  . co  m*/
        query.setParameter(i, value);
    }
}