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:com.fpmislata.banco.persistence.dao.impl.hibernate.CuentaBancariaDAOImplHibernate.java

@Override
public CuentaBancaria findByNumeroCuenta(String numeroCuenta) {
    Session session = sessionFactory.getCurrentSession();

    Query query = session.createQuery("SELECT cb FROM CuentaBancaria cb WHERE cb.numeroCuenta = :numeroCuenta");
    query.setString("numeroCuenta", numeroCuenta);

    CuentaBancaria cuentaBancaria = (CuentaBancaria) query.uniqueResult();

    return cuentaBancaria;
}

From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java

License:Apache License

public long getLastModified(JbpmContext jbpmContext, String filename) {
    Session session = jbpmContext.getSession();
    long lastModified = -1;
    String name = filename;//from  ww w. j av  a  2 s.co  m
    if (name.indexOf("WEB-INF") != -1) {
        name = name.substring(name.lastIndexOf("WEB-INF"));
    }
    Query query = session
            .createQuery(" select a from com.glaf.jbpm.model.ConfigFile as a where a.filename = ? ");
    query.setString(0, name);
    List<?> list = query.list();
    if (list != null && list.size() > 0) {
        ConfigFile model = (ConfigFile) list.get(0);
        lastModified = model.getLastModified();
    }
    return lastModified;
}

From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java

License:Apache License

public void saveConfigFile(JbpmContext jbpmContext, ConfigFile file) {
    Session session = jbpmContext.getSession();
    String name = file.getFilename();
    if (name.indexOf("WEB-INF") != -1) {
        name = name.substring(name.lastIndexOf("WEB-INF"));
    }//  ww  w. j ava 2 s.  c  om
    Query query = session
            .createQuery(" select a from com.glaf.jbpm.model.ConfigFile as a where a.filename = ? ");
    query.setString(0, name);
    List<Object> list = query.list();
    if (list != null && list.size() > 0) {
        ConfigFile model = (ConfigFile) list.get(0);
        model.setLastModified(file.getLastModified());
        session.update(model);
    } else {
        file.setFilename(name);
        session.save(file);
    }

}

From source file:com.globalsight.config.UserParameterPersistenceManagerLocal.java

License:Apache License

/**
 * Retrieve a specific user parameter object with passed parameter name (as
 * editable object)./*from  w w w.  jav a  2 s . c  om*/
 * 
 * @param p_name
 *            user parameter to retreive
 * @throws RemoteException
 *             Application Server Error
 * @throws UserParameterEntityException
 *             Error retrieving a specific user parameter.
 * @return User parameter object with matching name
 */
public UserParameter getUserParameter(String p_userId, String p_name)
        throws RemoteException, UserParameterEntityException {
    String hql = "from UserParameterImpl u where u.userId = :USER_ID " + " and u.name = :NAME ";

    Session session = HibernateUtil.getSession();

    Query query = session.createQuery(hql);
    query.setString("USER_ID", p_userId);
    query.setString("NAME", p_name);

    try {
        List result = query.list();

        if (result == null || result.size() == 0) {
            return null;
        }

        return (UserParameter) result.get(0);
    } catch (Exception e) {
        throw new UserParameterEntityException(e);
    } finally {
        // session.close();
    }
}

From source file:com.globalsight.config.UserParameterPersistenceManagerLocal.java

License:Apache License

/**
 * Return all user parameter objects from data store for a specific user (as
 * read-write objects)./* ww w.j av a 2  s.c o  m*/
 * 
 * @throws RemoteException
 *             Application Server Error
 * @throws UserParameterEntityException
 *             Error getting collection of user parameters from data store.
 * @return Collection of all user parameters
 */
public Collection getUserParameters(String p_userId) throws RemoteException, UserParameterEntityException {
    String hql = "from UserParameterImpl u where u.userId = :USER_ID";

    Session session = HibernateUtil.getSession();

    Query query = session.createQuery(hql);
    query.setString("USER_ID", p_userId);

    try {
        List result = query.list();

        // Some parameters may be missing, auto-create them.
        if (createUserParameters(p_userId, result, session)) {
            // reload from database
            result = query.list();
        }

        return result;
    } catch (PersistenceException ex) {
        throw new UserParameterEntityException(ex);
    } finally {
        // session.close();
    }
}

