Example usage for org.hibernate Query setBoolean

List of usage examples for org.hibernate Query setBoolean

Introduction

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

Prototype

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

Source Link

Document

Bind a named boolean-valued parameter.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.RigProviderActivator.java

License:Open Source License

@Override
public void stop(final BundleContext context) throws Exception {
    this.logger.info("Stopping " + context.getBundle().getSymbolicName() + " bundle.");
    this.serverReg.unregister();

    /* Clean up identity tokens. */
    this.idenTokReg.unregister();
    IdentityTokenRegister.getInstance().expunge();

    this.runnableReg.unregister();

    /* Take all rigs offline. */
    Session ses = DataAccessActivator.getNewSession();
    if (ses != null) {
        Query qu = ses.createQuery("UPDATE Rig SET active=:false, in_session=:false, online=:false, "
                + "session_id=:null, offline_reason=:offline");
        qu.setBoolean("false", false);
        qu.setParameter("null", null, Hibernate.BIG_INTEGER);
        qu.setString("offline", "Scheduling Server shutting down.");

        ses.beginTransaction();//  w w w . j a va  2s  .  co  m
        int num = qu.executeUpdate();
        ses.getTransaction().commit();
        this.logger.info("Took " + num + " rigs offline for shutdown.");
        ses.close();
    }

    /* Cleanup the configuration service tracker. */
    RigProviderActivator.configTracker.close();
    RigProviderActivator.configTracker = null;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.session.SessionActivator.java

License:Open Source License

@Override
public void stop(BundleContext context) throws Exception {
    this.logger.info("Stopping the Session bundle...");
    this.soapReg.unregister();
    this.terminatorService.unregister();
    this.sessionCheckerReg.unregister();
    SessionActivator.bookingsTracker.close();

    /* Terminate all in progress sessions. */
    Session ses = DataAccessActivator.getNewSession();
    if (ses != null) {
        Query qu = ses
                .createQuery("UPDATE Session SET active=:false, removal_reason=:reason, removal_time=:time "
                        + " WHERE active=:true");
        qu.setBoolean("false", false);
        qu.setBoolean("true", true);
        qu.setString("reason", "Scheduling Server shutting down.");
        qu.setTimestamp("time", new Date());

        ses.beginTransaction();/*w  ww.j  a va2s . c o m*/
        int num = qu.executeUpdate();
        ses.getTransaction().commit();
        this.logger.info("Terminated " + num + " sessions for shutdown.");
        ses.close();
    }
}

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

License:Open Source License

public List queryList(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  . j a  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.list();
}

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

License:Open Source License

public void queryNoResult(String namedQuery, Map<String, Object> params) {
    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  ww  .j  a  v  a  2s  .  c  om*/
        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));
        }
    }
    query.executeUpdate();
    HibernateUtility.getSession().flush();
    HibernateUtility.getSession().clear();
}

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 www  .  ja  v  a 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.hslife.orcamento.repository.CartaoCreditoRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<CartaoCredito> findDescricaoOrTipoCartaoOrAtivoByUsuario(String descricao, TipoCartao tipo,
        Usuario usuario, Boolean ativo) {
    StringBuilder hql = new StringBuilder();
    hql.append("FROM CartaoCredito cartao WHERE ");
    if (descricao != null) {
        hql.append("cartao.descricao LIKE '%");
        hql.append(descricao);/*from   w w w .  jav  a  2 s .com*/
        hql.append("%' AND ");
    }
    if (tipo != null) {
        hql.append("cartao.tipoCartao = :tipo AND ");
    }
    if (ativo != null) {
        hql.append("cartao.ativo = :ativo AND ");
    }

    hql.append("cartao.usuario.id = :idUsuario ORDER BY cartao.descricao ASC");

    Query hqlQuery = getQuery(hql.toString());

    if (tipo != null) {
        hqlQuery.setParameter("tipo", tipo);
    }

    if (ativo != null) {
        hqlQuery.setBoolean("ativo", ativo);
    }

    hqlQuery.setLong("idUsuario", usuario.getId());

    return hqlQuery.list();
}

From source file:br.com.hslife.orcamento.repository.ContaRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Conta> findDescricaoOrTipoContaOrAtivoByUsuario(String descricao, TipoConta[] tipoConta,
        Usuario usuario, Boolean ativo) {
    StringBuilder hql = new StringBuilder();
    hql.append("FROM Conta conta WHERE ");
    if (descricao != null) {
        hql.append("conta.descricao LIKE '%");
        hql.append(descricao);/* ww  w .  ja  v  a  2  s.c  o m*/
        hql.append("%' AND ");
    }
    if (tipoConta != null && tipoConta.length != 0) {
        hql.append("conta.tipoConta IN (:tipo) AND ");
    }
    if (ativo != null) {
        hql.append("conta.ativo = :ativo AND ");
    }

    hql.append("conta.usuario.id = :idUsuario ORDER BY conta.descricao ASC");

    Query hqlQuery = getQuery(hql.toString());

    if (tipoConta != null && tipoConta.length != 0) {
        hqlQuery.setParameterList("tipo", tipoConta);
    }
    if (ativo != null) {
        hqlQuery.setBoolean("ativo", ativo);
    }

    hqlQuery.setLong("idUsuario", usuario.getId());

    return hqlQuery.list();
}

From source file:br.com.hslife.orcamento.repository.ItemDespensaRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ItemDespensa> findByDespensaUsuarioAndArquivado(Despensa despensa, Usuario usuario,
        boolean arquivado) {
    String hql = "select item from ItemDespensa as item inner join item.despensa as des where des.id = :idDespensa and des.usuario.id = :idUsuario and item.arquivado = :arquivado order by item.descricao asc";
    Query query = getSession().createQuery(hql);
    query.setLong("idDespensa", despensa.getId());
    query.setLong("idUsuario", usuario.getId());
    query.setBoolean("arquivado", arquivado);
    return query.list();
}

From source file:br.com.hslife.orcamento.repository.ItemDespensaRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ItemDespensa> findByUsuarioAndArquivado(Usuario usuario, boolean arquivado) {
    String hql = "select item from ItemDespensa as item inner join item.despensa as des where des.usuario.id = :idUsuario and item.arquivado = :arquivado order by item.descricao asc";
    Query query = getSession().createQuery(hql);
    query.setLong("idUsuario", usuario.getId());
    query.setBoolean("arquivado", arquivado);
    return query.list();
}

From source file:br.com.hslife.orcamento.repository.ItemDespensaRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ItemDespensa> findAllPerecivelByUsuario(Usuario usuario) {
    String hql = "select item from ItemDespensa as item inner join item.despensa as des where des.usuario.id = :idUsuario and item.perecivel = :perecivel and item.arquivado = :arquivado order by item.descricao asc";
    Query query = getSession().createQuery(hql);
    query.setLong("idUsuario", usuario.getId());
    query.setBoolean("perecivel", true);
    query.setBoolean("arquivado", false);
    return query.list();
}