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.bancomat.springmvc.dao.UtenteDao.java

public static boolean isUtente(int id) {
    session = HibernateUtil.getSessionFactory().openSession();
    Transaction tsc = session.beginTransaction();
    Query qry = session.createQuery("from Utente where idUtente = :id");
    qry.setInteger("id", id);
    if (qry.uniqueResult() != null) {
        return true;
    } else {//from  www.  j  a v a2s. co  m
        return false;
    }

}

From source file:com.bolao.persistencia.dao.GrupoDAO.java

public List<Grupo> list(ModoConsulta mc, Object object) {
    Session session = HibernateFactory.getSessionFactory();
    session.beginTransaction();/*  www.j  a va2 s.  c  o m*/
    if (mc == ModoConsulta.DEFAULT || object == null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo");
        lista = query.list();
    } else if (mc == ModoConsulta.CODIGO && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo where codigo =:XCODIGO");
        query.setInteger("XCODIGO", Integer.parseInt(String.valueOf(object)));
        lista = query.list();
    } else if (mc == ModoConsulta.GRUPO && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo where descricao like :XDESCRICAO");
        query.setString("XDESCRICAO", "%" + String.valueOf(object) + "%");
        lista = query.list();
    }
    session.getTransaction().commit();
    session.close();
    return lista;
}

From source file:com.bolao.persistencia.dao.TimeDAO.java

public List<Time> list(ModoConsulta modoConsulta, Object object, Object dataObject) {
    try {/*w w w. ja v  a  2s.co  m*/
        Session session = HibernateFactory.getSessionFactory();
        session.beginTransaction();
        if (modoConsulta == ModoConsulta.CIDADE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.cidade like :XCIDADE order by t.codigo,t.cidade ");
            query.setString("XCIDADE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.CODIGO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.codigo =:xcodigo order by t.cidade asc,t.codigo desc");
            query.setInteger("xcodigo", Integer.parseInt(String.valueOf(object)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DATA_CADASTRO && object != null && !object.toString().isEmpty()
                && dataObject != null && !dataObject.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(
                    " from Time t where t.datacadastro between :XDATAINI AND :XDATAFIM  order by t.cidade asc,t.codigo desc");
            query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object)));
            query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DATA_FUNDACAO && object != null && !object.toString().isEmpty()
                && dataObject != null && !dataObject.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(
                    " from Time t where t.datafundacao between :XDATAINI AND :XDATAFIM order by t.cidade asc,t.codigo desc");
            query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object)));
            query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DEFAULT || object == null || object.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(" from Time t order by t.codigo,t.cidade ");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.EMAIL && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.email like :XEMAIL order by t.codigo,t.cidade");
            query.setString("XEMAIL", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.ENDERECO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.endereco like :XENDERECO order by t.codigo,t.cidade");
            query.setString("XENDERECO", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.SITE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.site like :XSITE order by t.codigo,t.cidade");
            query.setString("XSITE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.TELEFONE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.telefone like :XTELEFONE order by t.codigo,t.cidade");
            query.setString("XTELEFONE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.TIME && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.nome like :XNOME order by t.codigo,t.cidade");
            query.setString("XNOME", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DESCRICAO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.descricao like :XNOME order by t.codigo,t.cidade");
            query.setString("XNOME", "%" + String.valueOf(object) + "%");
            lista = query.list();
        }
        session.getTransaction().commit();
        session.close();
    } catch (Exception e) {
    }
    return lista;
}

From source file:com.bullx.cacdata.CACData.java

License:Open Source License

