Example usage for org.hibernate SQLQuery setLong

List of usage examples for org.hibernate SQLQuery setLong

Introduction

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

Prototype

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

Source Link

Document

Bind a positional long-valued parameter.

Usage

From source file:br.gov.jfrj.siga.hibernate.ExDao.java

License:Open Source License

/**
 * Le da tabela o campo do tipo BLOB e converte para um array de bytes.
 * mtodo no usa as facilidade do HIBERNATE em virtude da ausencia de
 * suporte para estes campos./*from   w w  w . java  2s  .com*/
 */
// public ExModelo consultarConteudoBlob(final ExModelo modelo)
// throws SQLException {
// final StringBuilder cmd = new StringBuilder(
// "SELECT CONTEUDO_BLOB_MOD FROM EX_MODELO " + "WHERE ID_MOD= ? ");
// final Connection conn = getSessao().connection();
// final PreparedStatement psBlob = conn.prepareStatement(cmd.toString());
// psBlob.setLong(1, modelo.getIdMod());
// final ResultSet rset = psBlob.executeQuery();
// rset.next();
// final Blob blob = rset.getBlob("CONTEUDO_BLOB_MOD");
// if (blob != null) {
// final byte[] ba = blob.getBytes(1, (int) blob.length());
// modelo.setConteudoBlobMod2(ba);
// }
// return modelo;
// }

public List consultarPaginaInicial(DpPessoa pes, DpLotacao lot, Integer idTipoForma) {
    try {
        SQLQuery sql = (SQLQuery) getSessao().getNamedQuery("consultarPaginaInicial");

        sql.setLong("idPessoaIni", pes.getIdPessoaIni());
        sql.setLong("idLotacaoIni", lot.getIdLotacaoIni());
        sql.setInteger("idTipoForma", idTipoForma);

        List result = sql.list();

        return result;

    } catch (final NullPointerException e) {
        return null;
    }
}

From source file:ch.astina.hesperid.dao.hibernate.AssetDAOHibernate.java

License:Apache License

public void deleteClientHierarchy(ClientHierarchy clientHierarchy) {
    if (clientHierarchy == null || clientHierarchy.getId() == null) {
        return;//from w  w  w  . j a  va  2s.c o m
    }

    SQLQuery query = session.createSQLQuery("DELETE FROM client_hierarchy WHERE id = ?");
    query.setLong(0, clientHierarchy.getId());

    query.executeUpdate();
}

From source file:ch.astina.hesperid.dao.hibernate.AssetDAOHibernate.java

License:Apache License

public void deleteAllClientHierarchies(Asset asset) {
    if (asset == null || asset.getId() == null) {
        return;//from w ww . j  a  v  a 2  s . c om
    }

    SQLQuery query = session
            .createSQLQuery("DELETE FROM client_hierarchy WHERE first_asset = ? OR second_asset = ?");
    query.setLong(0, asset.getId());
    query.setLong(1, asset.getId());

    query.executeUpdate();
}

