Example usage for org.hibernate SQLQuery setInteger

List of usage examples for org.hibernate SQLQuery setInteger

Introduction

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

Prototype

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

Source Link

Document

Bind a positional int-valued parameter.

Usage

From source file:br.com.bluesoft.pronto.dao.SprintDao.java

License:Open Source License

private void preencheTotaisDeEsforcoEValorDeNegocioDoSprint(final Sprint sprint) {
    final String sql = "select sprint, sum(t.valor_de_negocio) as valor_de_negocio_total, sum(t.esforco) as esforco_total from ticket t where t.sprint = :sprint and t.pai is null group by sprint";
    final SQLQuery query = getSession().createSQLQuery(sql);
    query.setInteger("sprint", sprint.getSprintKey());
    query.addScalar("sprint", Hibernate.INTEGER);
    query.addScalar("valor_de_negocio_total", Hibernate.INTEGER);
    query.addScalar("esforco_total", Hibernate.DOUBLE);
    final Object[] o = (Object[]) query.uniqueResult();

    int valorDeNegocioTotal = 0;
    double esforcoTotal = 0d;

    if (o != null) {
        valorDeNegocioTotal = (Integer) o[1];
        esforcoTotal = (Double) o[2];
    }/*from   ww  w  .j av  a2s .  c om*/

    sprint.setEsforcoTotal(esforcoTotal);
    sprint.setValorDeNegocioTotal(valorDeNegocioTotal);

}

From source file:br.com.sgejs.dao.DaoAluno.java

public int salvarAluno(int arquivo, Aluno aluno) throws HibernateException {
    int id = (int) persiste(aluno);
    SQLQuery query = sessao
            .createSQLQuery("insert into arquivo_alunos(arquivo_id,aluno_id) values(:arquivo,:aluno)");
    return query.setInteger("arquivo", arquivo).setInteger("aluno", id).executeUpdate();
}

From source file:br.com.sgejs.dao.DaoArquivo.java

public void atualizar(Arquivo arquivo) throws HibernateException {
    SQLQuery query = sessao
            .createSQLQuery("update arquivo set ano=:ano, caixa=:caixa, curso=:curso, tipo=:tipo where id=:id");
    query.setInteger("ano", arquivo.getAno()).setString("caixa", arquivo.getCaixa())
            .setInteger("curso", arquivo.getCurso().ordinal()).setInteger("tipo", arquivo.getTipo().ordinal())
            .setLong("id", arquivo.getId());
    query.executeUpdate();/* w w  w .  j  a va 2  s  .c o  m*/
}

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./*  w  w  w. j av  a  2  s.  c om*/
 */
// 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:ca.myewb.controllers.actions.csv.RenewalList.java

License:Open Source License

public void handle(Context ctx) throws Exception {
    if (urlParams.getParam() == null && !currentUser.isAdmin()) {
        throw getSecurityException("You don't have the right permissions to view a full upgrades list!",
                path + "/chapter/ChapterList");
    }// w  w w .  j a  v  a2  s.  com

    GroupModel chapter = null;

    if (urlParams.getParam() != null) {
        chapter = (GroupModel) getAndCheckFromUrl(GroupModel.class);

        if (!Permissions.canAdministerGroupMembership(currentUser, chapter)) {
            throw getSecurityException("You don't have the right permissions to view an upgrades list!",
                    path + "/chapter/ChapterInfo/" + chapter.getId());
        }
    }

    Vector<String[]> csvData = new Vector<String[]>();
    csvData.add(new String[] { "Upgrade Date", "First name", "Last name", "Email", "Phone", "Address1", "Suite",
            "Address2", "City", "Province", "Postal Code", "Country", "Renewal?", "Student?", "Upgraded by",
            "Language" });
    String query = "select " + "r.start, " + "u.firstname, " + "u.lastname, " + "u.email, " + "u.phone, "
            + "u.address1, " + "u.suite, " + "u.address2, " + "u.city, " + "u.province, " + "u.postalcode, "
            + "u.country, " + "(case when prev.id is null then 'no' else 'yes' end) as renewal, "
            + "(case when u.student = 'n' then 'no' else 'yes' end) as student, "
            + "(case when u.upgradelevel = 'n' then 'National' when u.upgradelevel='c' then 'Chapter' else 'Unknown' end) as upgradedby, "
            + "(case when u.language = 'fr' then 'fr' else 'en' end) as language " + "from users u "
            + "left join roles prev on prev.userid = u.id and prev.end is not null and prev.groupid=6 "
            + "join roles r on r.userid=u.id and r.groupid=6 and r.end is null ";

    if (chapter != null) {
        query += "join roles chapter on chapter.userid=u.id and chapter.groupid=? and chapter.end is null and chapter.level='m' ";
    }

    query += "group by u.id order by r.start desc limit 0, 800";

    SQLQuery hibQuery = hibernateSession.createSQLQuery(query).addScalar("start", Hibernate.STRING)
            .addScalar("firstname", Hibernate.STRING).addScalar("lastname", Hibernate.STRING)
            .addScalar("email", Hibernate.STRING).addScalar("phone", Hibernate.STRING)
            .addScalar("address1", Hibernate.STRING).addScalar("suite", Hibernate.STRING)
            .addScalar("address2", Hibernate.STRING).addScalar("city", Hibernate.STRING)
            .addScalar("province", Hibernate.STRING).addScalar("postalcode", Hibernate.STRING)
            .addScalar("country", Hibernate.STRING).addScalar("renewal", Hibernate.STRING)
            .addScalar("student", Hibernate.STRING).addScalar("upgradedby", Hibernate.STRING)
            .addScalar("language", Hibernate.STRING);

    if (chapter != null) {
        hibQuery.setInteger(0, chapter.getId());
    }

    List memberList = hibQuery.list();

    Iterator members = memberList.iterator();

    while (members.hasNext()) {
        csvData.add(toStringArray((Object[]) members.next()));
    }

    try {
        this.setInterpageVar("csvData", csvData);
        this.setInterpageVar("csvFileName", "upgradeslist.csv");
    } catch (IllegalStateException e) {
        //session timeout!
        throw new IllegalStateException("Session timeout on CSV!", e);
    }

    throw new RedirectionException(path + "/csvfile/upgradeslist.csv");
}