@SuppressWarnings("unchecked")
private DOMElement getMonitorData() {
    DOMElement monitorNode = new DOMElement("monitordata");

    // sensor?/*from   w w w  .j  ava  2s.co  m*/
    int dataNumber = 0;

    ConfigIedDAO iedDAO = new ConfigIedDAO();
    List<ConfigIed> list = iedDAO.findAll();

    monitorNode.setAttribute("cacid", list.get(0).getConfigCac().getCacId());
    HashMap<String, String> objectMapper = new HashMap<String, String>();
    //add mappers the first is the ied class, the second is the query string
    objectMapper.put("SIML", "DataSiml");
    objectMapper.put("SPDC", "DataSpdc");
    objectMapper.put("MMXN", "DataMmxn");
    objectMapper.put("ZSAR", "DataZsar");
    objectMapper.put("SIMG", "DataSimg");
    objectMapper.put("SENV", "DataSenv");

    for (int i = 0; i < list.size(); i++) {
        ConfigIed ied = list.get(i);

        String objectString = objectMapper.get(ied.getLnClass());
        String queryString = "from " + objectString
                + " as inst where inst.lnInst=? order by inst.dataTime desc";
        Query query = iedDAO.getSession().createQuery(queryString);
        query.setInteger(0, ied.getLnInst());
        query.setFirstResult(0);
        query.setMaxResults(1);
        List<Node> thizNodes = getDataNodes(ied.getLnClass(), query, ied);
        for (int j = 0; j < thizNodes.size(); j++, dataNumber++) {
            monitorNode.add(thizNodes.get(j));
        }
    }

    monitorNode.setAttribute("datanodenum", Integer.toString(dataNumber));

    return monitorNode;
}

From source file:com.campitos.spring.web.DAOAlumnoImpl.java

/**
 * Este metodo busca un cliente por medio de su Id
 * @param id Este parametro es el Id del cliente que se quiere buscar
 * @return El tipo de retorno es el cliente buscado
 *///from w  ww  .  ja v a  2  s .  c o  m
public Alumno buscarPorId(int id) {
    begin();
    Query q = getSession().createQuery("from Alumno where id = :id");
    q.setInteger("id", id);
    Alumno p = (Alumno) q.uniqueResult();
    commit();
    close();
    return p;

}

From source file:com.campitos.spring.web.DAOCalificacionImpl.java

/**
 * Este metodo busca un cliente por medio de su Id
 * @param id Este parametro es el Id del cliente que se quiere buscar
 * @return El tipo de retorno es el cliente buscado
 *//*  ww  w .  j a  v a  2s . c  o  m*/
public Calificacion buscarPorId(int id) {
    begin();
    Query q = getSession().createQuery("from Calificacion where id = :id");
    q.setInteger("id", id);
    Calificacion p = (Calificacion) q.uniqueResult();
    commit();
    close();
    return p;

}

From source file:com.candy.db.FundamentalDataProc.java

/**
 * select one record by date(year,quarter) and type TODO year and quarter
 * @param symbol//from  w  w w. j  av a 2s  .c o m
 * @param type
 * @param year
 * @param quarter
 * @return 
 */