From source file:ch.astina.hesperid.dao.hibernate.AssetDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Asset> getAllRelatedAssets(Asset asset) {
    List<Asset> assets = new ArrayList<Asset>();

    String sql = "SELECT a.* FROM client_hierarchy ch INNER JOIN asset a ON a.id = ch.first_asset  WHERE first_asset = ?";
    SQLQuery query = session.createSQLQuery(sql);
    query.setLong(0, asset.getId());
    query.addEntity(Asset.class);

    assets.addAll(query.list());//from w  w w.j  a v a 2 s . c  o m

    sql = "SELECT a.* FROM client_hierarchy ch INNER JOIN asset a ON a.id = ch.first_asset  WHERE second_asset = ?";
    query = session.createSQLQuery(sql);
    query.setLong(0, asset.getId());
    query.addEntity(Asset.class);

    assets.addAll(query.list());

    return assets;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAO.java

License:Apache License

/**
 * Executes given <var>sql</var>.
 * <p>//  w  ww. j a  v  a  2 s  .  co m
 * Should be an <code>INSERT</code> or <code>UPDATE</code> statement.
 * </p>
 */
protected final void executeUpdate(final String sql, final Serializable... parameters) {
    getHibernateTemplate().execute(new HibernateCallback() {

        //
        // HibernateCallback
        //

        public final Object doInHibernate(final Session session) throws HibernateException, SQLException {
            final SQLQuery sqlQuery = session.createSQLQuery(sql);
            for (int i = 0; i < parameters.length; i++) {
                Serializable parameter = parameters[i];
                if (parameter instanceof Long) {
                    sqlQuery.setLong(i, (Long) parameter);
                } else if (parameter instanceof Integer) {
                    sqlQuery.setInteger(i, (Integer) parameter);
                } else if (parameter instanceof Character) {
                    sqlQuery.setCharacter(i, (Character) parameter);
                } else if (parameter instanceof Date) {
                    sqlQuery.setDate(i, (Date) parameter);
                } else {
                    sqlQuery.setSerializable(i, parameter);
                }
            }
            sqlQuery.executeUpdate();
            return null;
        }
    });
}

From source file:com.aw.core.db.support.WhereBuilder2.java

License:Open Source License

public void setParams(SQLQuery sqlQuery) {
    for (int i = 0; i < params.size(); i++) {
        Object param = params.get(i);
        if (param instanceof Long)
            sqlQuery.setLong(i, (Long) param);
        else if (param instanceof Integer)
            sqlQuery.setInteger(i, (Integer) param);
        else if (param instanceof Date)
            sqlQuery.setDate(i, (Date) param);
        else if (param instanceof String)
            sqlQuery.setString(i, (String) param);
        else if (param instanceof BigDecimal)
            sqlQuery.setBigDecimal(i, (BigDecimal) param);
        else if (param == null)
            sqlQuery.setParameter(i, null);
        else//from   ww w .ja v  a 2s.co m
            throw new IllegalArgumentException("Implementar codigo param:" + param.getClass());
    }
    //To change body of created methods use File | Settings | File Templates.
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

/** Get the size of a multiple json value item */
public static int getJsonMultipleValueDataSize(Session session, JsonMultipleValueItem item)
        throws ConnexienceException {
    SQLQuery q = session.createSQLQuery("select count(id) from datasetjson where itemid=:itemid");
    q.setLong("itemid", item.getId());
    //q.addEntity(Long.class);
    return ((Number) q.uniqueResult()).intValue();
}

From source file:com.dungnv.streetfood.business.CategoryDishBusiness.java

License:Open Source License

@Override
public List<CategoryDTO> getListCategoryByDish(String userName, String localeCode, String countryCode,
        String token//
        , String id, boolean isIn) {

    StringBuilder sql = new StringBuilder("select c.id, c.name from Category c ");
    sql.append(" where c.id ");
    sql.append(isIn ? " in " : " not in ");
    sql.append(" (select distinct category_id from category_dish where dish_id = ? ) ");

    SQLQuery query = gettDAO().getSession().createSQLQuery(sql.toString());
    query.addScalar("id", StringType.INSTANCE);
    query.addScalar("name", StringType.INSTANCE);
    query.setLong(0, Long.valueOf(id));
    query.setResultTransformer(Transformers.aliasToBean(CategoryDTO.class));
    return query.list();
}

From source file:com.dungnv.streetfood.business.CategoryDishBusiness.java

License:Open Source License

@Override
public List<DishDTO> getListDishByCategory(String userName, String localeCode, String countryCode, String token//
        , String id, boolean isIn) {
    StringBuilder sql = new StringBuilder("select c.id, c.name from dish c ");
    sql.append(" where c.id ");
    sql.append(isIn ? "in" : " not in");
    sql.append(" (select distinct dish_id from category_dish where category_id = ? ) ");

    SQLQuery query = gettDAO().getSession().createSQLQuery(sql.toString());
    query.addScalar("id", StringType.INSTANCE);
    query.addScalar("name", StringType.INSTANCE);
    query.setLong(0, Long.valueOf(id));
    query.setResultTransformer(Transformers.aliasToBean(DishDTO.class));
    return query.list();
}

From source file:com.dungnv.streetfood.business.DishArticleBusiness.java

License:Open Source License

@Override
public List<ArticleDTO> getListArticleByDish(String userName, String localeCode, String countryCode,
        String token, String id) {
    SQLQuery query = gettDAO().getSession().createSQLQuery("select c.id, c.name from article c "
            + " inner join dish_article l on c.id = l.article_id" + " where l.dish_id = ? ");
    query.addScalar("id", StringType.INSTANCE);
    query.addScalar("name", StringType.INSTANCE);
    query.setLong(0, Long.valueOf(id));
    query.setResultTransformer(Transformers.aliasToBean(ArticleDTO.class));
    return query.list();
}