From source file:com.globalsight.everest.costing.CostingEngineLocal.java

License:Apache License

private float getCurrencyFactorByName(String targetName, String companyId) {

    StringBuilder sb = new StringBuilder();
    sb.append("select new Currency(c.conversionFactor) ");
    sb.append("from Currency c ");
    sb.append("where c.isoCurrency.name like :targetName ");
    sb.append("and c.companyId = :companyId");

    Session session = HibernateUtil.getSession();
    Transaction transaction = session.beginTransaction();
    Query query = session.createQuery(sb.toString());
    query.setString("targetName", targetName + "%");
    query.setString("companyId", companyId);
    query.setMaxResults(1);//  w ww  .j  a v a  2  s  .  c o  m
    Currency currency = (Currency) query.uniqueResult();
    transaction.commit();
    return currency.getConversionFactor();

}

From source file:com.globalsight.everest.costing.CostingEngineLocal.java

License:Apache License

public Currency getCurrencyByName(String targetName, String companyId)
        throws RemoteException, CostingException, GeneralException {
    StringBuilder sb = new StringBuilder();

    sb.append("from Currency c ");
    sb.append("where c.isoCurrency.name like :targetName ");
    sb.append("and c.companyId = :companyId");

    Session session = HibernateUtil.getSession();
    Transaction transaction = session.beginTransaction();
    Query query = session.createQuery(sb.toString());
    query.setString("targetName", targetName + "%");
    query.setString("companyId", companyId);
    query.setMaxResults(1);/* w ww .java2  s  .  com*/
    Currency currency = (Currency) query.uniqueResult();
    transaction.commit();
    return currency;
}

From source file:com.google.code.mymon3y.persistencia.dao.hibernate.CategoriaDAOHibernate.java

License:Open Source License

/**
 * @see com.google.code.mymon3y.persistencia.dao.CategoriaDAO#findByNomeELoginDoUsuario(java.lang.String,
 *      java.lang.String)/*from  ww w  .  j a  v a  2s  .c  o m*/
 */
public Categoria findByNomeELoginDoUsuario(final String nome, final String login)
        throws PersistenciaMyMon3yException {
    Categoria result = null;

    result = (Categoria) executarOperacao(new Comando() {

        public Object executar() {

            Query q = getSession().getNamedQuery("categoria.nomeCategoriaLoginDoUsuario");
            q.setString("nome", nome);
            q.setString("loginDoUsuario", login);

            return q.list().size() > 0 ? q.list().get(0) : null;
        }

    });
    fazerAntesDoLoadSessaoFechada(result);
    return result;
}

From source file:com.google.code.mymon3y.persistencia.dao.hibernate.CategoriaDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
/* (non-Javadoc)/*from w w  w. ja  v  a 2 s. co  m*/
 * @see com.google.code.mymon3y.persistencia.dao.CategoriaDAO#findsByNomeELoginDoUsuario(java.lang.String, java.lang.String)
 */
@Override
public List<Categoria> findsByNomeELoginDoUsuario(final String nome, final String login)
        throws PersistenciaMyMon3yException {
    List<Categoria> result = null;

    result = (List<Categoria>) executarOperacao(new Comando() {

        public Object executar() {

            Query q = getSession().getNamedQuery("categorias.nomeCategoriaLoginDoUsuario");
            q.setString("nome", "%" + nome + "%");
            q.setString("loginDoUsuario", login);

            return q.list();
        }

    });

    return result;
}

From source file:com.google.code.mymon3y.persistencia.dao.hibernate.TransacaoDAOHibernate.java

License:Open Source License

/**
 * @see com.google.code.mymon3y.persistencia.dao.TransacaoDAO#getTransacoes(java.lang.String, java.util.Date,
 *      java.util.Date)// www  . j a v  a 2 s . co  m
 */
@SuppressWarnings("unchecked")
public List<Transacao> getTransacoes(final String login, final Date inicio, final Date fim)
        throws PersistenciaMyMon3yException {
    List<Transacao> result = null;

    result = (List<Transacao>) executarOperacao(new Comando() {

        public Object executar() {

            Query q = getSession().getNamedQuery("transacao.transacoes");
            q.setString("loginDoUsuario", login);
            q.setDate("dataInicio", inicio);
            q.setDate("dataFim", fim);
            return q.list();
        }

    });
    return result;
}