Example usage for org.hibernate SQLQuery setBigInteger

List of usage examples for org.hibernate SQLQuery setBigInteger

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setBigInteger.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setBigInteger(int position, BigInteger val) 

Source Link

Document

Bind a positional BigDecimal-valued parameter.

Usage

From source file:es.emergya.bbdd.dao.RecursoHome.java

License:Open Source License

@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
public void updateLastGpsSQL(HistoricoGPS historicoGPS, BigInteger idRecurso) {
    SQLQuery query = getSession()
            .createSQLQuery("update recursos set fk_historico_gps = :HISTORICO where x_recurso = :ID");
    query.setBigInteger("ID", idRecurso);
    query.setLong("HISTORICO", historicoGPS.getId());
    query.executeUpdate();/*from w  w w .  j a  v  a 2s . c  om*/
}

From source file:org.mousephenotype.dcc.utils.persistence.HibernateManager.java

License:Apache License

public <T> List<T> nativeQuery(String query, Class<T> clazz,
        com.google.common.collect.Table<String, Class, Object> parameters) {
    this.refreshSession();
    Transaction transaction = null;/*from   w ww.j  ava2 s .  c  o m*/
    List<T> result = null;
    try {
        transaction = session.beginTransaction();
        SQLQuery sqlQuery = session.createSQLQuery(query).addEntity(clazz);
        if (parameters != null) {
            for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) {
                if (entry.getColumnKey().equals(String.class)) {
                    sqlQuery.setString(entry.getRowKey(), (String) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(Long.class)) {
                    sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(BigInteger.class)) {
                    sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue());
                    continue;
                }
                logger.error("Type {} not registered", entry.getValue().getClass());
            }
        }

        result = sqlQuery.list();
        transaction.commit();
    } catch (RuntimeException ex) {
        if (transaction != null) {
            logger.error("rolling back transaction {}", ex);
            transaction.rollback();
        }
    }
    return result;
}

From source file:org.mousephenotype.dcc.utils.persistence.HibernateManager.java

License:Apache License

public List nativeQuery(String query, Map<String, org.hibernate.type.Type> scalars,
        com.google.common.collect.Table<String, Class, Object> parameters) {

    this.refreshSession();
    Transaction transaction = null;/*from   w  w w  .  j  ava2  s .c o m*/
    List result = null;
    try {
        transaction = session.beginTransaction();
        SQLQuery sqlQuery = session.createSQLQuery(query);
        if (scalars != null) {
            for (Map.Entry<String, org.hibernate.type.Type> entry : scalars.entrySet()) {
                sqlQuery.addScalar(entry.getKey(), entry.getValue());
            }
        }
        if (parameters != null) {
            for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) {
                if (entry.getColumnKey().equals(String.class)) {
                    sqlQuery.setString(entry.getRowKey(), (String) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(Long.class)) {
                    sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue());
                    continue;
                }
                if (entry.getColumnKey().equals(BigInteger.class)) {
                    sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue());
                    continue;
                }
                logger.error("Type {} not registered", entry.getValue().getClass());
            }
        }

        result = sqlQuery.list();
        transaction.commit();
    } catch (RuntimeException ex) {
        if (transaction != null) {
            logger.error("rolling back transaction {}", ex);
            transaction.rollback();
        }
    }
    return result;
}

From source file:org.tsm.concharto.service.EventSearchServiceHib.java

License:Apache License

private SQLQuery createQuery(String prefix, Geometry boundingBox, SearchParams params) {
    StringBuffer select = new StringBuffer(prefix).append(SQL_SELECT_STUB);
    select.append(SQL_TIME_JOIN); //always join on time, so we can order by time
    StringBuffer clause = new StringBuffer();
    boolean hasConjuncted = false;
    if (params.getVisibility() == Visibility.NORMAL) {
        hasConjuncted = addClause(hasConjuncted, clause, SQL_VISIBLE_CLAUSE);
    } else if (params.getVisibility() == Visibility.HIDDEN) {
        hasConjuncted = addClause(hasConjuncted, clause, SQL_HIDDEN_CLAUSE);
    } else if (params.getVisibility() == Visibility.FLAGGED) {
        hasConjuncted = addClause(hasConjuncted, clause, SQL_FLAGGED_CLAUSE);
    }//from  w w w.j  a v a2  s .  c o m
    if (!StringUtils.isEmpty(params.getTextFilter())) {
        select.append(SQL_SEARCH_JOIN);
        hasConjuncted = addClause(hasConjuncted, clause, SQL_MATCH_CLAUSE);
    }
    if (boundingBox != null) {
        select.append(SQL_GEO_JOIN);
        hasConjuncted = addClause(hasConjuncted, clause, SQL_MBRWITHIN_CLAUSE);
    }
    if (params.getTimeRange() != null) {
        if (params.isIncludeTimeRangeOverlaps()) {
            addClause(hasConjuncted, clause, SQL_TIMERANGE_CLAUSE);
        } else {
            addClause(hasConjuncted, clause, SQL_TIMERANGE_EXCLUDE_OVERLAPS_CLAUSE);
        }
    }
    if (!StringUtils.isEmpty(params.getUserTag())) {
        //special case for empty tags
        if (!UNTAGGED.equals(params.getUserTag())) {
            select.append(SQL_TAG_JOIN);
            hasConjuncted = addClause(hasConjuncted, clause, SQL_TAG_CLAUSE);
        } else {
            select.append(SQL_TAG_EMPTY_JOIN);
            hasConjuncted = addClause(hasConjuncted, clause, SQL_TAG_EMPTY_CLAUSE);
        }
    }
    if (!StringUtils.isEmpty(params.getCatalog())) {
        hasConjuncted = addClause(hasConjuncted, clause, SQL_CATALOG_CLAUSE);
    }
    clause.append(SQL_ORDER_CLAUSE);
    select.append(clause);

    // Note: Hibernate always uses prepared statements
    SQLQuery sqlQuery = this.sessionFactory.getCurrentSession().createSQLQuery(select.toString());

    if (boundingBox != null) {
        sqlQuery.setString(PARAM_GEOM_TEXT, boundingBox.toText());
    }
    if (!StringUtils.isEmpty(params.getTextFilter())) {
        sqlQuery.setString(PARAM_SEARCH_TEXT, params.getTextFilter());
    }
    if (!StringUtils.isEmpty(params.getUserTag())) {
        //special case for empty tags
        if (!UNTAGGED.equals(params.getUserTag())) {
            sqlQuery.setString(PARAM_TAG, StringUtils.trim(params.getUserTag()));
        }
    }
    if (!StringUtils.isEmpty(params.getCatalog())) {
        sqlQuery.setString(PARAM_CATALOG, StringUtils.trim(params.getCatalog()));
    }
    if (params.getTimeRange() != null) {
        sqlQuery.setBigInteger(PARAM_EARLIEST,
                BigInteger.valueOf(params.getTimeRange().getBegin().getDate().getTime()));
        sqlQuery.setBigInteger(PARAM_LATEST,
                BigInteger.valueOf(params.getTimeRange().getEnd().getDate().getTime()));
    }
    return sqlQuery;
}