public FundamentalDataRec readDataByDate(String symbol, int type, int year, int quarter) {
    try {
        begin();
        Query q = getSession().createQuery(
                "from Fundamentaldata where symbol = :symbol and year = :year and quarter = :quarter and type = :type");
        q.setString("symbol", symbol);
        q.setInteger("year", year);
        q.setInteger("quarter", quarter);
        q.setInteger("type", type);
        Fundamentaldata fdata = (Fundamentaldata) q.uniqueResult();
        commit();

        if (fdata == null)
            return null;
        FundamentalDataRec rec = new FundamentalDataRec();
        for (int i = 0; i < methodGetNameLst.length; i++) {
            try {
                Double value = (Double) methodGetValueLst[i].invoke(fdata); // return double
                String name = (String) methodGetNameLst[i].invoke(fdata);
                if (name != null) {
                    rec.setNameValue(name, value);
                }
            } catch (Exception e) {
                // skip it
                System.out.println("ERROR - unable to get column value/name = " + i);
            }
        }
        return rec;
    } catch (HibernateException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.candy.db.FundamentalDataProc.java

/**
 * read records from table/*from   w w  w.  j a va2 s .  c  o  m*/
 * @param symbol
 * @param count
 * @param qtv
 * @return 
 */
public ArrayList<FundamentalDataRec> readDataByCount(String symbol, int type, int count, boolean qtv) {
    try {
        begin();
        Query q = null;
        if (qtv)
            q = getSession().createQuery(
                    "from Fundamentaldata where symbol = :symbol and quarter != 0 and type = :type order by year desc");
        else
            q = getSession().createQuery(
                    "from Fundamentaldata where symbol = :symbol and quarter = 0 and type = :type order by year desc");
        q.setString("symbol", symbol);
        q.setInteger("type", type);
        if (count != 0) {
            q.setFirstResult(0);
            q.setMaxResults(count);
        }
        List<Fundamentaldata> results = q.list();
        commit();
        if (results.isEmpty()) {
            return null;
        } else {
            ArrayList<FundamentalDataRec> retLst = new ArrayList();
            for (Fundamentaldata fdata : results) {
                FundamentalDataRec rec = new FundamentalDataRec();
                rec.year = fdata.getId().getYear();
                rec.quarter = fdata.getId().getQuarter();
                rec.setType(fdata.getId().getType());
                for (int i = 0; i < methodGetValueLst.length; i++) {
                    try {
                        Double value = (Double) methodGetValueLst[i].invoke(fdata); // return double
                        String name = (String) methodGetNameLst[i].invoke(fdata);
                        if (name != null) {
                            rec.setNameValue(name, value);
                        }
                        //                            else {  // TODO
                        //                                System.out.println("ERROR - fundamental name is null " + i);
                        //                            }
                    } catch (Exception e) {
                        System.out.println("ERROR - unable to get column value/name = " + i);
                    }
                }
                retLst.add(rec);
            }
            return retLst;
        }
    } catch (HibernateException e) {
        return null;
    }
}

From source file:com.candy.db.FundamentalDataProc.java

/**
 * /*from w w w . j a va2s.c  om*/
 * @param symbol
 * @param type
 * @param year
 * @param quarter
 * @return 
 */
//    @Deprecated
//    public boolean isDataExist(String symbol, int type, int year, int quarter) {
//        try {
//            begin();
//            Query q = getSession().createQuery("from Fundamentaldata where symbol = :symbol and year = :year and quarter = :quarter and type = :type");            
//            q.setString("symbol", symbol);
//            q.setInteger("year", year);
//            q.setInteger("quarter", quarter);
//            q.setInteger("type", type);
//            boolean exist = (q.uniqueResult() != null);
//            commit();
//            return exist;
//        }catch (HibernateException e) {
//            return false;
//        }        
//    }

public boolean isDataExistByFileName(String symbol, String fileName, int type) {
    try {
        begin();
        Query q = getSession().createQuery(
                "from Fundamentaldata where symbol = :symbol and filename = :filename and type = :type");
        q.setString("symbol", symbol);
        q.setInteger("type", type);
        q.setString("filename", fileName);
        boolean exist = (q.uniqueResult() != null);
        commit();
        return exist;
    } catch (HibernateException e) {
        return false;
    }
}

From source file:com.candy.db.FundamentalDataProc.java

public ArrayList<FundamentalDataRec> getLastQData(String symbol, int lastQoffset) {
    try {/*from  w  w w .java  2  s.  c  o  m*/
        Query q = getSession().createQuery(
                "from Fundamentaldata where symbol = :symbol and quarter > :offset order by year desc");
        q.setString("symbol", symbol);
        q.setInteger("offset", lastQoffset);
        List<Fundamentaldata> results = q.list();
        if (results.isEmpty()) {
            return null;
        } else {
            ArrayList<FundamentalDataRec> retLst = new ArrayList();
            for (Fundamentaldata fdata : results) {
                FundamentalDataRec rec = new FundamentalDataRec();
                rec.year = fdata.getId().getYear();
                rec.quarter = fdata.getId().getQuarter() - lastQoffset;
                rec.setType(fdata.getId().getType());
                for (int i = 0; i < methodGetValueLst.length; i++) {
                    try {
                        Double value = (Double) methodGetValueLst[i].invoke(fdata); // return double
                        String name = (String) methodGetNameLst[i].invoke(fdata);
                        if (name != null) {
                            rec.setNameValue(name, value);
                        }
                    } catch (Exception e) {
                        System.out.println("ERROR - unable to get column value/name = " + i);
                    }
                }
                retLst.add(rec);
            }
            return retLst;
        }
    } catch (HibernateException e) {
        return null;
    }
}