Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

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

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java

License:Open Source License

public Object queryUnique(String namedQuery, Map<String, Object> params) {
    HibernateUtility.getSession().clear();
    Query query = HibernateUtility.getSession().getNamedQuery(namedQuery);
    for (String key : params.keySet()) {
        if (params.get(key) instanceof String) {
            query.setString(key, (String) params.get(key));
        }/*from  w w  w . ja va 2  s  . c o m*/
        if (params.get(key) instanceof Long) {
            query.setLong(key, (Long) params.get(key));
        }
        if (params.get(key) instanceof Integer) {
            query.setInteger(key, (Integer) params.get(key));
        }
        if (params.get(key) instanceof Boolean) {
            query.setBoolean(key, (Boolean) params.get(key));
        }
        if (params.get(key) instanceof Double) {
            query.setDouble(key, (Double) params.get(key));
        }
        if (params.get(key) instanceof Date) {
            query.setDate(key, (Date) params.get(key));
        }
    }
    return query.uniqueResult();
}

From source file:br.com.livraria.dao.FuncionarioDAO.java

public Funcionario autenticar(String cpf, String senha) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Funcionario funcionario = null;//ww  w. java  2 s  .  c o  m

    try {
        Query consulta = sessao.getNamedQuery("Funcionario.autenticar");
        consulta.setString("CPF", cpf);
        consulta.setString("Senha", senha);
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return funcionario;

}

From source file:br.com.ln.dao.ClienteDao.java

public static LnCliente grabClienteCpf(String documento) {

    Session session = null;/*from  ww  w  .  j a  va2s  . c o  m*/
    Transaction tx = null;
    LnCliente lnCliente = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName("acessocontrol");
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnCliente.findByCliStDocumento");
        query.setString("cliStDocumento", documento);

        List l = query.list();
        tx.commit();

        if (l != null && !l.isEmpty()) {
            lnCliente = (LnCliente) l.get(0);
        }
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    return lnCliente;
}

From source file:br.com.ln.dao.HistoricoDao.java

public static boolean grabVerificaHistorico(String usuStCodigo) {

    Session session = null;/*from   w  w  w  .j  a  v a  2 s  .c o m*/
    Transaction tx;
    List<LnHistorico> listHis;
    boolean retorno = false;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnHistorico.findByUsuStCodigo");
        query.setString("usuStCodigo", usuStCodigo);

        listHis = query.list();
        tx.commit();

        if (listHis != null) {
            retorno = listHis.isEmpty();
        } else {
            retorno = false;
        }
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    return retorno;
}

From source file:br.com.ln.dao.PerfilDao.java

/**
 * Descricao do Perfil/* ww  w  . j a v a 2  s . c o m*/
 * @param clazz
 * @param strDbName
 * @return List Object
 */
public static LnPerfil grabPerfilperStDesc(String perStDescricao) {

    Session session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
    Transaction tx = session.beginTransaction();
    LnPerfil lnPerfil = null;

    try {
        Query query = session.getNamedQuery("LnPerfil.findByPerStDescricao");
        query.setString("perStDescricao", perStDescricao);

        List l = query.list();

        if (l != null && !l.isEmpty()) {
            lnPerfil = (LnPerfil) l.get(0);
        }

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnPerfil;
}

From source file:br.com.ln.dao.UsuarioDao.java

/**
 * grabUsuario Get list user for code active.
 * @param usuStCodigo//w  w w . j a v  a 2  s  .c o  m
 * @param usuChAtivo
 * @return 
 */

public static LnUsuario grabUsuario(String usuStCodigo, Character usuChAtivo) {

    Session session = null;
    Transaction tx;
    LnUsuario lnUsuario = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnUsuario.findAllUsuStCodigoUsuChAtivo");
        query.setString("usuStCodigo", usuStCodigo);
        query.setCharacter("usuChAtivo", usuChAtivo);

        List l = query.list();
        tx.commit();

        if (l != null && l.size() > 0) {
            lnUsuario = (LnUsuario) l.get(0);
        } else {
            lnUsuario = null;
        }
    } catch (HibernateException ex) {
        logger.error("Hibernate Exception : " + ex.getMessage());
    } finally {

        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnUsuario;
}

From source file:br.com.ln.dao.UsuarioDao.java

/**
 * grabUsuario Get list user for code.// w  ww.ja  v a2s.c  o  m
 * @param usuStCodigo
 * @return 
 */
public static LnUsuario grabUsuario(String usuStCodigo) {

    Session session = null;
    Transaction tx;
    LnUsuario lnUsuario = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnUsuario.findByUsuStCodigo");
        query.setString("usuStCodigo", usuStCodigo);

        List l = query.list();
        tx.commit();

        if (l != null && l.size() > 0) {
            lnUsuario = (LnUsuario) l.get(0);
        } else {
            lnUsuario = null;
        }
    } catch (HibernateException ex) {
        logger.error("Hibernate Exception : " + ex.getMessage());
    } finally {

        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnUsuario;
}

From source file:br.com.ln.dao.UsuarioDao.java

/**
 * grabListUsuario Get user for document.
 * @param documento//ww  w.jav  a  2s. c o m
 * @return 
 */
public static LnUsuario grabUsuarioDocumento(String documento) {

    Session session = null;
    Transaction tx;
    LnUsuario lnUsuario = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnUsuario.findByUsuStCpf");
        query.setString("usuStCpf", documento);
        List l = query.list();
        tx.commit();

        if (l != null && !l.isEmpty()) {
            lnUsuario = (LnUsuario) l.get(0);
        }

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnUsuario;
}

From source file:br.com.ln.hibernate.Postgress.java

/**
 * Pesquisa de usuario e senha para validacao.
 * @param usuStCodigo//w w  w  .  j  a  va2  s .co m
 * @param strDbName
 * @return 
 */

public static LnUsuario grabUsuario(String usuStCodigo, Character usuChAtivo) {

    Session session = null;
    Transaction tx;
    LnUsuario lnUsuario = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnUsuario.findAllUsuStCodigoUsuChAtivo");
        query.setString("usuStCodigo", usuStCodigo);
        query.setCharacter("usuChAtivo", usuChAtivo);

        List l = query.list();
        tx.commit();

        if (l != null && l.size() > 0) {
            lnUsuario = (LnUsuario) l.get(0);
        } else {
            lnUsuario = null;
        }
    } catch (HibernateException ex) {
        System.out.println("Hibernate Exception : " + ex.getMessage());
    } finally {

        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnUsuario;
}

From source file:br.com.ln.hibernate.Postgress.java

public static LnUsuario grabUsuario(String usuStCodigo) {

    Session session = null;/*from   w w  w .  j  av a 2 s  .c  om*/
    Transaction tx;
    LnUsuario lnUsuario = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.getNamedQuery("LnUsuario.findByUsuStCodigo");
        query.setString("usuStCodigo", usuStCodigo);

        List l = query.list();
        tx.commit();

        if (l != null && l.size() > 0) {
            lnUsuario = (LnUsuario) l.get(0);
        } else {
            lnUsuario = null;
        }
    } catch (HibernateException ex) {
        System.out.println("Hibernate Exception : " + ex.getMessage());
    } finally {

        if (session != null && session.isOpen()) {
            session.close();
        }
    }
    return lnUsuario;
}