From source file:celepsa.rrcc.da.DocumentoDA.java

public int registrarAdjunto(Tmadjunto objSistema, Tmdocumento objDocumento) throws Exception {

    String squery = "INSERT INTO Tmadjunto(id, tmDocumento_id, Nombre, eliminado, scodigo)"
            + "VALUES (:id,:doc, :nom, '0', :scod)";
    logger.debug("In registrarStakeholderDocumentoAdjunto");
    try {/*  w  w w  . jav  a 2s  .c o  m*/
        org.hibernate.Transaction tx = session.beginTransaction();
        SQLQuery query = session.createSQLQuery(squery);
        query.setInteger("id", CrearIDAdjunto());
        query.setInteger("doc", objDocumento.getId());
        query.setString("nom", objSistema.getNombre());
        query.setString("scod", objSistema.getScodigo());

        int res = query.executeUpdate();
        tx.commit();
        logger.debug("Out registrarStakeholderDocumentoAdjunto");
        return res;
    } catch (NumberFormatException | HibernateException e) {
        logger.error(e.getMessage());
        throw e;
    }
}

From source file:celepsa.rrcc.da.StakeholderDA.java

public int registrarStakeholderDocumento(Tmstakepersona objSistema1, DocumentoBE objSistema2) throws Exception {

    String squery = "INSERT INTO `RRHH`.`PersonaDocumento` (`tmDocumento_id`, `tmStakePersona_id`, est) VALUES (:doc, :per, 1);";
    logger.debug("registrarStakeholderDocumento");
    try {//from w  w w  .j  a  v  a2 s.c o m
        org.hibernate.Transaction tx = session.beginTransaction();
        SQLQuery query = session.createSQLQuery(squery);
        query.setInteger("doc", Integer.parseInt(objSistema2.getId()));
        query.setInteger("per", (objSistema1.getId()));
        int res = query.executeUpdate();
        tx.commit();
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

}

From source file:celepsa.rrcc.da.StakeholderDA.java

public boolean eliminarDocumento(Tmstakepersona objStakeholder) throws Exception {
    logger.debug("eliminarDocumento");
    String squery = " UPDATE tmDocumento SET  eliminado = 2 WHERE id = :id ";

    try {/*  w w  w  .  j  ava  2s.  co m*/

        org.hibernate.Transaction tx = session.beginTransaction();
        SQLQuery query = session.createSQLQuery(squery);
        query.setInteger("id", (objStakeholder.getId()));
        query.executeUpdate();
        tx.commit();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:celepsa.rrcc.da.StakeholderDA.java

public boolean eliminarDocumentoStakeholder(Tmstakepersona objStakeholder, DocumentoBE objDocumento)
        throws Exception {
    logger.debug("eliminarDocumentoStakeholder");
    String squery = "DELETE FROM `RRHH`.`PersonaDocumento` WHERE `tmDocumento_id`=:doc and`tmStakePersona_id`=:per";
    try {/*from  w w w. j  a v a  2s .c  o  m*/
        org.hibernate.Transaction tx = session.beginTransaction();
        SQLQuery query = session.createSQLQuery(squery);
        query.setInteger("doc", Integer.parseInt(objDocumento.getId()));
        query.setInteger("per", (objStakeholder.getId()));
        query.executeUpdate();
        tx.commit();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:celepsa.rrcc.da.StakeholderDA.java

public Tmstakepersona obtenerDocumento(Tmstakepersona objStakeholder) throws Exception {
    logger.debug("obtenerDocumento");
    try {/*from  w  w w. j  a v a  2 s  . c o m*/
        String sQuery = " from Tmstakepersona WHERE id = :id ";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.setInteger("id", (objStakeholder.getId()));
        return (Tmstakepersona) query.list().get(0);

    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}